Skip to contentSkip to conversation

NFSD: Disallow layoutget during grace period

PATCH Superseded Sergey Bashirov 3 participants 4 messages Aug 25, 2025 – Sep 5, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 NFSD: Disallow layoutget during grace period

When the server is recovering from a reboot and is in a grace period, any operation that may result in deletion or reallocation of block extents should not be allowed. See RFC 8881, section 18.43.3.

If multiple clients write data to the same file, rebooting the server during writing may result in file corruption. In the worst case, the exported XFS may also become corrupted. Observed this behavior while testing pNFS block volume setup.

---
 fs/nfsd/nfs4proc.c | 5 +++++
 1 file changed, 5 insertions(+)
fs/nfsd/nfs4proc.c +5 -0
index bfebe6e25638a..3000b43be9221 100644
@@ -2435,6 +2435,7 @@ static __be32
 nfsd4_layoutget(struct svc_rqst *rqstp,
 		struct nfsd4_compound_state *cstate, union nfsd4_op_u *u)
 {
+	struct net *net = SVC_NET(rqstp);
 	struct nfsd4_layoutget *lgp = &u->layoutget;
 	struct svc_fh *current_fh = &cstate->current_fh;
 	const struct nfsd4_layout_ops *ops;
@@ -2486,6 +2487,10 @@ nfsd4_layoutget(struct svc_rqst *rqstp,
 	if (lgp->lg_seg.length == 0)
 		goto out;
 
+	nfserr = nfserr_grace;
+	if (locks_in_grace(net))
+		goto out;
+
 	nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lgp->lg_sid,
 						true, lgp->lg_layout_type, &ls);
 	if (nfserr) {
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 29 lines · Sergey Bashirov

When the server is recovering from a reboot and is in a grace period, any operation that may result in deletion or reallocation of block extents should not be allowed. See RFC 8881, section 18.43.3.

If multiple clients write data to the same file, rebooting the server during writing may result in file corruption. In the worst case, the exported XFS may also become corrupted. Observed this behavior while testing pNFS block volume setup.

---
 fs/nfsd/nfs4proc.c | 5 +++++
 1 file changed, 5 insertions(+)
fs/nfsd/nfs4proc.c +1 -0
index bfebe6e25638a..3000b43be9221 100644
@@ -2435,6 +2435,7 @@ static __be32
 nfsd4_layoutget(struct svc_rqst *rqstp,
 		struct nfsd4_compound_state *cstate, union nfsd4_op_u *u)
 {
+	struct net *net = SVC_NET(rqstp);
 	struct nfsd4_layoutget *lgp = &u->layoutget;
 	struct svc_fh *current_fh = &cstate->current_fh;
 	const struct nfsd4_layout_ops *ops;

fs/nfsd/nfs4proc.c nfsd4_layoutget(struct svc_rqst *rqstp, · line 2496

Quoted 10 lines
fs/nfsd/nfs4proc.c +4 -0
@@ -2486,6 +2487,10 @@ nfsd4_layoutget(struct svc_rqst *rqstp,
 	if (lgp->lg_seg.length == 0)
 		goto out;
 
+	nfserr = nfserr_grace;
+	if (locks_in_grace(net))
+		goto out;
+
 	nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lgp->lg_sid,
 						true, lgp->lg_layout_type, &ls);
 	if (nfserr) {

This seems like a reasonable thing to do, but I wonder if it makes sense across all different pNFS layout types? This restriction is definitely not needed for the (trivial) in-kernel flexfiles server, for instance.

Maybe it'd be best to push this down into the individual layout drivers and let them make the decision?

Signature · 1 line
Jeff Layton <[email protected]>
#2 lore raw

Hi Jeff,

Quoted 7 lines · Jeff Layton

This seems like a reasonable thing to do, but I wonder if it makes sense across all different pNFS layout types? This restriction is definitely not needed for the (trivial) in-kernel flexfiles server, for instance.

Maybe it'd be best to push this down into the individual layout drivers and let them make the decision?

Good point. The spec says: "If the metadata server is in a grace period, and does not persist layouts and device ID to device address mappings, then it MUST return NFS4ERR_GRACE". As far as I understand, this is a requirement for a specific implementation option. So moving this logic to the layout driver level seems reasonable to me. Will submit new patch.

--
Sergey Bashirov

maintainer
#3 lore raw
In reply to Sergey Bashirov

From: Chuck Lever <[email protected]>

Quoted 10 lines · Sergey Bashirov

When the server is recovering from a reboot and is in a grace period, any operation that may result in deletion or reallocation of block extents should not be allowed. See RFC 8881, section 18.43.3.

If multiple clients write data to the same file, rebooting the server during writing may result in file corruption. In the worst case, the exported XFS may also become corrupted. Observed this behavior while testing pNFS block volume setup.

[...]

Applied to nfsd-testing, thanks!

[1/1] NFSD: Disallow layoutget during grace period

      commit: c4df20612a34b4713e81e0b3612a84481f6ae82e

--
Chuck Lever