Commit 88022d72 authored by Ming Lei's avatar Ming Lei Committed by Jens Axboe

blk-mq: don't handle failure in .get_budget

It is enough to just check if we can get the budget via .get_budget().
And we don't need to deal with device state change in .get_budget().

For SCSI, one issue to be fixed is that we have to call
scsi_mq_uninit_cmd() to free allocated ressources if SCSI device fails
to handle the request. And it isn't enough to simply call
blk_mq_end_request() to do that if this request is marked as
RQF_DONTPREP.

Fixes: 0df21c86(scsi: implement .get_budget and .put_budget for blk-mq)
Signed-off-by: default avatarMing Lei <ming.lei@redhat.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 826a70a0
...@@ -94,23 +94,18 @@ static void blk_mq_do_dispatch_sched(struct blk_mq_hw_ctx *hctx) ...@@ -94,23 +94,18 @@ static void blk_mq_do_dispatch_sched(struct blk_mq_hw_ctx *hctx)
do { do {
struct request *rq; struct request *rq;
blk_status_t ret;
if (e->type->ops.mq.has_work && if (e->type->ops.mq.has_work &&
!e->type->ops.mq.has_work(hctx)) !e->type->ops.mq.has_work(hctx))
break; break;
ret = blk_mq_get_dispatch_budget(hctx); if (!blk_mq_get_dispatch_budget(hctx))
if (ret == BLK_STS_RESOURCE)
break; break;
rq = e->type->ops.mq.dispatch_request(hctx); rq = e->type->ops.mq.dispatch_request(hctx);
if (!rq) { if (!rq) {
blk_mq_put_dispatch_budget(hctx); blk_mq_put_dispatch_budget(hctx);
break; break;
} else if (ret != BLK_STS_OK) {
blk_mq_end_request(rq, ret);
continue;
} }
/* /*
...@@ -146,22 +141,17 @@ static void blk_mq_do_dispatch_ctx(struct blk_mq_hw_ctx *hctx) ...@@ -146,22 +141,17 @@ static void blk_mq_do_dispatch_ctx(struct blk_mq_hw_ctx *hctx)
do { do {
struct request *rq; struct request *rq;
blk_status_t ret;
if (!sbitmap_any_bit_set(&hctx->ctx_map)) if (!sbitmap_any_bit_set(&hctx->ctx_map))
break; break;
ret = blk_mq_get_dispatch_budget(hctx); if (!blk_mq_get_dispatch_budget(hctx))
if (ret == BLK_STS_RESOURCE)
break; break;
rq = blk_mq_dequeue_from_ctx(hctx, ctx); rq = blk_mq_dequeue_from_ctx(hctx, ctx);
if (!rq) { if (!rq) {
blk_mq_put_dispatch_budget(hctx); blk_mq_put_dispatch_budget(hctx);
break; break;
} else if (ret != BLK_STS_OK) {
blk_mq_end_request(rq, ret);
continue;
} }
/* /*
......
...@@ -1137,13 +1137,8 @@ bool blk_mq_dispatch_rq_list(struct request_queue *q, struct list_head *list, ...@@ -1137,13 +1137,8 @@ bool blk_mq_dispatch_rq_list(struct request_queue *q, struct list_head *list,
} }
} }
if (!got_budget) { if (!got_budget && !blk_mq_get_dispatch_budget(hctx))
ret = blk_mq_get_dispatch_budget(hctx);
if (ret == BLK_STS_RESOURCE)
break; break;
if (ret != BLK_STS_OK)
goto fail_rq;
}
list_del_init(&rq->queuelist); list_del_init(&rq->queuelist);
...@@ -1170,7 +1165,6 @@ bool blk_mq_dispatch_rq_list(struct request_queue *q, struct list_head *list, ...@@ -1170,7 +1165,6 @@ bool blk_mq_dispatch_rq_list(struct request_queue *q, struct list_head *list,
break; break;
} }
fail_rq:
if (unlikely(ret != BLK_STS_OK)) { if (unlikely(ret != BLK_STS_OK)) {
errors++; errors++;
blk_mq_end_request(rq, BLK_STS_IOERR); blk_mq_end_request(rq, BLK_STS_IOERR);
...@@ -1642,12 +1636,10 @@ static void __blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx, ...@@ -1642,12 +1636,10 @@ static void __blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx,
if (!blk_mq_get_driver_tag(rq, NULL, false)) if (!blk_mq_get_driver_tag(rq, NULL, false))
goto insert; goto insert;
ret = blk_mq_get_dispatch_budget(hctx); if (!blk_mq_get_dispatch_budget(hctx)) {
if (ret == BLK_STS_RESOURCE) {
blk_mq_put_driver_tag(rq); blk_mq_put_driver_tag(rq);
goto insert; goto insert;
} else if (ret != BLK_STS_OK) }
goto fail_rq;
new_cookie = request_to_qc_t(hctx, rq); new_cookie = request_to_qc_t(hctx, rq);
...@@ -1665,7 +1657,6 @@ static void __blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx, ...@@ -1665,7 +1657,6 @@ static void __blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx,
__blk_mq_requeue_request(rq); __blk_mq_requeue_request(rq);
goto insert; goto insert;
default: default:
fail_rq:
*cookie = BLK_QC_T_NONE; *cookie = BLK_QC_T_NONE;
blk_mq_end_request(rq, ret); blk_mq_end_request(rq, ret);
return; return;
......
...@@ -147,14 +147,13 @@ static inline void blk_mq_put_dispatch_budget(struct blk_mq_hw_ctx *hctx) ...@@ -147,14 +147,13 @@ static inline void blk_mq_put_dispatch_budget(struct blk_mq_hw_ctx *hctx)
q->mq_ops->put_budget(hctx); q->mq_ops->put_budget(hctx);
} }
static inline blk_status_t blk_mq_get_dispatch_budget( static inline bool blk_mq_get_dispatch_budget(struct blk_mq_hw_ctx *hctx)
struct blk_mq_hw_ctx *hctx)
{ {
struct request_queue *q = hctx->queue; struct request_queue *q = hctx->queue;
if (q->mq_ops->get_budget) if (q->mq_ops->get_budget)
return q->mq_ops->get_budget(hctx); return q->mq_ops->get_budget(hctx);
return BLK_STS_OK; return true;
} }
#endif #endif
...@@ -1955,27 +1955,22 @@ static void scsi_mq_put_budget(struct blk_mq_hw_ctx *hctx) ...@@ -1955,27 +1955,22 @@ static void scsi_mq_put_budget(struct blk_mq_hw_ctx *hctx)
put_device(&sdev->sdev_gendev); put_device(&sdev->sdev_gendev);
} }
static blk_status_t scsi_mq_get_budget(struct blk_mq_hw_ctx *hctx) static bool scsi_mq_get_budget(struct blk_mq_hw_ctx *hctx)
{ {
struct request_queue *q = hctx->queue; struct request_queue *q = hctx->queue;
struct scsi_device *sdev = q->queuedata; struct scsi_device *sdev = q->queuedata;
blk_status_t ret;
ret = prep_to_mq(scsi_prep_state_check(sdev, NULL));
if (ret == BLK_STS_RESOURCE || ret != BLK_STS_OK)
return ret;
if (!get_device(&sdev->sdev_gendev)) if (!get_device(&sdev->sdev_gendev))
goto out; goto out;
if (!scsi_dev_queue_ready(q, sdev)) if (!scsi_dev_queue_ready(q, sdev))
goto out_put_device; goto out_put_device;
return BLK_STS_OK; return true;
out_put_device: out_put_device:
put_device(&sdev->sdev_gendev); put_device(&sdev->sdev_gendev);
out: out:
return BLK_STS_RESOURCE; return false;
} }
static blk_status_t scsi_queue_rq(struct blk_mq_hw_ctx *hctx, static blk_status_t scsi_queue_rq(struct blk_mq_hw_ctx *hctx,
......
...@@ -92,7 +92,7 @@ struct blk_mq_queue_data { ...@@ -92,7 +92,7 @@ struct blk_mq_queue_data {
typedef blk_status_t (queue_rq_fn)(struct blk_mq_hw_ctx *, typedef blk_status_t (queue_rq_fn)(struct blk_mq_hw_ctx *,
const struct blk_mq_queue_data *); const struct blk_mq_queue_data *);
typedef blk_status_t (get_budget_fn)(struct blk_mq_hw_ctx *); typedef bool (get_budget_fn)(struct blk_mq_hw_ctx *);
typedef void (put_budget_fn)(struct blk_mq_hw_ctx *); typedef void (put_budget_fn)(struct blk_mq_hw_ctx *);
typedef enum blk_eh_timer_return (timeout_fn)(struct request *, bool); typedef enum blk_eh_timer_return (timeout_fn)(struct request *, bool);
typedef int (init_hctx_fn)(struct blk_mq_hw_ctx *, void *, unsigned int); typedef int (init_hctx_fn)(struct blk_mq_hw_ctx *, void *, unsigned int);
......
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