* [PATCH 0/4] pNFS: reclaim uncommitted layout writes after a server restart
@ 2026-12-01 14:18 Christoph Engelbert via B4 Relay
2026-12-01 14:18 ` [PATCH 1/4] NFSv4.1: encode loca_reclaim in LAYOUTCOMMIT Christoph Engelbert via B4 Relay
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Christoph Engelbert via B4 Relay @ 2026-12-01 14:18 UTC (permalink / raw)
To: Trond Myklebust, Anna Schumaker
Cc: linux-nfs, Benjamin Coddington, Christoph Hellwig, Chuck Lever,
Christoph Engelbert
A block or SCSI layout client writes file data straight to the storage
device, into extents the metadata server allocated as unwritten. The
server learns that the extents now hold data only from LAYOUTCOMMIT.
If the server restarts between the writes and the commit, the client
never tells it: the data is on the device, but every other client
reads those blocks as zeros. The writer reads its own page cache and
sees nothing wrong. Its close() returned 0 until Benjamin Coddington's
commit below. Now it fails with EIO, but the data is still lost.
RFC 8881, section 12.7.4 gives the recovery: a LAYOUTCOMMIT with
loca_reclaim set, sent during the server's grace period. nfsd accepts
one. The Linux client never sends it:
- encode_layoutcommit() hardcodes loca_reclaim to false.
- nfs4_layoutcommit_done() ignores NFS4ERR_GRACE, so a commit refused
during grace is never sent again.
- pnfs_layout_handle_reboot() returns and invalidates the layouts,
and the layout driver's record of the uncommitted extents goes with
them.
We hit this on a block-layout export served from XFS. Writes made under
a layout in the minutes before a metadata server restart read back as
zeros on a second client (about 25 MiB per file, 12,909 blocks). fio on
the writer reported success.
Patch 1 encodes the flag and sends a reclaiming commit on a privileged
slot. Patch 2 retries a commit refused with NFS4ERR_GRACE. Patch 3 adds
a prepare_layoutcommit_reclaim layout driver operation and sends the
reclaim from pnfs_layout_handle_reboot(), before each layout is
returned or invalidated. A refused reclaim is recorded as a writeback
error, so fsync() and close() report it. Patch 4 implements the
operation for the block and SCSI layouts. It includes extents whose
ordinary commit was still in flight at the restart.
The series is based on Trond's testing branch, because it builds on
Benjamin Coddington's "pnfs/blocklayout: report data lost to a failed
LAYOUTCOMMIT" there. With that commit, a commit refused with
NFS4ERR_GRACE fails fsync() with EIO instead of returning 0; patch 2
turns it into a retry. Patch 4 keeps a failed reclaim from recording
that error, since recovery sends the reclaim again.
Tested on arm64 under QEMU, on the testing branch and on v7.3-rc7, with
two VMs: nfsd exporting XFS with pnfs on an nvmet NVMe/TCP namespace
(SCSI layouts), and a client that writes 64 MiB with O_DIRECT, keeps
the file open without fsync(), and closes it after nfsd restarts:
- Client connected through the restart: without the series the file
is lost (size 0, all zeros). With it, the LAYOUTCOMMIT with
loca_reclaim set is accepted before RECLAIM_COMPLETE, and the file
is intact in every run, on both bases.
- Client cut off until grace is over: the data cannot be saved. On
the testing branch, fsync() or close() fails with EIO, with or
without the series. On v7.3-rc7 both return 0, with or without the
series. That report comes from Benjamin's commit, not from this
series, so a backport of the series should carry it too.
The reproducer builds both kernels and a Debian root file system in
Docker and runs the VMs with QEMU (KVM, HVF, or TCG):
https://gist.github.com/noctarius/bd6055d0c0bb2c9e7d630076ddc59806
Not tested: the block layout (blkmapd), an ordinary LAYOUTCOMMIT in
flight at the restart, and a server that refuses a reclaim sent during
grace (patch 3's EIO path; a client that misses grace never sends one).
The series was written with the help of an LLM-based coding assistant.
It was used to trace the client's recovery and LAYOUTCOMMIT paths
against RFC 8881, to draft the changes and changelogs, and to run
checkpatch. I reviewed the changes and the analysis behind them.
Signed-off-by: Christoph Engelbert <me@noctarius.com>
---
Christoph Engelbert (4):
NFSv4.1: encode loca_reclaim in LAYOUTCOMMIT
NFSv4.1: retry a LAYOUTCOMMIT refused with NFS4ERR_GRACE
pNFS: reclaim uncommitted layout writes after a server restart
pnfs/blocklayout: reclaim uncommitted extents after a server restart
fs/nfs/blocklayout/blocklayout.c | 8 +++
fs/nfs/blocklayout/blocklayout.h | 8 +++
fs/nfs/blocklayout/extent_tree.c | 118 +++++++++++++++++++++++++++--------
fs/nfs/nfs4proc.c | 11 +++-
fs/nfs/nfs4xdr.c | 2 +-
fs/nfs/pnfs.c | 130 ++++++++++++++++++++++++++++++++++++++-
fs/nfs/pnfs.h | 8 +++
include/linux/nfs_xdr.h | 1 +
8 files changed, 254 insertions(+), 32 deletions(-)
---
base-commit: 3e19991734326332c736e24c9b47b2cffb8f9e42
change-id: 20261201-pnfs-layoutcommit-reclaim-nfs-testing-be4ad2026feb
Best regards,
--
Christoph Engelbert <me@noctarius.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/4] NFSv4.1: encode loca_reclaim in LAYOUTCOMMIT
2026-12-01 14:18 [PATCH 0/4] pNFS: reclaim uncommitted layout writes after a server restart Christoph Engelbert via B4 Relay
@ 2026-12-01 14:18 ` Christoph Engelbert via B4 Relay
2026-12-04 9:42 ` Christoph Hellwig
2026-12-01 14:18 ` [PATCH 2/4] NFSv4.1: retry a LAYOUTCOMMIT refused with NFS4ERR_GRACE Christoph Engelbert via B4 Relay
` (2 subsequent siblings)
3 siblings, 1 reply; 8+ messages in thread
From: Christoph Engelbert via B4 Relay @ 2026-12-01 14:18 UTC (permalink / raw)
To: Trond Myklebust, Anna Schumaker
Cc: linux-nfs, Benjamin Coddington, Christoph Hellwig, Chuck Lever,
Christoph Engelbert
From: Christoph Engelbert <me@noctarius.com>
LAYOUTCOMMIT carries a reclaim flag for committing, during a server's
grace period, a layout that was granted before the server restarted
(RFC 8881, section 18.42.3). The client has always encoded it as
false.
Add a reclaim field to the arguments, encode it, and send a reclaiming
LAYOUTCOMMIT on a privileged slot, since it is sent by the state
manager while recovery is in progress. Its completion leaves the status
alone instead of ignoring or retrying errors, so that the state manager
can tell a refused reclaim from one that has to be sent again.
Nothing sets the field yet.
Signed-off-by: Christoph Engelbert <me@noctarius.com>
---
fs/nfs/nfs4proc.c | 10 +++++++++-
fs/nfs/nfs4xdr.c | 2 +-
include/linux/nfs_xdr.h | 1 +
3 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 13f4e2570b73..bea74c922655 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -10078,6 +10078,13 @@ nfs4_layoutcommit_done(struct rpc_task *task, void *calldata)
if (!nfs41_sequence_done(task, &data->res.seq_res))
return;
+ /*
+ * A reclaim is sent by the state manager during recovery, which
+ * decides what its outcome means for the data it covers.
+ */
+ if (data->args.reclaim)
+ return;
+
switch (task->tk_status) { /* Just ignore these failures */
case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */
case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */
@@ -10180,7 +10187,8 @@ nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync)
task_setup_data.workqueue = nfsiod_workqueue;
}
nfs4_init_sequence(NFS_SERVER(data->args.inode)->nfs_client,
- &data->args.seq_args, &data->res.seq_res, 1, 0);
+ &data->args.seq_args, &data->res.seq_res, 1,
+ data->args.reclaim);
task = rpc_run_task(&task_setup_data);
if (IS_ERR(task))
return PTR_ERR(task);
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index c0971af20154..d4fa5c5e8207 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -2097,7 +2097,7 @@ encode_layoutcommit(struct xdr_stream *xdr,
/* Only whole file layouts */
p = xdr_encode_hyper(p, 0); /* offset */
p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
- *p = cpu_to_be32(0); /* reclaim */
+ *p = cpu_to_be32(args->reclaim);
encode_nfs4_stateid(xdr, &args->stateid);
if (args->lastbytewritten != U64_MAX) {
p = reserve_space(xdr, 20);
diff --git a/include/linux/nfs_xdr.h b/include/linux/nfs_xdr.h
index c0e29b4dfa62..0b98ca4d6ef6 100644
--- a/include/linux/nfs_xdr.h
+++ b/include/linux/nfs_xdr.h
@@ -315,6 +315,7 @@ struct nfs4_layoutcommit_args {
struct page *layoutupdate_page;
struct page **layoutupdate_pages;
__be32 *start_p;
+ bool reclaim;
};
struct nfs4_layoutcommit_res {
--
Git-157)
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/4] NFSv4.1: retry a LAYOUTCOMMIT refused with NFS4ERR_GRACE
2026-12-01 14:18 [PATCH 0/4] pNFS: reclaim uncommitted layout writes after a server restart Christoph Engelbert via B4 Relay
2026-12-01 14:18 ` [PATCH 1/4] NFSv4.1: encode loca_reclaim in LAYOUTCOMMIT Christoph Engelbert via B4 Relay
@ 2026-12-01 14:18 ` Christoph Engelbert via B4 Relay
2026-12-04 9:42 ` Christoph Hellwig
2026-12-01 14:18 ` [PATCH 3/4] pNFS: reclaim uncommitted layout writes after a server restart Christoph Engelbert via B4 Relay
2026-12-01 14:18 ` [PATCH 4/4] pnfs/blocklayout: reclaim uncommitted extents " Christoph Engelbert via B4 Relay
3 siblings, 1 reply; 8+ messages in thread
From: Christoph Engelbert via B4 Relay @ 2026-12-01 14:18 UTC (permalink / raw)
To: Trond Myklebust, Anna Schumaker
Cc: linux-nfs, Benjamin Coddington, Christoph Hellwig, Chuck Lever,
Christoph Engelbert
From: Christoph Engelbert <me@noctarius.com>
A server in its grace period refuses a LAYOUTCOMMIT that does not set
loca_reclaim with NFS4ERR_GRACE. nfs4_layoutcommit_done() ignores that
error, so the commit is never sent again. Commit f770d34f7112
("pnfs/blocklayout: report data lost to a failed LAYOUTCOMMIT") made the
block layout put the extents back and record -EIO, so fsync() and
close() now fail for data that a commit after the grace period would
have recorded. Before that commit, they returned 0 while the server
still had the blocks as unwritten.
NFS4ERR_GRACE asks the client to try again later, so take the generic
error path, which delays and retries the commit as it does for
NFS4ERR_DELAY. A commit of a layout granted before the restart is sent
as a reclaim by the state manager before the grace period ends.
Fixes: e59d27e05a64 ("NFSv4.1: Fix layoutcommit error handling")
Signed-off-by: Christoph Engelbert <me@noctarius.com>
---
fs/nfs/nfs4proc.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index bea74c922655..ea7bf329771e 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -10089,7 +10089,6 @@ nfs4_layoutcommit_done(struct rpc_task *task, void *calldata)
case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */
case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */
case -NFS4ERR_BADLAYOUT: /* no layout */
- case -NFS4ERR_GRACE: /* loca_recalim always false */
task->tk_status = 0;
break;
case -NFS4ERR_OLD_STATEID: {
--
Git-157)
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/4] pNFS: reclaim uncommitted layout writes after a server restart
2026-12-01 14:18 [PATCH 0/4] pNFS: reclaim uncommitted layout writes after a server restart Christoph Engelbert via B4 Relay
2026-12-01 14:18 ` [PATCH 1/4] NFSv4.1: encode loca_reclaim in LAYOUTCOMMIT Christoph Engelbert via B4 Relay
2026-12-01 14:18 ` [PATCH 2/4] NFSv4.1: retry a LAYOUTCOMMIT refused with NFS4ERR_GRACE Christoph Engelbert via B4 Relay
@ 2026-12-01 14:18 ` Christoph Engelbert via B4 Relay
2026-12-04 9:43 ` Christoph Hellwig
2026-12-01 14:18 ` [PATCH 4/4] pnfs/blocklayout: reclaim uncommitted extents " Christoph Engelbert via B4 Relay
3 siblings, 1 reply; 8+ messages in thread
From: Christoph Engelbert via B4 Relay @ 2026-12-01 14:18 UTC (permalink / raw)
To: Trond Myklebust, Anna Schumaker
Cc: linux-nfs, Benjamin Coddington, Christoph Hellwig, Chuck Lever,
Christoph Engelbert
From: Christoph Engelbert <me@noctarius.com>
A client that wrote to the storage devices through a layout, and had
not committed the layout when the metadata server restarted, has data
on the devices that the server does not know about. On a block or SCSI
layout it sits in blocks the server allocated as unwritten, which every
other client reads as zeros. The writer finds out only if a
LAYOUTCOMMIT it sends after the restart fails.
RFC 8881, section 12.7.4 gives a LAYOUTCOMMIT with loca_reclaim set,
sent during the server's grace period, as the only way to recover it.
The client never sends one. On a restart, pnfs_layout_handle_reboot()
returns and invalidates the layouts, and the layout driver's record of
what was written under them goes with them.
Add a prepare_layoutcommit_reclaim operation for layout drivers that
can say which writes the server has not acknowledged, and send a
reclaiming LAYOUTCOMMIT from pnfs_layout_handle_reboot(), which runs in
the state manager after the opens are reclaimed and before
RECLAIM_COMPLETE, for every layout before it is returned or
invalidated. The reclaim does not take NFS_INO_LAYOUTCOMMITTING: a
commit sent before the restart may still hold it, waiting for the
recovery this runs in.
An error that leaves the server unasked keeps the layout and retries
recovery. A server that refuses the reclaim has lost the data, which is
recorded as a writeback error on the mapping, so that the next fsync()
or close() reports it instead of returning 0.
Fixes: 863a3c6c686d ("NFSv4.1: layoutcommit")
Signed-off-by: Christoph Engelbert <me@noctarius.com>
---
fs/nfs/pnfs.c | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
fs/nfs/pnfs.h | 8 ++++
2 files changed, 135 insertions(+), 3 deletions(-)
diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c
index d2ff78acbed9..f0906f27f99c 100644
--- a/fs/nfs/pnfs.c
+++ b/fs/nfs/pnfs.c
@@ -919,6 +919,110 @@ pnfs_layout_bulk_destroy_byserver_locked(struct nfs_client *clp,
return 0;
}
+/*
+ * Errors after which a reclaiming LAYOUTCOMMIT is sent again on the next
+ * pass of recovery, rather than taken as the server's refusal.
+ */
+static bool pnfs_layoutcommit_reclaim_again(int status)
+{
+ switch (status) {
+ case -NFS4ERR_DELAY:
+ case -NFS4ERR_BADSESSION:
+ case -NFS4ERR_DEADSESSION:
+ case -NFS4ERR_BADSLOT:
+ case -NFS4ERR_SEQ_MISORDERED:
+ case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
+ case -NFS4ERR_STALE_CLIENTID:
+ case -ENOMEM:
+ case -EAGAIN:
+ case -ETIMEDOUT:
+ return true;
+ }
+ return false;
+}
+
+/*
+ * Send one reclaiming LAYOUTCOMMIT. Returns 1 when the layout driver could
+ * fit only part of the writes into it and another has to follow, 0 when
+ * none are left, and a negative error otherwise.
+ */
+static int pnfs_layoutcommit_reclaim_one(struct inode *inode)
+{
+ struct pnfs_layoutdriver_type *ld = NFS_SERVER(inode)->pnfs_curr_ld;
+ struct nfs4_layoutcommit_data *data;
+ struct pnfs_layout_hdr *lo;
+ int status, more = 0;
+
+ data = kzalloc_obj(*data, GFP_NOFS);
+ if (!data)
+ return -ENOMEM;
+
+ spin_lock(&inode->i_lock);
+ lo = NFS_I(inode)->layout;
+ if (!lo || !pnfs_layout_is_valid(lo)) {
+ spin_unlock(&inode->i_lock);
+ kfree(data);
+ return 0;
+ }
+ nfs4_stateid_copy(&data->args.stateid, &lo->plh_stateid);
+ data->cred = get_cred(lo->plh_lc_cred);
+ spin_unlock(&inode->i_lock);
+
+ INIT_LIST_HEAD(&data->lseg_list);
+ data->args.inode = inode;
+ data->args.reclaim = true;
+ data->args.bitmask = NFS_SERVER(inode)->cache_consistency_bitmask;
+ nfs_fattr_init(&data->fattr);
+ data->res.fattr = &data->fattr;
+ data->res.server = NFS_SERVER(inode);
+
+ status = ld->prepare_layoutcommit_reclaim(&data->args);
+ if (status == -ENOSPC) {
+ more = 1;
+ } else if (status) {
+ put_cred(data->cred);
+ kfree(data);
+ return status == -ENODATA ? 0 : status;
+ }
+
+ status = nfs4_proc_layoutcommit(data, true);
+ return status ? status : more;
+}
+
+/*
+ * Commit the writes made under a layout granted before the server
+ * restarted. The data is on the storage devices, but only a LAYOUTCOMMIT
+ * with loca_reclaim set, sent during the server's grace period, makes the
+ * server record where (RFC 8881, section 12.7.4), and once the layout is
+ * destroyed the layout driver no longer knows either.
+ *
+ * Returns -EAGAIN when recovery should try again. A server that refuses
+ * the reclaim has lost the data, which is recorded as a writeback error on
+ * the mapping for fsync() and close() to report.
+ */
+static int pnfs_layoutcommit_reclaim(struct inode *inode)
+{
+ struct pnfs_layoutdriver_type *ld = NFS_SERVER(inode)->pnfs_curr_ld;
+ int status;
+
+ if (!ld || !ld->prepare_layoutcommit_reclaim)
+ return 0;
+
+ do {
+ status = pnfs_layoutcommit_reclaim_one(inode);
+ } while (status == 1);
+
+ if (!status)
+ return 0;
+ if (pnfs_layoutcommit_reclaim_again(status))
+ return -EAGAIN;
+ mapping_set_error(inode->i_mapping, -EIO);
+ pr_warn_ratelimited("NFS: %s refused to reclaim writes to inode %llu after a restart: %d\n",
+ NFS_SERVER(inode)->nfs_client->cl_hostname,
+ inode->i_ino, status);
+ return 0;
+}
+
static int
pnfs_layout_free_bulk_destroy_list(struct list_head *layout_list,
enum pnfs_layout_destroy_mode mode)
@@ -935,6 +1039,21 @@ pnfs_layout_free_bulk_destroy_list(struct list_head *layout_list,
lo->plh_inode->i_ino);
inode = lo->plh_inode;
+ if (mode == PNFS_LAYOUT_REBOOT &&
+ pnfs_layoutcommit_reclaim(inode) == -EAGAIN) {
+ /*
+ * Keep the layout for the next pass: once it is
+ * invalid, its writes can no longer be reclaimed.
+ */
+ spin_lock(&inode->i_lock);
+ list_del_init(&lo->plh_bulk_destroy);
+ spin_unlock(&inode->i_lock);
+ pnfs_put_layout_hdr(lo);
+ nfs_iput_and_deactive(inode);
+ ret = -EAGAIN;
+ continue;
+ }
+
pnfs_layoutcommit_inode(inode, false);
spin_lock(&inode->i_lock);
@@ -1054,6 +1173,10 @@ static int pnfs_layout_bulk_list_reboot(struct list_head *list)
list_for_each_entry(lo, list, plh_bulk_destroy) {
server = NFS_SERVER(lo->plh_inode);
+ /* Returning the layout ends the record of what it wrote. */
+ ret = pnfs_layoutcommit_reclaim(lo->plh_inode);
+ if (ret)
+ goto err;
ret = pnfs_layout_return_on_reboot(lo);
switch (ret) {
case 0:
@@ -1081,8 +1204,7 @@ int pnfs_layout_handle_reboot(struct nfs_client *clp)
pnfs_layout_build_recover_list_byclient(clp, &list);
if (!list_empty(&list))
ret = pnfs_layout_bulk_list_reboot(&list);
- ret2 = pnfs_layout_do_destroy_byclid(clp, &list,
- PNFS_LAYOUT_INVALIDATE);
+ ret2 = pnfs_layout_do_destroy_byclid(clp, &list, PNFS_LAYOUT_REBOOT);
if (!ret)
ret = ret2;
return (ret == 0) ? 0 : -EAGAIN;
@@ -3741,7 +3863,9 @@ void pnfs_cleanup_layoutcommit(struct nfs4_layoutcommit_data *data)
if (nfss->pnfs_curr_ld->cleanup_layoutcommit)
nfss->pnfs_curr_ld->cleanup_layoutcommit(data);
- pnfs_list_write_lseg_done(data->args.inode, &data->lseg_list);
+ /* A reclaim takes neither segments nor NFS_INO_LAYOUTCOMMITTING. */
+ if (!data->args.reclaim)
+ pnfs_list_write_lseg_done(data->args.inode, &data->lseg_list);
}
/*
diff --git a/fs/nfs/pnfs.h b/fs/nfs/pnfs.h
index bbe56b682dc0..b4d212e990cd 100644
--- a/fs/nfs/pnfs.h
+++ b/fs/nfs/pnfs.h
@@ -127,6 +127,7 @@ enum pnfs_layout_destroy_mode {
PNFS_LAYOUT_INVALIDATE = 0,
PNFS_LAYOUT_BULK_RETURN,
PNFS_LAYOUT_FILE_BULK_RETURN,
+ PNFS_LAYOUT_REBOOT,
};
struct nfs4_deviceid_node;
@@ -198,6 +199,13 @@ struct pnfs_layoutdriver_type {
void (*cleanup_layoutcommit) (struct nfs4_layoutcommit_data *data);
int (*prepare_layoutcommit) (struct nfs4_layoutcommit_args *args);
+ /*
+ * As prepare_layoutcommit, for a LAYOUTCOMMIT with loca_reclaim set
+ * after a server restart: encode every write made under the layout
+ * that the server has not acknowledged, including those of a commit
+ * still in flight. Returns -ENODATA when there is none.
+ */
+ int (*prepare_layoutcommit_reclaim) (struct nfs4_layoutcommit_args *args);
int (*prepare_layoutstats) (struct nfs42_layoutstat_args *args);
void (*cancel_io)(struct pnfs_layout_segment *lseg,
--
Git-157)
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 4/4] pnfs/blocklayout: reclaim uncommitted extents after a server restart
2026-12-01 14:18 [PATCH 0/4] pNFS: reclaim uncommitted layout writes after a server restart Christoph Engelbert via B4 Relay
` (2 preceding siblings ...)
2026-12-01 14:18 ` [PATCH 3/4] pNFS: reclaim uncommitted layout writes after a server restart Christoph Engelbert via B4 Relay
@ 2026-12-01 14:18 ` Christoph Engelbert via B4 Relay
3 siblings, 0 replies; 8+ messages in thread
From: Christoph Engelbert via B4 Relay @ 2026-12-01 14:18 UTC (permalink / raw)
To: Trond Myklebust, Anna Schumaker
Cc: linux-nfs, Benjamin Coddington, Christoph Hellwig, Chuck Lever,
Christoph Engelbert
From: Christoph Engelbert <me@noctarius.com>
Implement prepare_layoutcommit_reclaim for the block and SCSI layouts.
It encodes the extents written and not yet committed, as an ordinary
commit does, and also those still tagged EXTENT_COMMITTING: a commit
sent before the restart has not been acknowledged by the restarted
server either, and may be waiting for the recovery the reclaim runs in.
A successful reclaim marks both kinds committed, so that commit finds
nothing left to mark when it completes.
A failed reclaim puts its extents back without recording a writeback
error. The state manager sends the reclaim again after an error that
leaves the server unasked, and records the error itself when the server
refuses it. Reporting every failure, as ext_tree_mark_committed() does
for an ordinary commit, would fail fsync() and close() for data that
the next pass of recovery commits.
The new size is the end of every write the server has not
acknowledged. bl_lwb cannot give it, since a commit takes it when it is
sent, so keep the end of those writes in bl_lwb_pending as well, and
forget it once a commit succeeds with nothing left uncommitted.
Signed-off-by: Christoph Engelbert <me@noctarius.com>
---
fs/nfs/blocklayout/blocklayout.c | 8 +++
fs/nfs/blocklayout/blocklayout.h | 8 +++
fs/nfs/blocklayout/extent_tree.c | 118 ++++++++++++++++++++++++++++++---------
3 files changed, 108 insertions(+), 26 deletions(-)
diff --git a/fs/nfs/blocklayout/blocklayout.c b/fs/nfs/blocklayout/blocklayout.c
index 86039e04d4fc..f90e2ac950d9 100644
--- a/fs/nfs/blocklayout/blocklayout.c
+++ b/fs/nfs/blocklayout/blocklayout.c
@@ -779,6 +779,12 @@ bl_prepare_layoutcommit(struct nfs4_layoutcommit_args *arg)
return ext_tree_prepare_commit(arg);
}
+static int
+bl_prepare_layoutcommit_reclaim(struct nfs4_layoutcommit_args *arg)
+{
+ return ext_tree_prepare_commit_reclaim(arg);
+}
+
static void
bl_cleanup_layoutcommit(struct nfs4_layoutcommit_data *lcdata)
{
@@ -978,6 +984,7 @@ static struct pnfs_layoutdriver_type blocklayout_type = {
.free_lseg = bl_free_lseg,
.return_range = bl_return_range,
.prepare_layoutcommit = bl_prepare_layoutcommit,
+ .prepare_layoutcommit_reclaim = bl_prepare_layoutcommit_reclaim,
.cleanup_layoutcommit = bl_cleanup_layoutcommit,
.set_layoutdriver = bl_set_layoutdriver,
.alloc_deviceid_node = bl_alloc_deviceid_node,
@@ -1044,6 +1051,7 @@ static struct pnfs_layoutdriver_type scsilayout_type = {
.free_lseg = bl_free_lseg,
.return_range = bl_return_range,
.prepare_layoutcommit = bl_prepare_layoutcommit,
+ .prepare_layoutcommit_reclaim = bl_prepare_layoutcommit_reclaim,
.cleanup_layoutcommit = bl_cleanup_layoutcommit,
.set_layoutdriver = bl_set_layoutdriver,
.alloc_deviceid_node = bl_alloc_deviceid_node,
diff --git a/fs/nfs/blocklayout/blocklayout.h b/fs/nfs/blocklayout/blocklayout.h
index 8a0b4e0d7cd3..fd82b4f700aa 100644
--- a/fs/nfs/blocklayout/blocklayout.h
+++ b/fs/nfs/blocklayout/blocklayout.h
@@ -147,6 +147,13 @@ struct pnfs_block_layout {
spinlock_t bl_ext_lock; /* Protects list manipulation */
bool bl_scsi_layout;
u64 bl_lwb;
+ /*
+ * The end of the writes the server has not acknowledged yet: bl_lwb
+ * is handed to a LAYOUTCOMMIT when it is sent, this only once one
+ * succeeds with nothing left uncommitted. A reclaim after a server
+ * restart sends it as the new size.
+ */
+ u64 bl_lwb_pending;
};
static inline struct pnfs_block_layout *
@@ -188,6 +195,7 @@ int ext_tree_mark_written(struct pnfs_block_layout *bl, sector_t start,
bool ext_tree_lookup(struct pnfs_block_layout *bl, sector_t isect,
struct pnfs_block_extent *ret, bool rw);
int ext_tree_prepare_commit(struct nfs4_layoutcommit_args *arg);
+int ext_tree_prepare_commit_reclaim(struct nfs4_layoutcommit_args *arg);
void ext_tree_mark_committed(struct nfs4_layoutcommit_args *arg, int status);
/* rpc_pipefs.c */
diff --git a/fs/nfs/blocklayout/extent_tree.c b/fs/nfs/blocklayout/extent_tree.c
index aa657be6cf98..88f3b1df1154 100644
--- a/fs/nfs/blocklayout/extent_tree.c
+++ b/fs/nfs/blocklayout/extent_tree.c
@@ -500,6 +500,8 @@ ext_tree_mark_written(struct pnfs_block_layout *bl, sector_t start,
out:
if (bl->bl_lwb < lwb)
bl->bl_lwb = lwb;
+ if (bl->bl_lwb_pending < lwb)
+ bl->bl_lwb_pending = lwb;
spin_unlock(&bl->bl_ext_lock);
__ext_put_deviceids(&tmp);
@@ -529,6 +531,29 @@ static void ext_tree_free_commitdata(struct nfs4_layoutcommit_args *arg,
}
}
+/*
+ * Whether a commit carries the extent: one written and not yet committed,
+ * and for a reclaim after a server restart also one whose commit was in
+ * flight, which the restarted server has not acknowledged either.
+ */
+static bool ext_tree_uncommitted(struct pnfs_block_extent *be, bool reclaim)
+{
+ if (be->be_state != PNFS_BLOCK_INVALID_DATA)
+ return false;
+ return be->be_tag == EXTENT_WRITTEN ||
+ (reclaim && be->be_tag == EXTENT_COMMITTING);
+}
+
+/* The last byte a commit reports as written. Caller holds bl_ext_lock. */
+static u64 ext_tree_lastbyte(struct pnfs_block_layout *bl, bool reclaim)
+{
+ u64 lwb = reclaim ? bl->bl_lwb_pending : bl->bl_lwb;
+
+ if (!reclaim)
+ bl->bl_lwb = 0;
+ return lwb ? lwb - 1 : U64_MAX;
+}
+
static __be32 *encode_block_extent(struct pnfs_block_extent *be, __be32 *p)
{
p = xdr_encode_opaque_fixed(p, be->be_device->deviceid.data,
@@ -553,6 +578,7 @@ static __be32 *encode_scsi_range(struct pnfs_block_extent *be, __be32 *p)
* @buffer_size: size of the output buffer
* @count: output pointer to the number of encoded extents
* @lastbyte: output pointer to the last written byte
+ * @reclaim: encode for a reclaim after a server restart
*
* Return values:
* %0: Success, all required extents encoded, outputs are valid
@@ -560,14 +586,14 @@ static __be32 *encode_scsi_range(struct pnfs_block_extent *be, __be32 *p)
*/
static int
ext_tree_try_encode_commit(struct pnfs_block_layout *bl, __be32 *p,
- size_t buffer_size, size_t *count, __u64 *lastbyte)
+ size_t buffer_size, size_t *count, __u64 *lastbyte,
+ bool reclaim)
{
struct pnfs_block_extent *be;
spin_lock(&bl->bl_ext_lock);
for (be = ext_tree_first(&bl->bl_ext_rw); be; be = ext_tree_next(be)) {
- if (be->be_state != PNFS_BLOCK_INVALID_DATA ||
- be->be_tag != EXTENT_WRITTEN)
+ if (!ext_tree_uncommitted(be, reclaim))
continue;
(*count)++;
@@ -577,8 +603,7 @@ ext_tree_try_encode_commit(struct pnfs_block_layout *bl, __be32 *p,
}
}
for (be = ext_tree_first(&bl->bl_ext_rw); be; be = ext_tree_next(be)) {
- if (be->be_state != PNFS_BLOCK_INVALID_DATA ||
- be->be_tag != EXTENT_WRITTEN)
+ if (!ext_tree_uncommitted(be, reclaim))
continue;
if (bl->bl_scsi_layout)
@@ -587,8 +612,7 @@ ext_tree_try_encode_commit(struct pnfs_block_layout *bl, __be32 *p,
p = encode_block_extent(be, p);
be->be_tag = EXTENT_COMMITTING;
}
- *lastbyte = (bl->bl_lwb != 0) ? bl->bl_lwb - 1 : U64_MAX;
- bl->bl_lwb = 0;
+ *lastbyte = ext_tree_lastbyte(bl, reclaim);
spin_unlock(&bl->bl_ext_lock);
return 0;
@@ -601,6 +625,7 @@ ext_tree_try_encode_commit(struct pnfs_block_layout *bl, __be32 *p,
* @buffer_size: size of the output buffer
* @count: output pointer to the number of encoded extents
* @lastbyte: output pointer to the last written byte
+ * @reclaim: encode for a reclaim after a server restart
*
* Return values:
* %0: Success, all required extents encoded, outputs are valid
@@ -608,15 +633,15 @@ ext_tree_try_encode_commit(struct pnfs_block_layout *bl, __be32 *p,
*/
static int
ext_tree_encode_commit(struct pnfs_block_layout *bl, __be32 *p,
- size_t buffer_size, size_t *count, __u64 *lastbyte)
+ size_t buffer_size, size_t *count, __u64 *lastbyte,
+ bool reclaim)
{
struct pnfs_block_extent *be, *be_prev;
int ret = 0;
spin_lock(&bl->bl_ext_lock);
for (be = ext_tree_first(&bl->bl_ext_rw); be; be = ext_tree_next(be)) {
- if (be->be_state != PNFS_BLOCK_INVALID_DATA ||
- be->be_tag != EXTENT_WRITTEN)
+ if (!ext_tree_uncommitted(be, reclaim))
continue;
(*count)++;
@@ -634,8 +659,7 @@ ext_tree_encode_commit(struct pnfs_block_layout *bl, __be32 *p,
be_prev = be;
}
if (!ret) {
- *lastbyte = (bl->bl_lwb != 0) ? bl->bl_lwb - 1 : U64_MAX;
- bl->bl_lwb = 0;
+ *lastbyte = ext_tree_lastbyte(bl, reclaim);
} else {
*lastbyte = be_prev->be_f_offset + be_prev->be_length;
*lastbyte <<= SECTOR_SHIFT;
@@ -646,17 +670,8 @@ ext_tree_encode_commit(struct pnfs_block_layout *bl, __be32 *p,
return ret;
}
-/**
- * ext_tree_prepare_commit - encode extents that need to be committed
- * @arg: layout commit data
- *
- * Return values:
- * %0: Success, all required extents are encoded
- * %-ENOSPC: Some extents are encoded, but not all, due to RPC size limit
- * %-ENOMEM: Out of memory, extents not encoded
- */
-int
-ext_tree_prepare_commit(struct nfs4_layoutcommit_args *arg)
+static int
+__ext_tree_prepare_commit(struct nfs4_layoutcommit_args *arg, bool reclaim)
{
struct pnfs_block_layout *bl = BLK_LO2EXT(NFS_I(arg->inode)->layout);
size_t count = 0, buffer_size = PAGE_SIZE;
@@ -670,7 +685,11 @@ ext_tree_prepare_commit(struct nfs4_layoutcommit_args *arg)
arg->layoutupdate_pages = &arg->layoutupdate_page;
ret = ext_tree_try_encode_commit(bl, start_p + 1, buffer_size,
- &count, &arg->lastbytewritten);
+ &count, &arg->lastbytewritten, reclaim);
+ if (reclaim && !ret && !count) {
+ ext_tree_free_commitdata(arg, buffer_size);
+ return -ENODATA;
+ }
if (unlikely(ret)) {
ext_tree_free_commitdata(arg, buffer_size);
@@ -691,7 +710,7 @@ ext_tree_prepare_commit(struct nfs4_layoutcommit_args *arg)
}
ret = ext_tree_encode_commit(bl, start_p + 1, buffer_size,
- &count, &arg->lastbytewritten);
+ &count, &arg->lastbytewritten, reclaim);
}
*start_p = cpu_to_be32(count);
@@ -715,6 +734,42 @@ ext_tree_prepare_commit(struct nfs4_layoutcommit_args *arg)
return ret;
}
+/**
+ * ext_tree_prepare_commit - encode extents that need to be committed
+ * @arg: layout commit data
+ *
+ * Return values:
+ * %0: Success, all required extents are encoded
+ * %-ENOSPC: Some extents are encoded, but not all, due to RPC size limit
+ * %-ENOMEM: Out of memory, extents not encoded
+ */
+int
+ext_tree_prepare_commit(struct nfs4_layoutcommit_args *arg)
+{
+ return __ext_tree_prepare_commit(arg, false);
+}
+
+/**
+ * ext_tree_prepare_commit_reclaim - encode extents for a reclaim
+ * @arg: layout commit data
+ *
+ * As ext_tree_prepare_commit(), for a LAYOUTCOMMIT with loca_reclaim set
+ * after a server restart. It also encodes the extents of a commit that was
+ * in flight, and reports the end of every write the server has not
+ * acknowledged as the last byte written.
+ *
+ * Return values:
+ * %0: Success, all required extents are encoded
+ * %-ENODATA: Nothing to reclaim, nothing encoded
+ * %-ENOSPC: Some extents are encoded, but not all, due to RPC size limit
+ * %-ENOMEM: Out of memory, extents not encoded
+ */
+int
+ext_tree_prepare_commit_reclaim(struct nfs4_layoutcommit_args *arg)
+{
+ return __ext_tree_prepare_commit(arg, true);
+}
+
void
ext_tree_mark_committed(struct nfs4_layoutcommit_args *arg, int status)
{
@@ -750,9 +805,20 @@ ext_tree_mark_committed(struct nfs4_layoutcommit_args *arg, int status)
be = ext_try_to_merge_left(root, be);
be = ext_try_to_merge_right(root, be);
}
+ if (!status) {
+ for (be = ext_tree_first(root); be; be = ext_tree_next(be))
+ if (ext_tree_uncommitted(be, true))
+ break;
+ if (!be)
+ bl->bl_lwb_pending = 0;
+ }
spin_unlock(&bl->bl_ext_lock);
- if (uncommitted) {
+ /*
+ * A failed reclaim is sent again by the state manager, which records
+ * the error itself when the server refuses it.
+ */
+ if (uncommitted && !arg->reclaim) {
filemap_set_wb_err(arg->inode->i_mapping, -EIO);
errseq_set(&arg->inode->i_sb->s_wb_err, -EIO);
}
--
Git-157)
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/4] NFSv4.1: encode loca_reclaim in LAYOUTCOMMIT
2026-12-01 14:18 ` [PATCH 1/4] NFSv4.1: encode loca_reclaim in LAYOUTCOMMIT Christoph Engelbert via B4 Relay
@ 2026-12-04 9:42 ` Christoph Hellwig
0 siblings, 0 replies; 8+ messages in thread
From: Christoph Hellwig @ 2026-12-04 9:42 UTC (permalink / raw)
To: me
Cc: Trond Myklebust, Anna Schumaker, linux-nfs, Benjamin Coddington,
Christoph Hellwig, Chuck Lever
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/4] NFSv4.1: retry a LAYOUTCOMMIT refused with NFS4ERR_GRACE
2026-12-01 14:18 ` [PATCH 2/4] NFSv4.1: retry a LAYOUTCOMMIT refused with NFS4ERR_GRACE Christoph Engelbert via B4 Relay
@ 2026-12-04 9:42 ` Christoph Hellwig
0 siblings, 0 replies; 8+ messages in thread
From: Christoph Hellwig @ 2026-12-04 9:42 UTC (permalink / raw)
To: me
Cc: Trond Myklebust, Anna Schumaker, linux-nfs, Benjamin Coddington,
Chuck Lever
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 3/4] pNFS: reclaim uncommitted layout writes after a server restart
2026-12-01 14:18 ` [PATCH 3/4] pNFS: reclaim uncommitted layout writes after a server restart Christoph Engelbert via B4 Relay
@ 2026-12-04 9:43 ` Christoph Hellwig
0 siblings, 0 replies; 8+ messages in thread
From: Christoph Hellwig @ 2026-12-04 9:43 UTC (permalink / raw)
To: me
Cc: Trond Myklebust, Anna Schumaker, linux-nfs, Benjamin Coddington,
Christoph Hellwig, Chuck Lever
On Tue, Dec 01, 2026 at 03:18:37PM +0100, Christoph Engelbert via B4 Relay wrote:
> + /*
> + * As prepare_layoutcommit, for a LAYOUTCOMMIT with loca_reclaim set
> + * after a server restart: encode every write made under the layout
> + * that the server has not acknowledged, including those of a commit
> + * still in flight. Returns -ENODATA when there is none.
> + */
> + int (*prepare_layoutcommit_reclaim) (struct nfs4_layoutcommit_args *args);
Wouldn't it make a lot more sense to pass the reclaim flag through
nfs4_layoutcommit_args instead of adding another method?
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-12-04 9:44 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 14:18 [PATCH 0/4] pNFS: reclaim uncommitted layout writes after a server restart Christoph Engelbert via B4 Relay
2026-12-01 14:18 ` [PATCH 1/4] NFSv4.1: encode loca_reclaim in LAYOUTCOMMIT Christoph Engelbert via B4 Relay
2026-12-04 9:42 ` Christoph Hellwig
2026-12-01 14:18 ` [PATCH 2/4] NFSv4.1: retry a LAYOUTCOMMIT refused with NFS4ERR_GRACE Christoph Engelbert via B4 Relay
2026-12-04 9:42 ` Christoph Hellwig
2026-12-01 14:18 ` [PATCH 3/4] pNFS: reclaim uncommitted layout writes after a server restart Christoph Engelbert via B4 Relay
2026-12-04 9:43 ` Christoph Hellwig
2026-12-01 14:18 ` [PATCH 4/4] pnfs/blocklayout: reclaim uncommitted extents " Christoph Engelbert via B4 Relay
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox