From patchwork Fri Aug 25 19:00:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 9922677 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0FD776022E for ; Fri, 25 Aug 2017 19:01:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 000F728464 for ; Fri, 25 Aug 2017 19:01:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E921F284AA; Fri, 25 Aug 2017 19:01:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2FD2D28464 for ; Fri, 25 Aug 2017 19:01:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755592AbdHYTBp (ORCPT ); Fri, 25 Aug 2017 15:01:45 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:34381 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754749AbdHYTBp (ORCPT ); Fri, 25 Aug 2017 15:01:45 -0400 X-IronPort-AV: E=Sophos;i="5.41,426,1498492800"; d="scan'208";a="45255265" Received: from sjappemgw11.hgst.com (HELO sjappemgw12.hgst.com) ([199.255.44.62]) by ob1.hgst.iphmx.com with ESMTP; 26 Aug 2017 03:01:04 +0800 Received: from thinkpad-bart.sdcorp.global.sandisk.com (HELO thinkpad-bart.int.fusionio.com) ([10.11.172.152]) by sjappemgw12.hgst.com with ESMTP; 25 Aug 2017 12:00:57 -0700 From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , "Martin K . Petersen" , Hannes Reinecke Subject: [PATCH] block: Call .initialize_rq_fn() also for filesystem requests Date: Fri, 25 Aug 2017 12:00:57 -0700 Message-Id: <20170825190057.15592-1-bart.vanassche@wdc.com> X-Mailer: git-send-email 2.14.1 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Since .initialize_rq_fn() is called from inside blk_get_request() that function is only called for pass-through requests but not for filesystem requests. There is agreement in the SCSI community that the jiffies_at_alloc and retries members of struct scsi_cmnd should be initialized at request allocation time instead of when preparing a request. This will allow to preserve the value of these members when requeuing a request. Since the block layer does not yet allow block drivers to initialize filesystem requests without overriding request_queue.make_request_fn, move the .initialize_rq_fn() calls from blk_get_request() into blk_mq_rq_ctx_init() and blk_rq_init(). See also https://www.spinics.net/lists/linux-scsi/msg108934.html. Signed-off-by: Bart Van Assche Cc: Christoph Hellwig Cc: Martin K. Petersen Cc: Hannes Reinecke --- block/blk-core.c | 20 +++++++------------- block/blk-mq.c | 4 ++++ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index 78a46794053e..463aa0ee36ce 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -126,6 +126,9 @@ void blk_rq_init(struct request_queue *q, struct request *rq) rq->start_time = jiffies; set_start_time_ns(rq); rq->part = NULL; + + if (q && q->initialize_rq_fn) + q->initialize_rq_fn(rq); } EXPORT_SYMBOL(blk_rq_init); @@ -1420,21 +1423,12 @@ 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) { - req = blk_mq_alloc_request(q, op, + if (q->mq_ops) + return blk_mq_alloc_request(q, op, (gfp_mask & __GFP_DIRECT_RECLAIM) ? 0 : BLK_MQ_REQ_NOWAIT); - if (!IS_ERR(req) && q->mq_ops->initialize_rq_fn) - q->mq_ops->initialize_rq_fn(req); - } else { - req = blk_old_get_request(q, op, gfp_mask); - if (!IS_ERR(req) && q->initialize_rq_fn) - q->initialize_rq_fn(req); - } - - return req; + else + return blk_old_get_request(q, op, gfp_mask); } EXPORT_SYMBOL(blk_get_request); diff --git a/block/blk-mq.c b/block/blk-mq.c index 21f2cff217ce..fdb33f8a2860 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -273,6 +273,7 @@ EXPORT_SYMBOL(blk_mq_can_queue); static struct request *blk_mq_rq_ctx_init(struct blk_mq_alloc_data *data, unsigned int tag, unsigned int op) { + struct request_queue *q = data->q; struct blk_mq_tags *tags = blk_mq_tags_from_data(data); struct request *rq = tags->static_rqs[tag]; @@ -325,6 +326,9 @@ static struct request *blk_mq_rq_ctx_init(struct blk_mq_alloc_data *data, rq->end_io_data = NULL; rq->next_rq = NULL; + if (q->mq_ops->initialize_rq_fn) + q->mq_ops->initialize_rq_fn(rq); + data->ctx->rq_dispatched[op_is_sync(op)]++; return rq; }