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: 9138159 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 5133060467 for ; Fri, 27 May 2016 11:12:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 41E7827CF9 for ; Fri, 27 May 2016 11:12:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2FAD62818B; Fri, 27 May 2016 11:12:15 +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=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 ADE6127CF9 for ; Fri, 27 May 2016 11:12:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753485AbcE0LMF (ORCPT ); Fri, 27 May 2016 07:12:05 -0400 Received: from mail-pa0-f43.google.com ([209.85.220.43]:34802 "EHLO mail-pa0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753491AbcE0LMC (ORCPT ); Fri, 27 May 2016 07:12:02 -0400 Received: by mail-pa0-f43.google.com with SMTP id bz2so9756709pad.1 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=K4OaW7Z3z1AsRUfQZjzQNZcYQte5oFjRGTmMSpXKGsZ07KkQc8bfiO9Kj948i1hJgr aYaBBA2U9z4kKoh/3U0SbvabZbUoldQzm4xfoly5zmXx4IIB4AsxYyyrHGqzrHMz+dO0 AfSGspdj5EE+4/KQUkJR+IF9CyJVyVFJqeN1XR44bGxE+eGCCpGmLPZfuTWlQezyoARQ iUdS/h985ev+4gL+ToRxK4Dc9KsfoalwVlAngqKuNQ6pHAAbj+Pj/+iH+z2WrSyXvLXj kdT3Oxk6lMssdTCLRKQTxxHDJcaxuLjwXSKhiRe/f0UkmC11qrJ3dUkFS1Co+IBx+eVo GwAQ== X-Gm-Message-State: ALyK8tJsQvfSCqOzyhkjiv0Qq9+PwxdlY2cf/j3X+oa0lKrGHhSgyJHdzVj05jNz6PuVxi50 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-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);