]> www.infradead.org Git - users/hch/misc.git/commitdiff
NFSD: Allow layoutcommit during grace period
authorSergey Bashirov <sergeybashirov@gmail.com>
Thu, 4 Sep 2025 15:48:44 +0000 (18:48 +0300)
committerChuck Lever <chuck.lever@oracle.com>
Wed, 1 Oct 2025 19:54:01 +0000 (15:54 -0400)
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>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
fs/nfsd/nfs4proc.c

index 2dc8910f8f722323c237d91292d6c4e4f5e6d1cd..33c21666fa7f517abfd5b4268083eaa37315dc92 100644 (file)
@@ -2526,6 +2526,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;
@@ -2561,23 +2562,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;
 }