From patchwork Sun Jun 9 02:18:54 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 2693421 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 2BC443FC23 for ; Sun, 9 Jun 2013 02:23:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752941Ab3FICUB (ORCPT ); Sat, 8 Jun 2013 22:20:01 -0400 Received: from mail-pb0-f46.google.com ([209.85.160.46]:38971 "EHLO mail-pb0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752582Ab3FICTz (ORCPT ); Sat, 8 Jun 2013 22:19:55 -0400 Received: by mail-pb0-f46.google.com with SMTP id rq2so1029758pbb.33 for ; Sat, 08 Jun 2013 19:19:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=5vka5SwOKdhLoN5yAwNoy4ZUL0CLKplrlGy8bkK1Ja8=; b=YVVWjoNHd8dYr2Og6F8+dZg73HOTjev0XNWVsSKa7ccgF+/VzT/DwMZ+KOL0zm7hMD yRG+cQnn8/DKxs9Q9DcCE16CVOmLDDMP3cGiPUfLVRb/qg2MV/0k6se1XeQ0pjKRAabx JwlblBeEzvnTWhrdSg8j4WZsZDddsWeSpl9H/G7jtHij1CUuKK0wyRRWQmfpR8IdrybW s+aYFuANnENT/snHFdZjj99Pa5De1P5nHIQlKw95AqNcmLVsJamusHgXvxhXLeYn+w/T pOSL8ZFXxCqQpG7wD0iu9EKi2rbTG974Oq+8Kqvy+fo+upmi2JJfXz4X87qgicGGqIH9 s/rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=5vka5SwOKdhLoN5yAwNoy4ZUL0CLKplrlGy8bkK1Ja8=; b=HlA9uNZEUtlVcm+z9srrTgAc/IMDF68CTRPjxKySammNKnSa5iUrCIcr6hsh5BSPWk dExCMMQMX65kqaxBNA889Viv4cfn/dIY8jKQojT2byf2iVnSZhE0kVqYeOfurR0+zyeN I6GYcRjZr+0HscSDDTcnscZi1GMRZ14o32LsAfXpyJb/0oiEO9XM/mfTUMaWWapQneVR Re3qZCyENl4ahf+MTz6c/9s3HwWAtKMBODxbeIG8P4VoKiXyKSl3574qmlEVEnzvJLcV BFiNvsRCAjQeRyghpOgK+jmcLXnSohNxFaiNknRP78UNqOCh29tvVJhKGvKPTxbmskVL LPZQ== X-Received: by 10.66.232.40 with SMTP id tl8mr8735648pac.121.1370744395313; Sat, 08 Jun 2013 19:19:55 -0700 (PDT) Received: from moria.home.lan (c-107-3-149-94.hsd1.ca.comcast.net. [107.3.149.94]) by mx.google.com with ESMTPSA id un15sm9511110pab.7.2013.06.08.19.19.54 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 08 Jun 2013 19:19:54 -0700 (PDT) From: Kent Overstreet To: axboe@kernel.dk, tytso@mit.edu, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: Kent Overstreet , Yehuda Sadeh , Alex Elder , ceph-devel@vger.kernel.org Subject: [PATCH 12/26] rbd: Refactor bio cloning, don't clone biovecs Date: Sat, 8 Jun 2013 19:18:54 -0700 Message-Id: <1370744348-15407-13-git-send-email-koverstreet@google.com> X-Mailer: git-send-email 1.8.3.rc1 In-Reply-To: <1370744348-15407-1-git-send-email-koverstreet@google.com> References: <1370744348-15407-1-git-send-email-koverstreet@google.com> X-Gm-Message-State: ALoCoQn7omD3SPbYj2b+opstN/+kJCLTAhR1Wbj/g48eEruqkewKz7811xcE8OCRGOrAPEWKTK6yY65Kzclbki0OnHSxHeeGgpzSHngb2E0NlulTeCQ5ruK878G+jt3nt2nYx7NeiWXZseABqX3vhpDidJtfpUKpTbeb/7cQGEgz+x7gdHOs2ojf1F/s214vhuJzsfO4Ffa0VC1r12tfc4kpDHh1YQyTNg== Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org 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 Cc: Jens Axboe Cc: Yehuda Sadeh Cc: Alex Elder 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 2a27dca..ed17d33 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -1170,73 +1170,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;