[PATCH 4/5] [PATCH 4/5] block: make blk_get/put_request work for blk-mq drivers

From: Christoph Hellwig
Date: Fri Oct 04 2013 - 09:51:04 EST


Consumers of the block layer shouldn't have to care if a driver uses
blk-mq or not, so make blk_get/put_request call the mq equivalents
underneath.

Signed-off-by: Christoph Hellwig <hch@xxxxxx>
---
block/blk-core.c | 31 ++++++++++++++++++++-----------
block/blk-mq.c | 1 -
drivers/block/mtip32xx/mtip32xx.c | 2 +-
3 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/block/blk-core.c b/block/blk-core.c
index 5620e58..6d7fd79 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -1080,7 +1080,8 @@ retry:
goto retry;
}

-struct request *blk_get_request(struct request_queue *q, int rw, gfp_t gfp_mask)
+static struct request *blk_old_get_request(struct request_queue *q, int rw,
+ gfp_t gfp_mask)
{
struct request *rq;

@@ -1097,6 +1098,14 @@ struct request *blk_get_request(struct request_queue *q, int rw, gfp_t gfp_mask)

return rq;
}
+
+struct request *blk_get_request(struct request_queue *q, int rw, gfp_t gfp_mask)
+{
+ if (q->mq_ops)
+ return blk_mq_alloc_request(q, rw, gfp_mask);
+ else
+ return blk_old_get_request(q, rw, gfp_mask);
+}
EXPORT_SYMBOL(blk_get_request);

/**
@@ -1133,12 +1142,7 @@ EXPORT_SYMBOL(blk_get_request);
struct request *blk_make_request(struct request_queue *q, struct bio *bio,
gfp_t gfp_mask)
{
- struct request *rq;
-
- if (q->mq_ops)
- rq = blk_mq_alloc_request(q, bio_data_dir(bio), gfp_mask);
- else
- rq = blk_get_request(q, bio_data_dir(bio), gfp_mask);
+ struct request *rq = blk_get_request(q, bio_data_dir(bio), gfp_mask);

if (unlikely(!rq))
return ERR_PTR(-ENOMEM);
@@ -1276,12 +1280,17 @@ EXPORT_SYMBOL_GPL(__blk_put_request);

void blk_put_request(struct request *req)
{
- unsigned long flags;
struct request_queue *q = req->q;

- spin_lock_irqsave(q->queue_lock, flags);
- __blk_put_request(q, req);
- spin_unlock_irqrestore(q->queue_lock, flags);
+ if (q->mq_ops)
+ blk_mq_free_request(req);
+ else {
+ unsigned long flags;
+
+ spin_lock_irqsave(q->queue_lock, flags);
+ __blk_put_request(q, req);
+ spin_unlock_irqrestore(q->queue_lock, flags);
+ }
}
EXPORT_SYMBOL(blk_put_request);

diff --git a/block/blk-mq.c b/block/blk-mq.c
index 423089d..709747f 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -268,7 +268,6 @@ void blk_mq_free_request(struct request *rq)
hctx = q->mq_ops->map_queue(q, ctx->cpu);
__blk_mq_free_request(hctx, ctx, rq);
}
-EXPORT_SYMBOL(blk_mq_free_request);

void blk_mq_finish_request(struct request *rq, int error)
{
diff --git a/drivers/block/mtip32xx/mtip32xx.c b/drivers/block/mtip32xx/mtip32xx.c
index 4427178..3c4c668 100644
--- a/drivers/block/mtip32xx/mtip32xx.c
+++ b/drivers/block/mtip32xx/mtip32xx.c
@@ -158,7 +158,7 @@ static struct mtip_cmd *mtip_get_int_command(struct driver_data *dd)

static void mtip_put_int_command(struct driver_data *dd, struct mtip_cmd *cmd)
{
- blk_mq_free_request(blk_mq_rq_from_pdu(cmd));
+ blk_put_request(blk_mq_rq_from_pdu(cmd));
}

/*
--
1.7.10.4


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/