From patchwork Mon Sep 24 22:34:56 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 1500771 Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from mx4-phx2.redhat.com (mx4-phx2.redhat.com [209.132.183.25]) by patchwork1.kernel.org (Postfix) with ESMTP id 1CD103FE80 for ; Mon, 24 Sep 2012 22:39:07 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx4-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q8OMbDP5026085; Mon, 24 Sep 2012 18:37:13 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q8OMZsto009247 for ; Mon, 24 Sep 2012 18:35:54 -0400 Received: from mx1.redhat.com (ext-mx13.extmail.prod.ext.phx2.redhat.com [10.5.110.18]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q8OMZnmW003519 for ; Mon, 24 Sep 2012 18:35:49 -0400 Received: from mail-pa0-f46.google.com (mail-pa0-f46.google.com [209.85.220.46]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q8OMZUrI027107 for ; Mon, 24 Sep 2012 18:35:49 -0400 Received: by mail-pa0-f46.google.com with SMTP id hz1so1170114pad.33 for ; Mon, 24 Sep 2012 15:35:49 -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=gPNFJfFES3yATmu1+qubxWjjUsLbYy1cPtDJogiH1KI=; b=Q/+LaSQvtC8maQJacSwzT2Aj8uBobozk3/xtSrdPu5+sMMOJmFpYKEgGhyBl3/hbeV kCX0Vey9QRl7g1xaRM+mrG7kR3lDcqwsLWKUhaYRwYD/QJgBGZEPJ4AfjrFdFP9xhq1U UFX/VcfgClN9lhumAdhT61y+Z4+/fB9hhS5UeoK96h/y3JFNIEtwBUgmOb61A6iYA/4g qLVfhkxghADFuFBWFgG58JjBdbiPYKkZ9ApX1NUydk4MVf4A/+pkP8ZMzPOxoiUgrbIq enTa3lztQlQpyR7qrgP2v2qKwMFCL8IPFnhNtn5zplXdkYWjbcHfv9TXgkoSySfS38tq oMPQ== 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=gPNFJfFES3yATmu1+qubxWjjUsLbYy1cPtDJogiH1KI=; b=LJ/P7kNX10Nmhf9+/vNNNLknyDzjcvS05ZNpH8pQHUPwaxCqcRwbO1hMnMmMQJAHyT jhSn9g9UJrSL6bl2i1vrVmrQSDev+ZjJW4kvCL8eLt1RbcC4E2JDIUPFNGCuSBnTdRVG PwAwzMRJE51RSwm2hCiwbTIvxiLtf+W3NRRbKfkGJMkFaGAp12poz5tVNBdw1KUoqFxa sEuR3ehj4mhwAoZFb7p9WQz1858tdy1ZzznBJTbXkyEI3xNkD8oI59uHSzaml5bPeM0z Kn6YcDKofdV3gOAK7WYCzY/So6OoAt1tAVxfXPFmOOm2Rd47a5abO+Moa/+JBdMegEFu xCxQ== Received: by 10.68.232.194 with SMTP id tq2mr40306984pbc.111.1348526149081; Mon, 24 Sep 2012 15:35:49 -0700 (PDT) Received: by 10.68.232.194 with SMTP id tq2mr40306971pbc.111.1348526148996; Mon, 24 Sep 2012 15:35:48 -0700 (PDT) Received: from formenos.mtv.corp.google.com (formenos.mtv.corp.google.com [172.18.110.66]) by mx.google.com with ESMTPS id nu8sm133316pbc.45.2012.09.24.15.35.47 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 24 Sep 2012 15:35:48 -0700 (PDT) From: Kent Overstreet To: linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org, dm-devel@redhat.com Date: Mon, 24 Sep 2012 15:34:56 -0700 Message-Id: <1348526106-17074-17-git-send-email-koverstreet@google.com> In-Reply-To: <1348526106-17074-1-git-send-email-koverstreet@google.com> References: <1348526106-17074-1-git-send-email-koverstreet@google.com> X-Gm-Message-State: ALoCoQnErdU2K/ufFXK2wcXB3SRUHR/PlLQZCuPuU3qANApSMF9MYTida3v6FiH4wrp7ZPpWpLX/oos8UPPb9KodRemJ9n/SEKc03CMnJ/keEmYW6R7Ihj/uD4akH6ooV3emWcN6ZJC4v0XFO602bTk4cLqkOzD73SPD2j0/FRGwDVQXgaD+klk+uto0DV6KE51guXgVj0Dk X-RedHat-Spam-Score: -3.512 (BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, SPF_PASS) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-Scanned-By: MIMEDefang 2.68 on 10.5.110.18 X-loop: dm-devel@redhat.com Cc: tj@kernel.org, axboe@kernel.dk, Kent Overstreet , vgoyal@redhat.com Subject: [dm-devel] [PATCH v3 16/26] block: Add bio_copy_data() X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com This gets open coded quite a bit and it's tricky to get right, so make a generic version and convert some existing users over to it instead. Signed-off-by: Kent Overstreet CC: Jens Axboe --- fs/bio.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/bio.h | 2 ++ 2 files changed, 72 insertions(+) diff --git a/fs/bio.c b/fs/bio.c index 9a30dcf..d433825 100644 --- a/fs/bio.c +++ b/fs/bio.c @@ -827,6 +827,76 @@ void bio_advance(struct bio *bio, unsigned bytes) } EXPORT_SYMBOL(bio_advance); +/** + * bio_copy_data - copy contents of data buffers from one chain of bios to + * another + * @src: source bio list + * @dst: destination bio list + * + * If @src and @dst are single bios, bi_next must be NULL - otherwise, treats + * @src and @dst as linked lists of bios. + * + * Stops when it reaches the end of either @src or @dst - that is, copies + * min(src->bi_size, dst->bi_size) bytes (or the equivalent for lists of bios). + */ +void bio_copy_data(struct bio *dst, struct bio *src) +{ + struct bio_vec *src_bv, *dst_bv; + unsigned src_offset, dst_offset, bytes; + void *src_p, *dst_p; + + src_bv = bio_iovec(src); + dst_bv = bio_iovec(dst); + + src_offset = src_bv->bv_offset; + dst_offset = dst_bv->bv_offset; + + while (1) { + if (src_offset == src_bv->bv_offset + src_bv->bv_len) { + src_bv++; + if (src_bv == bio_iovec_idx(src, src->bi_vcnt)) { + src = src->bi_next; + if (!src) + break; + + src_bv = bio_iovec(src); + } + + src_offset = src_bv->bv_offset; + } + + if (dst_offset == dst_bv->bv_offset + dst_bv->bv_len) { + dst_bv++; + if (dst_bv == bio_iovec_idx(dst, dst->bi_vcnt)) { + dst = dst->bi_next; + if (!dst) + break; + + dst_bv = bio_iovec(dst); + } + + dst_offset = dst_bv->bv_offset; + } + + bytes = min(dst_bv->bv_offset + dst_bv->bv_len - dst_offset, + src_bv->bv_offset + src_bv->bv_len - src_offset); + + src_p = kmap_atomic(src_bv->bv_page); + dst_p = kmap_atomic(dst_bv->bv_page); + + memcpy(dst_p + dst_bv->bv_offset, + src_p + src_bv->bv_offset, + bytes); + + kunmap_atomic(dst_p); + kunmap_atomic(src_p); + + src_offset += bytes; + dst_offset += bytes; + } +} +EXPORT_SYMBOL(bio_copy_data); + struct bio_map_data { struct bio_vec *iovecs; struct sg_iovec *sgvecs; diff --git a/include/linux/bio.h b/include/linux/bio.h index 3bf696b..467e101 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -289,6 +289,8 @@ static inline void bio_flush_dcache_pages(struct bio *bi) } #endif +extern void bio_copy_data(struct bio *dst, struct bio *src); + extern struct bio *bio_copy_user(struct request_queue *, struct rq_map_data *, unsigned long, unsigned int, int, gfp_t); extern struct bio *bio_copy_user_iov(struct request_queue *,