Commit b2c9cd37 authored by Akinobu Mita's avatar Akinobu Mita Committed by Linus Torvalds

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: default avatarAkinobu Mita <akinobu.mita@gmail.com>
Cc: Jens Axboe <axboe@kernel.dk>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent b2588c4b
...@@ -1361,14 +1361,9 @@ static int __init setup_fail_make_request(char *str) ...@@ -1361,14 +1361,9 @@ static int __init setup_fail_make_request(char *str)
} }
__setup("fail_make_request=", setup_fail_make_request); __setup("fail_make_request=", setup_fail_make_request);
static int should_fail_request(struct bio *bio) static bool should_fail_request(struct hd_struct *part, unsigned int bytes)
{ {
struct hd_struct *part = bio->bi_bdev->bd_part; return part->make_it_fail && should_fail(&fail_make_request, bytes);
if (part_to_disk(part)->part0.make_it_fail || part->make_it_fail)
return should_fail(&fail_make_request, bio->bi_size);
return 0;
} }
static int __init fail_make_request_debugfs(void) static int __init fail_make_request_debugfs(void)
...@@ -1381,9 +1376,10 @@ late_initcall(fail_make_request_debugfs); ...@@ -1381,9 +1376,10 @@ late_initcall(fail_make_request_debugfs);
#else /* CONFIG_FAIL_MAKE_REQUEST */ #else /* CONFIG_FAIL_MAKE_REQUEST */
static inline int should_fail_request(struct bio *bio) static inline bool should_fail_request(struct hd_struct *part,
unsigned int bytes)
{ {
return 0; return false;
} }
#endif /* CONFIG_FAIL_MAKE_REQUEST */ #endif /* CONFIG_FAIL_MAKE_REQUEST */
...@@ -1466,6 +1462,7 @@ static inline void __generic_make_request(struct bio *bio) ...@@ -1466,6 +1462,7 @@ static inline void __generic_make_request(struct bio *bio)
old_dev = 0; old_dev = 0;
do { do {
char b[BDEVNAME_SIZE]; char b[BDEVNAME_SIZE];
struct hd_struct *part;
q = bdev_get_queue(bio->bi_bdev); q = bdev_get_queue(bio->bi_bdev);
if (unlikely(!q)) { if (unlikely(!q)) {
...@@ -1489,7 +1486,10 @@ static inline void __generic_make_request(struct bio *bio) ...@@ -1489,7 +1486,10 @@ static inline void __generic_make_request(struct bio *bio)
if (unlikely(test_bit(QUEUE_FLAG_DEAD, &q->queue_flags))) if (unlikely(test_bit(QUEUE_FLAG_DEAD, &q->queue_flags)))
goto end_io; goto end_io;
if (should_fail_request(bio)) part = bio->bi_bdev->bd_part;
if (should_fail_request(part, bio->bi_size) ||
should_fail_request(&part_to_disk(part)->part0,
bio->bi_size))
goto end_io; goto end_io;
/* /*
...@@ -1704,11 +1704,9 @@ int blk_insert_cloned_request(struct request_queue *q, struct request *rq) ...@@ -1704,11 +1704,9 @@ int blk_insert_cloned_request(struct request_queue *q, struct request *rq)
if (blk_rq_check_limits(q, rq)) if (blk_rq_check_limits(q, rq))
return -EIO; return -EIO;
#ifdef CONFIG_FAIL_MAKE_REQUEST if (rq->rq_disk &&
if (rq->rq_disk && rq->rq_disk->part0.make_it_fail && should_fail_request(&rq->rq_disk->part0, blk_rq_bytes(rq)))
should_fail(&fail_make_request, blk_rq_bytes(rq)))
return -EIO; return -EIO;
#endif
spin_lock_irqsave(q->queue_lock, flags); spin_lock_irqsave(q->queue_lock, flags);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment