From: =?UTF-8?q?Matias=20Bj=C3=B8rling?= Subject: [PATCH 1/5 v2] blk-mq: Add prep/unprep support Date: Wed, 15 Apr 2015 14:34:40 +0200 Message-ID: <1429101284-19490-2-git-send-email-m@bjorling.me> References: <1429101284-19490-1-git-send-email-m@bjorling.me> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: javier@paletta.io, keith.busch@intel.com, =?UTF-8?q?Matias=20Bj=C3=B8rling?= To: hch@infradead.org, axboe@fb.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org Return-path: In-Reply-To: <1429101284-19490-1-git-send-email-m@bjorling.me> Sender: linux-kernel-owner@vger.kernel.org List-Id: linux-fsdevel.vger.kernel.org Allow users to hook into prep/unprep functions just before an IO is dispatched to the device driver. This is necessary for request-based logic to take place at upper layers. Signed-off-by: Matias Bj=C3=B8rling --- block/blk-mq.c | 28 ++++++++++++++++++++++++++-- include/linux/blk-mq.h | 1 + 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 33c4285..f3dd028 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -338,6 +338,11 @@ EXPORT_SYMBOL(__blk_mq_end_request); =20 void blk_mq_end_request(struct request *rq, int error) { + struct request_queue *q =3D rq->q; + + if (q->unprep_rq_fn) + q->unprep_rq_fn(q, rq); + if (blk_update_request(rq, error, blk_rq_bytes(rq))) BUG(); __blk_mq_end_request(rq, error); @@ -753,6 +758,17 @@ static void flush_busy_ctxs(struct blk_mq_hw_ctx *= hctx, struct list_head *list) } } =20 +static int blk_mq_prep_rq(struct request_queue *q, struct request *rq) +{ + if (!q->prep_rq_fn) + return 0; + + if (rq->cmd_flags & REQ_DONTPREP) + return 0; + + return q->prep_rq_fn(q, rq); +} + /* * Run this hardware queue, pulling any software queues mapped to it i= n. * Note that this function currently has various problems around order= ing @@ -812,11 +828,15 @@ static void __blk_mq_run_hw_queue(struct blk_mq_h= w_ctx *hctx) bd.list =3D dptr; bd.last =3D list_empty(&rq_list); =20 - ret =3D q->mq_ops->queue_rq(hctx, &bd); + ret =3D blk_mq_prep_rq(q, rq); + if (likely(!ret)) + ret =3D q->mq_ops->queue_rq(hctx, &bd); switch (ret) { case BLK_MQ_RQ_QUEUE_OK: queued++; continue; + case BLK_MQ_RQ_QUEUE_DONE: + continue; case BLK_MQ_RQ_QUEUE_BUSY: list_add(&rq->queuelist, &rq_list); __blk_mq_requeue_request(rq); @@ -1270,10 +1290,14 @@ static void blk_mq_make_request(struct request_= queue *q, struct bio *bio) * error (busy), just add it to our list as we previously * would have done */ - ret =3D q->mq_ops->queue_rq(data.hctx, &bd); + ret =3D blk_mq_prep_rq(q, rq); + if (likely(!ret)) + ret =3D q->mq_ops->queue_rq(data.hctx, &bd); if (ret =3D=3D BLK_MQ_RQ_QUEUE_OK) goto done; else { + if (ret =3D=3D BLK_MQ_RQ_QUEUE_DONE) + goto done; __blk_mq_requeue_request(rq); =20 if (ret =3D=3D BLK_MQ_RQ_QUEUE_ERROR) { diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h index 7aec861..d7b39af 100644 --- a/include/linux/blk-mq.h +++ b/include/linux/blk-mq.h @@ -140,6 +140,7 @@ enum { BLK_MQ_RQ_QUEUE_OK =3D 0, /* queued fine */ BLK_MQ_RQ_QUEUE_BUSY =3D 1, /* requeue IO for later */ BLK_MQ_RQ_QUEUE_ERROR =3D 2, /* end IO with error */ + BLK_MQ_RQ_QUEUE_DONE =3D 3, /* IO is already handled */ =20 BLK_MQ_F_SHOULD_MERGE =3D 1 << 0, BLK_MQ_F_TAG_SHARED =3D 1 << 1, --=20 1.9.1