From patchwork Fri May 27 11:11:22 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: 68733 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp22484qge; Fri, 27 May 2016 04:12:20 -0700 (PDT) X-Received: by 10.98.69.202 with SMTP id n71mr22084561pfi.82.1464347540044; Fri, 27 May 2016 04:12:20 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z63si7476314pfb.210.2016.05.27.04.12.19; Fri, 27 May 2016 04:12:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753567AbcE0LMF (ORCPT + 30 others); Fri, 27 May 2016 07:12:05 -0400 Received: from mail-pa0-f53.google.com ([209.85.220.53]:36234 "EHLO mail-pa0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753485AbcE0LMC (ORCPT ); Fri, 27 May 2016 07:12:02 -0400 Received: by mail-pa0-f53.google.com with SMTP id eu11so30234835pad.3 for ; Fri, 27 May 2016 04:12:01 -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=KEtaRTM7rraiWzKdmlS11NRYft17FqYdcD/nPe9q/4ic1MO9LbWc3t5OGhNtDndp2I U7dRKmbPxvQRacyyHNNEzLCAirGWtgeal8i85FhGOactS3X6LihkcZBEBplVMuavSdkV 6+ZFkrS5lXhK2Dvx1gqw15QFNVCWOOAuk2yyA= 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=Aj3EfMc8WVX5Fx0YxpxZO0dW2yLVRswxfCXwCFVSVpVd5DQ5XgvRawcZBtsWJRM9xI CkEVV5t3yZPddiUxerg/BR9VrThyaK7o4LlUhtqTTjAed4uoPm3ukg+EWt1AC6Ej6zzx Z5FwnltqSAXxyJ3JT7gomSv/sJVHggvkxfuwAoN/nF4HgMBhFoXEAX7toW6xtG6j/GLG lU2quoeYEl5rQ4fwJRm9J31sHZvp8i5YWmmj7qbEmAyIQi68KqmoqMd+YdEUDiBReztg O9JPhGk7lQQ/CdzObK2SULeKlJ5/6Afk5hE86jbbudQWWGx/+IAW+M0MZI04I9gnmWLv HRCQ== X-Gm-Message-State: ALyK8tI093oDnC63xY/qcWjU4ndeu/hJJwm7zsATfUC8p7uXpR8s54K5W9Uq1lotYnmpLmKI X-Received: by 10.66.26.37 with SMTP id i5mr21716910pag.15.1464347520978; Fri, 27 May 2016 04:12:00 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([175.111.195.49]) by smtp.gmail.com with ESMTPSA id vi6sm27430788pab.21.2016.05.27.04.11.54 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 27 May 2016 04:12:00 -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 v2 1/3] block: Introduce blk_bio_map_sg() to map one bio Date: Fri, 27 May 2016 19:11:22 +0800 Message-Id: <2f0f6811938dafd14c6c7b1dbe8fbabfdcbb19c1.1464346333.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) -- 1.7.9.5 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);