From patchwork Mon Sep 24 22:34:51 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 1500761 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 E9C68DF280 for ; Mon, 24 Sep 2012 22:39: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 q8OMb82U026018; Mon, 24 Sep 2012 18:37:08 -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 q8OMZoI6009208 for ; Mon, 24 Sep 2012 18:35:50 -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 q8OMZjVK019404 for ; Mon, 24 Sep 2012 18:35:45 -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 q8OMZWDc031435 for ; Mon, 24 Sep 2012 18:35:43 -0400 Received: by mail-pb0-f46.google.com with SMTP id rr4so7786719pbb.33 for ; Mon, 24 Sep 2012 15:35:43 -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=UoRa4859UxdYLYDKrDsM6tA0rGHoWSBMmmUv9NysjLY=; b=as3Ani4gAnfMn5eb6IZxW8+xjW1uizXnC1GoZoVscfgGuBE+QU3/hW7k95A6kR/vwn 1x9rubm7sP9CAA80LJQN5XWPy6iUmXOkrcvp/s/KjDghj3iinGDDbCxkOEOCCBeIUO2X NyRrTo2CLbAki2lAHUg/BdRIcnvJhXL8p4Gs9yphvWfBbvVmdMd4GgbZaUGArJkOQFN+ JipL28yZYfxtTmEkelh4SVm+bI9hUae9pUZPQCmWnTjuiKmOqMNDCgOstKhW4AhsyUrg vRYyQc3IqWbTo8dNwqwkkLFJu7OZ3d7y+sGqr91mF8zTK3IPxfhh+y01fePn0GDRxYz1 K2GA== 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=UoRa4859UxdYLYDKrDsM6tA0rGHoWSBMmmUv9NysjLY=; b=fWVaDb0IA0tUiOvClOs+on094YRFS3gf4FJNsF+w3iUa2k86T94MKvE5x3hDC2E1sD 7aJUtUBGJ0PAMY1nqdFVD++rRueQQffT8c1mn+6hogKjSPYtvMGHLIW2qL50RkdsVMjt ohDcZz0dBCLvRuKx9G/d9FWuRrhswR72eJL+zwkYH9blAIcBPfSrUYzw5X50OoyocPxu INu1MB0+NzQRiwSYjr/Vi6Re/OJje6Skh3EHCWncYhwUjePnjN9uOcq+iNWvfJ/njtrz EsE0EkjHBRm9Dxzqds/5qdRl6SdnElAQogWV/yjDdLi6xv21hQI1mIpRR1NJP+iU4SuB ATKw== Received: by 10.68.197.70 with SMTP id is6mr40302375pbc.64.1348526143411; Mon, 24 Sep 2012 15:35:43 -0700 (PDT) Received: by 10.68.197.70 with SMTP id is6mr40302356pbc.64.1348526143255; Mon, 24 Sep 2012 15:35:43 -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 nu8sm133316pbc.45.2012.09.24.15.35.42 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 24 Sep 2012 15:35:42 -0700 (PDT) From: Kent Overstreet To: linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org, dm-devel@redhat.com Date: Mon, 24 Sep 2012 15:34:51 -0700 Message-Id: <1348526106-17074-12-git-send-email-koverstreet@google.com> In-Reply-To: <1348526106-17074-1-git-send-email-koverstreet@google.com> References: <1348526106-17074-1-git-send-email-koverstreet@google.com> X-Gm-Message-State: ALoCoQlPb75x+uiIgkxTTbXcP93d6lPRl8MNulSLFPdZAZuD9g+KZx+fYHDqlSW9LtbHlQeabGxgB59JB+ivpliLUtJ9tSp2xPumO+zFObIyCZz+ULcR117Pee2uav1Jksp8B1TLAHUe4R7qMtu9Wi4w1p8c0UvirXnnVzNTUsVz1F5xSezYGVIbJCOUyCkEWsA73b2JjYsD X-RedHat-Spam-Score: -3.512 (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 , vgoyal@redhat.com Subject: [dm-devel] [PATCH v3 11/26] block: Add submit_bio_wait(), remove from md 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 Random cleanup - this code was duplicated and it's not really specific to md. Also added the ability to return the actual error code. Signed-off-by: Kent Overstreet CC: Jens Axboe CC: NeilBrown Acked-by: Tejun Heo --- drivers/md/raid1.c | 19 ------------------- drivers/md/raid10.c | 19 ------------------- fs/bio.c | 36 ++++++++++++++++++++++++++++++++++++ include/linux/bio.h | 1 + 4 files changed, 37 insertions(+), 38 deletions(-) diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c index deff0cd..28f506a 100644 --- a/drivers/md/raid1.c +++ b/drivers/md/raid1.c @@ -2048,25 +2048,6 @@ static void fix_read_error(struct r1conf *conf, int read_disk, } } -static void bi_complete(struct bio *bio, int error) -{ - complete((struct completion *)bio->bi_private); -} - -static int submit_bio_wait(int rw, struct bio *bio) -{ - struct completion event; - rw |= REQ_SYNC; - - init_completion(&event); - bio->bi_private = &event; - bio->bi_end_io = bi_complete; - submit_bio(rw, bio); - wait_for_completion(&event); - - return test_bit(BIO_UPTODATE, &bio->bi_flags); -} - static int narrow_write_error(struct r1bio *r1_bio, int i) { struct mddev *mddev = r1_bio->mddev; diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c index 6d06d83..f001c1b 100644 --- a/drivers/md/raid10.c +++ b/drivers/md/raid10.c @@ -2410,25 +2410,6 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10 } } -static void bi_complete(struct bio *bio, int error) -{ - complete((struct completion *)bio->bi_private); -} - -static int submit_bio_wait(int rw, struct bio *bio) -{ - struct completion event; - rw |= REQ_SYNC; - - init_completion(&event); - bio->bi_private = &event; - bio->bi_end_io = bi_complete; - submit_bio(rw, bio); - wait_for_completion(&event); - - return test_bit(BIO_UPTODATE, &bio->bi_flags); -} - static int narrow_write_error(struct r10bio *r10_bio, int i) { struct bio *bio = r10_bio->master_bio; diff --git a/fs/bio.c b/fs/bio.c index 062ba8f..9a30dcf 100644 --- a/fs/bio.c +++ b/fs/bio.c @@ -750,6 +750,42 @@ int bio_add_page(struct bio *bio, struct page *page, unsigned int len, } EXPORT_SYMBOL(bio_add_page); +struct submit_bio_ret { + struct completion event; + int error; +}; + +static void submit_bio_wait_endio(struct bio *bio, int error) +{ + struct submit_bio_ret *ret = bio->bi_private; + + ret->error = error; + complete(&ret->event); +} + +/** + * submit_bio_wait - submit a bio, and wait until it completes + * @rw: whether to %READ or %WRITE, or maybe to %READA (read ahead) + * @bio: The &struct bio which describes the I/O + * + * Simple wrapper around submit_bio(). Returns 0 on success, or the error from + * bio_endio() on failure. + */ +int submit_bio_wait(int rw, struct bio *bio) +{ + struct submit_bio_ret ret; + + rw |= REQ_SYNC; + init_completion(&ret.event); + bio->bi_private = &ret; + bio->bi_end_io = submit_bio_wait_endio; + submit_bio(rw, bio); + wait_for_completion(&ret.event); + + return ret.error; +} +EXPORT_SYMBOL(submit_bio_wait); + /** * bio_advance - increment/complete a bio by some number of bytes * @bio: bio to advance diff --git a/include/linux/bio.h b/include/linux/bio.h index d985e90..3bf696b 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -252,6 +252,7 @@ extern void bio_endio(struct bio *, int); struct request_queue; extern int bio_phys_segments(struct request_queue *, struct bio *); +extern int submit_bio_wait(int rw, struct bio *bio); extern void bio_advance(struct bio *, unsigned); extern void bio_init(struct bio *);