From patchwork Mon Oct 15 20:09:06 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 1596011 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 589CB40ABA 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 q9FKBT85006978; Mon, 15 Oct 2012 16:11:29 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q9FKAdwN027147 for ; Mon, 15 Oct 2012 16:10:39 -0400 Received: from mx1.redhat.com (ext-mx16.extmail.prod.ext.phx2.redhat.com [10.5.110.21]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q9FKAYew003311 for ; Mon, 15 Oct 2012 16:10:34 -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 q9FK9oem018987 for ; Mon, 15 Oct 2012 16:10:32 -0400 Received: by mail-da0-f46.google.com with SMTP id n41so2761046dak.33 for ; Mon, 15 Oct 2012 13:10:32 -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=XhwLGxkWRZEWY0Rwo90dheMcF0UA1K/lVgQ3IGEwNak=; b=BIsFFs1DgT8tzYBDzPVqGQPerfvaZtGVq4nFp2/PblnPsRxXpNE9FlxVS7X8UGAgVM geEAWBBbiW90A9iObkKUr2XG0sdiPSKc9YCh9QmhZ6yDLCkGSFNRha0X6WeLeo37IWBi T0tgjv0SDlPzorKtqg7ct3uTCZG6uC0D44IO55BtdsrnE99hPe95smLa01dq5S/DvtYZ jFMDy49T/mBYraHEdakVs8PObDWaRsREmdt1azqROJ6UBGdof1ihGcn6uqUeISrkzokM F4NgkIlKvm1v+NnRCo1HYDzwo3Rof0QtERlVTiZg70vW14L4lY0YLflDO+izyvfmXGLS sDyg== 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=XhwLGxkWRZEWY0Rwo90dheMcF0UA1K/lVgQ3IGEwNak=; b=FPp7b64qbyw8ngf2/FGDnNkZtCvY8uVxA9OMQUDvKSIsbNPP3Rln16KE2Ctllden1M ygRHJOWo/PVbzAbkGRf+hDxpd/dmv9TU/AKauh0mjS421V1aaAq26x5ZslnNxHWbLu3g p+YFLIuUN+cXjxHmIwCwn9AFbF6ea7V9b6rSeEGus+k2Qoc3/ubxmb/tIMvE3KqufkZu ZkGvSvtJj2DwkzNresUY+V3MSAwOBt0EhMpXXscczhObyfzHhuRj/tG1uG4TRaGS3vOw u3821Rgnlka3bBXEezfV5XUjhsOgMDEsS4JY6aRg30FhwEFwaq1QrK2Nio7wbdDol5EG FcYg== Received: by 10.68.212.74 with SMTP id ni10mr40371309pbc.20.1350331832622; Mon, 15 Oct 2012 13:10:32 -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.31 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 15 Oct 2012 13:10:32 -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:06 -0700 Message-Id: <1350331769-14856-33-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: ALoCoQlj3Ahic055B6zdbhXulXoX8u8AOqVcumIprO4NvlLqSM5wKbQGyPoztJXtd6chf86GPGLIkec5rD5sZng6Ac4CgxpDcBcObumbkKD3EYIF9unh0uUqIu2a+3yARTDxxhijufEn35hQnHKdwHGnc+jpVVS4ESIptoFIPEoJUrcp90/UTHlYmICREPgwq5nJilbWu3GT 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.25 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 03/26] block: Refactor blk_update_request() 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 Converts it to use bio_advance(), simplifying it quite a bit in the process. Signed-off-by: Kent Overstreet CC: Jens Axboe --- block/blk-core.c | 84 +++++++++++--------------------------------------------- 1 file changed, 16 insertions(+), 68 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index 2d739ca..55c833c9 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -153,25 +153,19 @@ EXPORT_SYMBOL(blk_rq_init); static void req_bio_endio(struct request *rq, struct bio *bio, unsigned int nbytes, int error) { + /* + * XXX: bio_endio() does this. only need this because of the weird + * flush seq thing. + */ if (error) clear_bit(BIO_UPTODATE, &bio->bi_flags); else if (!test_bit(BIO_UPTODATE, &bio->bi_flags)) error = -EIO; - if (unlikely(nbytes > bio->bi_size)) { - printk(KERN_ERR "%s: want %u bytes done, %u left\n", - __func__, nbytes, bio->bi_size); - nbytes = bio->bi_size; - } - if (unlikely(rq->cmd_flags & REQ_QUIET)) set_bit(BIO_QUIET, &bio->bi_flags); - bio->bi_size -= nbytes; - bio->bi_sector += (nbytes >> 9); - - if (bio_integrity(bio)) - bio_integrity_advance(bio, nbytes); + bio_advance(bio, nbytes); /* don't actually finish bio if it's part of flush sequence */ if (bio->bi_size == 0 && !(rq->cmd_flags & REQ_FLUSH_SEQ)) @@ -2214,8 +2208,7 @@ EXPORT_SYMBOL(blk_fetch_request); **/ bool blk_update_request(struct request *req, int error, unsigned int nr_bytes) { - int total_bytes, bio_nbytes, next_idx = 0; - struct bio *bio; + int total_bytes; if (!req->bio) return false; @@ -2259,56 +2252,21 @@ bool blk_update_request(struct request *req, int error, unsigned int nr_bytes) blk_account_io_completion(req, nr_bytes); - total_bytes = bio_nbytes = 0; - while ((bio = req->bio) != NULL) { - int nbytes; + total_bytes = 0; + while (req->bio) { + struct bio *bio = req->bio; + unsigned bio_bytes = min(bio->bi_size, nr_bytes); - if (nr_bytes >= bio->bi_size) { + if (bio_bytes == bio->bi_size) req->bio = bio->bi_next; - nbytes = bio->bi_size; - req_bio_endio(req, bio, nbytes, error); - next_idx = 0; - bio_nbytes = 0; - } else { - int idx = bio->bi_idx + next_idx; - - if (unlikely(idx >= bio->bi_vcnt)) { - blk_dump_rq_flags(req, "__end_that"); - printk(KERN_ERR "%s: bio idx %d >= vcnt %d\n", - __func__, idx, bio->bi_vcnt); - break; - } - - nbytes = bio_iovec_idx(bio, idx)->bv_len; - BIO_BUG_ON(nbytes > bio->bi_size); - - /* - * not a complete bvec done - */ - if (unlikely(nbytes > nr_bytes)) { - bio_nbytes += nr_bytes; - total_bytes += nr_bytes; - break; - } - /* - * advance to the next vector - */ - next_idx++; - bio_nbytes += nbytes; - } + req_bio_endio(req, bio, bio_bytes, error); - total_bytes += nbytes; - nr_bytes -= nbytes; + total_bytes += bio_bytes; + nr_bytes -= bio_bytes; - bio = req->bio; - if (bio) { - /* - * end more in this run, or just return 'not-done' - */ - if (unlikely(nr_bytes <= 0)) - break; - } + if (!nr_bytes) + break; } /* @@ -2324,16 +2282,6 @@ bool blk_update_request(struct request *req, int error, unsigned int nr_bytes) return false; } - /* - * if the request wasn't completed, update state - */ - if (bio_nbytes) { - req_bio_endio(req, bio, bio_nbytes, error); - bio->bi_idx += next_idx; - bio_iovec(bio)->bv_offset += nr_bytes; - bio_iovec(bio)->bv_len -= nr_bytes; - } - req->__data_len -= total_bytes; req->buffer = bio_data(req->bio);