@@ -3150,6 +3150,7 @@ static void fixup_low_keys(struct btrfs_fs_info *fs_info,
}
}
+
/*
* update item key.
*
@@ -3182,6 +3183,63 @@ void btrfs_set_item_key_safe(struct btrfs_fs_info *fs_info,
fixup_low_keys(fs_info, path, &disk_key, 1);
}
+noinline void btrfs_set_item_key_debug(struct btrfs_fs_info *fs_info,
+ struct btrfs_path *path,
+ struct btrfs_key *new_key)
+{
+ struct btrfs_disk_key disk_key;
+ struct btrfs_key key;
+ struct extent_buffer *eb;
+ u64 extent_end;
+ u64 extent_offset = 0;
+ u64 num_bytes;
+ u64 disk_bytenr;
+ struct btrfs_file_extent_item *fi;
+ int extent_type;
+ int slot;
+
+ eb = path->nodes[0];
+ slot = path->slots[0];
+
+ btrfs_item_key_to_cpu(eb, &key, path->slots[0]);
+
+ fi = btrfs_item_ptr(eb, path->slots[0],
+ struct btrfs_file_extent_item);
+ extent_type = btrfs_file_extent_type(eb, fi);
+
+ BUG_ON(extent_type == BTRFS_FILE_EXTENT_INLINE);
+
+ disk_bytenr = btrfs_file_extent_disk_bytenr(eb, fi);
+ num_bytes = btrfs_file_extent_disk_num_bytes(eb, fi);
+ extent_offset = btrfs_file_extent_offset(eb, fi);
+ extent_end = key.offset + btrfs_file_extent_num_bytes(eb, fi);
+
+ if (slot > 0) {
+ btrfs_item_key(eb, &disk_key, slot - 1);
+ if (comp_keys(&disk_key, new_key) >= 0) {
+ struct btrfs_key tmp;
+ btrfs_item_key_to_cpu(eb, &tmp, slot - 1);
+ pr_info("(slot - 1) is bigger: key.offset=%llu new_key.offset=%llu extent_end=%llu num_bytes=%llu disk_bytenr=%llu
extent_offset=%llu\n",
+ tmp.offset, new_key->offset, extent_end, num_bytes, disk_bytenr, extent_offset);
+ BUG_ON(1);
+ }
+ }
+ if (slot < btrfs_header_nritems(eb) - 1) {
+ btrfs_item_key(eb, &disk_key, slot + 1);
+
+ if (comp_keys(&disk_key, new_key) <= 0) {
+ struct btrfs_key tmp;
+ btrfs_item_key_to_cpu(eb, &tmp, slot + 1);
+ pr_info("(slot + 1) is smaller: key.offset=%llu new_key.offset=%llu extent_end=%llu num_bytes=%llu disk_bytenr=%llu
extent_offset=%llu\n",
+ tmp.offset, new_key->offset, extent_end, num_bytes, disk_bytenr, extent_offset);
+ BUG_ON(1);
+ }
+ }
+
+ btrfs_set_item_key_safe(fs_info, path, new_key);
+}
+
+
/*
* try to push data from one node into the next node left in the
* tree.
@@ -3660,6 +3660,9 @@ int btrfs_previous_extent_item(struct btrfs_root *root,
void btrfs_set_item_key_safe(struct btrfs_fs_info *fs_info,
struct btrfs_path *path,
struct btrfs_key *new_key);
+void btrfs_set_item_key_debug(struct btrfs_fs_info *fs_info,
+ struct btrfs_path *path,
+ struct btrfs_key *new_key);
struct extent_buffer *btrfs_root_node(struct btrfs_root *root);
struct extent_buffer *btrfs_lock_root_node(struct btrfs_root *root);
int btrfs_find_next_key(struct btrfs_root *root, struct btrfs_path *path,
@@ -678,6 +678,7 @@ next:
free_extent_map(split2);
}
+
/*
* this is very complex, but the basic idea is to drop all extents
* in the range start - end. hint_block is filled in with a block number
@@ -871,7 +872,7 @@ next_slot:
memcpy(&new_key, &key, sizeof(new_key));
new_key.offset = end;
- btrfs_set_item_key_safe(root->fs_info, path, &new_key);
+ btrfs_set_item_key_debug(root->fs_info, path, &new_key);
extent_offset += end - key.offset;
btrfs_set_file_extent_offset(leaf, fi, extent_offset);