ntfs: handle block device cache flush in fsync paths
Subsystems (2)
cover ntfs: handle block device cache flush in fsync paths
Regular-file fsync currently ignores a block device cache flush failure, while directory fsync never issues a cache flush. Both can report success without ensuring that the data and metadata reached stable storage.
The first patch returns and logs flush failures from regular-file fsync. The second adds a flush to directory fsync and reports its failure. The syncfs path already handles flush errors.
QEMU blkdebug injected -EIO for flush_to_disk on ntfs-next at 04fb910da2c8. Before these changes, both file and directory fsync returned success while syncfs returned -EIO. With the respective fixes, both fsync calls return -EIO. A kretprobe confirmed the flush failures.
DaeMyung Kang (2):
ntfs: report block device flush failures from fsync
ntfs: flush the block device when syncing a directory
fs/ntfs/dir.c | 2 ++ fs/ntfs/file.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-)
base-commit: 04fb910da2c857cdf99a331c576c3e5e7197c6dd
Signature · 1 line
2.43.0
PATCH 1/2 ntfs: report block device flush failures from fsync
ntfs_file_fsync() calls blkdev_issue_flush() after writeback but discards its return value. If the device cannot flush its write cache, fsync() reports success even though the file is not guaranteed to be durable.
Reproduce this with QEMU blkdebug failing flush_to_disk with -EIO. On ntfs-next at 04fb910da2c8, a kretprobe recorded -EIO from blkdev_issue_flush() while fsync() returned 0. With this change, fsync() returns -EIO and logs the failure. The syncfs() path already reports this error.
--- fs/ntfs/file.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/ntfs/file.c +2 -2
@@ -417,14 +417,14 @@ int ntfs_file_fsync(struct file *filp, loff_t start, loff_t end, err =sync_blockdev (vi->i_sb->s_bdev);if (unlikely (err && !ret)) ret = err; +if (!ret) + ret =blkdev_issue_flush (vi->i_sb->s_bdev);if (likely (!ret))ntfs_debug ("Done." );else ntfs_warning (vi->i_sb,"Failed to f%ssync inode 0x%llx. Error %u." , datasync ?"data" :"" , ni->mft_no, -ret); -if (!ret) -blkdev_issue_flush (vi->i_sb->s_bdev);return ret; }
Signature · 1 line
2.43.0
Re: [PATCH 1/2] ntfs: report block device flush failures from fsync
Quoted 28 lines · DaeMyung Kang
ntfs_file_fsync()callsblkdev_issue_flush()after writeback but discards its return value. If the device cannot flush its write cache,fsync()reports success even though the file is not guaranteed to be durable.Reproduce this with QEMU blkdebug failing
flush_to_diskwith-EIO. On ntfs-next at04fb910da2c8, a kretprobe recorded-EIOfromblkdev_issue_flush()whilefsync()returned 0. With this change,fsync()returns-EIOand logs the failure. Thesyncfs()path already reports this error.Fixes 9c87959601e8 ("ntfs: update file operations")Signed-off-by DaeMyung Kang <[email protected]>--- fs/ntfs/file.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/ntfs/file.c +2
-0@@ -417,14 +417,14 @@ int ntfs_file_fsync(struct file *filp, loff_t start, loff_t end, err =sync_blockdev (vi->i_sb->s_bdev);if (unlikely (err && !ret)) ret = err; +if (!ret) + ret =blkdev_issue_flush (vi->i_sb->s_bdev);if (likely (!ret))
fs/ntfs/file.c int ntfs_file_fsync(struct file *filp, loff_t start, loff_t end, · line 430
Quoted 10 lines
fs/ntfs/file.c +0
-2ntfs_debug ("Done." ); else ntfs_warning(vi->i_sb,"Failed to f%ssync inode 0x%llx. Error %u." , datasync ? "data" : "", ni->mft_no, -ret); -if (!ret) -blkdev_issue_flush (vi->i_sb->s_bdev);return ret; }
Looks good to me.
PATCH 2/2 ntfs: flush the block device when syncing a directory
In reply to DaeMyung Kangntfs_dir_fsync() writes directory metadata and calls sync_blockdev(), but does not flush the block device write cache. A successful fsync() can therefore leave the directory's metadata in a volatile device cache.
Issue a cache flush after successful writeback and return any flush error. This matches the regular-file fsync and syncfs paths.
With QEMU blkdebug injecting -EIO for flush_to_disk, fsync() on an NTFS directory returned 0 before this change while syncfs() returned -EIO. After this change, both return -EIO. A kretprobe confirmed the flush error in the directory fsync path.
--- fs/ntfs/dir.c | 2 ++ 1 file changed, 2 insertions(+)
fs/ntfs/dir.c +2 -0
@@ -1192,6 +1192,8 @@ static int ntfs_dir_fsync(struct file *filp, loff_t start, loff_t end, err =sync_blockdev (vi->i_sb->s_bdev);if (unlikely (err && !ret)) ret = err; +if (!ret) + ret =blkdev_issue_flush (vi->i_sb->s_bdev);if (likely (!ret))ntfs_debug ("Done." );else
Signature · 1 line
2.43.0
Re: [PATCH 2/2] ntfs: flush the block device when syncing a directory
Quoted 24 lines · DaeMyung Kang
ntfs_dir_fsync()writes directory metadata and callssync_blockdev(), but does not flush the block device write cache. A successfulfsync()can therefore leave the directory's metadata in a volatile device cache.Issue a cache flush after successful writeback and return any flush error. This matches the regular-file fsync and syncfs paths.
With QEMU blkdebug injecting
-EIOforflush_to_disk,fsync()on an NTFS directory returned 0 before this change whilesyncfs()returned-EIO. After this change, both return-EIO. A kretprobe confirmed the flush error in the directory fsync path.Fixes 1e9ea7e04472 ("Revert "fs: Remove NTFS classic"")Signed-off-by DaeMyung Kang <[email protected]>--- fs/ntfs/dir.c | 2 ++ 1 file changed, 2 insertions(+)fs/ntfs/dir.c +0
-0
fs/ntfs/dir.c static int ntfs_dir_fsync(struct file *filp, loff_t start, loff_t end, · line 1199
Quoted 8 lines
fs/ntfs/dir.c +2
-0@@ -1192,6 +1192,8 @@ static int ntfs_dir_fsync(struct file *filp, loff_t start, loff_t end, err =sync_blockdev (vi->i_sb->s_bdev);if (unlikely (err && !ret)) ret = err; +if (!ret) + ret =blkdev_issue_flush (vi->i_sb->s_bdev);if (likely (!ret))ntfs_debug ("Done." );else
Looks good to me.
Quoted 17 lines · DaeMyung Kang
Regular-file fsync currently ignores a block device cache flush failure, while directory fsync never issues a cache flush. Both can report success without ensuring that the data and metadata reached stable storage.
The first patch returns and logs flush failures from regular-file fsync. The second adds a flush to directory fsync and reports its failure. The syncfs path already handles flush errors.
QEMU blkdebug injected
-EIOforflush_to_diskon ntfs-next at04fb910da2c8. Before these changes, both file and directory fsync returned success while syncfs returned-EIO. With the respective fixes, both fsync calls return-EIO. A kretprobe confirmed the flush failures.DaeMyung Kang (2):
ntfs: report block device flush failures from fsync
ntfs: flush the block device when syncing a directory
Quoted 6 lines
fs/ntfs/dir.c | 2 ++ fs/ntfs/file.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-)base-commit:
04fb910da2c857cdf99a331c576c3e5e7197c6dd
The series looks good to me.
Quoted 9 lines · DaeMyung Kang
Regular-file fsync currently ignores a block device cache flush failure, while directory fsync never issues a cache flush. Both can report success without ensuring that the data and metadata reached stable storage.
The first patch returns and logs flush failures from regular-file fsync. The second adds a flush to directory fsync and reports its failure. The syncfs path already handles flush errors.
Quoted 8 lines
QEMU blkdebug injected
-EIOforflush_to_diskon ntfs-next at04fb910da2c8. Before these changes, both file and directory fsync returned success while syncfs returned-EIO. With the respective fixes, both fsync calls return-EIO. A kretprobe confirmed the flush failures.DaeMyung Kang (2):
ntfs: report block device flush failures from fsync
ntfs: flush the block device when syncing a directory
Applied them to #ntfs-next.
Thanks!