From: Nikolay Borisov <nborisov@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: Nikolay Borisov <nborisov@suse.com>
Subject: [PATCH 3/3] btrfs: Ensure btrfs_pin_reserved_extent is always called with valid transaction
Date: Mon, 2 Dec 2019 11:40:15 +0200 [thread overview]
Message-ID: <20191202094015.19444-4-nborisov@suse.com> (raw)
In-Reply-To: <20191202094015.19444-1-nborisov@suse.com>
btrfs_pin_reserved_extent only makes sense when called with a valid
transaction handle. At the moment all cases when it's called and
the transaction handle passed to its caller are from error context in
which 'btrfs_fs_info::pinned_extents' is not going to be processed e.g.
btrfs_Free_fs_roots <--called from open_ctree error label or
close_ctree, after all transaction processing has ceased.
btrfs_free_log_root_tree
free_log_tree
walk_log_tree
btrfs_drop_and_free_fs_root
btrfs_Free_log <-- called if fs is flagged BTRFS_FS_STATE_ERROR, all
IO is stopped.
free_log_tree
walk_log_tree
To make this explicit in the code rework the 3 call sites where
btrfs_pin_reserved_extent is called. This is in preparation to moving
pinned extent machinery to btrfs_transaction.
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
fs/btrfs/tree-log.c | 49 ++++++++++++++++++++++-----------------------
1 file changed, 24 insertions(+), 25 deletions(-)
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index 6ccf260b313e..b76150cce0fe 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -2712,20 +2712,18 @@ static noinline int walk_down_log_tree(struct btrfs_trans_handle *trans,
free_extent_buffer(next);
return ret;
}
-
- if (trans) {
- btrfs_tree_lock(next);
- btrfs_set_lock_blocking_write(next);
- btrfs_clean_tree_block(next);
- btrfs_wait_tree_block_writeback(next);
- btrfs_tree_unlock(next);
- } else {
+ if (!trans) {
if (test_and_clear_bit(EXTENT_BUFFER_DIRTY, &next->bflags))
clear_extent_buffer_dirty(next);
+ return ret;
}
- WARN_ON(root_owner !=
- BTRFS_TREE_LOG_OBJECTID);
+ btrfs_tree_lock(next);
+ btrfs_set_lock_blocking_write(next);
+ btrfs_clean_tree_block(next);
+ btrfs_wait_tree_block_writeback(next);
+ btrfs_tree_unlock(next);
+ WARN_ON(root_owner != BTRFS_TREE_LOG_OBJECTID);
ret = btrfs_pin_reserved_extent(fs_info,
bytenr, blocksize);
if (ret) {
@@ -2791,18 +2789,18 @@ static noinline int walk_up_log_tree(struct btrfs_trans_handle *trans,
struct extent_buffer *next;
next = path->nodes[*level];
-
- if (trans) {
- btrfs_tree_lock(next);
- btrfs_set_lock_blocking_write(next);
- btrfs_clean_tree_block(next);
- btrfs_wait_tree_block_writeback(next);
- btrfs_tree_unlock(next);
- } else {
+ if (!trans) {
if (test_and_clear_bit(EXTENT_BUFFER_DIRTY, &next->bflags))
clear_extent_buffer_dirty(next);
+ return ret;
}
+ btrfs_tree_lock(next);
+ btrfs_set_lock_blocking_write(next);
+ btrfs_clean_tree_block(next);
+ btrfs_wait_tree_block_writeback(next);
+ btrfs_tree_unlock(next);
+
WARN_ON(root_owner != BTRFS_TREE_LOG_OBJECTID);
ret = btrfs_pin_reserved_extent(fs_info,
path->nodes[*level]->start,
@@ -2873,17 +2871,18 @@ static int walk_log_tree(struct btrfs_trans_handle *trans,
next = path->nodes[orig_level];
- if (trans) {
- btrfs_tree_lock(next);
- btrfs_set_lock_blocking_write(next);
- btrfs_clean_tree_block(next);
- btrfs_wait_tree_block_writeback(next);
- btrfs_tree_unlock(next);
- } else {
+ if (!trans) {
if (test_and_clear_bit(EXTENT_BUFFER_DIRTY, &next->bflags))
clear_extent_buffer_dirty(next);
+ goto out;
}
+ btrfs_tree_lock(next);
+ btrfs_set_lock_blocking_write(next);
+ btrfs_clean_tree_block(next);
+ btrfs_wait_tree_block_writeback(next);
+ btrfs_tree_unlock(next);
+
ret = btrfs_pin_reserved_extent(fs_info, next->start,
next->len);
if (ret)
--
2.17.1
next prev parent reply other threads:[~2019-12-02 9:40 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-02 9:40 [PATCH 0/3] Cleanups from pinned rework try Nikolay Borisov
2019-12-02 9:40 ` [PATCH 1/3] btrfs: Remove WARN_ON in walk_log_tree Nikolay Borisov
2019-12-03 17:21 ` David Sterba
2019-12-02 9:40 ` [PATCH 2/3] btrfs: Remove redundant WARN_ON in walk_down_log_tree Nikolay Borisov
2019-12-02 9:40 ` Nikolay Borisov [this message]
2019-12-03 17:42 ` [PATCH 0/3] Cleanups from pinned rework try David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191202094015.19444-4-nborisov@suse.com \
--to=nborisov@suse.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).