Re: [PATCH] 9p: fix data corruption with writeback caching during concurrent stat

From: David Howells

Date: Wed Feb 18 2026 - 09:04:43 EST


Christian Schoenebeck <linux_oss@xxxxxxxxxxxxx> wrote:

> > - int retval = filemap_fdatawrite(inode->i_mapping);
> > + int retval = filemap_write_and_wait(inode->i_mapping);
>
> Haven't reviewed thorougly, but this looks wrong to me. The point about write-
> back is not having to wait for completion.

You should do this if AT_STATX_FORCE_SYNC is set and otherwise not if
AT_STATX_DONT_SYNC is set.

> > + v9fs_stat2inode(st, d_inode(dentry), dentry->d_sb,
> > + (v9ses->cache & CACHE_WRITEBACK) ? V9FS_STAT2INODE_KEEP_ISIZE : 0);
>
> And this measure alone (along with the same change in v9fs_vfs_getattr_dotl()
> that is) would not fix the misbehavior you encountered?

As mentioned in response to v2, I think this is the wrong approach and that
you should compare the retrieved stat->length to ->netfs.remote_i_size and not
update ->i_size if there was no change. Ideally you'd also compare mtime too,
but you don't know what mtime changed to:-/.

David