Skip to contentSkip to conversation

Btrfs: fix missing error return if writeback for extent buffer never started

PATCH In review [email protected] 3 participants 3 messages Sep 11, 2019 – Sep 23, 2019 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Btrfs: fix missing error return if writeback for extent buffer never started

From: Filipe Manana <[email protected]>

If lock_extent_buffer_for_io() fails, it returns a negative value, but its caller btree_write_cache_pages() ignores such error. This means that a call to flush_write_bio(), from lock_extent_buffer_for_io(), might have failed. We should make btree_write_cache_pages() notice such error values and stop immediatelly, making sure filemap_fdatawrite_range() returns an error to the transaction commit path. A failure from flush_write_bio() should also result in the endio callback end_bio_extent_buffer_writepage() being invoked, which sets the BTRFS_FS_*_ERR bits appropriately, so that there's no risk a transaction or log commit doesn't catch a writeback failure.

---
 fs/btrfs/extent_io.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/btrfs/extent_io.c +4 -0
index 1ff438fd5bc2..13a683da71d2 100644
@@ -3969,6 +3969,10 @@ int btree_write_cache_pages(struct address_space *mapping,
 			if (!ret) {
 				free_extent_buffer(eb);
 				continue;
+			} else if (ret < 0) {
+				done = 1;
+				free_extent_buffer(eb);
+				break;
 			}
 
 			ret = write_one_eb(eb, wbc, &epd);
Signature · 1 line
2.11.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · On Wed, Sep 11, 2019 at 05:42:28PM +0100, [email protected] wrote:

From: Filipe Manana <[email protected]>

If lock_extent_buffer_for_io() fails, it returns a negative value, but its caller btree_write_cache_pages() ignores such error. This means that a call to flush_write_bio(), from lock_extent_buffer_for_io(), might have failed. We should make btree_write_cache_pages() notice such error values and stop immediatelly, making sure filemap_fdatawrite_range() returns an error to the transaction commit path. A failure from flush_write_bio() should also result in the endio callback end_bio_extent_buffer_writepage() being invoked, which sets the BTRFS_FS_*_ERR bits appropriately, so that there's no risk a transaction or log commit doesn't catch a writeback failure.

Quoted 1 line

Thanks,

Josef

#2 lore raw
In reply to [email protected]
Quoted 13 lines · On Wed, Sep 11, 2019 at 05:42:28PM +0100, [email protected] wrote:

From: Filipe Manana <[email protected]>

If lock_extent_buffer_for_io() fails, it returns a negative value, but its caller btree_write_cache_pages() ignores such error. This means that a call to flush_write_bio(), from lock_extent_buffer_for_io(), might have failed. We should make btree_write_cache_pages() notice such error values and stop immediatelly, making sure filemap_fdatawrite_range() returns an error to the transaction commit path. A failure from flush_write_bio() should also result in the endio callback end_bio_extent_buffer_writepage() being invoked, which sets the BTRFS_FS_*_ERR bits appropriately, so that there's no risk a transaction or log commit doesn't catch a writeback failure.

Quoted 1 line

Added to misc-next, thanks.