Check for I_DIRTY_PAGES state in gfs2_fsync() is racy because __writeback_single_inode() unconditionally clears the flag and reinstates it only later based on PAGECACHE_TAG_DIRTY tag. If gfs2_fsync() unlocked read of i_state hits in between, it will not see I_DIRTY_PAGES although there may be dirty folios in the mapping. Check for PAGECACHE_TAG_DIRTY instead and use inode_is_dirty() helper for inode metadata dirtiness check. Signed-off-by: Jan Kara --- fs/gfs2/file.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c index 1efd0679badd..f5532f72ab99 100644 --- a/fs/gfs2/file.c +++ b/fs/gfs2/file.c @@ -749,7 +749,7 @@ static int gfs2_fsync(struct file *file, loff_t start, loff_t end, { struct address_space *mapping = file->f_mapping; struct inode *inode = mapping->host; - int sync_state = inode_state_read_once(inode) & I_DIRTY; + bool dirty_data = mapping_tagged(inode->i_mapping, PAGECACHE_TAG_DIRTY); struct gfs2_glock *gl = gfs2_inode_glock(inode); struct gfs2_inode *ip = GFS2_I(inode); int ret = 0, ret1 = 0; @@ -760,12 +760,8 @@ static int gfs2_fsync(struct file *file, loff_t start, loff_t end, return ret1; } - if (!gfs2_is_jdata(ip)) - sync_state &= ~I_DIRTY_PAGES; - if (datasync) - sync_state &= ~I_DIRTY_SYNC; - - if (sync_state) { + if (inode_is_dirty(inode, datasync) || + (gfs2_is_jdata(ip) && dirty_data)) { ret = sync_inode_metadata(inode, 1); if (ret) return ret; -- 2.53.0