From: Baolin Wang <baolin.wang@linaro.org>
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 1/3] block: Introduce blk_bio_map_sg() to map one bio
Date: Wed, 25 May 2016 14:12:29 +0800 [thread overview]
Message-ID: <abe693fad3abb0adfc0cf9ca5b3d287fdb0f2d5b.1464144791.git.baolin.wang@linaro.org> (raw)
In-Reply-To: <cover.1464144790.git.baolin.wang@linaro.org>
In-Reply-To: <cover.1464144790.git.baolin.wang@linaro.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.
Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
block/blk-merge.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
include/linux/blkdev.h | 3 +++
2 files changed, 48 insertions(+)
diff --git a/block/blk-merge.c b/block/blk-merge.c
index 2613531..9b92af4 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -417,6 +417,51 @@ single_segment:
}
/*
+ * map a bio to scatterlist, return number of sg entries setup.
+ */
+int blk_bio_map_sg(struct request_queue *q, struct bio *bio,
+ struct scatterlist *sglist,
+ struct scatterlist **sg)
+{
+ struct bio_vec bvec, bvprv = { NULL };
+ struct bvec_iter iter;
+ int nsegs, cluster;
+
+ nsegs = 0;
+ cluster = blk_queue_cluster(q);
+
+ if (bio->bi_rw & REQ_DISCARD) {
+ /*
+ * This is a hack - drivers should be neither modifying the
+ * biovec, nor relying on bi_vcnt - but because of
+ * blk_add_request_payload(), a discard bio may or may not have
+ * a payload we need to set up here (thank you Christoph) and
+ * bi_vcnt is really the only way of telling if we need to.
+ */
+
+ if (bio->bi_vcnt)
+ goto single_segment;
+
+ return 0;
+ }
+
+ if (bio->bi_rw & REQ_WRITE_SAME) {
+single_segment:
+ *sg = sglist;
+ bvec = bio_iovec(bio);
+ sg_set_page(*sg, bvec.bv_page, bvec.bv_len, bvec.bv_offset);
+ return 1;
+ }
+
+ bio_for_each_segment(bvec, bio, iter)
+ __blk_segment_map_sg(q, &bvec, sglist, &bvprv, sg,
+ &nsegs, &cluster);
+
+ return nsegs;
+}
+EXPORT_SYMBOL(blk_bio_map_sg);
+
+/*
* map a request to scatterlist, return number of sg entries setup. Caller
* must make sure sg can hold rq->nr_phys_segments entries
*/
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 1fd8fdf..e5de4f8 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1013,6 +1013,9 @@ 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,
+ struct scatterlist **sg);
extern void blk_dump_rq_flags(struct request *, char *);
extern long nr_blockdev_pages(void);
--
1.7.9.5
next prev parent reply other threads:[~2016-05-25 6:13 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-25 6:12 [RFC 0/3] Introduce the bulk mode method when sending request to crypto layer Baolin Wang
2016-05-25 6:12 ` Baolin Wang [this message]
2016-05-25 8:52 ` [RFC 1/3] block: Introduce blk_bio_map_sg() to map one bio Ming Lei
2016-05-25 9:02 ` Baolin Wang
2016-05-25 6:12 ` [RFC 2/3] crypto: Introduce CRYPTO_ALG_BULK flag Baolin Wang
2016-05-27 6:31 ` Milan Broz
2016-05-27 7:04 ` Baolin Wang
2016-05-27 7:53 ` Milan Broz
2016-05-27 9:04 ` Baolin Wang
2016-05-25 6:12 ` [RFC 3/3] md: dm-crypt: Introduce the bulk mode method when sending request Baolin Wang
2016-05-26 14:04 ` Mike Snitzer
2016-05-27 6:03 ` Baolin Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=abe693fad3abb0adfc0cf9ca5b3d287fdb0f2d5b.1464144791.git.baolin.wang@linaro.org \
--to=baolin.wang@linaro.org \
--cc=agk@redhat.com \
--cc=arnd@arndb.de \
--cc=axboe@kernel.dk \
--cc=broonie@kernel.org \
--cc=dan.j.williams@intel.com \
--cc=davem@davemloft.net \
--cc=dm-devel@redhat.com \
--cc=ebiggers3@gmail.com \
--cc=herbert@gondor.apana.org.au \
--cc=js1304@gmail.com \
--cc=keith.busch@intel.com \
--cc=kent.overstreet@gmail.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-raid@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=ming.lei@canonical.com \
--cc=sagig@mellanox.com \
--cc=shli@kernel.org \
--cc=smueller@chronox.de \
--cc=snitzer@redhat.com \
--cc=standby24x7@gmail.com \
--cc=tadeusz.struk@intel.com \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®