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: 9138163 X-Patchwork-Delegate: herbert@gondor.apana.org.au 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 98BA3607DA 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 8A7F127CF9 for ; Fri, 27 May 2016 11:12:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7EF0B28135; 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=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 2725228137 for ; Fri, 27 May 2016 11:12:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753574AbcE0LMJ (ORCPT ); Fri, 27 May 2016 07:12:09 -0400 Received: from mail-pa0-f48.google.com ([209.85.220.48]:35115 "EHLO mail-pa0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753491AbcE0LMH (ORCPT ); Fri, 27 May 2016 07:12:07 -0400 Received: by mail-pa0-f48.google.com with SMTP id fy7so22880487pac.2 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=WLCrw/GTRDaNyfyaJi0yZl0xACI3LDD3DekA2BLABIhAhWidSfUd8XOza3+Y9xJHXM ETWW/Du/3kEY20gRSnbhWXPJWDARyCkWfHZrLgld+2D+TEzKW7zlEk8X8TCKl58oxn32 WAo09CvU+EcwOXQPYDamgkwjKBr+1rHcQbaCFMuh4Z4fSt1DqvW1E5u2BKjjvGfqA2uJ UZTP376JwH1AWMAo3fpYlIQOeXXIUx7+bHOcIfV6CzfEr/OUfwZsndsIRQN8bnKe4Vy7 67qwqWzuc15MDAnZuaXMFECZ4deiI8hPAdy7cIQJLZPq30D0vE7lfiE2GGvszAT9L8RK /XvQ== X-Gm-Message-State: ALyK8tJuMK3hxpmp8Moxe2AKPcIedJCk9xUmrXWh8w7k43TnsNNrWCtUP53kRzbfIWgD3N2U 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-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@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);