Linux XFS filesystem development
 help / color / mirror / Atom feed
* [PATCH] xfs: fix fallback data device flush for realtime inodes
@ 2026-07-29  7:39 Hongling Zeng
  2026-07-29  8:34 ` Christoph Hellwig
  0 siblings, 1 reply; 4+ messages in thread
From: Hongling Zeng @ 2026-07-29  7:39 UTC (permalink / raw)
  To: cem, dchinner
  Cc: linux-xfs, linux-kernel, zhongling0719, Hongling Zeng, stable

xfs_file_fsync() has a fallback flush for the case where the log force
was a no-op, for example fdatasync/O_DSYNC overwrites of already
allocated file data with no metadata updates.

The current fallback path is limited to non-realtime inodes and always
flushes mp->m_ddev_targp. This misses realtime inodes whose data target
is selected by the inode and may be mp->m_rtdev_targp.

Use xfs_inode_buftarg(ip) to obtain the actual data target for the inode,
and perform the fallback flush when the log force did not flush anything
and the log target is the same as that data target.

This preserves the existing behavior for regular inodes while allowing
the fallback flush to cover realtime inodes whose data target shares the
log device.

Fixes: 2291dab2c9d1 ("xfs: Always flush caches when integrity is required")
Cc: stable@vger.kernel.org
Signed-off-by: Hongling Zeng <zenghongling@kylinos.cn>
---
 fs/xfs/xfs_file.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
index 0ade13b31335..2a6186f67979 100644
--- a/fs/xfs/xfs_file.c
+++ b/fs/xfs/xfs_file.c
@@ -166,17 +166,22 @@ 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
+	 * data device cache for fdatasync/O_DSYNC overwrites of already
+	 * allocated file data with no metadata updates.
+	 *
+	 * Use the inode's actual data target (which may be the RT device
+	 * for realtime inodes) and flush only if it shares the device
+	 * with 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 *data_targp = xfs_inode_buftarg(ip);
+
+		if (mp->m_logdev_targp == data_targp) {
+			err2 = blkdev_issue_flush(data_targp->bt_bdev);
+			if (err2 && !error)
+				error = err2;
+		}
 	}
 
 	return error;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-07-29 14:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-29  7:39 [PATCH] xfs: fix fallback data device flush for realtime inodes Hongling Zeng
2026-07-29  8:34 ` Christoph Hellwig
2026-07-29  8:59   ` Hongling Zeng
2026-07-29 14:28     ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox