From patchwork Mon Oct 15 20:09:18 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 1596021 Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from mx4-phx2.redhat.com (mx4-phx2.redhat.com [209.132.183.25]) by patchwork2.kernel.org (Postfix) with ESMTP id 9E93CDFB34 for ; Mon, 15 Oct 2012 20:14:52 +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 q9FKBPeW006942; Mon, 15 Oct 2012 16:11:25 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q9FKAsOZ027285 for ; Mon, 15 Oct 2012 16:10:54 -0400 Received: from mx1.redhat.com (ext-mx13.extmail.prod.ext.phx2.redhat.com [10.5.110.18]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q9FKAndV024048 for ; Mon, 15 Oct 2012 16:10:49 -0400 Received: from mail-da0-f46.google.com (mail-da0-f46.google.com [209.85.210.46]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9FK9m2t007506 for ; Mon, 15 Oct 2012 16:10:48 -0400 Received: by mail-da0-f46.google.com with SMTP id n41so2761040dak.33 for ; Mon, 15 Oct 2012 13:10:48 -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=JgNFE/JVw9clrUnjs88M5jm5zJtoBmLD6DLN6Uj3fvI=; b=P1fCWrK61S3t+1AYZhdm0chUmShRUk3L2GfKHOSHzI+rK5r0GzVG9TjKrCO/P3TS68 NgJd+VMFh7sIyYbKczQj8R/04zEFJLM0BoVbLpvpRRmm7MCW/vjaM6297FAQRfkQGxNh xMfmwmN+wZdfORxUyrg87NY78zd03pO3i/+CKNZPUI25es+3bn5fRq8nVwvTKgxKNPZm qlhQpmJTppBiMVo7klceUbYjpPjeTbmHjH+UTvxc3wV1dfqJ3CK9h3GSH+x1obFobCk+ KnPbg6u8k8vGOCE/pTw6M0OIAV6zDkzOf+cKMA3jhrlxeEQj6aQgZzeWiYHpdGp5XuG4 lvaw== 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=JgNFE/JVw9clrUnjs88M5jm5zJtoBmLD6DLN6Uj3fvI=; b=BGgt4EpcddwoRl2PCex1NpSirQOJHZOWapDpSpAolpRAfkFhtTO7PNrF+vm9wf3TMi PxPkQWmcnALt9tyCNwFTTCzqaoKKI0/X5Y+vaeNSQ4JH12anTPxpAAAfk5zJEO7uGEth 3ze7JwkilRjGaU/n2RPb2gIl7pUfue9JX0+0EkVaXpfkOWb5NBVsyPeV/HmJxkVmGyRk W8F1FVtCkjxL02Sq5iTyc3cAjPt2b4e4q2CdxBaOkWtfKi2gw7QVZKj36p9T+5aK6UzM 3URAb5Pb2hz6tli5uHaHw81oF/9H8MBJZ97LK8x/sbGIQvWcnHC4zraldD0YAHSojoui d7Dg== Received: by 10.68.234.71 with SMTP id uc7mr40213072pbc.72.1350331848397; Mon, 15 Oct 2012 13:10: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 k9sm3021703paz.22.2012.10.15.13.10.47 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 15 Oct 2012 13:10:47 -0700 (PDT) From: Kent Overstreet To: linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org, dm-devel@redhat.com Date: Mon, 15 Oct 2012 13:09:18 -0700 Message-Id: <1350331769-14856-45-git-send-email-koverstreet@google.com> In-Reply-To: <1350331769-14856-1-git-send-email-koverstreet@google.com> References: <1350331769-14856-1-git-send-email-koverstreet@google.com> X-Gm-Message-State: ALoCoQnzaBX5DyPZgH6aOewDFQ6VSaYPLBNA5fQDy+FqejSkH5z+3tP7aUHMW/jPKN/oHYhVi+Eis/Qd2OvUfIUjmAxDQGaNqyZEzndyWw+Hc8zURqpwSldq0xdSlIlj7moPHXeAyYGvBFCUZIkps6Rjx+b7eo7ITlQX9cReKMc/K9fh/mS2eIkjoR1JwZ2Oy/AQc5WAS3Qn X-RedHat-Spam-Score: -3.072 (BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, SPF_PASS) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 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 Subject: [dm-devel] [PATCH v2 15/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 1342a16..7fb9f4e 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 949c48a..92015ce 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -286,6 +286,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 *,