Skip to content

Commit d2eee25

Browse files
committed
Merge tag 'for-5.6-rc2-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux
Pull btrfs fixes from David Sterba: "These are fixes that were found during testing with help of error injection, plus some other stable material. There's a fixup to patch added to rc1 causing locking in wrong context warnings, tests found one more deadlock scenario. The patches are tagged for stable, two of them now in the queue but we'd like all three released at the same time. I'm not happy about fixes to fixes in such a fast succession during rcs, but I hope we found all the fallouts of commit 28553fa ('Btrfs: fix race between shrinking truncate and fiemap')" * tag 'for-5.6-rc2-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux: Btrfs: fix deadlock during fast fsync when logging prealloc extents beyond eof Btrfs: fix btrfs_wait_ordered_range() so that it waits for all ordered extents btrfs: fix bytes_may_use underflow in prealloc error condtition btrfs: handle logged extent failure properly btrfs: do not check delayed items are empty for single transaction cleanup btrfs: reset fs_root to NULL on error in open_ctree btrfs: destroy qgroup extent records on transaction abort
2 parents a3163ca + a5ae50d commit d2eee25

File tree

7 files changed

+44
-10
lines changed

7 files changed

+44
-10
lines changed

fs/btrfs/disk-io.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3200,6 +3200,7 @@ int __cold open_ctree(struct super_block *sb,
32003200
if (IS_ERR(fs_info->fs_root)) {
32013201
err = PTR_ERR(fs_info->fs_root);
32023202
btrfs_warn(fs_info, "failed to read fs tree: %d", err);
3203+
fs_info->fs_root = NULL;
32033204
goto fail_qgroup;
32043205
}
32053206

@@ -4276,6 +4277,7 @@ static int btrfs_destroy_delayed_refs(struct btrfs_transaction *trans,
42764277
cond_resched();
42774278
spin_lock(&delayed_refs->lock);
42784279
}
4280+
btrfs_qgroup_destroy_extent_records(trans);
42794281

42804282
spin_unlock(&delayed_refs->lock);
42814283

@@ -4501,7 +4503,6 @@ void btrfs_cleanup_one_transaction(struct btrfs_transaction *cur_trans,
45014503
wake_up(&fs_info->transaction_wait);
45024504

45034505
btrfs_destroy_delayed_inodes(fs_info);
4504-
btrfs_assert_delayed_root_empty(fs_info);
45054506

45064507
btrfs_destroy_marked_extents(fs_info, &cur_trans->dirty_pages,
45074508
EXTENT_DIRTY);

fs/btrfs/extent-tree.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4430,6 +4430,8 @@ int btrfs_alloc_logged_file_extent(struct btrfs_trans_handle *trans,
44304430

44314431
ret = alloc_reserved_file_extent(trans, 0, root_objectid, 0, owner,
44324432
offset, ins, 1);
4433+
if (ret)
4434+
btrfs_pin_extent(fs_info, ins->objectid, ins->offset, 1);
44334435
btrfs_put_block_group(block_group);
44344436
return ret;
44354437
}

fs/btrfs/inode.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4103,8 +4103,9 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
41034103
return -ENOMEM;
41044104
path->reada = READA_BACK;
41054105

4106-
lock_extent_bits(&BTRFS_I(inode)->io_tree, lock_start, (u64)-1,
4107-
&cached_state);
4106+
if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID)
4107+
lock_extent_bits(&BTRFS_I(inode)->io_tree, lock_start, (u64)-1,
4108+
&cached_state);
41084109

41094110
/*
41104111
* We want to drop from the next block forward in case this new size is
@@ -4368,11 +4369,10 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
43684369
if (!ret && last_size > new_size)
43694370
last_size = new_size;
43704371
btrfs_ordered_update_i_size(inode, last_size, NULL);
4372+
unlock_extent_cached(&BTRFS_I(inode)->io_tree, lock_start,
4373+
(u64)-1, &cached_state);
43714374
}
43724375

4373-
unlock_extent_cached(&BTRFS_I(inode)->io_tree, lock_start, (u64)-1,
4374-
&cached_state);
4375-
43764376
btrfs_free_path(path);
43774377
return ret;
43784378
}
@@ -9824,6 +9824,7 @@ static int __btrfs_prealloc_file_range(struct inode *inode, int mode,
98249824
struct btrfs_root *root = BTRFS_I(inode)->root;
98259825
struct btrfs_key ins;
98269826
u64 cur_offset = start;
9827+
u64 clear_offset = start;
98279828
u64 i_size;
98289829
u64 cur_bytes;
98299830
u64 last_alloc = (u64)-1;
@@ -9858,6 +9859,15 @@ static int __btrfs_prealloc_file_range(struct inode *inode, int mode,
98589859
btrfs_end_transaction(trans);
98599860
break;
98609861
}
9862+
9863+
/*
9864+
* We've reserved this space, and thus converted it from
9865+
* ->bytes_may_use to ->bytes_reserved. Any error that happens
9866+
* from here on out we will only need to clear our reservation
9867+
* for the remaining unreserved area, so advance our
9868+
* clear_offset by our extent size.
9869+
*/
9870+
clear_offset += ins.offset;
98619871
btrfs_dec_block_group_reservations(fs_info, ins.objectid);
98629872

98639873
last_alloc = ins.offset;
@@ -9937,9 +9947,9 @@ static int __btrfs_prealloc_file_range(struct inode *inode, int mode,
99379947
if (own_trans)
99389948
btrfs_end_transaction(trans);
99399949
}
9940-
if (cur_offset < end)
9941-
btrfs_free_reserved_data_space(inode, NULL, cur_offset,
9942-
end - cur_offset + 1);
9950+
if (clear_offset < end)
9951+
btrfs_free_reserved_data_space(inode, NULL, clear_offset,
9952+
end - clear_offset + 1);
99439953
return ret;
99449954
}
99459955

fs/btrfs/ordered-data.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,10 +679,15 @@ int btrfs_wait_ordered_range(struct inode *inode, u64 start, u64 len)
679679
}
680680
btrfs_start_ordered_extent(inode, ordered, 1);
681681
end = ordered->file_offset;
682+
/*
683+
* If the ordered extent had an error save the error but don't
684+
* exit without waiting first for all other ordered extents in
685+
* the range to complete.
686+
*/
682687
if (test_bit(BTRFS_ORDERED_IOERR, &ordered->flags))
683688
ret = -EIO;
684689
btrfs_put_ordered_extent(ordered);
685-
if (ret || end == 0 || end == start)
690+
if (end == 0 || end == start)
686691
break;
687692
end--;
688693
}

fs/btrfs/qgroup.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4002,3 +4002,16 @@ int btrfs_qgroup_trace_subtree_after_cow(struct btrfs_trans_handle *trans,
40024002
}
40034003
return ret;
40044004
}
4005+
4006+
void btrfs_qgroup_destroy_extent_records(struct btrfs_transaction *trans)
4007+
{
4008+
struct btrfs_qgroup_extent_record *entry;
4009+
struct btrfs_qgroup_extent_record *next;
4010+
struct rb_root *root;
4011+
4012+
root = &trans->delayed_refs.dirty_extent_root;
4013+
rbtree_postorder_for_each_entry_safe(entry, next, root, node) {
4014+
ulist_free(entry->old_roots);
4015+
kfree(entry);
4016+
}
4017+
}

fs/btrfs/qgroup.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,5 +414,6 @@ int btrfs_qgroup_add_swapped_blocks(struct btrfs_trans_handle *trans,
414414
u64 last_snapshot);
415415
int btrfs_qgroup_trace_subtree_after_cow(struct btrfs_trans_handle *trans,
416416
struct btrfs_root *root, struct extent_buffer *eb);
417+
void btrfs_qgroup_destroy_extent_records(struct btrfs_transaction *trans);
417418

418419
#endif

fs/btrfs/transaction.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ void btrfs_put_transaction(struct btrfs_transaction *transaction)
121121
BUG_ON(!list_empty(&transaction->list));
122122
WARN_ON(!RB_EMPTY_ROOT(
123123
&transaction->delayed_refs.href_root.rb_root));
124+
WARN_ON(!RB_EMPTY_ROOT(
125+
&transaction->delayed_refs.dirty_extent_root));
124126
if (transaction->delayed_refs.pending_csums)
125127
btrfs_err(transaction->fs_info,
126128
"pending csums is %llu",

0 commit comments

Comments
 (0)