[PATCH 1/2] NFSv4/pNFS: prevent i_size regression while layoutcommit is outstanding
From: Lucheng Bao
Date: Thu Oct 08 2026 - 18:31:39 EST
Commit ac46bd374c9a ("pNFS: Ensure we layoutcommit before revalidating
attributes") replaced outstanding-layoutcommit attribute filtering with
synchronization before explicit revalidation. For layouts requiring
LAYOUTCOMMIT, OPEN attributes can still shrink i_size before metadata
synchronization completes.
Commit d8c951c313ed ("NFSv4.1: Don't trust attributes if a pNFS
LAYOUTCOMMIT is outstanding") moved LAYOUTCOMMIT post-op attribute
processing after cleanup, leaving another unprotected window after
NFS_INO_LAYOUTCOMMITTING is cleared.
Extend the existing writeback checks to reject smaller sizes while a
LAYOUTCOMMIT is pending or in flight, preserving size increases and WCC
checks. Process the reply's attributes and establish their generation
barrier before cleanup removes that protection.
Fixes: d8c951c313ed ("NFSv4.1: Don't trust attributes if a pNFS LAYOUTCOMMIT is outstanding")
Fixes: ac46bd374c9a ("pNFS: Ensure we layoutcommit before revalidating attributes")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lucheng Bao <lubao@xxxxxxxxxxxxxxxx>
---
fs/nfs/inode.c | 8 ++++++--
fs/nfs/nfs4proc.c | 2 +-
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index 3022454f7698..11432f521b04 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -1636,7 +1636,9 @@ static void nfs_wcc_update_inode(struct inode *inode, struct nfs_fattr *fattr)
if ((fattr->valid & NFS_ATTR_FATTR_PRESIZE)
&& (fattr->valid & NFS_ATTR_FATTR_SIZE)
&& i_size_read(inode) == nfs_size_to_loff_t(fattr->pre_size)
- && !nfs_have_writebacks(inode)) {
+ && !nfs_have_writebacks(inode)
+ && (nfs_size_to_loff_t(fattr->size) >= i_size_read(inode)
+ || !pnfs_layoutcommit_outstanding(inode))) {
trace_nfs_size_wcc(inode, fattr->size);
i_size_write(inode, nfs_size_to_loff_t(fattr->size));
}
@@ -2392,7 +2394,9 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
if (new_isize != cur_isize && !have_delegation) {
/* Do we perhaps have any outstanding writes, or has
* the file grown beyond our last write? */
- if (!nfs_have_writebacks(inode) || new_isize > cur_isize) {
+ if ((!nfs_have_writebacks(inode) &&
+ !pnfs_layoutcommit_outstanding(inode)) ||
+ new_isize > cur_isize) {
trace_nfs_size_update(inode, new_isize);
i_size_write(inode, new_isize);
if (!have_writers)
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 04b1987115d5..1ae047a062b8 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -10093,9 +10093,9 @@ static void nfs4_layoutcommit_release(void *calldata)
{
struct nfs4_layoutcommit_data *data = calldata;
- pnfs_cleanup_layoutcommit(data);
nfs_post_op_update_inode_force_wcc(data->args.inode,
data->res.fattr);
+ pnfs_cleanup_layoutcommit(data);
put_cred(data->cred);
nfs_iput_and_deactive(data->inode);
kfree(data);
--
2.34.1