Skip to content

Commit fc17b65

Browse files
Christoph Hellwigaxboe
authored andcommitted
blk-mq: switch ->queue_rq return value to blk_status_t
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]>
1 parent 2a842ac commit fc17b65

File tree

18 files changed

+131
-142
lines changed

18 files changed

+131
-142
lines changed

block/blk-mq.c

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ bool blk_mq_dispatch_rq_list(struct request_queue *q, struct list_head *list)
924924
{
925925
struct blk_mq_hw_ctx *hctx;
926926
struct request *rq;
927-
int errors, queued, ret = BLK_MQ_RQ_QUEUE_OK;
927+
int errors, queued;
928928

929929
if (list_empty(list))
930930
return false;
@@ -935,6 +935,7 @@ bool blk_mq_dispatch_rq_list(struct request_queue *q, struct list_head *list)
935935
errors = queued = 0;
936936
do {
937937
struct blk_mq_queue_data bd;
938+
blk_status_t ret;
938939

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

977978
ret = q->mq_ops->queue_rq(hctx, &bd);
978-
switch (ret) {
979-
case BLK_MQ_RQ_QUEUE_OK:
980-
queued++;
981-
break;
982-
case BLK_MQ_RQ_QUEUE_BUSY:
979+
if (ret == BLK_STS_RESOURCE) {
983980
blk_mq_put_driver_tag_hctx(hctx, rq);
984981
list_add(&rq->queuelist, list);
985982
__blk_mq_requeue_request(rq);
986983
break;
987-
default:
988-
pr_err("blk-mq: bad return on queue: %d\n", ret);
989-
case BLK_MQ_RQ_QUEUE_ERROR:
984+
}
985+
986+
if (unlikely(ret != BLK_STS_OK)) {
990987
errors++;
991988
blk_mq_end_request(rq, BLK_STS_IOERR);
992-
break;
989+
continue;
993990
}
994991

995-
if (ret == BLK_MQ_RQ_QUEUE_BUSY)
996-
break;
992+
queued++;
997993
} while (!list_empty(list));
998994

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

14151411
if (q->elevator)
14161412
goto insert;
@@ -1426,18 +1422,19 @@ static void __blk_mq_try_issue_directly(struct request *rq, blk_qc_t *cookie,
14261422
* would have done
14271423
*/
14281424
ret = q->mq_ops->queue_rq(hctx, &bd);
1429-
if (ret == BLK_MQ_RQ_QUEUE_OK) {
1425+
switch (ret) {
1426+
case BLK_STS_OK:
14301427
*cookie = new_cookie;
14311428
return;
1432-
}
1433-
1434-
if (ret == BLK_MQ_RQ_QUEUE_ERROR) {
1429+
case BLK_STS_RESOURCE:
1430+
__blk_mq_requeue_request(rq);
1431+
goto insert;
1432+
default:
14351433
*cookie = BLK_QC_T_NONE;
1436-
blk_mq_end_request(rq, BLK_STS_IOERR);
1434+
blk_mq_end_request(rq, ret);
14371435
return;
14381436
}
14391437

1440-
__blk_mq_requeue_request(rq);
14411438
insert:
14421439
blk_mq_sched_insert_request(rq, false, true, false, may_sleep);
14431440
}

drivers/block/loop.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,7 +1674,7 @@ int loop_unregister_transfer(int number)
16741674
EXPORT_SYMBOL(loop_register_transfer);
16751675
EXPORT_SYMBOL(loop_unregister_transfer);
16761676

1677-
static int loop_queue_rq(struct blk_mq_hw_ctx *hctx,
1677+
static blk_status_t loop_queue_rq(struct blk_mq_hw_ctx *hctx,
16781678
const struct blk_mq_queue_data *bd)
16791679
{
16801680
struct loop_cmd *cmd = blk_mq_rq_to_pdu(bd->rq);
@@ -1683,7 +1683,7 @@ static int loop_queue_rq(struct blk_mq_hw_ctx *hctx,
16831683
blk_mq_start_request(bd->rq);
16841684

16851685
if (lo->lo_state != Lo_bound)
1686-
return BLK_MQ_RQ_QUEUE_ERROR;
1686+
return BLK_STS_IOERR;
16871687

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

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

1701-
return BLK_MQ_RQ_QUEUE_OK;
1701+
return BLK_STS_OK;
17021702
}
17031703

17041704
static void loop_handle_cmd(struct loop_cmd *cmd)

drivers/block/mtip32xx/mtip32xx.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3633,16 +3633,16 @@ static bool mtip_check_unal_depth(struct blk_mq_hw_ctx *hctx,
36333633
return false;
36343634
}
36353635

3636-
static int mtip_issue_reserved_cmd(struct blk_mq_hw_ctx *hctx,
3637-
struct request *rq)
3636+
static blk_status_t mtip_issue_reserved_cmd(struct blk_mq_hw_ctx *hctx,
3637+
struct request *rq)
36383638
{
36393639
struct driver_data *dd = hctx->queue->queuedata;
36403640
struct mtip_int_cmd *icmd = rq->special;
36413641
struct mtip_cmd *cmd = blk_mq_rq_to_pdu(rq);
36423642
struct mtip_cmd_sg *command_sg;
36433643

36443644
if (mtip_commands_active(dd->port))
3645-
return BLK_MQ_RQ_QUEUE_BUSY;
3645+
return BLK_STS_RESOURCE;
36463646

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

36673667
blk_mq_start_request(rq);
36683668
mtip_issue_non_ncq_command(dd->port, rq->tag);
3669-
return BLK_MQ_RQ_QUEUE_OK;
3669+
return 0;
36703670
}
36713671

3672-
static int mtip_queue_rq(struct blk_mq_hw_ctx *hctx,
3672+
static blk_status_t mtip_queue_rq(struct blk_mq_hw_ctx *hctx,
36733673
const struct blk_mq_queue_data *bd)
36743674
{
36753675
struct request *rq = bd->rq;
@@ -3681,15 +3681,14 @@ static int mtip_queue_rq(struct blk_mq_hw_ctx *hctx,
36813681
return mtip_issue_reserved_cmd(hctx, rq);
36823682

36833683
if (unlikely(mtip_check_unal_depth(hctx, rq)))
3684-
return BLK_MQ_RQ_QUEUE_BUSY;
3684+
return BLK_STS_RESOURCE;
36853685

36863686
blk_mq_start_request(rq);
36873687

36883688
ret = mtip_submit_request(hctx, rq);
36893689
if (likely(!ret))
3690-
return BLK_MQ_RQ_QUEUE_OK;
3691-
3692-
return BLK_MQ_RQ_QUEUE_ERROR;
3690+
return BLK_STS_OK;
3691+
return BLK_STS_IOERR;
36933692
}
36943693

36953694
static void mtip_free_cmd(struct blk_mq_tag_set *set, struct request *rq,

drivers/block/nbd.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index)
469469
nsock->pending = req;
470470
nsock->sent = sent;
471471
}
472-
return BLK_MQ_RQ_QUEUE_BUSY;
472+
return BLK_STS_RESOURCE;
473473
}
474474
dev_err_ratelimited(disk_to_dev(nbd->disk),
475475
"Send control failed (result %d)\n", result);
@@ -510,7 +510,7 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index)
510510
*/
511511
nsock->pending = req;
512512
nsock->sent = sent;
513-
return BLK_MQ_RQ_QUEUE_BUSY;
513+
return BLK_STS_RESOURCE;
514514
}
515515
dev_err(disk_to_dev(nbd->disk),
516516
"Send data failed (result %d)\n",
@@ -798,7 +798,7 @@ static int nbd_handle_cmd(struct nbd_cmd *cmd, int index)
798798
return ret;
799799
}
800800

801-
static int nbd_queue_rq(struct blk_mq_hw_ctx *hctx,
801+
static blk_status_t nbd_queue_rq(struct blk_mq_hw_ctx *hctx,
802802
const struct blk_mq_queue_data *bd)
803803
{
804804
struct nbd_cmd *cmd = blk_mq_rq_to_pdu(bd->rq);
@@ -822,13 +822,9 @@ static int nbd_queue_rq(struct blk_mq_hw_ctx *hctx,
822822
* appropriate.
823823
*/
824824
ret = nbd_handle_cmd(cmd, hctx->queue_num);
825-
if (ret < 0)
826-
ret = BLK_MQ_RQ_QUEUE_ERROR;
827-
if (!ret)
828-
ret = BLK_MQ_RQ_QUEUE_OK;
829825
complete(&cmd->send_complete);
830826

831-
return ret;
827+
return ret < 0 ? BLK_STS_IOERR : BLK_STS_OK;
832828
}
833829

834830
static int nbd_add_socket(struct nbd_device *nbd, unsigned long arg,

drivers/block/null_blk.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ static void null_request_fn(struct request_queue *q)
356356
}
357357
}
358358

359-
static int null_queue_rq(struct blk_mq_hw_ctx *hctx,
359+
static blk_status_t null_queue_rq(struct blk_mq_hw_ctx *hctx,
360360
const struct blk_mq_queue_data *bd)
361361
{
362362
struct nullb_cmd *cmd = blk_mq_rq_to_pdu(bd->rq);
@@ -373,7 +373,7 @@ static int null_queue_rq(struct blk_mq_hw_ctx *hctx,
373373
blk_mq_start_request(bd->rq);
374374

375375
null_handle_cmd(cmd);
376-
return BLK_MQ_RQ_QUEUE_OK;
376+
return BLK_STS_OK;
377377
}
378378

379379
static void null_init_queue(struct nullb *nullb, struct nullb_queue *nq)

drivers/block/rbd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4154,14 +4154,14 @@ static void rbd_queue_workfn(struct work_struct *work)
41544154
blk_mq_end_request(rq, errno_to_blk_status(result));
41554155
}
41564156

4157-
static int rbd_queue_rq(struct blk_mq_hw_ctx *hctx,
4157+
static blk_status_t rbd_queue_rq(struct blk_mq_hw_ctx *hctx,
41584158
const struct blk_mq_queue_data *bd)
41594159
{
41604160
struct request *rq = bd->rq;
41614161
struct work_struct *work = blk_mq_rq_to_pdu(rq);
41624162

41634163
queue_work(rbd_wq, work);
4164-
return BLK_MQ_RQ_QUEUE_OK;
4164+
return BLK_STS_OK;
41654165
}
41664166

41674167
static void rbd_free_disk(struct rbd_device *rbd_dev)

drivers/block/virtio_blk.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ static void virtblk_done(struct virtqueue *vq)
214214
spin_unlock_irqrestore(&vblk->vqs[qid].lock, flags);
215215
}
216216

217-
static int virtio_queue_rq(struct blk_mq_hw_ctx *hctx,
217+
static blk_status_t virtio_queue_rq(struct blk_mq_hw_ctx *hctx,
218218
const struct blk_mq_queue_data *bd)
219219
{
220220
struct virtio_blk *vblk = hctx->queue->queuedata;
@@ -246,7 +246,7 @@ static int virtio_queue_rq(struct blk_mq_hw_ctx *hctx,
246246
break;
247247
default:
248248
WARN_ON_ONCE(1);
249-
return BLK_MQ_RQ_QUEUE_ERROR;
249+
return BLK_STS_IOERR;
250250
}
251251

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

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

287287
if (notify)
288288
virtqueue_notify(vblk->vqs[qid].vq);
289-
return BLK_MQ_RQ_QUEUE_OK;
289+
return BLK_STS_OK;
290290
}
291291

292292
/* return id (s/n) string for *disk to *id_str

drivers/block/xen-blkfront.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ static inline bool blkif_request_flush_invalid(struct request *req,
881881
!info->feature_fua));
882882
}
883883

884-
static int blkif_queue_rq(struct blk_mq_hw_ctx *hctx,
884+
static blk_status_t blkif_queue_rq(struct blk_mq_hw_ctx *hctx,
885885
const struct blk_mq_queue_data *qd)
886886
{
887887
unsigned long flags;
@@ -904,16 +904,16 @@ static int blkif_queue_rq(struct blk_mq_hw_ctx *hctx,
904904

905905
flush_requests(rinfo);
906906
spin_unlock_irqrestore(&rinfo->ring_lock, flags);
907-
return BLK_MQ_RQ_QUEUE_OK;
907+
return BLK_STS_OK;
908908

909909
out_err:
910910
spin_unlock_irqrestore(&rinfo->ring_lock, flags);
911-
return BLK_MQ_RQ_QUEUE_ERROR;
911+
return BLK_STS_IOERR;
912912

913913
out_busy:
914914
spin_unlock_irqrestore(&rinfo->ring_lock, flags);
915915
blk_mq_stop_hw_queue(hctx);
916-
return BLK_MQ_RQ_QUEUE_BUSY;
916+
return BLK_STS_RESOURCE;
917917
}
918918

919919
static void blkif_complete_rq(struct request *rq)

drivers/md/dm-rq.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ static int dm_mq_init_request(struct blk_mq_tag_set *set, struct request *rq,
727727
return __dm_rq_init_rq(set->driver_data, rq);
728728
}
729729

730-
static int dm_mq_queue_rq(struct blk_mq_hw_ctx *hctx,
730+
static blk_status_t dm_mq_queue_rq(struct blk_mq_hw_ctx *hctx,
731731
const struct blk_mq_queue_data *bd)
732732
{
733733
struct request *rq = bd->rq;
@@ -744,7 +744,7 @@ static int dm_mq_queue_rq(struct blk_mq_hw_ctx *hctx,
744744
}
745745

746746
if (ti->type->busy && ti->type->busy(ti))
747-
return BLK_MQ_RQ_QUEUE_BUSY;
747+
return BLK_STS_RESOURCE;
748748

749749
dm_start_request(md, rq);
750750

@@ -762,10 +762,10 @@ static int dm_mq_queue_rq(struct blk_mq_hw_ctx *hctx,
762762
rq_end_stats(md, rq);
763763
rq_completed(md, rq_data_dir(rq), false);
764764
blk_mq_delay_run_hw_queue(hctx, 100/*ms*/);
765-
return BLK_MQ_RQ_QUEUE_BUSY;
765+
return BLK_STS_RESOURCE;
766766
}
767767

768-
return BLK_MQ_RQ_QUEUE_OK;
768+
return BLK_STS_OK;
769769
}
770770

771771
static const struct blk_mq_ops dm_mq_ops = {

drivers/mtd/ubi/block.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ static void ubiblock_do_work(struct work_struct *work)
316316
blk_mq_end_request(req, errno_to_blk_status(ret));
317317
}
318318

319-
static int ubiblock_queue_rq(struct blk_mq_hw_ctx *hctx,
319+
static blk_status_t ubiblock_queue_rq(struct blk_mq_hw_ctx *hctx,
320320
const struct blk_mq_queue_data *bd)
321321
{
322322
struct request *req = bd->rq;
@@ -327,9 +327,9 @@ static int ubiblock_queue_rq(struct blk_mq_hw_ctx *hctx,
327327
case REQ_OP_READ:
328328
ubi_sgl_init(&pdu->usgl);
329329
queue_work(dev->wq, &pdu->work);
330-
return BLK_MQ_RQ_QUEUE_OK;
330+
return BLK_STS_OK;
331331
default:
332-
return BLK_MQ_RQ_QUEUE_ERROR;
332+
return BLK_STS_IOERR;
333333
}
334334

335335
}

0 commit comments

Comments
 (0)