From patchwork Mon Oct 15 20:08:43 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 1596231 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 F20773FD86 for ; Mon, 15 Oct 2012 20:17:00 +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 q9FKBAoW010250; Mon, 15 Oct 2012 16:11:10 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q9FKA1QG026917 for ; Mon, 15 Oct 2012 16:10:01 -0400 Received: from mx1.redhat.com (ext-mx15.extmail.prod.ext.phx2.redhat.com [10.5.110.20]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q9FK9ukQ008349 for ; Mon, 15 Oct 2012 16:09:56 -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 q9FK9oSb021846 for ; Mon, 15 Oct 2012 16:09:55 -0400 Received: by mail-pa0-f46.google.com with SMTP id hz1so5214226pad.33 for ; Mon, 15 Oct 2012 13:09:55 -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=5GWYvVd6o1Ih3AeoCur+AUo4gZUJv4t6ObsjnMB+41k=; b=CPSu0jifMwu+H8+h/Mk2+ngSt9V17sVkgCnt3ZewVkxdarVi0cyigPQwUAOpwRbWz5 nScPCRjuAxjwh0QSfJjHPTjfP7u52Saf1kg7Z9NIS4RZBD3p1ipwgIWtkpHPxlN5PPgu WhYp4m1DKfJUQyc4Yxg5yvcI6YJ9Ib6DR5GShKd1RdnF9qZA+a8lopD3ObDpZOyaXcbK jIQswoDGsx8/w+ucxlrk3PQUJR+zr3GxATAtLq1/xYyvgLr73RtjNmlALV7lscY0x6kj sGv1xHpPcvfsbtEnS8dU38JtANcBwdAlLf+O0EUOHR8oteLf/3rAuflsAglOBIH8i83I ywVg== 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=5GWYvVd6o1Ih3AeoCur+AUo4gZUJv4t6ObsjnMB+41k=; b=gHinnWEAnne0dxDBHWqAd3kHU9FG+d+kxTvwVhqOD5LDXyJiYgqGPzw0SjgnqBRWu9 rhRWCn8k26hkjFP0pUEtWjZF7iuC7ne1GNOTMPfIxTTt1V5nERQbmt9GU4MSfXEbToHI 9B50jXdnJUj16bVGD+TBwrU4ntYGPl03FiX2yHOy7pG4n9IhqyZY8yGz+iQpdtrrJi8n eo2FddEIHHF6PS0oNGNlFMc6HfMhvxVr5Ur0pn/uFV28PK+l3YSn3lyRZDQUgTkGWJra ZHwpVXpeyDFFNIGypztV9sFPmTigABx0VnQrPsmyibMuJMAEqMDsfc1SDZ0nUuwlKLjl fCTQ== Received: by 10.68.218.39 with SMTP id pd7mr4905983pbc.121.1350331795302; Mon, 15 Oct 2012 13:09:55 -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.54 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 15 Oct 2012 13:09:54 -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:43 -0700 Message-Id: <1350331769-14856-10-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: ALoCoQlsSrLMy+FNC0Di5LqdIbwfu8TPbrRJXilUNyWPNbDbZjSYe0IMpVZJCm3Q+jb5GODGBcGmahHtKFqvy0ihxx2Hl8nREH3cYPaQh/58N5a0dQR/cE7x3cZpcYDtlxiaJz2db5gzFvPMpd+1zFPpoUj1XIB+gyg8Gp8X9IxhoypXnxxZIB3cFbyxK2oiZbsZkwVEUfdQ 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.67 on 10.5.11.11 X-Scanned-By: MIMEDefang 2.68 on 10.5.110.20 X-loop: dm-devel@redhat.com Cc: tj@kernel.org, axboe@kernel.dk, Kent Overstreet , vgoyal@redhat.com Subject: [dm-devel] [PATCH v4 09/24] 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 4ae3382..aeb74b8 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 20507eb..b20a9cd 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); extern void bio_advance(struct bio *, unsigned); extern void bio_init(struct bio *);