From patchwork Mon Oct 15 20:08:48 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 1596281 Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) by patchwork1.kernel.org (Postfix) with ESMTP id 272F03FD86 for ; Mon, 15 Oct 2012 20:17:59 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q9FKFNsN010976; Mon, 15 Oct 2012 16:15:24 -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 q9FKFMXV027708 for ; Mon, 15 Oct 2012 16:15:22 -0400 Received: from mx1.redhat.com (ext-mx16.extmail.prod.ext.phx2.redhat.com [10.5.110.21]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q9FKFHgn025201 for ; Mon, 15 Oct 2012 16:15:17 -0400 Received: from mail-pb0-f46.google.com (mail-pb0-f46.google.com [209.85.160.46]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9FKFFVs020327 for ; Mon, 15 Oct 2012 16:15:15 -0400 Received: by mail-pb0-f46.google.com with SMTP id rr4so5289124pbb.33 for ; Mon, 15 Oct 2012 13:15:15 -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=GsbHQhYUtL5MK9JYWIwGl9IOPovnVDyT8nVMBs4ln14=; b=HuIUYHE3L/h5RpWWP/KZBmiBH73TnqDRe9sDOu/jDks2sokS7eFnYIs/2wjPfRuQX7 PJrFSeQoumpzsNExlM2AzMkcfJedIszlTRevU6OqN8+1Qnd/TrqUUu4zolrGfZIcdnP9 yxcORGd5zV3Va9WtRVFo5mQoA/hRV3QvUmpMVCA8eAWkwiZNyXyZqXPWsKskoVk0wQHi 18DG7GTY9vIDH4pwfXNFgdjfBw7PG7m+JLbcWI6KkfI7I29J2mLnVgFVUN19tV00TZCt rW1FqUT2459QR2bODpz0Pzotkkg1o8CMmCfwgrxgA0vSOkIoOWlbGF4NyB2fu8ud5xta 7W8w== 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=GsbHQhYUtL5MK9JYWIwGl9IOPovnVDyT8nVMBs4ln14=; b=dKnWoSir7wi76QCswpO5lbyuBKLq2+KEzUQTlfnDv/4dHfBaV5APfi4vfu8v+wMgs8 wJSOco/e7j5Hi0SUItlaij+aCRJ1igY3HaucOJyljH+4M+kVPIhmnky82JhQ0ppTLuu3 A1D03WRzayFczhsdc1Dv3Yh+6+jiRbq0nc6+OGRsL92vQyrEgh2kkc2BoACILEWDdYc7 oFeojBPrh8ffGki6Es6c9PFvTHAS3YiWobalSvHkfISlLzn3VGHp4B5MyXIWBMUPpRiV AGuMxhM1IAWujTJFg4tGAAkZtvR5iHG0Xuv+VIS20eYRWfD3h4Lf5Ba1HSRky1ntRYDS QroA== Received: by 10.68.195.226 with SMTP id ih2mr41100050pbc.9.1350331806317; Mon, 15 Oct 2012 13:10:06 -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.03 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 15 Oct 2012 13:10:04 -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:08:48 -0700 Message-Id: <1350331769-14856-15-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: ALoCoQkRmHAwixRHepqm7ngHabyy4p3LjYNTVHggep8iOYxxil+4mLjU9BOScmKmp+NPA9cGLSPjHBm7w/uKDaf4CGBDgwBUPMx9Tn0jIqqh8GjM3xrb76hA9QOFotiWjkN/nTodK9Bk7Dlo+i21Nkc26vMnbHC9HgQK1ZbFow2GKeZ1rb5Ty2OFX4bLPwOYGgqXiIupGxGU 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.21 X-loop: dm-devel@redhat.com Cc: tj@kernel.org, axboe@kernel.dk, Kent Overstreet , vgoyal@redhat.com Subject: [dm-devel] [PATCH v4 14/24] 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 aeb74b8..d698f29d 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 b20a9cd..90d36c6 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 *,