Re: [BUG] 9p: data corruption with cache=mmap under concurrent stat/write

From: David Howells

Date: Mon Jan 05 2026 - 02:54:44 EST


Christian Schoenebeck <linux_oss@xxxxxxxxxxxxx> wrote:

> > > 2. Both getattr and setattr call filemap_fdatawrite() which initiates
> > >
> > > writeback but doesn't wait for completion. The subsequent server
> > > stat/wstat sees stale file size.
> > >
> > > Would using filemap_write_and_wait() instead be the correct fix?
>
> ... you are seeing a 2nd issue? getattr() output should not be related to
> mmap() access.

getattr() may flush outstanding dirty data on an inode so that the stats are
correct - but if so, it should wait for completion. If you look at cifs and
nfs, those uses filemap_datawait() or filemap_write_and_wait(), rather then
filemap_datawrite().

You might also want to check flags & AT_STATX_FORCE_SYNC and flags &
AT_STATX_DONT_SYNC.

I really ought to make afs honour AT_STATX_FORCE_SYNC.

David