Skip to contentSkip to conversation

Cleanups from pinned rework try

PATCH In review Nikolay Borisov 2 participants 6 messages Dec 2, 2019 – Dec 3, 2019 Btrfs file system

lore
Share & tools
lore
#0 lore raw

cover Cleanups from pinned rework try

Here are 3 minor cleanups resulting from dwelling in pinned extents rework. Those cleanup WARN_ONs and make it clear when btrfs_pin_reserved_extent is called with active transaction. No functional changes in any of them.

Nikolay Borisov (3):
btrfs: Remove WARN_ON in walk_log_tree
btrfs: Remove redundant WARN_ON in walk_down_log_tree
btrfs: Ensure btrfs_pin_reserved_extent is always called with valid
transaction

 fs/btrfs/tree-log.c | 60 ++++++++++++++++++---------------------------
 1 file changed, 24 insertions(+), 36 deletions(-)

--
2.17.1

#1 lore raw

PATCH 1/3 btrfs: Remove WARN_ON in walk_log_tree

The log_root passed to walk_log_tree is guaranteed to have its root_key.objectid always be BTRFS_TREE_LOG_OBJECTID. This is by merit that all log roots of an ordinary root are allocated in alloc_log_tree which hard-codes objectid to be BTRFS_TREE_LOG_OBJECTID.

In case walk_log_tree is called for a log tree found by btrfs_read_fs_root in btrfs_recover_log_trees, that function already ensures found_key.objectid is BTRFS_TREE_LOG_OBJECTID.

No functional changes.

---
 fs/btrfs/tree-log.c | 2 --
 1 file changed, 2 deletions(-)
fs/btrfs/tree-log.c +0 -2
index a30057feff2a..33d329f22534 100644
@@ -2893,8 +2893,6 @@ static int walk_log_tree(struct btrfs_trans_handle *trans,
 					clear_extent_buffer_dirty(next);
 			}
 
-			WARN_ON(log->root_key.objectid !=
-				BTRFS_TREE_LOG_OBJECTID);
 			ret = btrfs_pin_reserved_extent(fs_info, next->start,
 							next->len);
 			if (ret)
Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH 1/3] btrfs: Remove WARN_ON in walk_log_tree

Quoted 8 lines · Nikolay Borisov

The log_root passed to walk_log_tree is guaranteed to have its root_key.objectid always be BTRFS_TREE_LOG_OBJECTID. This is by merit that all log roots of an ordinary root are allocated in alloc_log_tree which hard-codes objectid to be BTRFS_TREE_LOG_OBJECTID.

In case walk_log_tree is called for a log tree found by btrfs_read_fs_root in btrfs_recover_log_trees, that function already ensures found_key.objectid is BTRFS_TREE_LOG_OBJECTID.

Agreed, if anything the warning should have been an assert at the beginning of the function.

#3 lore raw

PATCH 2/3 btrfs: Remove redundant WARN_ON in walk_down_log_tree

In reply to Nikolay Borisov

level <0 and level >= BTRFS_MAX_LEVEL are already performed upon extent buffer read by tree checker in btrfs_check_node. go. As far as 'level <= 0' we are guaranteed that level is '> 0' because the value of level _before_ reading 'next' is larger than 1 (otherwise we wouldn't have executed that code at all) this in turn guarantees that 'level' after btrfs_read_buffer is 'level - 1' since we verify this invariant in:

btrfs_read_buffer
btree_read_extent_buffer_pages
btrfs_verify_level_key

This guarantees that level can never be '<= 0' so the warn on is never triggered.

---
 fs/btrfs/tree-log.c | 9 ---------
 1 file changed, 9 deletions(-)
fs/btrfs/tree-log.c +0 -9
index 33d329f22534..6ccf260b313e 100644
@@ -2673,14 +2673,9 @@ static noinline int walk_down_log_tree(struct btrfs_trans_handle *trans,
 	u32 blocksize;
 	int ret = 0;
 
-	WARN_ON(*level < 0);
-	WARN_ON(*level >= BTRFS_MAX_LEVEL);
-
 	while (*level > 0) {
 		struct btrfs_key first_key;
 
-		WARN_ON(*level < 0);
-		WARN_ON(*level >= BTRFS_MAX_LEVEL);
 		cur = path->nodes[*level];
 
 		WARN_ON(btrfs_header_level(cur) != *level);
@@ -2747,7 +2742,6 @@ static noinline int walk_down_log_tree(struct btrfs_trans_handle *trans,
 			return ret;
 		}
 
-		WARN_ON(*level <= 0);
 		if (path->nodes[*level-1])
 			free_extent_buffer(path->nodes[*level-1]);
 		path->nodes[*level-1] = next;
@@ -2755,9 +2749,6 @@ static noinline int walk_down_log_tree(struct btrfs_trans_handle *trans,
 		path->slots[*level] = 0;
 		cond_resched();
 	}
-	WARN_ON(*level < 0);
-	WARN_ON(*level >= BTRFS_MAX_LEVEL);
-
 	path->slots[*level] = btrfs_header_nritems(path->nodes[*level]);
 
 	cond_resched();
Signature · 1 line
2.17.1
#4 lore raw

PATCH 3/3 btrfs: Ensure btrfs_pin_reserved_extent is always called with valid transaction

In reply to Nikolay Borisov

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.

---
 fs/btrfs/tree-log.c | 49 ++++++++++++++++++++++-----------------------
 1 file changed, 24 insertions(+), 25 deletions(-)
fs/btrfs/tree-log.c +24 -25
index 6ccf260b313e..b76150cce0fe 100644
@@ -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)
Signature · 1 line
2.17.1
#5 lore raw
In reply to Nikolay Borisov
Quoted 9 lines · Nikolay Borisov

Here are 3 minor cleanups resulting from dwelling in pinned extents rework. Those cleanup WARN_ONs and make it clear when btrfs_pin_reserved_extent is called with active transaction. No functional changes in any of them.

Nikolay Borisov (3):
btrfs: Remove WARN_ON in walk_log_tree
btrfs: Remove redundant WARN_ON in walk_down_log_tree
btrfs: Ensure btrfs_pin_reserved_extent is always called with valid
transaction

Added to misc-next, thanks.