Skip to content

Commit b2c9cd3

Browse files
mitatorvalds
authored andcommitted
fail_make_request: cleanup should_fail_request
This changes should_fail_request() to more usable wrapper function of should_fail(). It can avoid putting #ifdef CONFIG_FAIL_MAKE_REQUEST in the middle of a function. Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com> Cc: Jens Axboe <axboe@kernel.dk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent b2588c4 commit b2c9cd3

1 file changed

Lines changed: 12 additions & 14 deletions

File tree

‎block/blk-core.c‎

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,14 +1361,9 @@ static int __init setup_fail_make_request(char *str)
13611361
}
13621362
__setup("fail_make_request=", setup_fail_make_request);
13631363

1364-
static int should_fail_request(struct bio *bio)
1364+
static bool should_fail_request(struct hd_struct *part, unsigned int bytes)
13651365
{
1366-
struct hd_struct *part = bio->bi_bdev->bd_part;
1367-
1368-
if (part_to_disk(part)->part0.make_it_fail || part->make_it_fail)
1369-
return should_fail(&fail_make_request, bio->bi_size);
1370-
1371-
return 0;
1366+
return part->make_it_fail && should_fail(&fail_make_request, bytes);
13721367
}
13731368

13741369
static int __init fail_make_request_debugfs(void)
@@ -1381,9 +1376,10 @@ late_initcall(fail_make_request_debugfs);
13811376

13821377
#else /* CONFIG_FAIL_MAKE_REQUEST */
13831378

1384-
static inline int should_fail_request(struct bio *bio)
1379+
static inline bool should_fail_request(struct hd_struct *part,
1380+
unsigned int bytes)
13851381
{
1386-
return 0;
1382+
return false;
13871383
}
13881384

13891385
#endif /* CONFIG_FAIL_MAKE_REQUEST */
@@ -1466,6 +1462,7 @@ static inline void __generic_make_request(struct bio *bio)
14661462
old_dev = 0;
14671463
do {
14681464
char b[BDEVNAME_SIZE];
1465+
struct hd_struct *part;
14691466

14701467
q = bdev_get_queue(bio->bi_bdev);
14711468
if (unlikely(!q)) {
@@ -1489,7 +1486,10 @@ static inline void __generic_make_request(struct bio *bio)
14891486
if (unlikely(test_bit(QUEUE_FLAG_DEAD, &q->queue_flags)))
14901487
goto end_io;
14911488

1492-
if (should_fail_request(bio))
1489+
part = bio->bi_bdev->bd_part;
1490+
if (should_fail_request(part, bio->bi_size) ||
1491+
should_fail_request(&part_to_disk(part)->part0,
1492+
bio->bi_size))
14931493
goto end_io;
14941494

14951495
/*
@@ -1704,11 +1704,9 @@ int blk_insert_cloned_request(struct request_queue *q, struct request *rq)
17041704
if (blk_rq_check_limits(q, rq))
17051705
return -EIO;
17061706

1707-
#ifdef CONFIG_FAIL_MAKE_REQUEST
1708-
if (rq->rq_disk && rq->rq_disk->part0.make_it_fail &&
1709-
should_fail(&fail_make_request, blk_rq_bytes(rq)))
1707+
if (rq->rq_disk &&
1708+
should_fail_request(&rq->rq_disk->part0, blk_rq_bytes(rq)))
17101709
return -EIO;
1711-
#endif
17121710

17131711
spin_lock_irqsave(q->queue_lock, flags);
17141712

0 commit comments

Comments
 (0)