From: Kent Overstreet <kmo@daterainc.com>
To: axboe@kernel.dk
Cc: linux-kernel@vger.kernel.org, hch@infradead.org, tj@kernel.org,
nab@linux-iscsi.org, Kent Overstreet <kmo@daterainc.com>,
Yehuda Sadeh <yehuda@inktank.com>, Alex Elder <elder@inktank.com>,
ceph-devel@vger.kernel.org
Subject: [PATCH 16/23] rbd: Refactor bio cloning, don't clone biovecs
Date: Tue, 29 Oct 2013 13:18:09 -0700 [thread overview]
Message-ID: <1383077896-4132-17-git-send-email-kmo@daterainc.com> (raw)
In-Reply-To: <1383077896-4132-1-git-send-email-kmo@daterainc.com>
Now that we've got drivers converted to the new immutable bvec
primitives, bio splitting becomes much easier. In a few patches,
bio_clone() will be changed to share the old bio's bvec instead of
copying it, and bio_split() will do exactly what's being done here.
Signed-off-by: Kent Overstreet <kmo@daterainc.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Yehuda Sadeh <yehuda@inktank.com>
Cc: Alex Elder <elder@inktank.com>
Cc: ceph-devel@vger.kernel.org
---
drivers/block/rbd.c | 64 ++---------------------------------------------------
1 file changed, 2 insertions(+), 62 deletions(-)
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 3241d5e..f2381e3 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -1173,73 +1173,13 @@ static struct bio *bio_clone_range(struct bio *bio_src,
unsigned int len,
gfp_t gfpmask)
{
- struct bio_vec bv;
- struct bvec_iter iter;
- struct bvec_iter end_iter;
- unsigned int resid;
- unsigned int voff;
- unsigned short vcnt;
struct bio *bio;
- /* Handle the easy case for the caller */
-
- if (!offset && len == bio_src->bi_iter.bi_size)
- return bio_clone(bio_src, gfpmask);
-
- if (WARN_ON_ONCE(!len))
- return NULL;
- if (WARN_ON_ONCE(len > bio_src->bi_iter.bi_size))
- return NULL;
- if (WARN_ON_ONCE(offset > bio_src->bi_iter.bi_size - len))
- return NULL;
-
- /* Find first affected segment... */
-
- resid = offset;
- bio_for_each_segment(bv, bio_src, iter) {
- if (resid < bv.bv_len)
- break;
- resid -= bv.bv_len;
- }
- voff = resid;
-
- /* ...and the last affected segment */
-
- resid += len;
- __bio_for_each_segment(bv, bio_src, end_iter, iter) {
- if (resid <= bv.bv_len)
- break;
- resid -= bv.bv_len;
- }
- vcnt = end_iter.bi_idx = iter.bi_idx + 1;
-
- /* Build the clone */
-
- bio = bio_alloc(gfpmask, (unsigned int) vcnt);
+ bio = bio_clone(bio_src, gfpmask);
if (!bio)
return NULL; /* ENOMEM */
- bio->bi_bdev = bio_src->bi_bdev;
- bio->bi_iter.bi_sector = bio_src->bi_iter.bi_sector +
- (offset >> SECTOR_SHIFT);
- bio->bi_rw = bio_src->bi_rw;
- bio->bi_flags |= 1 << BIO_CLONED;
-
- /*
- * Copy over our part of the bio_vec, then update the first
- * and last (or only) entries.
- */
- memcpy(&bio->bi_io_vec[0], &bio_src->bi_io_vec[iter.bi_idx],
- vcnt * sizeof (struct bio_vec));
- bio->bi_io_vec[0].bv_offset += voff;
- if (vcnt > 1) {
- bio->bi_io_vec[0].bv_len -= voff;
- bio->bi_io_vec[vcnt - 1].bv_len = resid;
- } else {
- bio->bi_io_vec[0].bv_len = len;
- }
-
- bio->bi_vcnt = vcnt;
+ bio_advance(bio, offset);
bio->bi_iter.bi_size = len;
return bio;
--
1.8.4.rc3
next prev parent reply other threads:[~2013-10-29 20:18 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-29 20:17 [PATCH] Immutable biovecs Kent Overstreet
2013-10-29 20:17 ` [PATCH 01/23] block: Use rw_copy_check_uvector() Kent Overstreet
2013-10-29 20:17 ` [PATCH 02/23] block: Consolidate duplicated bio_trim() implementations Kent Overstreet
2013-10-29 20:17 ` [PATCH 03/23] bcache: Kill unaligned bvec hack Kent Overstreet
2013-10-29 20:17 ` [PATCH 05/23] dm: Use bvec_iter for dm_bio_record() Kent Overstreet
2013-10-29 20:17 ` [PATCH 06/23] block: Convert bio_iovec() to bvec_iter Kent Overstreet
2013-10-29 20:18 ` [PATCH 08/23] block: Immutable bio vecs Kent Overstreet
2013-10-29 20:18 ` [PATCH 09/23] block: Convert bio_copy_data() to bvec_iter Kent Overstreet
2013-10-29 20:18 ` [PATCH 10/23] bio-integrity: Convert " Kent Overstreet
2013-10-29 20:18 ` [PATCH 11/23] block: Kill bio_segments()/bi_vcnt usage Kent Overstreet
2013-10-29 20:18 ` [PATCH 12/23] block: Convert drivers to immutable biovecs Kent Overstreet
2013-10-29 20:18 ` [PATCH 13/23] aoe: Convert " Kent Overstreet
2013-10-29 20:18 ` [PATCH 14/23] ceph: " Kent Overstreet
2013-10-29 20:18 ` [PATCH 15/23] block: Kill bio_iovec_idx(), __bio_iovec() Kent Overstreet
2013-10-29 20:18 ` Kent Overstreet [this message]
2013-10-29 20:18 ` [PATCH 17/23] dm: Refactor for new bio cloning/splitting Kent Overstreet
2013-10-29 23:04 ` Mike Snitzer
2013-10-30 0:09 ` Mike Snitzer
2013-10-30 0:19 ` Kent Overstreet
2013-10-30 0:29 ` Mike Snitzer
2013-10-31 14:05 ` Jens Axboe
2013-10-29 20:18 ` [PATCH 18/23] block: Remove bi_idx hacks Kent Overstreet
2013-10-29 20:18 ` [PATCH 19/23] block: Generic bio chaining Kent Overstreet
2013-10-29 20:18 ` [PATCH 20/23] block: Rename bio_split() -> bio_pair_split() Kent Overstreet
2013-10-29 20:18 ` [PATCH 21/23] block: Introduce new bio_split() Kent Overstreet
2013-10-29 20:18 ` [PATCH 22/23] block: Kill bio_pair_split() Kent Overstreet
2013-10-29 20:18 ` [PATCH 23/23] block: Don't save/copy bvec array anymore, share when cloning Kent Overstreet
2013-10-29 20:36 ` [PATCH] Immutable biovecs Jens Axboe
2013-10-30 0:06 ` Kent Overstreet
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=1383077896-4132-17-git-send-email-kmo@daterainc.com \
--to=kmo@daterainc.com \
--cc=axboe@kernel.dk \
--cc=ceph-devel@vger.kernel.org \
--cc=elder@inktank.com \
--cc=hch@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nab@linux-iscsi.org \
--cc=tj@kernel.org \
--cc=yehuda@inktank.com \
/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
Powered by JetHome