From a94e648f03cf4e0def8ab3c74a1f9fe140720dd4 Mon Sep 17 00:00:00 2001 From: Hongling Zeng Date: Thu, 30 Jul 2026 16:42:36 +0800 Subject: [PATCH] xfs: use file target for post-log fsync fallback flush xfs_file_fsync() has a fallback flush for the case where the log force was a no-op, for example fdatasync/O_DSYNC writes that do not require metadata updates. The current fallback path is expressed in terms of the main data device and explicitly excludes realtime inodes. Realtime files with a separate realtime device are flushed before the log force, because their data must reach stable storage before the log commit. For the internal realtime device used by the zoned allocator, writes are out-of-place and update inode and bmap metadata from I/O completion, so the overwrite-without-metadata-update case does not apply in the same way. Even so, the current fallback condition is inconsistent because it is expressed as "non-realtime inode on the main data device" rather than in terms of the inode's actual file data target. Use xfs_inode_buftarg() to obtain the target that stores this file's data, and issue the fallback flush when the log force did not flush anything and the log target is the same as that file target. This preserves existing behavior for regular files while making the fallback logic consistent for files whose data target is selected by the inode. Fixes: bdc03eb5f98f ("xfs: allow internal RT devices for zoned mode") Signed-off-by: Hongling Zeng Suggested-by: Christoph Hellwig Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino --- fs/xfs/xfs_file.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 0ade13b31335..4745f047193c 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -166,17 +166,23 @@ xfs_file_fsync( } /* - * If we only have a single device, and the log force about was - * a no-op we might have to flush the data device cache here. - * This can only happen for fdatasync/O_DSYNC if we were overwriting - * an already allocated file and thus do not have any metadata to - * commit. + * If the log force was a no-op, we may still need to flush the + * file data target cache here. This can happen for fdatasync/O_DSYNC + * when no metadata needed to be committed. + * + * Use the inode's actual file data target rather than assuming the + * main data device. Realtime inodes with a separate realtime device + * are flushed before the log force, so this fallback only applies + * when the file data target is the same as the log target. */ - if (!log_flushed && !XFS_IS_REALTIME_INODE(ip) && - mp->m_logdev_targp == mp->m_ddev_targp) { - err2 = blkdev_issue_flush(mp->m_ddev_targp->bt_bdev); - if (err2 && !error) - error = err2; + if (!log_flushed) { + struct xfs_buftarg *file_targp = xfs_inode_buftarg(ip); + + if (mp->m_logdev_targp == file_targp) { + err2 = blkdev_issue_flush(file_targp->bt_bdev); + if (err2 && !error) + error = err2; + } } return error;