Skip to content

Commit 53f2bca

Browse files
Chengming Zhouaxboe
authored andcommitted
block/null_blk: Fix double blk_mq_start_request() warning
When CONFIG_BLK_DEV_NULL_BLK_FAULT_INJECTION is enabled, null_queue_rq() would return BLK_STS_RESOURCE or BLK_STS_DEV_RESOURCE for the request, which has been marked as MQ_RQ_IN_FLIGHT by blk_mq_start_request(). Then null_queue_rqs() put these requests in the rqlist, return back to the block layer core, which would try to queue them individually again, so the warning in blk_mq_start_request() triggered. Fix it by splitting the null_queue_rq() into two parts: the first is the preparation of request, the second is the handling of request. We put the blk_mq_start_request() after the preparation part, which may fail and return back to the block layer core. The throttling also belongs to the preparation part, so move it before blk_mq_start_request(). And change the return type of null_handle_cmd() to void, since it always return BLK_STS_OK now. Reported-by: <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ Fixes: d78bfa1 ("block/null_blk: add queue_rqs() support") Suggested-by: Bart Van Assche <[email protected]> Signed-off-by: Chengming Zhou <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent c96b817 commit 53f2bca

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

drivers/block/null_blk/main.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,19 +1464,13 @@ blk_status_t null_process_cmd(struct nullb_cmd *cmd, enum req_op op,
14641464
return BLK_STS_OK;
14651465
}
14661466

1467-
static blk_status_t null_handle_cmd(struct nullb_cmd *cmd, sector_t sector,
1468-
sector_t nr_sectors, enum req_op op)
1467+
static void null_handle_cmd(struct nullb_cmd *cmd, sector_t sector,
1468+
sector_t nr_sectors, enum req_op op)
14691469
{
14701470
struct nullb_device *dev = cmd->nq->dev;
14711471
struct nullb *nullb = dev->nullb;
14721472
blk_status_t sts;
14731473

1474-
if (test_bit(NULLB_DEV_FL_THROTTLED, &dev->flags)) {
1475-
sts = null_handle_throttled(cmd);
1476-
if (sts != BLK_STS_OK)
1477-
return sts;
1478-
}
1479-
14801474
if (op == REQ_OP_FLUSH) {
14811475
cmd->error = errno_to_blk_status(null_handle_flush(nullb));
14821476
goto out;
@@ -1493,7 +1487,6 @@ static blk_status_t null_handle_cmd(struct nullb_cmd *cmd, sector_t sector,
14931487

14941488
out:
14951489
nullb_complete_cmd(cmd);
1496-
return BLK_STS_OK;
14971490
}
14981491

14991492
static enum hrtimer_restart nullb_bwtimer_fn(struct hrtimer *timer)
@@ -1724,8 +1717,6 @@ static blk_status_t null_queue_rq(struct blk_mq_hw_ctx *hctx,
17241717
cmd->fake_timeout = should_timeout_request(rq) ||
17251718
blk_should_fake_timeout(rq->q);
17261719

1727-
blk_mq_start_request(rq);
1728-
17291720
if (should_requeue_request(rq)) {
17301721
/*
17311722
* Alternate between hitting the core BUSY path, and the
@@ -1738,6 +1729,15 @@ static blk_status_t null_queue_rq(struct blk_mq_hw_ctx *hctx,
17381729
return BLK_STS_OK;
17391730
}
17401731

1732+
if (test_bit(NULLB_DEV_FL_THROTTLED, &nq->dev->flags)) {
1733+
blk_status_t sts = null_handle_throttled(cmd);
1734+
1735+
if (sts != BLK_STS_OK)
1736+
return sts;
1737+
}
1738+
1739+
blk_mq_start_request(rq);
1740+
17411741
if (is_poll) {
17421742
spin_lock(&nq->poll_lock);
17431743
list_add_tail(&rq->queuelist, &nq->poll_list);
@@ -1747,7 +1747,8 @@ static blk_status_t null_queue_rq(struct blk_mq_hw_ctx *hctx,
17471747
if (cmd->fake_timeout)
17481748
return BLK_STS_OK;
17491749

1750-
return null_handle_cmd(cmd, sector, nr_sectors, req_op(rq));
1750+
null_handle_cmd(cmd, sector, nr_sectors, req_op(rq));
1751+
return BLK_STS_OK;
17511752
}
17521753

17531754
static void null_queue_rqs(struct request **rqlist)

0 commit comments

Comments
 (0)