From patchwork Wed Jun 1 04:58:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "(Exiting) Baolin Wang" X-Patchwork-Id: 9146051 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 9D4C560757 for ; Wed, 1 Jun 2016 05:00:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 94A91200E7 for ; Wed, 1 Jun 2016 05:00:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8797F25819; Wed, 1 Jun 2016 05:00:05 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable 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 04E07200E7 for ; Wed, 1 Jun 2016 05:00:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757189AbcFAE6v (ORCPT ); Wed, 1 Jun 2016 00:58:51 -0400 Received: from mail-pf0-f180.google.com ([209.85.192.180]:35216 "EHLO mail-pf0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754028AbcFAE6p (ORCPT ); Wed, 1 Jun 2016 00:58:45 -0400 Received: by mail-pf0-f180.google.com with SMTP id g64so7167898pfb.2 for ; Tue, 31 May 2016 21:58:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=52Z77MpJ2BTUH766RBrztxQXCx+/a14n6uRTE+ZKvvs=; b=ak+83mFR4N70PlOi+DCX537GRpziCQ87X1mNufPcgz3QqMh0+IaFD+FdxCvxbmZjLW d9bHGsF1TUi2KE9kqagbkhmDlOtnpsqNMOZh9G2rZRjWHXTtB04xqs9Nb4RkFg6lwigD avCVE654lAfMP0m7gwghe1br/iN1YwEmK0UXc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=52Z77MpJ2BTUH766RBrztxQXCx+/a14n6uRTE+ZKvvs=; b=Xqx5f0WYw7TSYktxeKMfMQj+5z/b58c2/TcG0MkgWxsLootXTe/Qqh1YA9owwrJUkV N9qYg50d7Y7vXg/WruPcxaJ3bzMOW86TE0aNbBnnFmUwgNdXUgF9gB1MRqc82xolSrQ/ hfPnHB7m0HJJ2wh6wpcp7cSpUcffJjUYOtG5FClk9De2kqLKB5hkC+GEGnHiQoBNdrss Yr4gS7myS1LM34+iTUaGU/pmuWhN8PsZLcXHnT1LPsXf0wpVeJ6jJr6EeE0k/bwVAb0I kNpESc4CfkOHvchVXgmvvfrz0LuYQOCqW0WVhLDYOxlqnRcZcoFyWeBsEelypvRsP9H3 kxwQ== X-Gm-Message-State: ALyK8tJpCnBB24h/5zhRsxv52Gy5zhrXWpk8Xdd82i9AvmSl7hFSix0+gleRGDG9xJu5WVI2 X-Received: by 10.98.25.147 with SMTP id 141mr4359679pfz.60.1464757124650; Tue, 31 May 2016 21:58:44 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([175.111.195.49]) by smtp.gmail.com with ESMTPSA id d71sm42764420pfd.80.2016.05.31.21.58.38 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 31 May 2016 21:58:44 -0700 (PDT) From: Baolin Wang To: axboe@kernel.dk, agk@redhat.com, snitzer@redhat.com, dm-devel@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net Cc: ebiggers3@gmail.com, js1304@gmail.com, tadeusz.struk@intel.com, smueller@chronox.de, standby24x7@gmail.com, shli@kernel.org, dan.j.williams@intel.com, martin.petersen@oracle.com, sagig@mellanox.com, kent.overstreet@gmail.com, keith.busch@intel.com, tj@kernel.org, ming.lei@canonical.com, broonie@kernel.org, arnd@arndb.de, linux-crypto@vger.kernel.org, linux-block@vger.kernel.org, linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, baolin.wang@linaro.org Subject: [RFC v3 1/4] block: Introduce blk_bio_map_sg() to map one bio Date: Wed, 1 Jun 2016 12:58:04 +0800 Message-Id: <2f0f6811938dafd14c6c7b1dbe8fbabfdcbb19c1.1464756501.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: 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 In dm-crypt, it need to map one bio to scatterlist for improving the hardware engine encryption efficiency. Thus this patch introduces the blk_bio_map_sg() function to map one bio with scatterlists. For avoiding the duplicated code in __blk_bios_map_sg() function, add one parameter to distinguish bio map or request map. Signed-off-by: Baolin Wang --- block/blk-merge.c | 36 +++++++++++++++++++++++++++++++----- include/linux/blkdev.h | 2 ++ 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/block/blk-merge.c b/block/blk-merge.c index 2613531..badae44 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -376,7 +376,7 @@ new_segment: static int __blk_bios_map_sg(struct request_queue *q, struct bio *bio, struct scatterlist *sglist, - struct scatterlist **sg) + struct scatterlist **sg, bool single_bio) { struct bio_vec bvec, bvprv = { NULL }; struct bvec_iter iter; @@ -408,13 +408,39 @@ single_segment: return 1; } - for_each_bio(bio) + if (!single_bio) { + for_each_bio(bio) + bio_for_each_segment(bvec, bio, iter) + __blk_segment_map_sg(q, &bvec, sglist, &bvprv, + sg, &nsegs, &cluster); + } else { bio_for_each_segment(bvec, bio, iter) - __blk_segment_map_sg(q, &bvec, sglist, &bvprv, sg, - &nsegs, &cluster); + __blk_segment_map_sg(q, &bvec, sglist, &bvprv, + sg, &nsegs, &cluster); + } + + return nsegs; +} + +/* + * Map a bio to scatterlist, return number of sg entries setup. Caller must + * make sure sg can hold bio segments entries. + */ +int blk_bio_map_sg(struct request_queue *q, struct bio *bio, + struct scatterlist *sglist) +{ + struct scatterlist *sg = NULL; + int nsegs = 0; + + if (bio) + nsegs = __blk_bios_map_sg(q, bio, sglist, &sg, true); + + if (sg) + sg_mark_end(sg); return nsegs; } +EXPORT_SYMBOL(blk_bio_map_sg); /* * map a request to scatterlist, return number of sg entries setup. Caller @@ -427,7 +453,7 @@ int blk_rq_map_sg(struct request_queue *q, struct request *rq, int nsegs = 0; if (rq->bio) - nsegs = __blk_bios_map_sg(q, rq->bio, sglist, &sg); + nsegs = __blk_bios_map_sg(q, rq->bio, sglist, &sg, false); if (unlikely(rq->cmd_flags & REQ_COPY_USER) && (blk_rq_bytes(rq) & q->dma_pad_mask)) { diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 1fd8fdf..5868062 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1013,6 +1013,8 @@ extern void blk_queue_write_cache(struct request_queue *q, bool enabled, bool fu extern struct backing_dev_info *blk_get_backing_dev_info(struct block_device *bdev); extern int blk_rq_map_sg(struct request_queue *, struct request *, struct scatterlist *); +extern int blk_bio_map_sg(struct request_queue *q, struct bio *bio, + struct scatterlist *sglist); extern void blk_dump_rq_flags(struct request *, char *); extern long nr_blockdev_pages(void);