From patchwork Mon Oct 15 20:09:05 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 1595811 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 125CB3FD86 for ; Mon, 15 Oct 2012 20:14:16 +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 q9FKBKQd010371; Mon, 15 Oct 2012 16:11:20 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q9FKAc2j027137 for ; Mon, 15 Oct 2012 16:10:38 -0400 Received: from mx1.redhat.com (ext-mx16.extmail.prod.ext.phx2.redhat.com [10.5.110.21]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q9FKAX4a004865 for ; Mon, 15 Oct 2012 16:10:33 -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 q9FK9j4Z018962 for ; Mon, 15 Oct 2012 16:10:31 -0400 Received: by mail-pa0-f46.google.com with SMTP id hz1so5214154pad.33 for ; Mon, 15 Oct 2012 13:10:31 -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=0F3qqsX+rsfVV8St9AQRugLPlsb+05qpIWPc30g8flY=; b=FwdvA5sXSPzO1RXK5U0I8iBj0dB2v5qZ3gRnaTXOe8pwQufGekbMmW7gXUDI90GTRi DBna6p4KhGAH7N08/RVpZvLXPdVPNTvxVFYDdGH/qH23zxUsVl/P+BJP0TuC3cL5hlcy 4qUW5c+h6mlUr9z0vXmcX51lNStDAeAIg9tHtuJ5lFWGP4DBcYy4EES1oQXVaLfCD+MX 8DuKLr40HZufFstHNeuFYMiZVTih/I5TiPEspaBMqrH1XKzW4RwXCGYxgmCSr4qLc4Ww DvK3LY1b/6kwqNjtyTmeuOC6NKtcqqfmuRnYNP0gXbDERuQlagVNvLxqaFt/z6gJtbM1 g/6A== 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=0F3qqsX+rsfVV8St9AQRugLPlsb+05qpIWPc30g8flY=; b=Me9aM1jv3p8wAJBtgb8ITyBSO/m6EM4+T5uUcyL9SvhY4omm/EODXEgAGEbzawyq+5 n3S7tZzfFvumgAqFdBpKrbLcXWiQjY3k7E32UPEKfKwhtly9BK+mqW3qdRmkoO9MKe95 qNsrwGPhQCp+w/1ZVmt1VfNbnOQZheI9G+psn7vVd+s/YSH2qQhbPuf617mg39cdItAF q5IcIzYGgAi2D6gyZ1ZBjWxiE2m2mDjQDzZ4pKfAGv524MJUkv/mvYm+8hSJxxudNgTP XcU07MQI/J3T3/YTPvrBjU9Cz/pWi7LhPe3hsFSASrZGElIhG9qTJx09J1IAxdIStDW9 KwAQ== Received: by 10.66.77.168 with SMTP id t8mr35754116paw.28.1350331831444; Mon, 15 Oct 2012 13:10:31 -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.30 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 15 Oct 2012 13:10:30 -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:05 -0700 Message-Id: <1350331769-14856-32-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: ALoCoQmEFvhjltLPQhUWDOj/DGFb9njFqEpZc0eKCMjRVQsFYb5jlktMl85mB0Z+OBdXfd9VLQshh8n+SWxFbgJyhZYjE+RuRs0Ce+EihcWwAbHxLee0Me6l79je5Pc997QqH/hN7bAu11FPVmQ6eGGdx9mG4OB7e2lcdX8FvRei69QkFoJaWQCbD3l4Pi7QT/V6WwgZICDg 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.22 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 Subject: [dm-devel] [PATCH v2 02/26] block: Add bio_advance() 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 is prep work for immutable bio vecs; we first want to centralize where bvecs are modified. Next two patches convert some existing code to use this function. Signed-off-by: Kent Overstreet CC: Jens Axboe --- fs/bio.c | 41 +++++++++++++++++++++++++++++++++++++++++ include/linux/bio.h | 2 ++ 2 files changed, 43 insertions(+) diff --git a/fs/bio.c b/fs/bio.c index 4783e31..07587c0 100644 --- a/fs/bio.c +++ b/fs/bio.c @@ -750,6 +750,47 @@ int bio_add_page(struct bio *bio, struct page *page, unsigned int len, } EXPORT_SYMBOL(bio_add_page); +/** + * bio_advance - increment/complete a bio by some number of bytes + * @bio: bio to advance + * @bytes: number of bytes to complete + * + * This updates bi_sector, bi_size and bi_idx; if the number of bytes to + * complete doesn't align with a bvec boundary, then bv_len and bv_offset will + * be updated on the last bvec as well. + * + * @bio will then represent the remaining, uncompleted portion of the io. + */ +void bio_advance(struct bio *bio, unsigned bytes) +{ + if (bio_integrity(bio)) + bio_integrity_advance(bio, bytes); + + bio->bi_sector += bytes >> 0; + bio->bi_size -= bytes; + + if (!bio->bi_size) + return; + + while (bytes) { + if (unlikely(bio->bi_idx >= bio->bi_vcnt)) { + printk(KERN_ERR "%s: bio idx %d >= vcnt %d\n", + __func__, bio->bi_idx, bio->bi_vcnt); + break; + } + + if (bytes >= bio_iovec(bio)->bv_len) { + bytes -= bio_iovec(bio)->bv_len; + bio->bi_idx++; + } else { + bio_iovec(bio)->bv_len -= bytes; + bio_iovec(bio)->bv_offset += bytes; + bytes = 0; + } + } +} +EXPORT_SYMBOL(bio_advance); + 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 7873465..6763cdf 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -248,6 +248,8 @@ extern void bio_endio(struct bio *, int); struct request_queue; extern int bio_phys_segments(struct request_queue *, struct bio *); +void bio_advance(struct bio *, unsigned); + extern void bio_init(struct bio *); extern void bio_reset(struct bio *);