All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bart Van Assche <bart.vanassche@sandisk.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: <linux-block@vger.kernel.org>, Christoph Hellwig <hch@lst.de>,
	"Bart Van Assche" <bart.vanassche@sandisk.com>,
	Hannes Reinecke <hare@suse.com>, "Omar Sandoval" <osandov@fb.com>
Subject: [PATCH v2 02/12] block: Introduce request_queue.initialize_rq_fn()
Date: Wed, 31 May 2017 15:52:36 -0700	[thread overview]
Message-ID: <20170531225246.26261-3-bart.vanassche@sandisk.com> (raw)
In-Reply-To: <20170531225246.26261-1-bart.vanassche@sandisk.com>

Several block drivers need to initialize the driver-private data
after having called blk_get_request() and before .prep_rq_fn() is
called, e.g. when submitting a REQ_OP_SCSI_* request. Avoid that
that initialization code has to be repeated after every
blk_get_request() call by adding a new callback function to struct
request_queue.

Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Hannes Reinecke <hare@suse.com>
Cc: Omar Sandoval <osandov@fb.com>
---
 block/blk-core.c       | 11 +++++++++--
 include/linux/blkdev.h |  4 ++++
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/block/blk-core.c b/block/blk-core.c
index 3bc431a77309..3f68bc1f044c 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -1308,12 +1308,19 @@ static struct request *blk_old_get_request(struct request_queue *q,
 struct request *blk_get_request(struct request_queue *q, unsigned int op,
 				gfp_t gfp_mask)
 {
+	struct request *req;
+
 	if (q->mq_ops)
-		return blk_mq_alloc_request(q, op,
+		req = blk_mq_alloc_request(q, op,
 			(gfp_mask & __GFP_DIRECT_RECLAIM) ?
 				0 : BLK_MQ_REQ_NOWAIT);
 	else
-		return blk_old_get_request(q, op, gfp_mask);
+		req = blk_old_get_request(q, op, gfp_mask);
+
+	if (!IS_ERR(req) && q->initialize_rq_fn)
+		q->initialize_rq_fn(req);
+
+	return req;
 }
 EXPORT_SYMBOL(blk_get_request);
 
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 6c4235018b49..cbc0028290e4 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -410,8 +410,12 @@ struct request_queue {
 	rq_timed_out_fn		*rq_timed_out_fn;
 	dma_drain_needed_fn	*dma_drain_needed;
 	lld_busy_fn		*lld_busy_fn;
+	/* Called just after a request is allocated */
 	init_rq_fn		*init_rq_fn;
+	/* Called just before a request is freed */
 	exit_rq_fn		*exit_rq_fn;
+	/* Called from inside blk_get_request() */
+	void (*initialize_rq_fn)(struct request *rq);
 
 	const struct blk_mq_ops	*mq_ops;
 
-- 
2.12.2

  parent reply	other threads:[~2017-05-31 22:52 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-31 22:52 [PATCH v2 00/12] More patches for kernel v4.13 Bart Van Assche
2017-05-31 22:52 ` [PATCH v2 01/12] block: Make request operation type argument declarations consistent Bart Van Assche
2017-05-31 22:52 ` Bart Van Assche [this message]
2017-06-01  6:06   ` [PATCH v2 02/12] block: Introduce request_queue.initialize_rq_fn() Christoph Hellwig
2017-05-31 22:52 ` [PATCH v2 03/12] block: Make most scsi_req_init() calls implicit Bart Van Assche
2017-06-01  6:08   ` Christoph Hellwig
2017-05-31 22:52 ` [PATCH v2 04/12] block: Change argument type of scsi_req_init() Bart Van Assche
2017-05-31 22:52 ` [PATCH v2 05/12] blk-mq: Initialize a request before assigning a tag Bart Van Assche
2017-06-01  6:09   ` Christoph Hellwig
2017-05-31 22:52 ` [PATCH v2 06/12] block: Add a comment above queue_lockdep_assert_held() Bart Van Assche
2017-05-31 22:52 ` [PATCH v2 07/12] block: Check locking assumptions at runtime Bart Van Assche
2017-06-01  6:09   ` Christoph Hellwig
2017-05-31 22:52 ` [PATCH v2 08/12] block: Document what queue type each function is intended for Bart Van Assche
2017-06-01  6:10   ` Christoph Hellwig
2017-05-31 22:52 ` [PATCH v2 09/12] blk-mq: Document locking assumptions Bart Van Assche
2017-06-01  6:11   ` Christoph Hellwig
2017-05-31 22:52 ` [PATCH v2 10/12] block: Constify disk_type Bart Van Assche
2017-05-31 22:52 ` [PATCH v2 11/12] blk-mq: Warn when attempting to run a hardware queue that is not mapped Bart Van Assche
2017-06-01  6:11   ` Christoph Hellwig
2017-05-31 22:52 ` [PATCH v2 12/12] block: Rename blk_mq_rq_{to,from}_pdu() Bart Van Assche
2017-06-01  6:08   ` Christoph Hellwig
2017-06-01 13:11     ` Bart Van Assche
2017-06-01 19:06       ` Jens Axboe
2017-06-01 19:17         ` Bart Van Assche
2017-06-01 19:28           ` Jens Axboe
2017-06-01 19:04     ` Jens Axboe

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=20170531225246.26261-3-bart.vanassche@sandisk.com \
    --to=bart.vanassche@sandisk.com \
    --cc=axboe@kernel.dk \
    --cc=hare@suse.com \
    --cc=hch@lst.de \
    --cc=linux-block@vger.kernel.org \
    --cc=osandov@fb.com \
    /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.