Skip to contentSkip to conversation

Btrfs: check if items are ordered when a leaf is marked dirty

PATCH In review Filipe David Borba Manana 2 participants 2 messages Apr 9, 2014 – Apr 14, 2014 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Btrfs: check if items are ordered when a leaf is marked dirty

To ease finding bugs during development related to modifying btree leaves in such a way that it makes its items not sorted by key anymore. Since this is an expensive check, it's only enabled if CONFIG_BTRFS_FS_CHECK_INTEGRITY is set, which isn't meant to be enabled for regular users.

---
 fs/btrfs/disk-io.c | 6 ++++++
 1 file changed, 6 insertions(+)
fs/btrfs/disk-io.c +6 -0
index d9698fd..8bf6628 100644
@@ -3695,6 +3695,12 @@ void btrfs_mark_buffer_dirty(struct extent_buffer *buf)
 		__percpu_counter_add(&root->fs_info->dirty_metadata_bytes,
 				     buf->len,
 				     root->fs_info->dirty_metadata_batch);
+#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
+	if (btrfs_header_level(buf) == 0 && check_leaf(root, buf)) {
+		btrfs_print_leaf(root, buf);
+		ASSERT(0);
+	}
+#endif
 }
 
 static void __btrfs_btree_balance_dirty(struct btrfs_root *root,
Signature · 1 line
1.9.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Filipe David Borba Manana

To ease finding bugs during development related to modifying btree leaves in such a way that it makes its items not sorted by key anymore. Since this is an expensive check, it's only enabled if CONFIG_BTRFS_FS_CHECK_INTEGRITY is set, which isn't meant to be enabled for regular users.

fs/btrfs/disk-io.c void btrfs_mark_buffer_dirty(struct extent_buffer *buf) · line 3699

Quoted 6 lines
fs/btrfs/disk-io.c +2 -0
@@ -3695,6 +3695,12 @@ void btrfs_mark_buffer_dirty(struct extent_buffer *buf)
 		__percpu_counter_add(&root->fs_info->dirty_metadata_bytes,
 				     buf->len,
 				     root->fs_info->dirty_metadata_batch);
+#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
+	if (btrfs_header_level(buf) == 0 && check_leaf(root, buf)) {

You coud also add the 'level == 0' to check_leaf() itself.