PAGECACHE_TAG_DIRTY is the authoritative source of dirty folios present in the mapping. Use that instead of looking at I_DIRTY_PAGES inode state which can get stale for example when folios are written directly with filemap_fdatawrite(), which is how orangefs_flush() and orangefs_fsync() write the mapping. So a getattr keeps serving the cached inode after the folios are clean. The dirty tag alone is not enough. folio_start_writeback() clears it and sets PAGECACHE_TAG_WRITEBACK before wait_for_direct_io() sends the write. OrangeFS writepages does not return until that call finishes, so I_DIRTY_PAGES still covers the round trip today. A getattr that looks only at the dirty tag stores the server's old size while the write is in flight. orangefs_writepage_locked() then reads that size and shortens the write. Hold the cached attributes while either tag is set. Signed-off-by: Jan Kara --- fs/orangefs/orangefs-utils.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/fs/orangefs/orangefs-utils.c b/fs/orangefs/orangefs-utils.c index 9ab1119ebd28..241b10858b31 100644 --- a/fs/orangefs/orangefs-utils.c +++ b/fs/orangefs/orangefs-utils.c @@ -233,6 +233,20 @@ static int orangefs_inode_is_stale(struct inode *inode, return 0; } +/* + * Dirty and writeback tags, not I_DIRTY_PAGES. filemap_fdatawrite() + * leaves that flag set after the folios are clean. folio_start_writeback() + * clears the dirty tag before wait_for_direct_io() returns, so the + * writeback tag is what covers the server write. + */ +static bool orangefs_writeback_pending(struct inode *inode) +{ + struct address_space *mapping = inode->i_mapping; + + return mapping_tagged(mapping, PAGECACHE_TAG_DIRTY) || + mapping_tagged(mapping, PAGECACHE_TAG_WRITEBACK); +} + int orangefs_inode_getattr(struct inode *inode, int flags) { struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode); @@ -247,7 +261,7 @@ int orangefs_inode_getattr(struct inode *inode, int flags) spin_lock(&inode->i_lock); /* Must have all the attributes in the mask and be within cache time. */ if ((!flags && time_before(jiffies, orangefs_inode->getattr_time)) || - orangefs_inode->attr_valid || inode_state_read(inode) & I_DIRTY_PAGES) { + orangefs_inode->attr_valid || orangefs_writeback_pending(inode)) { if (orangefs_inode->attr_valid) { spin_unlock(&inode->i_lock); write_inode_now(inode, 1); @@ -281,13 +295,13 @@ int orangefs_inode_getattr(struct inode *inode, int flags) spin_lock(&inode->i_lock); /* Must have all the attributes in the mask and be within cache time. */ if ((!flags && time_before(jiffies, orangefs_inode->getattr_time)) || - orangefs_inode->attr_valid || inode_state_read(inode) & I_DIRTY_PAGES) { + orangefs_inode->attr_valid || orangefs_writeback_pending(inode)) { if (orangefs_inode->attr_valid) { spin_unlock(&inode->i_lock); write_inode_now(inode, 1); goto again2; } - if (inode_state_read(inode) & I_DIRTY_PAGES) { + if (orangefs_writeback_pending(inode)) { ret = 0; goto out_unlock; } -- 2.53.0