Skip to content

Commit 9ca0e58

Browse files
adam900710kdave
authored andcommitted
btrfs: merge btrfs_orig_bbio_end_io() into btrfs_bio_end_io()
There are only two differences between the two functions: - btrfs_orig_bbio_end_io() does extra error propagation This is mostly to allow tolerance for write errors. - btrfs_orig_bbio_end_io() does extra pending_ios check This check can handle both the original bio, or the cloned one. (All accounting happens in the original one). This makes btrfs_orig_bbio_end_io() a much safer call. In fact we already had a double freeing error due to usage of btrfs_bio_end_io() in the error path of btrfs_submit_chunk(). So just move the whole content of btrfs_orig_bbio_end_io() into btrfs_bio_end_io(). For normal paths this brings no change, because they are already calling btrfs_orig_bbio_end_io() in the first place. For error paths (not only inside bio.c but also external callers), this change will introduce extra checks, especially for external callers, as they will error out without submitting the btrfs bio. But considering it's already in the error path, such slower but much safer checks are still an overall win. Signed-off-by: Qu Wenruo <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent ac325fc commit 9ca0e58

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

fs/btrfs/bio.c

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,6 @@ static void __btrfs_bio_end_io(struct btrfs_bio *bbio)
120120
}
121121
}
122122

123-
void btrfs_bio_end_io(struct btrfs_bio *bbio, blk_status_t status)
124-
{
125-
bbio->bio.bi_status = status;
126-
__btrfs_bio_end_io(bbio);
127-
}
128-
129123
static void btrfs_orig_write_end_io(struct bio *bio);
130124

131125
static void btrfs_bbio_propagate_error(struct btrfs_bio *bbio,
@@ -147,8 +141,9 @@ static void btrfs_bbio_propagate_error(struct btrfs_bio *bbio,
147141
}
148142
}
149143

150-
static void btrfs_orig_bbio_end_io(struct btrfs_bio *bbio)
144+
void btrfs_bio_end_io(struct btrfs_bio *bbio, blk_status_t status)
151145
{
146+
bbio->bio.bi_status = status;
152147
if (bbio->bio.bi_pool == &btrfs_clone_bioset) {
153148
struct btrfs_bio *orig_bbio = bbio->private;
154149

@@ -179,7 +174,7 @@ static int prev_repair_mirror(struct btrfs_failed_bio *fbio, int cur_mirror)
179174
static void btrfs_repair_done(struct btrfs_failed_bio *fbio)
180175
{
181176
if (atomic_dec_and_test(&fbio->repair_count)) {
182-
btrfs_orig_bbio_end_io(fbio->bbio);
177+
btrfs_bio_end_io(fbio->bbio, fbio->bbio->bio.bi_status);
183178
mempool_free(fbio, &btrfs_failed_bio_pool);
184179
}
185180
}
@@ -326,7 +321,7 @@ static void btrfs_check_read_bio(struct btrfs_bio *bbio, struct btrfs_device *de
326321
if (fbio)
327322
btrfs_repair_done(fbio);
328323
else
329-
btrfs_orig_bbio_end_io(bbio);
324+
btrfs_bio_end_io(bbio, bbio->bio.bi_status);
330325
}
331326

332327
static void btrfs_log_dev_io_error(struct bio *bio, struct btrfs_device *dev)
@@ -360,7 +355,7 @@ static void btrfs_end_bio_work(struct work_struct *work)
360355
if (is_data_bbio(bbio))
361356
btrfs_check_read_bio(bbio, bbio->bio.bi_private);
362357
else
363-
btrfs_orig_bbio_end_io(bbio);
358+
btrfs_bio_end_io(bbio, bbio->bio.bi_status);
364359
}
365360

366361
static void btrfs_simple_end_io(struct bio *bio)
@@ -380,7 +375,7 @@ static void btrfs_simple_end_io(struct bio *bio)
380375
} else {
381376
if (bio_op(bio) == REQ_OP_ZONE_APPEND && !bio->bi_status)
382377
btrfs_record_physical_zoned(bbio);
383-
btrfs_orig_bbio_end_io(bbio);
378+
btrfs_bio_end_io(bbio, bbio->bio.bi_status);
384379
}
385380
}
386381

@@ -394,7 +389,7 @@ static void btrfs_raid56_end_io(struct bio *bio)
394389
if (bio_op(bio) == REQ_OP_READ && is_data_bbio(bbio))
395390
btrfs_check_read_bio(bbio, NULL);
396391
else
397-
btrfs_orig_bbio_end_io(bbio);
392+
btrfs_bio_end_io(bbio, bbio->bio.bi_status);
398393

399394
btrfs_put_bioc(bioc);
400395
}
@@ -424,7 +419,7 @@ static void btrfs_orig_write_end_io(struct bio *bio)
424419
if (bio_op(bio) == REQ_OP_ZONE_APPEND && !bio->bi_status)
425420
stripe->physical = bio->bi_iter.bi_sector << SECTOR_SHIFT;
426421

427-
btrfs_orig_bbio_end_io(bbio);
422+
btrfs_bio_end_io(bbio, bbio->bio.bi_status);
428423
btrfs_put_bioc(bioc);
429424
}
430425

@@ -593,7 +588,7 @@ static void run_one_async_done(struct btrfs_work *work, bool do_free)
593588

594589
/* If an error occurred we just want to clean up the bio and move on. */
595590
if (bio->bi_status) {
596-
btrfs_orig_bbio_end_io(async->bbio);
591+
btrfs_bio_end_io(async->bbio, async->bbio->bio.bi_status);
597592
return;
598593
}
599594

@@ -768,11 +763,9 @@ static bool btrfs_submit_chunk(struct btrfs_bio *bbio, int mirror_num)
768763
ASSERT(bbio->bio.bi_pool == &btrfs_clone_bioset);
769764
ASSERT(remaining);
770765

771-
remaining->bio.bi_status = ret;
772-
btrfs_orig_bbio_end_io(remaining);
766+
btrfs_bio_end_io(remaining, ret);
773767
}
774-
bbio->bio.bi_status = ret;
775-
btrfs_orig_bbio_end_io(bbio);
768+
btrfs_bio_end_io(bbio, ret);
776769
/* Do not submit another chunk */
777770
return true;
778771
}

0 commit comments

Comments
 (0)