From patchwork Thu Nov 9 19:31:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 10051735 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BF612601EA for ; Thu, 9 Nov 2017 19:31:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B05FB29747 for ; Thu, 9 Nov 2017 19:31:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A53872B098; Thu, 9 Nov 2017 19:31:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE1EE2B097 for ; Thu, 9 Nov 2017 19:31:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754219AbdKITbZ (ORCPT ); Thu, 9 Nov 2017 14:31:25 -0500 Received: from mail-qt0-f195.google.com ([209.85.216.195]:48671 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754584AbdKITbL (ORCPT ); Thu, 9 Nov 2017 14:31:11 -0500 Received: by mail-qt0-f195.google.com with SMTP id f8so9102695qta.5 for ; Thu, 09 Nov 2017 11:31:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PXokZ4VtJkS9gGNii3MBUvodTTtZbcoIl8uKWIVtaeg=; b=GatI72Nr+UI/uul5ETNjf0TMpaGcPhx+dm0Lkte62WVh7ywEJvNi+dZkCHQedijbPJ pfZCWKtr8k21iCASaEichRuQqep3YQdvWgNJxNer1vwFdf5vlmbQFtkz5pS533FuRlvO xXl/+EhkNrIq45Vt4r+k4uPf0I+TQCjUxPikRyPqPfxFg8NIs0WayKndUDPE5HNPWM+C P0l/UtqYxDHdxn+LeYPjOtkfkn1JC45HpjVbzmndeY18bc72Xm1aNv8U5akkvZV+peYx MUrLZqobbvaINksSoF5CQ4VhQhrqM9+OuYmBxoD77+EA75YvNWWEFpCu8EXMel24S5ZO 18aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=PXokZ4VtJkS9gGNii3MBUvodTTtZbcoIl8uKWIVtaeg=; b=LHhpmi/dDVrF8t3Ppkx1S7xuqP8Sd9d9lOjvFRcyYtndBRp8K0p0MVBx3BKKAN/a8K KJqReYazhsqGu8c1rSWg9s092lhBXbKmrowNqIZLrVZAD9GghroysfnAO2I8L91p04by IbA9w1DCvUWfp9taMQ6K8qLeP4EdkyFy2Y5lOWx346+YiQPYYULFzgIRwDIA+9f1xVMv u2n8CEgm23thRfhdEy0slRhlpbuhW7/Ottuol6kSQmTXWgkn0p5jON/ERFTS+l5Ia6eo y6Gq0EJRijwS8vLm3FIVX0E6qNoqtrn+2B0vfHcz9I4qgvObsgRHKvCZoWeNI40+uyqm godQ== X-Gm-Message-State: AJaThX79Vq/7EV97/Gzr/GyOkSOew/NKdgFwol6kPt33gm0J/W4lm0R8 y72n1bWvV8lpqbDog2wvDPGE4g== X-Google-Smtp-Source: AGs4zMZ5+hQsUJznv1h9PpdZNE2Jx90/6PgNw1Fkj4xP9Dh0u0oOSjI9m3rkf843Ez87F6jtGx42Xg== X-Received: by 10.200.44.133 with SMTP id 5mr2646687qtw.169.1510255870495; Thu, 09 Nov 2017 11:31:10 -0800 (PST) Received: from localhost (cpe-2606-A000-4381-1201-225-22FF-FEB3-E51A.dyn6.twc.com. [2606:a000:4381:1201:225:22ff:feb3:e51a]) by smtp.gmail.com with ESMTPSA id h187sm5038161qkc.40.2017.11.09.11.31.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Nov 2017 11:31:09 -0800 (PST) From: Josef Bacik To: hannes@cmpxchg.org, linux-mm@kvack.org, akpm@linux-foundation.org, jack@suse.cz, linux-fsdevel@vger.kernel.org, kernel-team@fb.com, linux-btrfs@vger.kernel.org Cc: Josef Bacik Subject: [PATCH 6/6] btrfs: rework end io for extent buffer reads Date: Thu, 9 Nov 2017 14:31:01 -0500 Message-Id: <1510255861-8020-6-git-send-email-josef@toxicpanda.com> X-Mailer: git-send-email 2.7.5 In-Reply-To: <1510255861-8020-1-git-send-email-josef@toxicpanda.com> References: <1510255861-8020-1-git-send-email-josef@toxicpanda.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Josef Bacik Now that the only thing that keeps eb's alive is io_pages and it's refcount we need to hold the eb ref for the entire end io call so we don't get it removed out from underneath us. Also the hooks make no sense for us now, so rework this to be cleaner. Signed-off-by: Josef Bacik --- fs/btrfs/disk-io.c | 63 ++++-------------------------------------------- fs/btrfs/disk-io.h | 1 + fs/btrfs/extent_io.c | 67 +++++++++++++++++++++++++++------------------------- 3 files changed, 41 insertions(+), 90 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index f53127777783..2ef25f780a00 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -755,33 +755,13 @@ static int check_node(struct btrfs_root *root, struct extent_buffer *node) return ret; } -static int btree_readpage_end_io_hook(struct btrfs_io_bio *io_bio, - u64 phy_offset, struct page *page, - u64 start, u64 end, int mirror) +int btrfs_extent_buffer_end_read(struct extent_buffer *eb, int mirror) { + struct btrfs_fs_info *fs_info = eb->eb_info->fs_info; + struct btrfs_root *root = fs_info->tree_root; u64 found_start; int found_level; - struct extent_buffer *eb; - struct btrfs_root *root; - struct btrfs_fs_info *fs_info; int ret = 0; - int reads_done; - - if (!page->private) - goto out; - - eb = (struct extent_buffer *)page->private; - - /* the pending IO might have been the only thing that kept this buffer - * in memory. Make sure we have a ref for all this other checks - */ - extent_buffer_get(eb); - fs_info = eb->eb_info->fs_info; - root = fs_info->tree_root; - - reads_done = atomic_dec_and_test(&eb->io_pages); - if (!reads_done) - goto err; eb->read_mirror = mirror; if (test_bit(EXTENT_BUFFER_READ_ERR, &eb->bflags)) { @@ -833,45 +813,14 @@ static int btree_readpage_end_io_hook(struct btrfs_io_bio *io_bio, if (!ret) set_extent_buffer_uptodate(eb); err: - if (reads_done && - test_and_clear_bit(EXTENT_BUFFER_READAHEAD, &eb->bflags)) + if (test_and_clear_bit(EXTENT_BUFFER_READAHEAD, &eb->bflags)) btree_readahead_hook(eb, ret); - if (ret) { - /* - * our io error hook is going to dec the io pages - * again, we have to make sure it has something - * to decrement. - * - * TODO: Kill this, we've re-arranged how this works now so we - * don't need to do this io_pages dance. - */ - atomic_inc(&eb->io_pages); + if (ret) clear_extent_buffer_uptodate(eb); - } - if (reads_done) { - clear_bit(EXTENT_BUFFER_READING, &eb->bflags); - smp_mb__after_atomic(); - wake_up_bit(&eb->bflags, EXTENT_BUFFER_READING); - } - free_extent_buffer(eb); -out: return ret; } -static int btree_io_failed_hook(struct page *page, int failed_mirror) -{ - struct extent_buffer *eb; - - eb = (struct extent_buffer *)page->private; - set_bit(EXTENT_BUFFER_READ_ERR, &eb->bflags); - eb->read_mirror = failed_mirror; - atomic_dec(&eb->io_pages); - if (test_and_clear_bit(EXTENT_BUFFER_READAHEAD, &eb->bflags)) - btree_readahead_hook(eb, -EIO); - return -EIO; /* we fixed nothing */ -} - static void end_workqueue_bio(struct bio *bio) { struct btrfs_end_io_wq *end_io_wq = bio->bi_private; @@ -4553,9 +4502,7 @@ static int btree_merge_bio_hook(struct page *page, unsigned long offset, static const struct extent_io_ops btree_extent_io_ops = { /* mandatory callbacks */ .submit_bio_hook = btree_submit_bio_hook, - .readpage_end_io_hook = btree_readpage_end_io_hook, .merge_bio_hook = btree_merge_bio_hook, - .readpage_io_failed_hook = btree_io_failed_hook, .set_range_writeback = btrfs_set_range_writeback, .tree_fs_info = btree_fs_info, diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h index 7f7c35d6347a..e1f4fef91547 100644 --- a/fs/btrfs/disk-io.h +++ b/fs/btrfs/disk-io.h @@ -152,6 +152,7 @@ int btree_lock_page_hook(struct page *page, void *data, int btrfs_get_num_tolerated_disk_barrier_failures(u64 flags); int __init btrfs_end_io_wq_init(void); void btrfs_end_io_wq_exit(void); +int btrfs_extent_buffer_end_read(struct extent_buffer *eb, int mirror); #ifdef CONFIG_DEBUG_LOCK_ALLOC void btrfs_init_lockdep(void); diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index c7e8b6d678bd..7d4f42ffa6eb 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -20,6 +20,7 @@ #include "locking.h" #include "rcu-string.h" #include "backref.h" +#include "disk-io.h" static struct kmem_cache *extent_state_cache; static struct kmem_cache *extent_buffer_cache; @@ -5379,6 +5380,15 @@ int extent_buffer_uptodate(struct extent_buffer *eb) return test_bit(EXTENT_BUFFER_UPTODATE, &eb->bflags); } +static void mark_eb_failed(struct extent_buffer *eb, int failed_mirror) +{ + set_bit(EXTENT_BUFFER_READ_ERR, &eb->bflags); + eb->read_mirror = failed_mirror; + atomic_dec(&eb->io_pages); + if (test_and_clear_bit(EXTENT_BUFFER_READAHEAD, &eb->bflags)) + btree_readahead_hook(eb, -EIO); +} + static void end_bio_extent_buffer_readpage(struct bio *bio) { struct btrfs_io_bio *io_bio = btrfs_io_bio(bio); @@ -5387,12 +5397,13 @@ static void end_bio_extent_buffer_readpage(struct bio *bio) u64 unlock_start = 0, unlock_len = 0; int mirror_num = io_bio->mirror_num; int uptodate = !bio->bi_status; - int i, ret; + int i; bio_for_each_segment_all(bvec, bio, i) { struct page *page = bvec->bv_page; struct btrfs_eb_info *eb_info; struct extent_buffer *eb; + int reads_done; eb = (struct extent_buffer *)page->private; if (WARN_ON(!eb)) @@ -5401,41 +5412,33 @@ static void end_bio_extent_buffer_readpage(struct bio *bio) eb_info = eb->eb_info; if (!tree) tree = &eb_info->io_tree; + extent_buffer_get(eb); + reads_done = atomic_dec_and_test(&eb->io_pages); if (uptodate) { - /* - * btree_readpage_end_io_hook doesn't care about - * start/end so just pass 0. We'll kill this later. - */ - ret = tree->ops->readpage_end_io_hook(io_bio, 0, - page, 0, 0, - mirror_num); - if (ret) { - uptodate = 0; - } else { - u64 start = eb->start; - int c, num_pages; - - num_pages = num_extent_pages(eb->start, - eb->len); - for (c = 0; c < num_pages; c++) { - if (eb->pages[c] == page) - break; - start += PAGE_SIZE; - } - clean_io_failure(eb_info->fs_info, - &eb_info->io_failure_tree, - tree, start, page, 0, 0); + u64 start = eb->start; + int c, num_pages; + + num_pages = num_extent_pages(eb->start, + eb->len); + for (c = 0; c < num_pages; c++) { + if (eb->pages[c] == page) + break; + start += PAGE_SIZE; } + clean_io_failure(eb_info->fs_info, + &eb_info->io_failure_tree, + tree, start, page, 0, 0); } - /* - * We never fix anything in btree_io_failed_hook. - * - * TODO: rework the io failed hook to not assume we can fix - * anything. - */ + if (reads_done && btrfs_extent_buffer_end_read(eb, mirror_num)) + uptodate = 0; if (!uptodate) - tree->ops->readpage_io_failed_hook(page, mirror_num); - + mark_eb_failed(eb, mirror_num); + if (reads_done) { + clear_bit(EXTENT_BUFFER_READING, &eb->bflags); + smp_mb__after_atomic(); + wake_up_bit(&eb->bflags, EXTENT_BUFFER_READING); + } + free_extent_buffer(eb); if (unlock_start == 0) { unlock_start = eb->start; unlock_len = PAGE_SIZE;