Skip to content

Commit 36c86a9

Browse files
adam900710kdave
authored andcommitted
btrfs: output more debug messages for uncommitted transaction
Print extra information about how many dirty bytes an uncommitted has at the end of mount. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent c2f8226 commit 36c86a9

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

fs/btrfs/disk-io.c

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4483,6 +4483,48 @@ int btrfs_commit_super(struct btrfs_fs_info *fs_info)
44834483
return btrfs_commit_transaction(trans);
44844484
}
44854485

4486+
static void warn_about_uncommitted_trans(struct btrfs_fs_info *fs_info)
4487+
{
4488+
struct btrfs_transaction *trans;
4489+
struct btrfs_transaction *tmp;
4490+
bool found = false;
4491+
4492+
if (list_empty(&fs_info->trans_list))
4493+
return;
4494+
4495+
/*
4496+
* This function is only called at the very end of close_ctree(),
4497+
* thus no other running transaction, no need to take trans_lock.
4498+
*/
4499+
ASSERT(test_bit(BTRFS_FS_CLOSING_DONE, &fs_info->flags));
4500+
list_for_each_entry_safe(trans, tmp, &fs_info->trans_list, list) {
4501+
struct extent_state *cached = NULL;
4502+
u64 dirty_bytes = 0;
4503+
u64 cur = 0;
4504+
u64 found_start;
4505+
u64 found_end;
4506+
4507+
found = true;
4508+
while (!find_first_extent_bit(&trans->dirty_pages, cur,
4509+
&found_start, &found_end, EXTENT_DIRTY, &cached)) {
4510+
dirty_bytes += found_end + 1 - found_start;
4511+
cur = found_end + 1;
4512+
}
4513+
btrfs_warn(fs_info,
4514+
"transaction %llu (with %llu dirty metadata bytes) is not committed",
4515+
trans->transid, dirty_bytes);
4516+
btrfs_cleanup_one_transaction(trans, fs_info);
4517+
4518+
if (trans == fs_info->running_transaction)
4519+
fs_info->running_transaction = NULL;
4520+
list_del_init(&trans->list);
4521+
4522+
btrfs_put_transaction(trans);
4523+
trace_btrfs_transaction_commit(fs_info);
4524+
}
4525+
ASSERT(!found);
4526+
}
4527+
44864528
void __cold close_ctree(struct btrfs_fs_info *fs_info)
44874529
{
44884530
int ret;
@@ -4591,7 +4633,7 @@ void __cold close_ctree(struct btrfs_fs_info *fs_info)
45914633
btrfs_stop_all_workers(fs_info);
45924634

45934635
/* We shouldn't have any transaction open at this point */
4594-
ASSERT(list_empty(&fs_info->trans_list));
4636+
warn_about_uncommitted_trans(fs_info);
45954637

45964638
clear_bit(BTRFS_FS_OPEN, &fs_info->flags);
45974639
free_root_pointers(fs_info, true);

0 commit comments

Comments
 (0)