From 659ba0c292ab4302d1d067fb086ad0283fba4e37 Mon Sep 17 00:00:00 2001
From: Liu Bo <liub.liubo@gmail.com>
Date: Wed, 17 Oct 2012 22:59:22 +0800
Subject: [PATCH 3/3] Btrfs: debug part 2
Signed-off-by: Liu Bo <liub.liubo@gmail.com>
---
fs/btrfs/ctree.c | 22 ++++++++++++++++++++++
1 files changed, 22 insertions(+), 0 deletions(-)
@@ -379,6 +379,8 @@ u64 btrfs_get_tree_mod_seq(struct btrfs_fs_info *fs_info,
if (!elem->seq) {
elem->seq = btrfs_inc_tree_mod_seq(fs_info);
list_add_tail(&elem->list, &fs_info->tree_mod_seq_list);
+
+ BUG_ON((fs_info->tree_mod_seq_list.prev)->next != (&fs_info->tree_mod_seq_list));
}
seq = btrfs_inc_tree_mod_seq(fs_info);
spin_unlock(&fs_info->tree_mod_seq_lock);
@@ -403,9 +405,11 @@ void btrfs_put_tree_mod_seq(struct btrfs_fs_info *fs_info,
spin_lock(&fs_info->tree_mod_seq_lock);
list_del(&elem->list);
+
elem->seq = 0;
list_for_each_entry(cur_elem, &fs_info->tree_mod_seq_list, list) {
+ BUG_ON(!cur_elem);
if (cur_elem->seq < min_seq) {
if (seq_putting > cur_elem->seq) {
/*
@@ -1131,6 +1135,7 @@ __tree_mod_log_rewind(struct extent_buffer *eb, u64 time_seq,
unsigned long o_dst;
unsigned long o_src;
unsigned long p_size = sizeof(struct btrfs_key_ptr);
+ int rm = 0, rm_free = 0, rm_move = 0, add = 0;;
n = btrfs_header_nritems(eb);
while (tm && tm->seq >= time_seq) {
@@ -1142,13 +1147,18 @@ __tree_mod_log_rewind(struct extent_buffer *eb, u64 time_seq,
switch (tm->op) {
case MOD_LOG_KEY_REMOVE_WHILE_FREEING:
BUG_ON(tm->slot < n);
+ rm_free++;
case MOD_LOG_KEY_REMOVE_WHILE_MOVING:
+ if (tm->op == MOD_LOG_KEY_REMOVE_WHILE_MOVING)
+ rm_move++;
case MOD_LOG_KEY_REMOVE:
btrfs_set_node_key(eb, &tm->key, tm->slot);
btrfs_set_node_blockptr(eb, tm->slot, tm->blockptr);
btrfs_set_node_ptr_generation(eb, tm->slot,
tm->generation);
n++;
+ if (tm->op == MOD_LOG_KEY_REMOVE)
+ rm++;
break;
case MOD_LOG_KEY_REPLACE:
BUG_ON(tm->slot >= n);
@@ -1160,6 +1170,7 @@ __tree_mod_log_rewind(struct extent_buffer *eb, u64 time_seq,
case MOD_LOG_KEY_ADD:
/* if a move operation is needed it's in the log */
n--;
+ add = 0;
break;
case MOD_LOG_MOVE_KEYS:
o_dst = btrfs_node_key_ptr_offset(tm->slot);
@@ -1186,6 +1197,10 @@ __tree_mod_log_rewind(struct extent_buffer *eb, u64 time_seq,
if (tm->index != first_tm->index)
break;
}
+ if (n > 124 || (int)n < 0) {
+ printk("eb->start %llu eb->len %llu eb->level %d nritems %d n %d rm %d rm_free %d rm_move add %d\n",
+ eb->start, eb->len, btrfs_header_level(eb), btrfs_header_nritems(eb), n, rm, rm_free, rm_move, add);
+ }
btrfs_set_header_nritems(eb, n);
}
@@ -1564,6 +1579,13 @@ static noinline int generic_bin_search(struct extent_buffer *eb,
mid = (low + high) / 2;
offset = p + mid * item_size;
+ if (offset + sizeof(struct btrfs_disk_key) > eb->len) {
+ printk("offset %llu min_len %d eb->start %llu eb->len %llu, eb->level %d p %llu mid %d low %d high %d item %d max %d\n",
+ offset, sizeof(struct btrfs_disk_key), eb->start, eb->len, btrfs_header_level(eb),
+ p, mid, low, high, item_size, max);
+ BUG_ON(1);
+ }
+
if (!kaddr || offset < map_start ||
(offset + sizeof(struct btrfs_disk_key)) >
map_start + map_len) {
--
1.7.7.6