Skip to content

Commit 681ae50

Browse files
Josef BacikChris Mason
authored andcommitted
Btrfs: cleanup reserved space when freeing tree log on error
On error we will wait and free the tree log at unmount without a transaction. This means that the actual freeing of the blocks doesn't happen which means we complain about space leaks on unmount. So to fix this just skip the transaction specific cleanup part of the tree log free'ing if we don't have a transaction and that way we can free up our reserved space and our counters stay happy. Thanks, Signed-off-by: Josef Bacik <[email protected]> Signed-off-by: Chris Mason <[email protected]>
1 parent eb58bb3 commit 681ae50

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

fs/btrfs/tree-log.c

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2151,11 +2151,13 @@ static noinline int walk_down_log_tree(struct btrfs_trans_handle *trans,
21512151
return ret;
21522152
}
21532153

2154-
btrfs_tree_lock(next);
2155-
btrfs_set_lock_blocking(next);
2156-
clean_tree_block(trans, root, next);
2157-
btrfs_wait_tree_block_writeback(next);
2158-
btrfs_tree_unlock(next);
2154+
if (trans) {
2155+
btrfs_tree_lock(next);
2156+
btrfs_set_lock_blocking(next);
2157+
clean_tree_block(trans, root, next);
2158+
btrfs_wait_tree_block_writeback(next);
2159+
btrfs_tree_unlock(next);
2160+
}
21592161

21602162
WARN_ON(root_owner !=
21612163
BTRFS_TREE_LOG_OBJECTID);
@@ -2227,11 +2229,13 @@ static noinline int walk_up_log_tree(struct btrfs_trans_handle *trans,
22272229

22282230
next = path->nodes[*level];
22292231

2230-
btrfs_tree_lock(next);
2231-
btrfs_set_lock_blocking(next);
2232-
clean_tree_block(trans, root, next);
2233-
btrfs_wait_tree_block_writeback(next);
2234-
btrfs_tree_unlock(next);
2232+
if (trans) {
2233+
btrfs_tree_lock(next);
2234+
btrfs_set_lock_blocking(next);
2235+
clean_tree_block(trans, root, next);
2236+
btrfs_wait_tree_block_writeback(next);
2237+
btrfs_tree_unlock(next);
2238+
}
22352239

22362240
WARN_ON(root_owner != BTRFS_TREE_LOG_OBJECTID);
22372241
ret = btrfs_free_and_pin_reserved_extent(root,
@@ -2301,11 +2305,13 @@ static int walk_log_tree(struct btrfs_trans_handle *trans,
23012305

23022306
next = path->nodes[orig_level];
23032307

2304-
btrfs_tree_lock(next);
2305-
btrfs_set_lock_blocking(next);
2306-
clean_tree_block(trans, log, next);
2307-
btrfs_wait_tree_block_writeback(next);
2308-
btrfs_tree_unlock(next);
2308+
if (trans) {
2309+
btrfs_tree_lock(next);
2310+
btrfs_set_lock_blocking(next);
2311+
clean_tree_block(trans, log, next);
2312+
btrfs_wait_tree_block_writeback(next);
2313+
btrfs_tree_unlock(next);
2314+
}
23092315

23102316
WARN_ON(log->root_key.objectid !=
23112317
BTRFS_TREE_LOG_OBJECTID);
@@ -2608,13 +2614,10 @@ static void free_log_tree(struct btrfs_trans_handle *trans,
26082614
.process_func = process_one_buffer
26092615
};
26102616

2611-
if (trans) {
2612-
ret = walk_log_tree(trans, log, &wc);
2613-
2614-
/* I don't think this can happen but just in case */
2615-
if (ret)
2616-
btrfs_abort_transaction(trans, log, ret);
2617-
}
2617+
ret = walk_log_tree(trans, log, &wc);
2618+
/* I don't think this can happen but just in case */
2619+
if (ret)
2620+
btrfs_abort_transaction(trans, log, ret);
26182621

26192622
while (1) {
26202623
ret = find_first_extent_bit(&log->dirty_log_pages,

0 commit comments

Comments
 (0)