[PATCH v11 5/6] ntfs: do not clear the volume dirty bit during sync

From: Hongling Zeng

Date: Mon Sep 14 2026 - 01:53:24 EST


ntfs_sync_fs() clears VOLUME_IS_DIRTY while the volume is still mounted
read-write, so a sync running concurrently with an in-flight metadata
modification can clear and persist a bit that was just set: the
modification then lands on a volume that is clean on disk, and a crash
does not run chkdsk. Closing this from the writer side would mean
holding the $Volume mrec_lock across the whole operation.

Drop the ntfs_sync_fs() persistence point and leave the clearing to the
remount-to-read-only path, which the VFS reaches only after
sb_prepare_remount_readonly() has drained in-flight writers, and to
ntfs_put_super(), which runs after evict_inodes() on a quiesced
filesystem. A mounted read-write volume now keeps the dirty bit until
it is dismounted cleanly, which matches the NTFS semantics; the cost is
a needless chkdsk if the machine crashes between a sync and the unmount.

Also report sync_blockdev() and blkdev_issue_flush() failures instead
of discarding them: a failed cache flush is real, and
__sync_filesystem() propagates it to syncfs() callers.

The marking comment in ntfs_file_write_iter() is updated to match: the
dirty bit is only cleared at the quiescent transitions, under the same
$Volume mrec_lock the marking takes.

Reported-by: Baolin Liu <liubaolin@xxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Hongling Zeng <zenghongling@xxxxxxxxxx>
---
fs/ntfs/file.c | 7 ++++---
fs/ntfs/super.c | 22 +++++++++++++---------
2 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
index cfc7b36b7dff..99a2c7a5cf81 100644
--- a/fs/ntfs/file.c
+++ b/fs/ntfs/file.c
@@ -621,9 +621,10 @@ static ssize_t ntfs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)

/*
* The volume must be marked dirty before the modification is made,
- * without an unlocked check of the in-memory flag: ntfs_sync_fs()
- * can clear the bit concurrently and the modification would then
- * land on a volume that is clean on disk.
+ * without an unlocked check of the in-memory flag: the dirty bit
+ * is only cleared at the quiescent transitions, under the same
+ * $Volume mrec_lock this call takes, so an unlocked skip could
+ * lose the set to one of them.
*/
ntfs_set_volume_flags(vol, VOLUME_IS_DIRTY);

diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
index 3574c224fe28..f155f16b252d 100644
--- a/fs/ntfs/super.c
+++ b/fs/ntfs/super.c
@@ -486,8 +486,8 @@ int ntfs_set_volume_flags(struct ntfs_volume *vol, __le16 flags)
* This is the single point that persists the in-memory error state to disk.
* The runtime error paths only record NVolErrors() because they run under a
* variety of ntfs locks the dirty-bit write cannot be taken under (runlist
- * locks, vol->lcnbmp_lock, vol->mftbmp_lock, mrec_locks); the first
- * ntfs_sync_fs(), a remount, or the unmount then persists the flag here.
+ * locks, vol->lcnbmp_lock, vol->mftbmp_lock, mrec_locks); a remount to
+ * read-only, or the unmount, then persists the flag here.
*
* A hibernated volume is not written from these persistence paths:
* resuming Windows from a modified image corrupts it, so the dirty bit
@@ -1963,14 +1963,18 @@ static int ntfs_sync_fs(struct super_block *sb, int wait)
if (!wait)
return 0;

- /* If there are some dirty buffers in the bdev inode */
- if (ntfs_sync_volume_dirty_state(vol)) {
- ntfs_warning(sb, "Failed to sync dirty bit in volume information flags. Run chkdsk.");
- err = -EIO;
- }
+ /*
+ * The volume dirty bit is deliberately not cleared here: a sync
+ * running concurrently with an in-flight modification could clear
+ * and persist a bit that was just set, leaving the modification
+ * on a volume that is clean on disk. The bit is only cleared
+ * and persisted at quiescent state transitions: remounting
+ * read-only and clean unmount.
+ */
sync_inodes_sb(sb);
- sync_blockdev(sb->s_bdev);
- blkdev_issue_flush(sb->s_bdev);
+ err = sync_blockdev(sb->s_bdev);
+ if (!err)
+ err = blkdev_issue_flush(sb->s_bdev);
return err;
}

--
2.25.1