mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-07 11:26:02 +09:00
btrfs: fix error handling when submitting direct I/O bio
[ Upstream commit6d3113a193] In btrfs_submit_direct_hook(), if a direct I/O write doesn't span a RAID stripe or chunk, we submit orig_bio without cloning it. In this case, we don't increment pending_bios. Then, if btrfs_submit_dio_bio() fails, we decrement pending_bios to -1, and we never complete orig_bio. Fix it by initializing pending_bios to 1 instead of incrementing later. Fixing this exposes another bug: we put orig_bio prematurely and then put it again from end_io. Fix it by not putting orig_bio. After this change, pending_bios is really more of a reference count, but I'll leave that cleanup separate to keep the fix small. Fixes:e65e153554("btrfs: fix panic caused by direct IO") CC: stable@vger.kernel.org # 4.4+ Reviewed-by: Nikolay Borisov <nborisov@suse.com> Reviewed-by: Josef Bacik <josef@toxicpanda.com> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: Omar Sandoval <osandov@fb.com> Signed-off-by: David Sterba <dsterba@suse.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
3bd1e2596b
commit
74bee8344b
@@ -8399,7 +8399,6 @@ static int btrfs_submit_direct_hook(struct btrfs_dio_private *dip)
|
||||
|
||||
/* bio split */
|
||||
ASSERT(map_length <= INT_MAX);
|
||||
atomic_inc(&dip->pending_bios);
|
||||
do {
|
||||
clone_len = min_t(int, submit_len, map_length);
|
||||
|
||||
@@ -8450,7 +8449,8 @@ submit:
|
||||
if (!status)
|
||||
return 0;
|
||||
|
||||
bio_put(bio);
|
||||
if (bio != orig_bio)
|
||||
bio_put(bio);
|
||||
out_err:
|
||||
dip->errors = 1;
|
||||
/*
|
||||
@@ -8491,7 +8491,7 @@ static void btrfs_submit_direct(struct bio *dio_bio, struct inode *inode,
|
||||
bio->bi_private = dip;
|
||||
dip->orig_bio = bio;
|
||||
dip->dio_bio = dio_bio;
|
||||
atomic_set(&dip->pending_bios, 0);
|
||||
atomic_set(&dip->pending_bios, 1);
|
||||
io_bio = btrfs_io_bio(bio);
|
||||
io_bio->logical = file_offset;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user