Skip to content

Commit

Permalink
blk-mq: switch ->queue_rq return value to blk_status_t
Browse files Browse the repository at this point in the history
Use the same values for use for request completion errors as the return
value from ->queue_rq.  BLK_STS_RESOURCE is special cased to cause
a requeue, and all the others are completed as-is.

Signed-off-by: Christoph Hellwig <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Christoph Hellwig authored and axboe committed Jun 9, 2017
1 parent 2a842ac commit fc17b65
Show file tree
Hide file tree
Showing 18 changed files with 131 additions and 142 deletions.
37 changes: 17 additions & 20 deletions block/blk-mq.c
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ bool blk_mq_dispatch_rq_list(struct request_queue *q, struct list_head *list)
{
struct blk_mq_hw_ctx *hctx;
struct request *rq;
int errors, queued, ret = BLK_MQ_RQ_QUEUE_OK;
int errors, queued;

if (list_empty(list))
return false;
Expand All @@ -935,6 +935,7 @@ bool blk_mq_dispatch_rq_list(struct request_queue *q, struct list_head *list)
errors = queued = 0;
do {
struct blk_mq_queue_data bd;
blk_status_t ret;

rq = list_first_entry(list, struct request, queuelist);
if (!blk_mq_get_driver_tag(rq, &hctx, false)) {
Expand Down Expand Up @@ -975,25 +976,20 @@ bool blk_mq_dispatch_rq_list(struct request_queue *q, struct list_head *list)
}

ret = q->mq_ops->queue_rq(hctx, &bd);
switch (ret) {
case BLK_MQ_RQ_QUEUE_OK:
queued++;
break;
case BLK_MQ_RQ_QUEUE_BUSY:
if (ret == BLK_STS_RESOURCE) {
blk_mq_put_driver_tag_hctx(hctx, rq);
list_add(&rq->queuelist, list);
__blk_mq_requeue_request(rq);
break;
default:
pr_err("blk-mq: bad return on queue: %d\n", ret);
case BLK_MQ_RQ_QUEUE_ERROR:
}

if (unlikely(ret != BLK_STS_OK)) {
errors++;
blk_mq_end_request(rq, BLK_STS_IOERR);
break;
continue;
}

if (ret == BLK_MQ_RQ_QUEUE_BUSY)
break;
queued++;
} while (!list_empty(list));

hctx->dispatched[queued_to_index(queued)]++;
Expand Down Expand Up @@ -1031,7 +1027,7 @@ bool blk_mq_dispatch_rq_list(struct request_queue *q, struct list_head *list)
* - blk_mq_run_hw_queue() checks whether or not a queue has
* been stopped before rerunning a queue.
* - Some but not all block drivers stop a queue before
* returning BLK_MQ_RQ_QUEUE_BUSY. Two exceptions are scsi-mq
* returning BLK_STS_RESOURCE. Two exceptions are scsi-mq
* and dm-rq.
*/
if (!blk_mq_sched_needs_restart(hctx) &&
Expand Down Expand Up @@ -1410,7 +1406,7 @@ static void __blk_mq_try_issue_directly(struct request *rq, blk_qc_t *cookie,
};
struct blk_mq_hw_ctx *hctx;
blk_qc_t new_cookie;
int ret;
blk_status_t ret;

if (q->elevator)
goto insert;
Expand All @@ -1426,18 +1422,19 @@ static void __blk_mq_try_issue_directly(struct request *rq, blk_qc_t *cookie,
* would have done
*/
ret = q->mq_ops->queue_rq(hctx, &bd);
if (ret == BLK_MQ_RQ_QUEUE_OK) {
switch (ret) {
case BLK_STS_OK:
*cookie = new_cookie;
return;
}

if (ret == BLK_MQ_RQ_QUEUE_ERROR) {
case BLK_STS_RESOURCE:
__blk_mq_requeue_request(rq);
goto insert;
default:
*cookie = BLK_QC_T_NONE;
blk_mq_end_request(rq, BLK_STS_IOERR);
blk_mq_end_request(rq, ret);
return;
}

__blk_mq_requeue_request(rq);
insert:
blk_mq_sched_insert_request(rq, false, true, false, may_sleep);
}
Expand Down
6 changes: 3 additions & 3 deletions drivers/block/loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -1674,7 +1674,7 @@ int loop_unregister_transfer(int number)
EXPORT_SYMBOL(loop_register_transfer);
EXPORT_SYMBOL(loop_unregister_transfer);

static int loop_queue_rq(struct blk_mq_hw_ctx *hctx,
static blk_status_t loop_queue_rq(struct blk_mq_hw_ctx *hctx,
const struct blk_mq_queue_data *bd)
{
struct loop_cmd *cmd = blk_mq_rq_to_pdu(bd->rq);
Expand All @@ -1683,7 +1683,7 @@ static int loop_queue_rq(struct blk_mq_hw_ctx *hctx,
blk_mq_start_request(bd->rq);

if (lo->lo_state != Lo_bound)
return BLK_MQ_RQ_QUEUE_ERROR;
return BLK_STS_IOERR;

switch (req_op(cmd->rq)) {
case REQ_OP_FLUSH:
Expand All @@ -1698,7 +1698,7 @@ static int loop_queue_rq(struct blk_mq_hw_ctx *hctx,

kthread_queue_work(&lo->worker, &cmd->work);

return BLK_MQ_RQ_QUEUE_OK;
return BLK_STS_OK;
}

static void loop_handle_cmd(struct loop_cmd *cmd)
Expand Down
17 changes: 8 additions & 9 deletions drivers/block/mtip32xx/mtip32xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -3633,16 +3633,16 @@ static bool mtip_check_unal_depth(struct blk_mq_hw_ctx *hctx,
return false;
}

static int mtip_issue_reserved_cmd(struct blk_mq_hw_ctx *hctx,
struct request *rq)
static blk_status_t mtip_issue_reserved_cmd(struct blk_mq_hw_ctx *hctx,
struct request *rq)
{
struct driver_data *dd = hctx->queue->queuedata;
struct mtip_int_cmd *icmd = rq->special;
struct mtip_cmd *cmd = blk_mq_rq_to_pdu(rq);
struct mtip_cmd_sg *command_sg;

if (mtip_commands_active(dd->port))
return BLK_MQ_RQ_QUEUE_BUSY;
return BLK_STS_RESOURCE;

/* Populate the SG list */
cmd->command_header->opts =
Expand All @@ -3666,10 +3666,10 @@ static int mtip_issue_reserved_cmd(struct blk_mq_hw_ctx *hctx,

blk_mq_start_request(rq);
mtip_issue_non_ncq_command(dd->port, rq->tag);
return BLK_MQ_RQ_QUEUE_OK;
return 0;
}

static int mtip_queue_rq(struct blk_mq_hw_ctx *hctx,
static blk_status_t mtip_queue_rq(struct blk_mq_hw_ctx *hctx,
const struct blk_mq_queue_data *bd)
{
struct request *rq = bd->rq;
Expand All @@ -3681,15 +3681,14 @@ static int mtip_queue_rq(struct blk_mq_hw_ctx *hctx,
return mtip_issue_reserved_cmd(hctx, rq);

if (unlikely(mtip_check_unal_depth(hctx, rq)))
return BLK_MQ_RQ_QUEUE_BUSY;
return BLK_STS_RESOURCE;

blk_mq_start_request(rq);

ret = mtip_submit_request(hctx, rq);
if (likely(!ret))
return BLK_MQ_RQ_QUEUE_OK;

return BLK_MQ_RQ_QUEUE_ERROR;
return BLK_STS_OK;
return BLK_STS_IOERR;
}

static void mtip_free_cmd(struct blk_mq_tag_set *set, struct request *rq,
Expand Down
12 changes: 4 additions & 8 deletions drivers/block/nbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index)
nsock->pending = req;
nsock->sent = sent;
}
return BLK_MQ_RQ_QUEUE_BUSY;
return BLK_STS_RESOURCE;
}
dev_err_ratelimited(disk_to_dev(nbd->disk),
"Send control failed (result %d)\n", result);
Expand Down Expand Up @@ -510,7 +510,7 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index)
*/
nsock->pending = req;
nsock->sent = sent;
return BLK_MQ_RQ_QUEUE_BUSY;
return BLK_STS_RESOURCE;
}
dev_err(disk_to_dev(nbd->disk),
"Send data failed (result %d)\n",
Expand Down Expand Up @@ -798,7 +798,7 @@ static int nbd_handle_cmd(struct nbd_cmd *cmd, int index)
return ret;
}

static int nbd_queue_rq(struct blk_mq_hw_ctx *hctx,
static blk_status_t nbd_queue_rq(struct blk_mq_hw_ctx *hctx,
const struct blk_mq_queue_data *bd)
{
struct nbd_cmd *cmd = blk_mq_rq_to_pdu(bd->rq);
Expand All @@ -822,13 +822,9 @@ static int nbd_queue_rq(struct blk_mq_hw_ctx *hctx,
* appropriate.
*/
ret = nbd_handle_cmd(cmd, hctx->queue_num);
if (ret < 0)
ret = BLK_MQ_RQ_QUEUE_ERROR;
if (!ret)
ret = BLK_MQ_RQ_QUEUE_OK;
complete(&cmd->send_complete);

return ret;
return ret < 0 ? BLK_STS_IOERR : BLK_STS_OK;
}

static int nbd_add_socket(struct nbd_device *nbd, unsigned long arg,
Expand Down
4 changes: 2 additions & 2 deletions drivers/block/null_blk.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ static void null_request_fn(struct request_queue *q)
}
}

static int null_queue_rq(struct blk_mq_hw_ctx *hctx,
static blk_status_t null_queue_rq(struct blk_mq_hw_ctx *hctx,
const struct blk_mq_queue_data *bd)
{
struct nullb_cmd *cmd = blk_mq_rq_to_pdu(bd->rq);
Expand All @@ -373,7 +373,7 @@ static int null_queue_rq(struct blk_mq_hw_ctx *hctx,
blk_mq_start_request(bd->rq);

null_handle_cmd(cmd);
return BLK_MQ_RQ_QUEUE_OK;
return BLK_STS_OK;
}

static void null_init_queue(struct nullb *nullb, struct nullb_queue *nq)
Expand Down
4 changes: 2 additions & 2 deletions drivers/block/rbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -4154,14 +4154,14 @@ static void rbd_queue_workfn(struct work_struct *work)
blk_mq_end_request(rq, errno_to_blk_status(result));
}

static int rbd_queue_rq(struct blk_mq_hw_ctx *hctx,
static blk_status_t rbd_queue_rq(struct blk_mq_hw_ctx *hctx,
const struct blk_mq_queue_data *bd)
{
struct request *rq = bd->rq;
struct work_struct *work = blk_mq_rq_to_pdu(rq);

queue_work(rbd_wq, work);
return BLK_MQ_RQ_QUEUE_OK;
return BLK_STS_OK;
}

static void rbd_free_disk(struct rbd_device *rbd_dev)
Expand Down
10 changes: 5 additions & 5 deletions drivers/block/virtio_blk.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ static void virtblk_done(struct virtqueue *vq)
spin_unlock_irqrestore(&vblk->vqs[qid].lock, flags);
}

static int virtio_queue_rq(struct blk_mq_hw_ctx *hctx,
static blk_status_t virtio_queue_rq(struct blk_mq_hw_ctx *hctx,
const struct blk_mq_queue_data *bd)
{
struct virtio_blk *vblk = hctx->queue->queuedata;
Expand Down Expand Up @@ -246,7 +246,7 @@ static int virtio_queue_rq(struct blk_mq_hw_ctx *hctx,
break;
default:
WARN_ON_ONCE(1);
return BLK_MQ_RQ_QUEUE_ERROR;
return BLK_STS_IOERR;
}

vbr->out_hdr.type = cpu_to_virtio32(vblk->vdev, type);
Expand Down Expand Up @@ -276,8 +276,8 @@ static int virtio_queue_rq(struct blk_mq_hw_ctx *hctx,
/* Out of mem doesn't actually happen, since we fall back
* to direct descriptors */
if (err == -ENOMEM || err == -ENOSPC)
return BLK_MQ_RQ_QUEUE_BUSY;
return BLK_MQ_RQ_QUEUE_ERROR;
return BLK_STS_RESOURCE;
return BLK_STS_IOERR;
}

if (bd->last && virtqueue_kick_prepare(vblk->vqs[qid].vq))
Expand All @@ -286,7 +286,7 @@ static int virtio_queue_rq(struct blk_mq_hw_ctx *hctx,

if (notify)
virtqueue_notify(vblk->vqs[qid].vq);
return BLK_MQ_RQ_QUEUE_OK;
return BLK_STS_OK;
}

/* return id (s/n) string for *disk to *id_str
Expand Down
8 changes: 4 additions & 4 deletions drivers/block/xen-blkfront.c
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ static inline bool blkif_request_flush_invalid(struct request *req,
!info->feature_fua));
}

static int blkif_queue_rq(struct blk_mq_hw_ctx *hctx,
static blk_status_t blkif_queue_rq(struct blk_mq_hw_ctx *hctx,
const struct blk_mq_queue_data *qd)
{
unsigned long flags;
Expand All @@ -904,16 +904,16 @@ static int blkif_queue_rq(struct blk_mq_hw_ctx *hctx,

flush_requests(rinfo);
spin_unlock_irqrestore(&rinfo->ring_lock, flags);
return BLK_MQ_RQ_QUEUE_OK;
return BLK_STS_OK;

out_err:
spin_unlock_irqrestore(&rinfo->ring_lock, flags);
return BLK_MQ_RQ_QUEUE_ERROR;
return BLK_STS_IOERR;

out_busy:
spin_unlock_irqrestore(&rinfo->ring_lock, flags);
blk_mq_stop_hw_queue(hctx);
return BLK_MQ_RQ_QUEUE_BUSY;
return BLK_STS_RESOURCE;
}

static void blkif_complete_rq(struct request *rq)
Expand Down
8 changes: 4 additions & 4 deletions drivers/md/dm-rq.c
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ static int dm_mq_init_request(struct blk_mq_tag_set *set, struct request *rq,
return __dm_rq_init_rq(set->driver_data, rq);
}

static int dm_mq_queue_rq(struct blk_mq_hw_ctx *hctx,
static blk_status_t dm_mq_queue_rq(struct blk_mq_hw_ctx *hctx,
const struct blk_mq_queue_data *bd)
{
struct request *rq = bd->rq;
Expand All @@ -744,7 +744,7 @@ static int dm_mq_queue_rq(struct blk_mq_hw_ctx *hctx,
}

if (ti->type->busy && ti->type->busy(ti))
return BLK_MQ_RQ_QUEUE_BUSY;
return BLK_STS_RESOURCE;

dm_start_request(md, rq);

Expand All @@ -762,10 +762,10 @@ static int dm_mq_queue_rq(struct blk_mq_hw_ctx *hctx,
rq_end_stats(md, rq);
rq_completed(md, rq_data_dir(rq), false);
blk_mq_delay_run_hw_queue(hctx, 100/*ms*/);
return BLK_MQ_RQ_QUEUE_BUSY;
return BLK_STS_RESOURCE;
}

return BLK_MQ_RQ_QUEUE_OK;
return BLK_STS_OK;
}

static const struct blk_mq_ops dm_mq_ops = {
Expand Down
6 changes: 3 additions & 3 deletions drivers/mtd/ubi/block.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ static void ubiblock_do_work(struct work_struct *work)
blk_mq_end_request(req, errno_to_blk_status(ret));
}

static int ubiblock_queue_rq(struct blk_mq_hw_ctx *hctx,
static blk_status_t ubiblock_queue_rq(struct blk_mq_hw_ctx *hctx,
const struct blk_mq_queue_data *bd)
{
struct request *req = bd->rq;
Expand All @@ -327,9 +327,9 @@ static int ubiblock_queue_rq(struct blk_mq_hw_ctx *hctx,
case REQ_OP_READ:
ubi_sgl_init(&pdu->usgl);
queue_work(dev->wq, &pdu->work);
return BLK_MQ_RQ_QUEUE_OK;
return BLK_STS_OK;
default:
return BLK_MQ_RQ_QUEUE_ERROR;
return BLK_STS_IOERR;
}

}
Expand Down
Loading

0 comments on commit fc17b65

Please sign in to comment.