From patchwork Mon Oct 15 20:08:35 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 1595591 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 E165FDFB34 for ; Mon, 15 Oct 2012 20:13:06 +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 q9FK9qTG006631; Mon, 15 Oct 2012 16:09:54 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q9FK9oIH026880 for ; Mon, 15 Oct 2012 16:09:50 -0400 Received: from mx1.redhat.com (ext-mx16.extmail.prod.ext.phx2.redhat.com [10.5.110.21]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q9FK9jg8026494 for ; Mon, 15 Oct 2012 16:09:45 -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 q9FK9gLC018945 for ; Mon, 15 Oct 2012 16:09:44 -0400 Received: by mail-pa0-f46.google.com with SMTP id hz1so5214109pad.33 for ; Mon, 15 Oct 2012 13:09:44 -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=8srZ3WnSvawdp24LKyWWyhVoESzhywJ6vBV/9OwDpYQ=; b=kAnT5DUrUuNSHp8mWBUgpQQ+qCyx2ZaDjP0za249vBHvdCW2llva7/058zNWjMNotj kyRtApKKRJV4bL4ntEigui71LitdJv5lEwdvoguiXZsBP4EjoBQS6gpnu9pkmOkvNP1j 0Tdnz1Y4tqQyxSs4l4GgvLNRpy+sMdLqi8ew9U3Mjo4hxS4suc1ukPb+fmbkOvr5G11H OW/UbXGRNWa99xN2bXr4PtOIjtZEZMf6fA4k3xBPwdjwGhuRVW1VDmxlupkb/do3BvP8 OsnIobqJ+9y7vXf3JfpHvXm9S1jJ+03XBaNU79uwShSMqthucoGGApqiomPfhJrvEboc O66g== 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=8srZ3WnSvawdp24LKyWWyhVoESzhywJ6vBV/9OwDpYQ=; b=QlDNXtx69Kc9pGDq5FfpfWrx09BbM+iZAnnSroo1XCAhoWZMZHuBF+3rXnVa6+LJar mn6BGZvJYy8YtcbGOk4wr4xIIk1Y1QRybV8IBNKtdHN1E860HjErxCz0qj36bYVzdMl0 6Z+FiqtbYOoXzvxG9jkGUFzol5QNV7X5x2ySVPavV6mLPegcZfQOjK+verRh6aYFMNbS n0HjrsxVMaVrI8wWPXTNdeSiMR96eeqdrTgAsTrC0n4izmN5MtAX1v7A0w9f4nX2ttQn eDp8M77CW8MrrA6NBCNBFoM+CV/b7VtmCBOKZFxSOiov6ccg2de0mdlFyCddfYETgFnd 2P1A== Received: by 10.66.76.231 with SMTP id n7mr35840612paw.68.1350331784290; Mon, 15 Oct 2012 13:09:44 -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.09.42 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 15 Oct 2012 13:09:43 -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:35 -0700 Message-Id: <1350331769-14856-2-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: ALoCoQl9rIWlEwH4s7IrvGVXC/5qZKLgqGdrqei2JcNuTzOg+Rw24R38rv0ubTAlgXz6644d5iLOxZVqEkQliB+O3nDHcSf7Mwr8YPmzEhj0Tyxp6+uzghsJkf4mVSQejKIWEgCFdFVIPjyQDz7zWH4e90h8emZzSu/CqfsjO0HZkqn1qU0E1FFivBZI0yEruuOw0WwiuePX 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.23 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 01/24] 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 ++ include/linux/blk_types.h | 2 ++ 3 files changed, 45 insertions(+) diff --git a/fs/bio.c b/fs/bio.c index f16aa6b..dc3452e 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 >> 9; + bio->bi_size -= bytes; + + if (bio->bi_rw & BIO_NO_ADVANCE_ITER_MASK) + return; + + while (bytes) { + if (unlikely(bio->bi_idx >= bio->bi_vcnt)) { + WARN_ONCE(1, "bio idx %d >= vcnt %d\n", + 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 669b1cb..fcb4dba 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 *); +extern void bio_advance(struct bio *, unsigned); + extern void bio_init(struct bio *); extern void bio_reset(struct bio *); diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index cdf1119..c178d25 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -197,6 +197,8 @@ enum rq_flag_bits { REQ_SECURE) #define REQ_CLONE_MASK REQ_COMMON_MASK +#define BIO_NO_ADVANCE_ITER_MASK (REQ_DISCARD|REQ_WRITE_SAME) + /* This mask is used for both bio and request merge checking */ #define REQ_NOMERGE_FLAGS \ (REQ_NOMERGE | REQ_STARTED | REQ_SOFTBARRIER | REQ_FLUSH | REQ_FUA)