Linux NFS development
 help / color / mirror / Atom feed
* [PATCH v4 0/4] pNFS/flexfiles: I/O without a layout under FF_FLAGS_NO_IO_THRU_MDS
@ 2026-12-03 16:54 Benjamin Coddington
  2026-12-03 16:54 ` [PATCH v4 1/4] pNFS/flexfiles: pace writes that have no layout and can't use the MDS Benjamin Coddington
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Benjamin Coddington @ 2026-12-03 16:54 UTC (permalink / raw)
  To: Trond Myklebust, Anna Schumaker, Mike Snitzer
  Cc: Olga Kornievskaia, linux-nfs

From: Benjamin Coddington <bcodding@hammerspace.com>

When a file's flexfiles layouts carry FF_FLAGS_NO_IO_THRU_MDS, the client
keeps reads and writes off the MDS when it has no layout segment for
them.  Reads and writes handle that differently:

 - Reads test the inode's NFS_INO_NO_IO_THRU_MDS bit, wait a second
   between attempts, and honour io_maxretrans on soft mounts.

 - Writes test a bit on the layout header and return -EAGAIN.
   nfs_writepages() resends at once, so a writer spins for as long as
   there is no layout.  Once the header is freed the bit is gone and
   writes go through the MDS, and ff_layout_pg_init_write() sends them
   there whenever pnfs_generic_pg_check_layout() drops an invalidated
   segment.

Neither direction uses the MDS when the server has said there is no
layout to give.  After NFS4ERR_LAYOUTUNAVAILABLE, RFC 8435 says the I/O
is to go to the MDS (section 5.1.1).  Today reads wait and writes spin
until the 120 second fail bit expires, then send a LAYOUTGET that can
fail the same way.

Patch 1 has writes test the inode bit in both places, and paces
nfs_writepages(): the first resend after -EAGAIN is immediate, then
data-integrity writeback waits a second before each resend and other
writeback leaves the folios dirty.  Patch 2 removes the header bit,
which nothing tests after patch 1.  Patch 3 sends reads, writes and the
resend after a data server error through the MDS while the fail bit for
their iomode is set.  Patch 4 fixes two older MDS-fallback tracepoints
that read the layout header without i_lock, as patch 1 does for the one
it moves.

Patch 3 is how the server sends I/O to the MDS, as Trond described in
the v3 review: the client reports a data server it can't use with
LAYOUTERROR or LAYOUTRETURN, and the server decides whether to answer
the next LAYOUTGET with NFS4ERR_LAYOUTUNAVAILABLE.  The client sends no
other I/O for these files through the MDS.

This is the rest of the v3 series, on top of "pNFS: layout recalls and
writes that have to be resent":
https://lore.kernel.org/linux-nfs/cover.1796306148.git.bcodding@hammerspace.com/
That series has what v3's 1/5 and 2/5 were for.  Its patch 10 has
nfs_wb_folio() wait and resend a refused folio, its patch 5 is v3's 2/5,
and its patch 6 paces the O_DIRECT resend.

Tested on a KASAN kernel against a reffs MDS that hands out six-way
mirrored flexfiles layouts with FF_FLAGS_NO_IO_THRU_MDS, with knfsd as
the NFSv3 data server, injecting LAYOUTGET errors after a file recall:

 - With NFS4ERR_LAYOUTUNAVAILABLE, reads and writes go through the MDS
   at once, and the data written through the MDS is on every mirror.
   That includes writeback stopped after queueing its first folio, with
   a test-only delay, when the recall and the error arrive: the queued
   folio and the rest go through the MDS.

 - With a retryable error (NFS4ERR_SERVERFAULT) held for 6 to 8
   seconds, fsync retries once a second with no I/O to the MDS.  On
   the base it resends without a pause, or writes through the MDS once
   the layout header is gone.  SIGKILL ends a writer blocked in fsync,
   sync_file_range(SYNC_FILE_RANGE_WRITE) returns 0, and a soft mount
   with io_maxretrans=3 returns EIO after about 2 seconds.  A read of a
   folio that another open context had dirtied waits for the layout,
   flushes the folio to the data servers and returns the data.

 - The recall tests from the series this is based on still pass:
   buffered and O_DIRECT I/O under FSID, ALL and FILE recalls with
   every mirror checked, the O_DIRECT write from an mmap of the same
   file, writeback stopped between folios, and uncommitted UNSTABLE
   data.

Not tested: layouts with a single mirror.

The base is that series on Trond's testing branch at 3e1999173432.

Changes since v3:
https://lore.kernel.org/linux-nfs/cover.1795122899.git.bcodding@hammerspace.com/
 - 1/5 (writeback of a locked folio through the MDS) is dropped, and
   pg_allow_mds with it.
 - 2/5 is patch 5 of the base series.
 - Patch 1 (was 3/5): the O_DIRECT changes are gone, since the base
   series paces that resend.  nfs_writepages() waits after any second
   -EAGAIN, so the pg_nolayout descriptor bit is gone too, and the
   first resend is immediate.
 - Patches 2 and 3 (were 4/5 and 5/5): unchanged apart from a comment
   that mentioned pg_allow_mds.
 - New patch 4 (local sashiko review).

Benjamin Coddington (4):
  pNFS/flexfiles: pace writes that have no layout and can't use the MDS
  pNFS/flexfiles: remove the layout-header NO_IO_THRU_MDS bit
  pNFS/flexfiles: use the MDS when the server has no layout to give
  pNFS/flexfiles: emit the pg_init MDS-fallback tracepoints under i_lock

 fs/nfs/flexfilelayout/flexfilelayout.c | 156 ++++++++++++++++---------
 fs/nfs/flexfilelayout/flexfilelayout.h |  16 ---
 fs/nfs/internal.h                      |  10 +-
 fs/nfs/nfs4trace.c                     |   1 +
 fs/nfs/nfs4trace.h                     |   1 +
 fs/nfs/pnfs.c                          |  22 ++++
 fs/nfs/pnfs.h                          |   1 +
 fs/nfs/write.c                         |  13 +++
 8 files changed, 144 insertions(+), 76 deletions(-)


base-commit: 3e19991734326332c736e24c9b47b2cffb8f9e42
prerequisite-patch-id: 1bf389e0665f28a4f66068858631884b3ff270aa
prerequisite-patch-id: 674a8beed30311c64efccf670996a549edf25c9e
prerequisite-patch-id: 02c555c4e0f0ca007f265128080e777217679463
prerequisite-patch-id: b6845ef891faa85557c023fdae602004e258e122
prerequisite-patch-id: a1dfade3905aa336e6d6a296a3e056e105041072
prerequisite-patch-id: 30b5addaf02ea29abd0a5e446c35c8b71926ef81
prerequisite-patch-id: 3d02a5ce811d297818b0cb44a4ff616feaf4be0b
prerequisite-patch-id: 4e11b1d4d8fa707791d03518391ec18d2b479f34
prerequisite-patch-id: dbeb9d6825f0bd79715266abd14f8da66bf085f5
prerequisite-patch-id: 5f6e4082c18157d4d185fb973c7faacb91badd2f
prerequisite-patch-id: 64d6171847787b2db7444a73ae5a686afe8afb0c
-- 
2.53.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v4 1/4] pNFS/flexfiles: pace writes that have no layout and can't use the MDS
  2026-12-03 16:54 [PATCH v4 0/4] pNFS/flexfiles: I/O without a layout under FF_FLAGS_NO_IO_THRU_MDS Benjamin Coddington
@ 2026-12-03 16:54 ` Benjamin Coddington
  2026-12-03 16:54 ` [PATCH v4 2/4] pNFS/flexfiles: remove the layout-header NO_IO_THRU_MDS bit Benjamin Coddington
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Benjamin Coddington @ 2026-12-03 16:54 UTC (permalink / raw)
  To: Trond Myklebust, Anna Schumaker, Mike Snitzer
  Cc: Olga Kornievskaia, linux-nfs

From: Benjamin Coddington <bcodding@hammerspace.com>

When a write has no layout segment and its file's layouts carry
FF_FLAGS_NO_IO_THRU_MDS, ff_layout_pg_get_mirror_count_write() returns
-EAGAIN.  nfs_writepages() resends it at once, so a writer spins for as
long as pnfs_update_layout() has no layout to give: while
NFS_LAYOUT_BULK_RECALL is set, while LAYOUTGETs are blocked or failing,
and for the 120 seconds after NFS4ERR_LAYOUTUNAVAILABLE.

The check also tests a bit on the layout header.  Once that header has
been freed, a new one starts without the bit and the write goes through
the MDS.  ff_layout_pg_init_write() has no check at all: when
pnfs_generic_pg_check_layout() drops an invalidated segment, the rest of
the descriptor's writes go through the MDS.

Handle both places the way ff_layout_pg_init_read() handles reads: test
the inode's NFS_INO_NO_IO_THRU_MDS bit, return -ERESTARTSYS when the
task sending the write is killed or exiting, and on soft mounts give up
once the next pass would exceed io_maxretrans.

In nfs_writepages() the first resend after -EAGAIN is still immediate.
From the second one on, data-integrity writeback waits a second before
it resends, after the pass has unlocked its folios and requests, and a
fatal signal ends the wait.  Other writeback stops there and leaves the
folios dirty for a later pass.  nfs_wb_folio() and the O_DIRECT resend
already wait the same way.

The test is ff_layout_inode_no_fallback_to_mds(), which
ff_layout_pg_init_read() now uses too, and the refusal is
ff_layout_pg_refuse_write().  Emit the MDS-fallback tracepoint only when
the write does go through the MDS, and a new
pnfs_mds_fallback_write_refused tracepoint when it is refused.  No lseg
pins the layout header that either tracepoint reads, so emit them under
i_lock.

Fixes: 1d62e659c0bf ("NFSv4/flexfiles: honor FF_FLAGS_NO_IO_THRU_MDS in pg_get_mirror_count_write")
Signed-off-by: Benjamin Coddington <bcodding@hammerspace.com>
---
 fs/nfs/flexfilelayout/flexfilelayout.c | 88 ++++++++++++++++++--------
 fs/nfs/nfs4trace.c                     |  1 +
 fs/nfs/nfs4trace.h                     |  1 +
 fs/nfs/write.c                         | 13 ++++
 4 files changed, 77 insertions(+), 26 deletions(-)

diff --git a/fs/nfs/flexfilelayout/flexfilelayout.c b/fs/nfs/flexfilelayout/flexfilelayout.c
index 0c5004ec1c3b..2360fa787bfd 100644
--- a/fs/nfs/flexfilelayout/flexfilelayout.c
+++ b/fs/nfs/flexfilelayout/flexfilelayout.c
@@ -999,6 +999,49 @@ static bool ff_layout_pg_retry_wait(struct nfs_pageio_descriptor *pgio)
 	return true;
 }
 
+/*
+ * Returns true if the inode's layouts forbid I/O through the MDS.
+ */
+static bool ff_layout_inode_no_fallback_to_mds(struct inode *inode, u32 iomode)
+{
+	return nfs_no_io_thru_mds(inode);
+}
+
+/*
+ * Refuse a write that has no layout segment and can't go through the MDS:
+ * -EAGAIN so that the caller resends it, or a hard error when the caller
+ * should give up.
+ */
+static void ff_layout_pg_refuse_write(struct nfs_pageio_descriptor *pgio,
+				      struct nfs_page *req)
+{
+	struct inode *inode = pgio->pg_inode;
+	struct nfs_server *server = NFS_SERVER(inode);
+
+	/* No lseg pins the layout hdr, and it is detached under i_lock */
+	if (trace_pnfs_mds_fallback_write_refused_enabled()) {
+		spin_lock(&inode->i_lock);
+		trace_pnfs_mds_fallback_write_refused(inode, req_offset(req),
+						      req->wb_bytes, IOMODE_RW,
+						      NFS_I(inode)->layout,
+						      NULL);
+		spin_unlock(&inode->i_lock);
+	}
+	if (server->flags & (NFS_MOUNT_SOFT | NFS_MOUNT_SOFTERR) &&
+	    io_maxretrans && req->wb_nio >= io_maxretrans) {
+		if (server->flags & NFS_MOUNT_SOFTERR)
+			pgio->pg_error = -ETIMEDOUT;
+		else
+			pgio->pg_error = -EIO;
+		return;
+	}
+	if (fatal_signal_pending(current) || nfs_current_task_exiting()) {
+		pgio->pg_error = -ERESTARTSYS;
+		return;
+	}
+	pgio->pg_error = -EAGAIN;
+}
+
 static void
 ff_layout_pg_get_read(struct nfs_pageio_descriptor *pgio,
 		      struct nfs_page *req,
@@ -1120,7 +1163,7 @@ ff_layout_pg_init_read(struct nfs_pageio_descriptor *pgio,
 	 * FF_FLAGS_NO_IO_THRU_MDS may itself be gone by now, which is why
 	 * this asks the inode and not the hdr.
 	 */
-	if (!nfs_no_io_thru_mds(pgio->pg_inode))
+	if (!ff_layout_inode_no_fallback_to_mds(pgio->pg_inode, IOMODE_READ))
 		goto out_mds;
 retry_nolseg:
 	/* Retry getting layout segment if lower layer returned -EAGAIN */
@@ -1178,9 +1221,13 @@ ff_layout_pg_init_write(struct nfs_pageio_descriptor *pgio,
 					    IOMODE_RW, false))
 			return;
 	}
-	/* If no lseg, fall back to write through mds */
-	if (pgio->pg_lseg == NULL)
-		goto out_mds;
+	if (!pgio->pg_lseg) {
+		if (!ff_layout_inode_no_fallback_to_mds(pgio->pg_inode,
+							IOMODE_RW))
+			goto out_mds;
+		ff_layout_pg_refuse_write(pgio, req);
+		return;
+	}
 
 	/* Use a direct mapping of ds_idx to pgio mirror_idx */
 	if (pgio->pg_mirror_count != FF_LAYOUT_MIRROR_COUNT(pgio->pg_lseg))
@@ -1235,10 +1282,6 @@ static unsigned int
 ff_layout_pg_get_mirror_count_write(struct nfs_pageio_descriptor *pgio,
 				    struct nfs_page *req)
 {
-	struct inode *inode = pgio->pg_inode;
-	struct pnfs_layout_hdr *lo;
-	bool no_fallback;
-
 	if (!pgio->pg_lseg) {
 		if (pnfs_pgio_update_layout(pgio, req, req->wb_bytes,
 					    IOMODE_RW, false))
@@ -1246,26 +1289,19 @@ ff_layout_pg_get_mirror_count_write(struct nfs_pageio_descriptor *pgio,
 	}
 	if (pgio->pg_lseg)
 		return FF_LAYOUT_MIRROR_COUNT(pgio->pg_lseg);
-
-	trace_pnfs_mds_fallback_pg_get_mirror_count(pgio->pg_inode,
-			0, NFS4_MAX_UINT64, IOMODE_RW,
-			NFS_I(pgio->pg_inode)->layout,
-			pgio->pg_lseg);
-
-	/* No lseg pins the layout hdr, and it is detached under i_lock */
-	spin_lock(&inode->i_lock);
-	lo = NFS_I(inode)->layout;
-	no_fallback = lo && ff_layout_hdr_no_fallback_to_mds(lo);
-	spin_unlock(&inode->i_lock);
-	if (no_fallback) {
-		/*
-		 * FF_FLAGS_NO_IO_THRU_MDS: no current lseg but the server's
-		 * policy forbids MDS fallback.  Surface -EAGAIN so writeback
-		 * retries rather than silently issuing the WRITE via MDS.
-		 */
-		pgio->pg_error = -EAGAIN;
+	if (ff_layout_inode_no_fallback_to_mds(pgio->pg_inode, IOMODE_RW)) {
+		ff_layout_pg_refuse_write(pgio, req);
 		goto out;
 	}
+
+	if (trace_pnfs_mds_fallback_pg_get_mirror_count_enabled()) {
+		spin_lock(&pgio->pg_inode->i_lock);
+		trace_pnfs_mds_fallback_pg_get_mirror_count(pgio->pg_inode,
+				0, NFS4_MAX_UINT64, IOMODE_RW,
+				NFS_I(pgio->pg_inode)->layout,
+				pgio->pg_lseg);
+		spin_unlock(&pgio->pg_inode->i_lock);
+	}
 	/* no lseg means that pnfs is not in use, so no mirroring here */
 	nfs_pageio_reset_write_mds(pgio);
 out:
diff --git a/fs/nfs/nfs4trace.c b/fs/nfs/nfs4trace.c
index 3fdc013f56d8..93a84f546de8 100644
--- a/fs/nfs/nfs4trace.c
+++ b/fs/nfs/nfs4trace.c
@@ -25,6 +25,7 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(pnfs_mds_fallback_read_done);
 EXPORT_TRACEPOINT_SYMBOL_GPL(pnfs_mds_fallback_write_done);
 EXPORT_TRACEPOINT_SYMBOL_GPL(pnfs_mds_fallback_read_pagelist);
 EXPORT_TRACEPOINT_SYMBOL_GPL(pnfs_mds_fallback_write_pagelist);
+EXPORT_TRACEPOINT_SYMBOL_GPL(pnfs_mds_fallback_write_refused);
 EXPORT_TRACEPOINT_SYMBOL_GPL(pnfs_ds_connect);
 
 EXPORT_TRACEPOINT_SYMBOL_GPL(ff_layout_read_error);
diff --git a/fs/nfs/nfs4trace.h b/fs/nfs/nfs4trace.h
index de26df04da09..c756dab2df16 100644
--- a/fs/nfs/nfs4trace.h
+++ b/fs/nfs/nfs4trace.h
@@ -2160,6 +2160,7 @@ DEFINE_PNFS_LAYOUT_EVENT(pnfs_mds_fallback_read_done);
 DEFINE_PNFS_LAYOUT_EVENT(pnfs_mds_fallback_write_done);
 DEFINE_PNFS_LAYOUT_EVENT(pnfs_mds_fallback_read_pagelist);
 DEFINE_PNFS_LAYOUT_EVENT(pnfs_mds_fallback_write_pagelist);
+DEFINE_PNFS_LAYOUT_EVENT(pnfs_mds_fallback_write_refused);
 
 DECLARE_EVENT_CLASS(nfs4_deviceid_event,
 		TP_PROTO(
diff --git a/fs/nfs/write.c b/fs/nfs/write.c
index dd41e3bd88aa..b2de95c945c7 100644
--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -660,6 +660,7 @@ int nfs_writepages(struct address_space *mapping, struct writeback_control *wbc)
 	unsigned int mntflags = NFS_SERVER(inode)->flags;
 	struct nfs_server *nfss = NFS_SERVER(inode);
 	int priority = 0;
+	bool resent = false;
 	int err;
 
 	trace_nfs_writepages(inode, wbc->range_start, wbc->range_end - wbc->range_start);
@@ -697,6 +698,18 @@ int nfs_writepages(struct address_space *mapping, struct writeback_control *wbc)
 		nfs_pageio_complete(&pgio);
 		if (err == -EAGAIN && mntflags & NFS_MOUNT_SOFTERR)
 			break;
+		if (err == -EAGAIN && resent) {
+			if (wbc->sync_mode != WB_SYNC_ALL) {
+				err = 0;
+				break;
+			}
+			if (schedule_timeout_killable(HZ) &&
+			    fatal_signal_pending(current)) {
+				err = -ERESTARTSYS;
+				break;
+			}
+		}
+		resent = true;
 	} while (err < 0 && !nfs_error_is_fatal(err));
 	nfs_io_completion_put(ioc);
 
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v4 2/4] pNFS/flexfiles: remove the layout-header NO_IO_THRU_MDS bit
  2026-12-03 16:54 [PATCH v4 0/4] pNFS/flexfiles: I/O without a layout under FF_FLAGS_NO_IO_THRU_MDS Benjamin Coddington
  2026-12-03 16:54 ` [PATCH v4 1/4] pNFS/flexfiles: pace writes that have no layout and can't use the MDS Benjamin Coddington
@ 2026-12-03 16:54 ` Benjamin Coddington
  2026-12-03 16:54 ` [PATCH v4 3/4] pNFS/flexfiles: use the MDS when the server has no layout to give Benjamin Coddington
  2026-12-03 16:54 ` [PATCH v4 4/4] pNFS/flexfiles: emit the pg_init MDS-fallback tracepoints under i_lock Benjamin Coddington
  3 siblings, 0 replies; 5+ messages in thread
From: Benjamin Coddington @ 2026-12-03 16:54 UTC (permalink / raw)
  To: Trond Myklebust, Anna Schumaker, Mike Snitzer
  Cc: Olga Kornievskaia, linux-nfs

From: Benjamin Coddington <bcodding@hammerspace.com>

Nothing tests NFS4_FF_HDR_NO_IO_THRU_MDS since writes moved to the
inode's NFS_INO_NO_IO_THRU_MDS bit.  Remove it, its helper, and
nfs4_flexfile_layout::flags, which held only that bit.

Signed-off-by: Benjamin Coddington <bcodding@hammerspace.com>
---
 fs/nfs/flexfilelayout/flexfilelayout.c |  8 ++------
 fs/nfs/flexfilelayout/flexfilelayout.h | 16 ----------------
 fs/nfs/internal.h                      |  8 +++-----
 3 files changed, 5 insertions(+), 27 deletions(-)

diff --git a/fs/nfs/flexfilelayout/flexfilelayout.c b/fs/nfs/flexfilelayout/flexfilelayout.c
index 2360fa787bfd..2b9ca3cac73c 100644
--- a/fs/nfs/flexfilelayout/flexfilelayout.c
+++ b/fs/nfs/flexfilelayout/flexfilelayout.c
@@ -643,12 +643,8 @@ 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) {
-		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 */
+	if (fls->flags & FF_FLAGS_NO_IO_THRU_MDS)
 		nfs_set_no_io_thru_mds(lh->plh_inode);
-	}
 
 	p = xdr_inline_decode(&stream, 4);
 	if (!p)
@@ -1161,7 +1157,7 @@ ff_layout_pg_init_read(struct nfs_pageio_descriptor *pgio,
 	 * MDS there is no fallback to take, so wait for a layout on the
 	 * same terms as the -EAGAIN above.  The layout hdr that carried
 	 * FF_FLAGS_NO_IO_THRU_MDS may itself be gone by now, which is why
-	 * this asks the inode and not the hdr.
+	 * the flag is kept on the inode.
 	 */
 	if (!ff_layout_inode_no_fallback_to_mds(pgio->pg_inode, IOMODE_READ))
 		goto out_mds;
diff --git a/fs/nfs/flexfilelayout/flexfilelayout.h b/fs/nfs/flexfilelayout/flexfilelayout.h
index 6e3e2a1ac62b..a7520cf47bc4 100644
--- a/fs/nfs/flexfilelayout/flexfilelayout.h
+++ b/fs/nfs/flexfilelayout/flexfilelayout.h
@@ -120,16 +120,12 @@ struct nfs4_ff_layout_segment {
 	struct nfs4_ff_layout_mirror	*mirror_array[] __counted_by(mirror_array_cnt);
 };
 
-/* nfs4_flexfile_layout::flags bit indices */
-#define NFS4_FF_HDR_NO_IO_THRU_MDS  0   /* any lseg has had FF_FLAGS_NO_IO_THRU_MDS */
-
 struct nfs4_flexfile_layout {
 	struct pnfs_layout_hdr generic_hdr;
 	struct pnfs_ds_commit_info commit_info;
 	struct list_head	mirrors;
 	struct list_head	error_list; /* nfs4_ff_layout_ds_err */
 	atomic64_t		last_report_time; /* Layoutstat report times */
-	unsigned long		flags;
 };
 
 /*
@@ -193,18 +189,6 @@ ff_layout_no_fallback_to_mds(struct pnfs_layout_segment *lseg)
 	return FF_LAYOUT_LSEG(lseg)->flags & FF_FLAGS_NO_IO_THRU_MDS;
 }
 
-/*
- * Sticky hdr-level mirror of FF_FLAGS_NO_IO_THRU_MDS so callers that have
- * no current lseg (e.g. between LAYOUTRETURN and the next LAYOUTGET) can
- * still honor the no-MDS-fallback policy.
- */
-static inline bool
-ff_layout_hdr_no_fallback_to_mds(struct pnfs_layout_hdr *lo)
-{
-	return test_bit(NFS4_FF_HDR_NO_IO_THRU_MDS,
-			&FF_LAYOUT_FROM_HDR(lo)->flags);
-}
-
 static inline bool
 ff_layout_no_read_on_rw(struct pnfs_layout_segment *lseg)
 {
diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h
index 5a5c1b960546..208c83cc1d99 100644
--- a/fs/nfs/internal.h
+++ b/fs/nfs/internal.h
@@ -557,11 +557,9 @@ static inline bool nfs_file_io_is_buffered(struct nfs_inode *nfsi)
  * 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.
+ * layout forbids.  Flexfiles also retries reads and writes that have no
+ * layout segment instead of sending them through the MDS.  Servers are
+ * assumed to be consistent in their no-fallback policy per file.
  */
 #define NFS_INO_NO_IO_THRU_MDS	(30)
 
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v4 3/4] pNFS/flexfiles: use the MDS when the server has no layout to give
  2026-12-03 16:54 [PATCH v4 0/4] pNFS/flexfiles: I/O without a layout under FF_FLAGS_NO_IO_THRU_MDS Benjamin Coddington
  2026-12-03 16:54 ` [PATCH v4 1/4] pNFS/flexfiles: pace writes that have no layout and can't use the MDS Benjamin Coddington
  2026-12-03 16:54 ` [PATCH v4 2/4] pNFS/flexfiles: remove the layout-header NO_IO_THRU_MDS bit Benjamin Coddington
@ 2026-12-03 16:54 ` Benjamin Coddington
  2026-12-03 16:54 ` [PATCH v4 4/4] pNFS/flexfiles: emit the pg_init MDS-fallback tracepoints under i_lock Benjamin Coddington
  3 siblings, 0 replies; 5+ messages in thread
From: Benjamin Coddington @ 2026-12-03 16:54 UTC (permalink / raw)
  To: Trond Myklebust, Anna Schumaker, Mike Snitzer
  Cc: Olga Kornievskaia, linux-nfs

From: Benjamin Coddington <bcodding@hammerspace.com>

When LAYOUTGET fails with NFS4ERR_LAYOUTUNAVAILABLE, or with
NFS4ERR_TOOSMALL after the retry at the session's maximum reply size,
pnfs_update_layout() sets the layout's fail bit for that iomode and
returns no layout without sending another LAYOUTGET for the next 120
seconds.  If the file's layouts carried FF_FLAGS_NO_IO_THRU_MDS, reads
and writes wait for a layout the whole time, and then send a LAYOUTGET
that can fail the same way.  On a hard mount that repeats for as long
as the server keeps answering that way.

RFC 8435 says that after NFS4ERR_LAYOUTUNAVAILABLE "the I/O is to go to
the metadata server" (section 5.1.1), and that FF_FLAGS_NO_IO_THRU_MDS
is a hint (section 5.1.2).  Send the I/O through the MDS while the fail
bit is set, in ff_layout_inode_no_fallback_to_mds(), which reads,
writes and the resend after a data server error share.  This also lets
a server deal with a data server the client can't use: the client
reports the failure with LAYOUTERROR (or in LAYOUTRETURN) and returns
the layout, and the server can answer the next LAYOUTGET with
NFS4ERR_LAYOUTUNAVAILABLE.

Fixes: 2f007ba074ad ("pNFS/flexfiles: don't read through MDS when previous layout forbid it")
Fixes: 1d62e659c0bf ("NFSv4/flexfiles: honor FF_FLAGS_NO_IO_THRU_MDS in pg_get_mirror_count_write")
Fixes: ec906cf7bee6 ("pNFS/flexfiles: don't reset to MDS for v4 error when previous layout forbid it")
Signed-off-by: Benjamin Coddington <bcodding@hammerspace.com>
---
 fs/nfs/flexfilelayout/flexfilelayout.c | 40 +++++++++++++++-----------
 fs/nfs/internal.h                      |  6 ++--
 fs/nfs/pnfs.c                          | 22 ++++++++++++++
 fs/nfs/pnfs.h                          |  1 +
 4 files changed, 50 insertions(+), 19 deletions(-)

diff --git a/fs/nfs/flexfilelayout/flexfilelayout.c b/fs/nfs/flexfilelayout/flexfilelayout.c
index 2b9ca3cac73c..0402725a84a6 100644
--- a/fs/nfs/flexfilelayout/flexfilelayout.c
+++ b/fs/nfs/flexfilelayout/flexfilelayout.c
@@ -997,10 +997,14 @@ static bool ff_layout_pg_retry_wait(struct nfs_pageio_descriptor *pgio)
 
 /*
  * Returns true if the inode's layouts forbid I/O through the MDS.
+ * FF_FLAGS_NO_IO_THRU_MDS is a hint (RFC 8435, section 5.1.2), so set it
+ * aside while a failed LAYOUTGET for @iomode (NFS4ERR_LAYOUTUNAVAILABLE or
+ * NFS4ERR_TOOSMALL) keeps pnfs_update_layout() from sending another.
  */
 static bool ff_layout_inode_no_fallback_to_mds(struct inode *inode, u32 iomode)
 {
-	return nfs_no_io_thru_mds(inode);
+	return nfs_no_io_thru_mds(inode) &&
+	       !pnfs_layout_get_failed(inode, iomode);
 }
 
 /*
@@ -1151,13 +1155,12 @@ ff_layout_pg_init_read(struct nfs_pageio_descriptor *pgio,
 	}
 	/*
 	 * No segment, and no error to report either: pnfs_update_layout()
-	 * simply has nothing to give (NFS_LAYOUT_BULK_RECALL, a failed
-	 * pnfs_layout_io_test, blocked LAYOUTGETs, a layout being
-	 * returned).  If the server forbids reading this file through the
-	 * MDS there is no fallback to take, so wait for a layout on the
-	 * same terms as the -EAGAIN above.  The layout hdr that carried
-	 * FF_FLAGS_NO_IO_THRU_MDS may itself be gone by now, which is why
-	 * the flag is kept on the inode.
+	 * simply has nothing to give (NFS_LAYOUT_BULK_RECALL, blocked
+	 * LAYOUTGETs, a layout being returned).  If the server forbids
+	 * reading this file through the MDS there is no fallback to take,
+	 * so wait for a layout on the same terms as the -EAGAIN above.  The
+	 * layout hdr that carried FF_FLAGS_NO_IO_THRU_MDS may itself be
+	 * gone by now, which is why the flag is kept on the inode.
 	 */
 	if (!ff_layout_inode_no_fallback_to_mds(pgio->pg_inode, IOMODE_READ))
 		goto out_mds;
@@ -1445,7 +1448,8 @@ static int ff_layout_async_handle_error_v4(struct rpc_task *task,
 					   struct nfs4_state *state,
 					   struct nfs_client *clp,
 					   struct pnfs_layout_segment *lseg,
-					   struct nfs4_deviceid_node *devid)
+					   struct nfs4_deviceid_node *devid,
+					   u32 iomode)
 {
 	struct pnfs_layout_hdr *lo = lseg->pls_layout;
 	struct inode *inode = lo->plh_inode;
@@ -1534,8 +1538,9 @@ static int ff_layout_async_handle_error_v4(struct rpc_task *task,
 		return -NFS4ERR_RESET_TO_PNFS;
 reset:
 	/*
-	 * FF_FLAGS_NO_IO_THRU_MDS: never resend through the MDS.  The
-	 * caller would do so with force_mds set (ff_layout_reset_read(),
+	 * FF_FLAGS_NO_IO_THRU_MDS: don't resend through the MDS (see
+	 * ff_layout_inode_no_fallback_to_mds()).  The caller would do so
+	 * with force_mds set (ff_layout_reset_read(),
 	 * ff_layout_reset_write(hdr, false) -> pnfs_*_done_resend_to_mds()),
 	 * which builds a descriptor out of the plain MDS page ops and so
 	 * consults no layout at all -- this is the last point at which the
@@ -1545,7 +1550,7 @@ static int ff_layout_async_handle_error_v4(struct rpc_task *task,
 	 * pnfs_destroy_layout().  Having done so they can no longer ask the
 	 * layout hdr about the flag, hence the inode.
 	 */
-	if (nfs_no_io_thru_mds(inode)) {
+	if (ff_layout_inode_no_fallback_to_mds(inode, iomode)) {
 		dprintk("%s Retry through pNFS, no MDS fallback. Error %d\n",
 			__func__, task->tk_status);
 		return -NFS4ERR_RESET_TO_PNFS;
@@ -1630,7 +1635,8 @@ static int ff_layout_async_handle_error(struct rpc_task *task,
 					struct nfs4_state *state,
 					struct nfs_client *clp,
 					struct pnfs_layout_segment *lseg,
-					struct nfs4_deviceid_node *devid)
+					struct nfs4_deviceid_node *devid,
+					u32 iomode)
 {
 	int vers = clp->cl_nfs_mod->rpc_vers->number;
 
@@ -1650,7 +1656,7 @@ static int ff_layout_async_handle_error(struct rpc_task *task,
 						       lseg, devid);
 	case 4:
 		return ff_layout_async_handle_error_v4(task, op_status, state,
-						       clp, lseg, devid);
+						       clp, lseg, devid, iomode);
 	default:
 		/* should never happen */
 		WARN_ON_ONCE(1);
@@ -1784,7 +1790,7 @@ static int ff_layout_read_done_cb(struct rpc_task *task,
 	err = ff_layout_async_handle_error(task, hdr->res.op_status,
 					   hdr->args.context->state,
 					   hdr->ds_clp, hdr->lseg,
-					   hdr->ds_dev);
+					   hdr->ds_dev, IOMODE_READ);
 
 	trace_nfs4_pnfs_read(hdr, err);
 	clear_bit(NFS_IOHDR_RESEND_PNFS, &hdr->flags);
@@ -1994,7 +2000,7 @@ static int ff_layout_write_done_cb(struct rpc_task *task,
 	err = ff_layout_async_handle_error(task, hdr->res.op_status,
 					   hdr->args.context->state,
 					   hdr->ds_clp, hdr->lseg,
-					   hdr->ds_dev);
+					   hdr->ds_dev, IOMODE_RW);
 
 	trace_nfs4_pnfs_write(hdr, err);
 	clear_bit(NFS_IOHDR_RESEND_PNFS, &hdr->flags);
@@ -2045,7 +2051,7 @@ static int ff_layout_commit_done_cb(struct rpc_task *task,
 
 	err = ff_layout_async_handle_error(task, data->res.op_status,
 					   NULL, data->ds_clp, data->lseg,
-					   data->ds_dev);
+					   data->ds_dev, IOMODE_RW);
 
 	trace_nfs4_pnfs_commit_ds(data, err);
 	switch (err) {
diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h
index 208c83cc1d99..ee79d522de9a 100644
--- a/fs/nfs/internal.h
+++ b/fs/nfs/internal.h
@@ -558,8 +558,10 @@ static inline bool nfs_file_io_is_buffered(struct nfs_inode *nfsi)
  * 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.  Flexfiles also retries reads and writes that have no
- * layout segment instead of sending them through the MDS.  Servers are
- * assumed to be consistent in their no-fallback policy per file.
+ * layout segment instead of sending them through the MDS, unless a
+ * LAYOUTGET for that iomode has failed with NFS4ERR_LAYOUTUNAVAILABLE or
+ * NFS4ERR_TOOSMALL.  Servers are assumed to be consistent in their
+ * no-fallback policy per file.
  */
 #define NFS_INO_NO_IO_THRU_MDS	(30)
 
diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c
index 78cd101b7485..7fc55abb1e19 100644
--- a/fs/nfs/pnfs.c
+++ b/fs/nfs/pnfs.c
@@ -586,6 +586,28 @@ pnfs_layout_io_test_failed(struct pnfs_layout_hdr *lo, u32 iomode)
 	return true;
 }
 
+/*
+ * Returns true if a LAYOUTGET for @iomode failed with an error, such as
+ * NFS4ERR_LAYOUTUNAVAILABLE, in the last PNFS_LAYOUTGET_RETRY_TIMEOUT.
+ * pnfs_layout_io_test_failed() clears an expired fail bit only when
+ * pnfs_update_layout() gets that far, so check the time here too.
+ */
+bool pnfs_layout_get_failed(struct inode *inode, u32 iomode)
+{
+	struct pnfs_layout_hdr *lo;
+	unsigned long now = jiffies;
+	bool ret = false;
+
+	spin_lock(&inode->i_lock);
+	lo = NFS_I(inode)->layout;
+	if (lo && test_bit(pnfs_iomode_to_fail_bit(iomode), &lo->plh_flags))
+		ret = time_in_range(lo->plh_retry_timestamp,
+				    now - PNFS_LAYOUTGET_RETRY_TIMEOUT, now);
+	spin_unlock(&inode->i_lock);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(pnfs_layout_get_failed);
+
 static void
 pnfs_init_lseg(struct pnfs_layout_hdr *lo, struct pnfs_layout_segment *lseg,
 		const struct pnfs_layout_range *range,
diff --git a/fs/nfs/pnfs.h b/fs/nfs/pnfs.h
index 94bf24eaa0dc..bb66c637d287 100644
--- a/fs/nfs/pnfs.h
+++ b/fs/nfs/pnfs.h
@@ -308,6 +308,7 @@ int pnfs_generic_pg_writepages(struct nfs_pageio_descriptor *desc);
 size_t pnfs_generic_pg_test(struct nfs_pageio_descriptor *pgio,
 			    struct nfs_page *prev, struct nfs_page *req);
 void pnfs_set_lo_fail(struct pnfs_layout_segment *lseg);
+bool pnfs_layout_get_failed(struct inode *inode, u32 iomode);
 struct pnfs_layout_segment *pnfs_layout_process(struct nfs4_layoutget *lgp);
 void pnfs_layoutget_free(struct nfs4_layoutget *lgp);
 void pnfs_free_lseg_list(struct list_head *tmp_list);
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v4 4/4] pNFS/flexfiles: emit the pg_init MDS-fallback tracepoints under i_lock
  2026-12-03 16:54 [PATCH v4 0/4] pNFS/flexfiles: I/O without a layout under FF_FLAGS_NO_IO_THRU_MDS Benjamin Coddington
                   ` (2 preceding siblings ...)
  2026-12-03 16:54 ` [PATCH v4 3/4] pNFS/flexfiles: use the MDS when the server has no layout to give Benjamin Coddington
@ 2026-12-03 16:54 ` Benjamin Coddington
  3 siblings, 0 replies; 5+ messages in thread
From: Benjamin Coddington @ 2026-12-03 16:54 UTC (permalink / raw)
  To: Trond Myklebust, Anna Schumaker, Mike Snitzer
  Cc: Olga Kornievskaia, linux-nfs

From: Benjamin Coddington <bcodding@hammerspace.com>

ff_layout_pg_init_read() and ff_layout_pg_init_write() pass
NFS_I(inode)->layout to their MDS-fallback tracepoints, which read the
layout stateid from it.  When they get there without a layout segment,
nothing keeps the layout header from being detached and freed before
the tracepoint reads it.

The header is detached under i_lock.  Emit both tracepoints under
i_lock, as pnfs_mds_fallback_pg_get_mirror_count is.

Fixes: d5b9216fd511 ("pnfs/flexfiles: Add tracepoints for detecting pnfs fallback to MDS")
Signed-off-by: Benjamin Coddington <bcodding@hammerspace.com>
---
 fs/nfs/flexfilelayout/flexfilelayout.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/fs/nfs/flexfilelayout/flexfilelayout.c b/fs/nfs/flexfilelayout/flexfilelayout.c
index 0402725a84a6..28d2aaf237d3 100644
--- a/fs/nfs/flexfilelayout/flexfilelayout.c
+++ b/fs/nfs/flexfilelayout/flexfilelayout.c
@@ -1179,10 +1179,14 @@ ff_layout_pg_init_read(struct nfs_pageio_descriptor *pgio,
 		return;
 	goto retry;
 out_mds:
-	trace_pnfs_mds_fallback_pg_init_read(pgio->pg_inode,
-			0, NFS4_MAX_UINT64, IOMODE_READ,
-			NFS_I(pgio->pg_inode)->layout,
-			pgio->pg_lseg);
+	if (trace_pnfs_mds_fallback_pg_init_read_enabled()) {
+		spin_lock(&pgio->pg_inode->i_lock);
+		trace_pnfs_mds_fallback_pg_init_read(pgio->pg_inode,
+				0, NFS4_MAX_UINT64, IOMODE_READ,
+				NFS_I(pgio->pg_inode)->layout,
+				pgio->pg_lseg);
+		spin_unlock(&pgio->pg_inode->i_lock);
+	}
 	pgio->pg_maxretrans = 0;
 	nfs_pageio_reset_read_mds(pgio);
 }
@@ -1268,10 +1272,14 @@ ff_layout_pg_init_write(struct nfs_pageio_descriptor *pgio,
 out_mds:
 	if (ff_layout_pg_mirrors_busy(pgio))
 		goto out_eagain;
-	trace_pnfs_mds_fallback_pg_init_write(pgio->pg_inode,
-			0, NFS4_MAX_UINT64, IOMODE_RW,
-			NFS_I(pgio->pg_inode)->layout,
-			pgio->pg_lseg);
+	if (trace_pnfs_mds_fallback_pg_init_write_enabled()) {
+		spin_lock(&pgio->pg_inode->i_lock);
+		trace_pnfs_mds_fallback_pg_init_write(pgio->pg_inode,
+				0, NFS4_MAX_UINT64, IOMODE_RW,
+				NFS_I(pgio->pg_inode)->layout,
+				pgio->pg_lseg);
+		spin_unlock(&pgio->pg_inode->i_lock);
+	}
 	pgio->pg_maxretrans = 0;
 	nfs_pageio_reset_write_mds(pgio);
 	pgio->pg_error = -EAGAIN;
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-12-03 16:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 16:54 [PATCH v4 0/4] pNFS/flexfiles: I/O without a layout under FF_FLAGS_NO_IO_THRU_MDS Benjamin Coddington
2026-12-03 16:54 ` [PATCH v4 1/4] pNFS/flexfiles: pace writes that have no layout and can't use the MDS Benjamin Coddington
2026-12-03 16:54 ` [PATCH v4 2/4] pNFS/flexfiles: remove the layout-header NO_IO_THRU_MDS bit Benjamin Coddington
2026-12-03 16:54 ` [PATCH v4 3/4] pNFS/flexfiles: use the MDS when the server has no layout to give Benjamin Coddington
2026-12-03 16:54 ` [PATCH v4 4/4] pNFS/flexfiles: emit the pg_init MDS-fallback tracepoints under i_lock Benjamin Coddington

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox