btrfs: fix silent IO error loss in encoded writes and zoned split
PATCH 1/1 btrfs: fix silent IO error loss in encoded writes and zoned split
can_finish_ordered_extent() and btrfs_finish_ordered_zoned() set BTRFS_ORDERED_IOERR via bare set_bit(). Later, btrfs_mark_ordered_extent_error() in btrfs_finish_one_ordered() uses test_and_set_bit(), finds it already set, and skips mapping_set_error(). The error is never recorded on the inode's address_space, making it invisible to fsync. For encoded writes this causes btrfs receive to silently produce files with zero-filled holes.
Fix: replace bare set_bit(BTRFS_ORDERED_IOERR) with btrfs_mark_ordered_extent_error() which pairs test_and_set_bit() with mapping_set_error(), guaranteeing the error is recorded exactly once.
--- fs/btrfs/ordered-data.c | 2 +- fs/btrfs/zoned.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
fs/btrfs/ordered-data.c +1 -1
@@ -385,7 +385,7 @@ static bool can_finish_ordered_extent(struct btrfs_ordered_extent *ordered, }if (!uptodate) -set_bit (BTRFS_ORDERED_IOERR , &ordered->flags); +btrfs_mark_ordered_extent_error (ordered);if (ordered->bytes_left)return false;
fs/btrfs/zoned.c +1 -1
@@ -2136,7 +2136,7 @@ void btrfs_finish_ordered_zoned(struct btrfs_ordered_extent *ordered)continue ; }if (!btrfs_zoned_split_ordered (ordered, logical, len)) { -set_bit (BTRFS_ORDERED_IOERR , &ordered->flags); +btrfs_mark_ordered_extent_error (ordered);btrfs_err (fs_info,"failed to split ordered extent" ); goto out; }
Signature · 1 line
2.52.0
Quoted 8 lines · Michal Grzedzicki
can_finish_ordered_extent()andbtrfs_finish_ordered_zoned()setBTRFS_ORDERED_IOERRvia bareset_bit(). Later,btrfs_mark_ordered_extent_error()inbtrfs_finish_one_ordered()usestest_and_set_bit(), finds it already set, and skipsmapping_set_error(). The error is never recorded on the inode'saddress_space, making it invisible to fsync. For encoded writes this causes btrfs receive to silently produce files with zero-filled holes.
Quoted 5 lines
Fix: replace bare
set_bit(BTRFS_ORDERED_IOERR)withbtrfs_mark_ordered_extent_error()which pairstest_and_set_bit()withmapping_set_error(), guaranteeing the error is recorded exactly once.Signed-off-by Michal Grzedzicki <[email protected]>
Thanks,
Qu
Quoted 31 lines
--- fs/btrfs/ordered-data.c | 2 +- fs/btrfs/zoned.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)fs/btrfs/ordered-data.c +1
-1@@ -385,7 +385,7 @@ static bool can_finish_ordered_extent(struct btrfs_ordered_extent *ordered, }if (!uptodate) -set_bit (BTRFS_ORDERED_IOERR , &ordered->flags); +btrfs_mark_ordered_extent_error (ordered);if (ordered->bytes_left)return false;fs/btrfs/zoned.c +1
-1@@ -2136,7 +2136,7 @@ void btrfs_finish_ordered_zoned(struct btrfs_ordered_extent *ordered)continue ; }if (!btrfs_zoned_split_ordered (ordered, logical, len)) { -set_bit (BTRFS_ORDERED_IOERR , &ordered->flags); +btrfs_mark_ordered_extent_error (ordered);btrfs_err (fs_info,"failed to split ordered extent" ); goto out; }
Looks good,
Quoted 44 lines · Michal Grzedzicki
can_finish_ordered_extent()andbtrfs_finish_ordered_zoned()setBTRFS_ORDERED_IOERRvia bareset_bit(). Later,btrfs_mark_ordered_extent_error()inbtrfs_finish_one_ordered()usestest_and_set_bit(), finds it already set, and skipsmapping_set_error(). The error is never recorded on the inode'saddress_space, making it invisible to fsync. For encoded writes this causes btrfs receive to silently produce files with zero-filled holes.Fix: replace bare
set_bit(BTRFS_ORDERED_IOERR)withbtrfs_mark_ordered_extent_error()which pairstest_and_set_bit()withmapping_set_error(), guaranteeing the error is recorded exactly once.Signed-off-by Michal Grzedzicki <[email protected]>--- fs/btrfs/ordered-data.c | 2 +- fs/btrfs/zoned.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)fs/btrfs/ordered-data.c +1
-1@@ -385,7 +385,7 @@ static bool can_finish_ordered_extent(struct btrfs_ordered_extent *ordered, }if (!uptodate) -set_bit (BTRFS_ORDERED_IOERR , &ordered->flags); +btrfs_mark_ordered_extent_error (ordered);if (ordered->bytes_left)return false;fs/btrfs/zoned.c +1
-1@@ -2136,7 +2136,7 @@ void btrfs_finish_ordered_zoned(struct btrfs_ordered_extent *ordered)continue ; }if (!btrfs_zoned_split_ordered (ordered, logical, len)) { -set_bit (BTRFS_ORDERED_IOERR , &ordered->flags); +btrfs_mark_ordered_extent_error (ordered);btrfs_err (fs_info,"failed to split ordered extent" ); goto out; }