From patchwork Mon Oct 15 20:09:13 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 1595681 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 D9A56DFB34 for ; Mon, 15 Oct 2012 20:13:43 +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 q9FKBKNi006887; Mon, 15 Oct 2012 16:11:20 -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 q9FKAlYq027226 for ; Mon, 15 Oct 2012 16:10:47 -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 q9FKAgCF003373 for ; Mon, 15 Oct 2012 16:10:42 -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 q9FK9oen018987 for ; Mon, 15 Oct 2012 16:10:41 -0400 Received: by mail-da0-f46.google.com with SMTP id n41so2761046dak.33 for ; Mon, 15 Oct 2012 13:10:41 -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=wpgq1Aas8bg8/TYnRHFUVi1KdnXnZM+f66N84t3Ni4c=; b=YCfu9vjmLvcu7J4qivF98YNEjEGrUJWEgebodl3bvQBnqdLatWNnsYvv30FSdb+aEk XwB3aOmAKm1DoWO90aWWENB7Ok6yr8qqg0eeJtVwkfiTvqJJLykLOEQ1oMMa1l+nNnQ4 PCutp0P25y91bQ/R8y0LcjfeKhxttq6NJe0fgap1gQimjBriAjEXz8RpG4N6EIkdrc7U 7H799O1cahVcK+9bOGYL+Gl64NULboob7PUqdl6MHJmLBM+rZc16NKIiUKjMXN/fJmHa oX3Ohkp5PQNYoEDddPD6sd6C61LDdV9zR+BWmmakbCWdqJJVV2MiuCzZgg4zOz2hi0vf 8WKA== 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=wpgq1Aas8bg8/TYnRHFUVi1KdnXnZM+f66N84t3Ni4c=; b=Ah6NolrKe1YwKddVvj4A0X9XSTc+nyv6sZxioyBAFElQuXQ8vfk/n6oS+x6ptNMB2Q U4DMvKi5Iv6t3n+ytdpRW0DDxLUa6O6InmW4qieBN12979ADbmo3DYesyr29RetkEber tjykdgy8JufVK2XIzxrC9iVEfv3V4UMxA/PwBk5yJXqEYVw9iwTxe6xeJJ1AHf6mwS2p Yh2zYyDcqc9KCu9LV2+gAHgFAFtCFJJSFWAqhYsXnSFc1jfwM6rwm+o7ushULS+X0tRc JsczmXq5EEzb3t+JJ0p/nWJ38z/RUCsMsXKLfrB7gkYOmFwf6Xt40gIDpg+SfSstNjVc pGnQ== Received: by 10.68.232.198 with SMTP id tq6mr40301938pbc.31.1350331841309; Mon, 15 Oct 2012 13:10:41 -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.40 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 15 Oct 2012 13:10:40 -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:13 -0700 Message-Id: <1350331769-14856-40-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: ALoCoQk3a0Gy2DGBchOVAL+L1kCJSYCZ2uKe+ees/+H4+aBTAZXlPzEqblJF4U0lX9d+3/De0WrqLbleQPtVMLeoD14cm5TsceR9YFZFL2yZ2IutnYtXOF7m/VszwmR/EgddfqBmZ8KbYFQQA1P6wCloB2C2cZaFFpwGop1rrJXmB2mbJZAxm+KXYgWukFeRHWflppYMnNqj 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 10/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 --- 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 2488440..ee85154 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 addeac2..1342a16 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 92bff0e..949c48a 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -249,6 +249,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); void bio_advance(struct bio *, unsigned); extern void bio_init(struct bio *);