All of lore.kernel.org
 help / color / mirror / Atom feed
From: Shaohua Li <shli@kernel.org>
To: linux-kernel@vger.kernel.org
Cc: axboe@kernel.dk, hch@infradead.org
Subject: [patch]blk-mq: blk_mq_tag_to_rq should handle flush request
Date: Fri, 9 May 2014 20:07:33 +0800	[thread overview]
Message-ID: <20140509120733.GA27918@kernel.org> (raw)


flush request is special, which borrows tag from other request. Need a special
handling to get it from tag.

Signed-off-by: Shaohua Li <shli@fusionio.com>
---
 block/blk-flush.c                 |    4 +++-
 block/blk-mq.c                    |   13 +++++++++++--
 drivers/block/mtip32xx/mtip32xx.c |    2 +-
 include/linux/blk-mq.h            |    3 ++-
 include/linux/blkdev.h            |    1 +
 5 files changed, 18 insertions(+), 5 deletions(-)

Index: linux/block/blk-flush.c
===================================================================
--- linux.orig/block/blk-flush.c	2014-05-09 19:52:25.360415014 +0800
+++ linux/block/blk-flush.c	2014-05-09 19:53:59.795228450 +0800
@@ -231,8 +231,10 @@ static void flush_end_io(struct request
 	struct request *rq, *n;
 	unsigned long flags = 0;
 
-	if (q->mq_ops)
+	if (q->mq_ops) {
 		spin_lock_irqsave(&q->mq_flush_lock, flags);
+		q->flush_rq_tag_valid = false;
+	}
 
 	running = &q->flush_queue[q->flush_running_idx];
 	BUG_ON(q->flush_pending_idx == q->flush_running_idx);
Index: linux/block/blk-mq.c
===================================================================
--- linux.orig/block/blk-mq.c	2014-05-09 19:52:25.360415014 +0800
+++ linux/block/blk-mq.c	2014-05-09 19:57:58.432227506 +0800
@@ -336,6 +336,8 @@ void blk_mq_clone_flush_request(struct r
 
 	flush_rq->mq_ctx = orig_rq->mq_ctx;
 	flush_rq->tag = orig_rq->tag;
+	smp_wmb();
+	orig_rq->q->flush_rq_tag_valid = true;
 	memcpy(blk_mq_rq_to_pdu(flush_rq), blk_mq_rq_to_pdu(orig_rq),
 		hctx->cmd_size);
 }
@@ -481,8 +483,14 @@ void blk_mq_requeue_request(struct reque
 }
 EXPORT_SYMBOL(blk_mq_requeue_request);
 
-struct request *blk_mq_tag_to_rq(struct blk_mq_tags *tags, unsigned int tag)
+struct request *blk_mq_tag_to_rq(struct request_queue *q,
+	struct blk_mq_tags *tags, unsigned int tag)
 {
+	if (q->flush_rq_tag_valid) {
+		smp_rmb();
+		if (q->flush_rq->tag == tag)
+			return q->flush_rq;
+	}
 	return tags->rqs[tag];
 }
 EXPORT_SYMBOL(blk_mq_tag_to_rq);
@@ -512,7 +520,7 @@ static void blk_mq_timeout_check(void *_
 		if (tag >= hctx->tags->nr_tags)
 			break;
 
-		rq = blk_mq_tag_to_rq(hctx->tags, tag++);
+		rq = blk_mq_tag_to_rq(hctx->queue, hctx->tags, tag++);
 		if (rq->q != hctx->queue)
 			continue;
 		if (!test_bit(REQ_ATOM_STARTED, &rq->atomic_flags))
@@ -1510,6 +1518,7 @@ struct request_queue *blk_mq_init_queue(
 				GFP_KERNEL);
 	if (!q->flush_rq)
 		goto err_hw;
+	q->flush_rq_tag_valid = false;
 
 	if (blk_mq_init_hw_queues(q, set))
 		goto err_flush_rq;
Index: linux/include/linux/blk-mq.h
===================================================================
--- linux.orig/include/linux/blk-mq.h	2014-05-09 19:52:25.360415014 +0800
+++ linux/include/linux/blk-mq.h	2014-05-09 19:52:25.352415140 +0800
@@ -149,7 +149,8 @@ void blk_mq_free_request(struct request
 bool blk_mq_can_queue(struct blk_mq_hw_ctx *);
 struct request *blk_mq_alloc_request(struct request_queue *q, int rw, gfp_t gfp);
 struct request *blk_mq_alloc_reserved_request(struct request_queue *q, int rw, gfp_t gfp);
-struct request *blk_mq_tag_to_rq(struct blk_mq_tags *tags, unsigned int tag);
+struct request *blk_mq_tag_to_rq(struct request_queue *q,
+	struct blk_mq_tags *tags, unsigned int tag);
 
 struct blk_mq_hw_ctx *blk_mq_map_queue(struct request_queue *, const int ctx_index);
 struct blk_mq_hw_ctx *blk_mq_alloc_single_hw_queue(struct blk_mq_tag_set *, unsigned int);
Index: linux/drivers/block/mtip32xx/mtip32xx.c
===================================================================
--- linux.orig/drivers/block/mtip32xx/mtip32xx.c	2014-05-09 19:52:25.360415014 +0800
+++ linux/drivers/block/mtip32xx/mtip32xx.c	2014-05-09 19:52:25.352415140 +0800
@@ -195,7 +195,7 @@ static struct request *mtip_rq_from_tag(
 {
 	struct blk_mq_hw_ctx *hctx = dd->queue->queue_hw_ctx[0];
 
-	return blk_mq_tag_to_rq(hctx->tags, tag);
+	return blk_mq_tag_to_rq(dd->queue, hctx->tags, tag);
 }
 
 static struct mtip_cmd *mtip_cmd_from_tag(struct driver_data *dd,
Index: linux/include/linux/blkdev.h
===================================================================
--- linux.orig/include/linux/blkdev.h	2014-05-09 19:42:28.000000000 +0800
+++ linux/include/linux/blkdev.h	2014-05-09 19:53:07.591883317 +0800
@@ -461,6 +461,7 @@ struct request_queue {
 	struct list_head	flush_queue[2];
 	struct list_head	flush_data_in_flight;
 	struct request		*flush_rq;
+	bool			flush_rq_tag_valid;
 	spinlock_t		mq_flush_lock;
 
 	struct mutex		sysfs_lock;

             reply	other threads:[~2014-05-09 12:07 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-09 12:07 Shaohua Li [this message]
2014-05-09 15:00 ` [patch]blk-mq: blk_mq_tag_to_rq should handle flush request Christoph Hellwig
2014-05-10  4:00   ` Shaohua Li
2014-05-11 17:40     ` Jens Axboe
2014-05-30 14:09     ` Jens Axboe
2014-06-04 11:11       ` Christoph Hellwig
2014-06-04 14:15         ` Jens Axboe
2014-06-04 14:20           ` Christoph Hellwig
2014-06-04 14:54             ` Jens Axboe
2014-06-04 14:58               ` Christoph Hellwig
2014-06-04 15:02                 ` Jens Axboe
2014-06-04 15:05                   ` Christoph Hellwig
2014-06-04 15:08                     ` Jens Axboe
2014-06-04 15:10                       ` Christoph Hellwig
2014-06-04 15:11                         ` Jens Axboe
2014-06-04 15:16                           ` Christoph Hellwig
2014-06-04 15:19                             ` Jens Axboe
2014-06-04 15:22                       ` Christoph Hellwig
2014-06-04 15:28                         ` Jens Axboe
2014-06-04 15:31                   ` Christoph Hellwig
2014-06-04 15:39                     ` Jens Axboe
2014-06-04 15:47                       ` Jens Axboe
2014-06-04 16:25                         ` Jens Axboe
2014-06-05  1:27                           ` Shaohua Li
2014-06-05  2:05                             ` Jens Axboe
2014-06-05  2:27                               ` Shaohua Li
2014-06-05  2:40                                 ` Jens Axboe
2014-06-04 15:43                     ` Ming Lei
2014-06-04 15:48                       ` Jens Axboe
2014-06-04 16:00                         ` Ming Lei
2014-06-04 16:09                           ` Jens Axboe
2014-06-04 16:26                             ` Ming Lei
2014-06-04 16:28                               ` Jens Axboe
2014-06-04 16:33                                 ` Christoph Hellwig
2014-06-04 16:36                                   ` Ming Lei

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140509120733.GA27918@kernel.org \
    --to=shli@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=hch@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.