Skip to contentSkip to conversation

ntfs: handle block device cache flush in fsync paths

PATCH Applied DaeMyung Kang 3 participants 7 messages Oct 13 – Oct 14

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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
#1 lore raw

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.

Fixes 9c87959601e8 ("ntfs: update file operations")
---
 fs/ntfs/file.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/ntfs/file.c +2 -2
index 58afd310d57b..afc2efb4b699 100644
@@ -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
Reviewed-by Baolin Liu on v1 1/2
#2 lore raw

Re: [PATCH 1/2] ntfs: report block device flush failures from fsync

Quoted 28 lines · DaeMyung Kang

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.

Fixes 9c87959601e8 ("ntfs: update file operations")
---
  fs/ntfs/file.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
fs/ntfs/file.c +2 -0
index 58afd310d57b..afc2efb4b699 100644
@@ -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 -2
  		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;
  }
 

Looks good to me.

#3 lore raw

PATCH 2/2 ntfs: flush the block device when syncing a directory

In reply to DaeMyung Kang

ntfs_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.

Fixes 1e9ea7e04472 ("Revert "fs: Remove NTFS classic"")
---
 fs/ntfs/dir.c | 2 ++
 1 file changed, 2 insertions(+)
fs/ntfs/dir.c +2 -0
index 5a0e21e7c283..fce10baa2b93 100644
@@ -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
Reviewed-by Baolin Liu on v1 2/2
#4 lore raw

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 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.

Fixes 1e9ea7e04472 ("Revert "fs: Remove NTFS classic"")
---
  fs/ntfs/dir.c | 2 ++
  1 file changed, 2 insertions(+)
fs/ntfs/dir.c +0 -0
index 5a0e21e7c283..fce10baa2b93 100644

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.

Reviewed-by Baolin Liu on the v1 series
#5 lore raw
In reply to DaeMyung Kang
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 -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

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.

maintainer Applied
#6 lore raw
In reply to DaeMyung Kang
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 -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

Applied them to #ntfs-next.
Thanks!