Skip to content

Commit c4e7778

Browse files
fdmananamorbidrsa
authored andcommitted
btrfs: use verbose assertions in backref.c
While debugging a relocation issue I hit an assertion in backref.c but it was not super useful, since it could not tell what was the unexpected value that triggered the assertion. The stack trace was this: [583246.338097] assertion failed: !cache->nr_nodes, in fs/btrfs/backref.c:3158 [583246.339588] ------------[ cut here ]------------ [583246.340573] kernel BUG at fs/btrfs/backref.c:3158! [583246.342075] Oops: invalid opcode: 0000 [#1] SMP PTI [583246.343294] CPU: 5 UID: 0 PID: 677957 Comm: btrfs Not tainted 7.1.0-rc4-btrfs-next-234+ #1 PREEMPT(full) [583246.345715] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.2-0-gea1b7a073390-prebuilt.qemu.org 04/01/2014 [583246.348694] RIP: 0010:btrfs_backref_release_cache.cold+0x61/0x84 [btrfs] [583246.350759] Code: 90 d5 7c (...) [583246.354923] RSP: 0018:ffffd4fc88c93ad8 EFLAGS: 00010246 [583246.355982] RAX: 000000000000003e RBX: ffff8dec90d97020 RCX: 0000000000000000 [583246.357459] RDX: 0000000000000000 RSI: 0000000000000001 RDI: 00000000ffffffff [583246.359517] RBP: ffff8dec8eeb78c0 R08: 0000000000000000 R09: 3fffffffffefffff [583246.361180] R10: ffffd4fc88c93970 R11: 0000000000000003 R12: ffff8decd21f3470 [583246.363184] R13: 00000000fffffffe R14: ffff8decd21f3000 R15: ffff8decd21f3000 [583246.364666] FS: 00007f9a51751400(0000) GS:ffff8df3f4255000(0000) knlGS:0000000000000000 [583246.366287] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [583246.367443] CR2: 00007f9a518ed8f5 CR3: 00000004467c8002 CR4: 0000000000370ef0 [583246.368969] Call Trace: [583246.369541] <TASK> [583246.370040] relocate_block_group+0xf2/0x520 [btrfs] [583246.371243] btrfs_relocate_block_group+0x9a9/0x22e0 [btrfs] [583246.372443] ? preempt_count_add+0x47/0xa0 [583247.532978] ? btrfs_tree_read_lock_nested+0x19/0x90 [btrfs] [583247.534520] ? mutex_lock+0x1a/0x40 [583247.602233] ? btrfs_scrub_pause+0x2e/0x120 [btrfs] [583247.603543] btrfs_relocate_chunk+0x3b/0x1a0 [btrfs] [583247.604893] btrfs_balance+0x9d5/0x1920 [btrfs] [583247.606189] ? preempt_count_add+0x69/0xa0 [583247.607030] btrfs_ioctl+0x260c/0x2a20 [btrfs] [583247.608015] ? __memcg_slab_free_hook+0x156/0x1a0 [583247.636971] __x64_sys_ioctl+0x92/0xe0 [583247.679247] do_syscall_64+0x60/0xf20 [583247.753297] ? clear_bhb_loop+0x60/0xb0 [583247.756321] entry_SYSCALL_64_after_hwframe+0x76/0x7e [583247.787018] RIP: 0033:0x7f9a5186a8db [583247.787787] Code: 00 48 89 (...) [583247.791410] RSP: 002b:00007fff2ffa6ac0 EFLAGS: 00000246 ORIG_RAX: 0000000000000010 [583247.792897] RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 00007f9a5186a8db [583247.794319] RDX: 00007fff2ffa6bb0 RSI: 00000000c4009420 RDI: 0000000000000003 [583247.795714] RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000 [583247.797149] R10: 0000000000000000 R11: 0000000000000246 R12: 00007fff2ffa903f [583247.798685] R13: 00007fff2ffa6bb0 R14: 0000000000000002 R15: 0000000000000002 [583247.800136] </TASK> So update all simple assertions in backref.c to print out the values when they aren't testing simple boolean conditions. Reviewed-by: Qu Wenruo <wqu@suse.com> Signed-off-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 7af30ba commit c4e7778

1 file changed

Lines changed: 19 additions & 11 deletions

File tree

fs/btrfs/backref.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,7 @@ static bool lookup_backref_shared_cache(struct btrfs_backref_share_check_ctx *ct
12561256
* realizing. We cache results only for extent buffers that lead from
12571257
* the root node down to the leaf with the file extent item.
12581258
*/
1259-
ASSERT(level >= 0);
1259+
ASSERT(level >= 0, "level=%d", level);
12601260

12611261
entry = &ctx->path_cache_entries[level];
12621262

@@ -1327,7 +1327,7 @@ static void store_backref_shared_cache(struct btrfs_backref_share_check_ctx *ctx
13271327
* realizing. We cache results only for extent buffers that lead from
13281328
* the root node down to the leaf with the file extent item.
13291329
*/
1330-
ASSERT(level >= 0);
1330+
ASSERT(level >= 0, "level=%d", level);
13311331

13321332
if (is_shared)
13331333
gen = btrfs_get_last_root_drop_gen(fs_info);
@@ -2964,7 +2964,9 @@ int btrfs_backref_iter_next(struct btrfs_fs_info *fs_info, struct btrfs_backref_
29642964

29652965
if (btrfs_backref_iter_is_inline_ref(iter)) {
29662966
/* We're still inside the inline refs */
2967-
ASSERT(iter->cur_ptr < iter->end_ptr);
2967+
ASSERT(iter->cur_ptr < iter->end_ptr,
2968+
"iter->cur_ptr=%u iter->end_ptr=%u",
2969+
iter->cur_ptr, iter->end_ptr);
29682970

29692971
if (btrfs_backref_has_tree_block_info(iter)) {
29702972
/* First tree block info */
@@ -3030,7 +3032,7 @@ struct btrfs_backref_node *btrfs_backref_alloc_node(
30303032
{
30313033
struct btrfs_backref_node *node;
30323034

3033-
ASSERT(level >= 0 && level < BTRFS_MAX_LEVEL);
3035+
ASSERT(level >= 0 && level < BTRFS_MAX_LEVEL, "level=%d", level);
30343036
node = kzalloc_obj(*node, GFP_NOFS);
30353037
if (!node)
30363038
return node;
@@ -3052,7 +3054,7 @@ void btrfs_backref_free_node(struct btrfs_backref_cache *cache,
30523054
if (node) {
30533055
ASSERT(list_empty(&node->list));
30543056
ASSERT(list_empty(&node->lower));
3055-
ASSERT(node->eb == NULL);
3057+
ASSERT(node->eb == NULL, "node->eb->start=%llu", node->eb->start);
30563058
cache->nr_nodes--;
30573059
btrfs_put_root(node->root);
30583060
kfree(node);
@@ -3155,15 +3157,18 @@ void btrfs_backref_release_cache(struct btrfs_backref_cache *cache)
31553157

31563158
ASSERT(list_empty(&cache->pending_edge));
31573159
ASSERT(list_empty(&cache->useless_node));
3158-
ASSERT(!cache->nr_nodes);
3159-
ASSERT(!cache->nr_edges);
3160+
ASSERT(!cache->nr_nodes, "cache->nr_nodes=%d", cache->nr_nodes);
3161+
ASSERT(!cache->nr_edges, "cache->nr_edges=%d", cache->nr_edges);
31603162
}
31613163

31623164
static void btrfs_backref_link_edge(struct btrfs_backref_edge *edge,
31633165
struct btrfs_backref_node *lower,
31643166
struct btrfs_backref_node *upper)
31653167
{
3166-
ASSERT(upper && lower && upper->level == lower->level + 1);
3168+
ASSERT(upper != NULL);
3169+
ASSERT(lower != NULL);
3170+
ASSERT(upper->level == lower->level + 1, "upper->level=%d lower->level=%d",
3171+
upper->level, lower->level);
31673172
edge->node[LOWER] = lower;
31683173
edge->node[UPPER] = upper;
31693174
list_add_tail(&edge->list[LOWER], &lower->upper);
@@ -3283,7 +3288,9 @@ static int handle_indirect_tree_backref(struct btrfs_trans_handle *trans,
32833288

32843289
if (btrfs_root_level(&root->root_item) == cur->level) {
32853290
/* Tree root */
3286-
ASSERT(btrfs_root_bytenr(&root->root_item) == cur->bytenr);
3291+
ASSERT(btrfs_root_bytenr(&root->root_item) == cur->bytenr,
3292+
"root_bytenr=%llu cur->bytenr=%llu",
3293+
btrfs_root_bytenr(&root->root_item), cur->bytenr);
32873294
/*
32883295
* For reloc backref cache, we may ignore reloc root. But for
32893296
* general purpose backref cache, we can't rely on
@@ -3333,8 +3340,9 @@ static int handle_indirect_tree_backref(struct btrfs_trans_handle *trans,
33333340
/* Add all nodes and edges in the path */
33343341
for (; level < BTRFS_MAX_LEVEL; level++) {
33353342
if (!path->nodes[level]) {
3336-
ASSERT(btrfs_root_bytenr(&root->root_item) ==
3337-
lower->bytenr);
3343+
ASSERT(btrfs_root_bytenr(&root->root_item) == lower->bytenr,
3344+
"root_bytenr=%llu lower->bytenr=%llu",
3345+
btrfs_root_bytenr(&root->root_item), lower->bytenr);
33383346
/* Same as previous should_ignore_reloc_root() call */
33393347
if (btrfs_should_ignore_reloc_root(root) &&
33403348
cache->is_reloc) {

0 commit comments

Comments
 (0)