* [PATCH] NFSD: Allow layoutcommit during grace period
@ 2025-09-04 15:48 Sergey Bashirov
2025-09-08 14:36 ` Chuck Lever
0 siblings, 1 reply; 2+ messages in thread
From: Sergey Bashirov @ 2025-09-04 15:48 UTC (permalink / raw)
To: Chuck Lever, Jeff Layton, NeilBrown, Olga Kornievskaia, Dai Ngo,
Tom Talpey
Cc: linux-nfs, linux-kernel, Sergey Bashirov, Konstantin Evtushenko
If the loca_reclaim field is set to TRUE, this indicates that the client
is attempting to commit changes to a layout after the restart of the
metadata server during the metadata server's recovery grace period. This
type of request may be necessary when the client has uncommitted writes
to provisionally allocated byte-ranges of a file that were sent to the
storage devices before the restart of the metadata server. See RFC 8881,
section 18.42.3.
Without this, the client is not able to increase the file size and commit
preallocated extents when the block/scsi layout server is restarted
during a write and is in a grace period. And when the grace period ends,
the client also cannot perform layoutcommit because the old layout state
becomes invalid, resulting in file corruption.
Co-developed-by: Konstantin Evtushenko <koevtushenko@yandex.com>
Signed-off-by: Konstantin Evtushenko <koevtushenko@yandex.com>
Signed-off-by: Sergey Bashirov <sergeybashirov@gmail.com>
---
fs/nfsd/nfs4proc.c | 38 +++++++++++++++++++++++++-------------
1 file changed, 25 insertions(+), 13 deletions(-)
diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
index d7c58aa64f06..f9d1548db000 100644
--- a/fs/nfsd/nfs4proc.c
+++ b/fs/nfsd/nfs4proc.c
@@ -2521,6 +2521,7 @@ static __be32
nfsd4_layoutcommit(struct svc_rqst *rqstp,
struct nfsd4_compound_state *cstate, union nfsd4_op_u *u)
{
+ struct net *net = SVC_NET(rqstp);
struct nfsd4_layoutcommit *lcp = &u->layoutcommit;
const struct nfsd4_layout_seg *seg = &lcp->lc_seg;
struct svc_fh *current_fh = &cstate->current_fh;
@@ -2556,23 +2557,34 @@ nfsd4_layoutcommit(struct svc_rqst *rqstp,
}
}
- nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lcp->lc_sid,
- false, lcp->lc_layout_type,
- &ls);
- if (nfserr) {
- trace_nfsd_layout_commit_lookup_fail(&lcp->lc_sid);
- /* fixup error code as per RFC5661 */
- if (nfserr == nfserr_bad_stateid)
- nfserr = nfserr_badlayout;
+ nfserr = nfserr_grace;
+ if (locks_in_grace(net) && !lcp->lc_reclaim)
+ goto out;
+ nfserr = nfserr_no_grace;
+ if (!locks_in_grace(net) && lcp->lc_reclaim)
goto out;
- }
- /* LAYOUTCOMMIT does not require any serialization */
- mutex_unlock(&ls->ls_mutex);
+ if (!lcp->lc_reclaim) {
+ nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate,
+ &lcp->lc_sid, false, lcp->lc_layout_type, &ls);
+ if (nfserr) {
+ trace_nfsd_layout_commit_lookup_fail(&lcp->lc_sid);
+ /* fixup error code as per RFC5661 */
+ if (nfserr == nfserr_bad_stateid)
+ nfserr = nfserr_badlayout;
+ goto out;
+ }
+
+ /* LAYOUTCOMMIT does not require any serialization */
+ mutex_unlock(&ls->ls_mutex);
+ }
nfserr = ops->proc_layoutcommit(inode, rqstp, lcp);
- nfsd4_file_mark_deleg_written(ls->ls_stid.sc_file);
- nfs4_put_stid(&ls->ls_stid);
+
+ if (!lcp->lc_reclaim) {
+ nfsd4_file_mark_deleg_written(ls->ls_stid.sc_file);
+ nfs4_put_stid(&ls->ls_stid);
+ }
out:
return nfserr;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] NFSD: Allow layoutcommit during grace period
2025-09-04 15:48 [PATCH] NFSD: Allow layoutcommit during grace period Sergey Bashirov
@ 2025-09-08 14:36 ` Chuck Lever
0 siblings, 0 replies; 2+ messages in thread
From: Chuck Lever @ 2025-09-08 14:36 UTC (permalink / raw)
To: Jeff Layton, NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey,
Sergey Bashirov
Cc: Chuck Lever, linux-nfs, linux-kernel, Konstantin Evtushenko
From: Chuck Lever <chuck.lever@oracle.com>
On Thu, 04 Sep 2025 18:48:44 +0300, Sergey Bashirov wrote:
> If the loca_reclaim field is set to TRUE, this indicates that the client
> is attempting to commit changes to a layout after the restart of the
> metadata server during the metadata server's recovery grace period. This
> type of request may be necessary when the client has uncommitted writes
> to provisionally allocated byte-ranges of a file that were sent to the
> storage devices before the restart of the metadata server. See RFC 8881,
> section 18.42.3.
>
> [...]
Applied to nfsd-testing, thanks!
[1/1] NFSD: Allow layoutcommit during grace period
commit: ad996d67c7798b41c44203e40c535c3c4d97168a
--
Chuck Lever
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-09-08 14:36 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-04 15:48 [PATCH] NFSD: Allow layoutcommit during grace period Sergey Bashirov
2025-09-08 14:36 ` Chuck Lever
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox