* [PATCH v3] xfs: use file target for post-log fsync fallback flush
@ 2026-07-30 8:42 Hongling Zeng
2026-07-30 8:48 ` Christoph Hellwig
0 siblings, 1 reply; 2+ messages in thread
From: Hongling Zeng @ 2026-07-30 8:42 UTC (permalink / raw)
To: hch, cem, dchinner; +Cc: linux-xfs, linux-kernel, zhongling0719, Hongling Zeng
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 <zenghongling@kylinos.cn>
Suggested-by: Christoph Hellwig <hch@infradead.org>
---
Change in v3:
- Correct the fix tag.
---
Change in v2:
- Update commit log based on Christoph Hellwig's explanation about realtime
device flushing and the internal realtime device used by the zoned allocator.
- Rename data_targp to file_targp to avoid confusion with the main data
device.
---
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;
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH v3] xfs: use file target for post-log fsync fallback flush
2026-07-30 8:42 [PATCH v3] xfs: use file target for post-log fsync fallback flush Hongling Zeng
@ 2026-07-30 8:48 ` Christoph Hellwig
0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2026-07-30 8:48 UTC (permalink / raw)
To: Hongling Zeng; +Cc: hch, cem, dchinner, linux-xfs, linux-kernel, zhongling0719
On Thu, Jul 30, 2026 at 04:42:36PM +0800, Hongling Zeng wrote:
> 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 <zenghongling@kylinos.cn>
> Suggested-by: Christoph Hellwig <hch@infradead.org>
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-07-30 8:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-30 8:42 [PATCH v3] xfs: use file target for post-log fsync fallback flush Hongling Zeng
2026-07-30 8:48 ` Christoph Hellwig
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.