aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/disk-io.c
diff options
context:
space:
mode:
authorJosef Bacik <jbacik@fusionio.com>2013-09-19 16:07:01 -0400
committerChris Mason <chris.mason@fusionio.com>2013-11-11 21:51:02 -0500
commit06ea65a398a2501e94beee3a425d07e1846ff25a (patch)
treeda8445a365ceecd4df89a9d6a3da79afaa320765 /fs/btrfs/disk-io.c
parentdd3cc16b8750251ea9b1a843ce7806e82b015d5e (diff)
Btrfs: add a sanity test for btrfs_split_item
While looking at somebodys corruption I became completely convinced that btrfs_split_item was broken, so I wrote this test to verify that it was working as it was supposed to. Thankfully it appears to be working as intended, so just add this test to make sure nobody breaks it in the future. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
Diffstat (limited to 'fs/btrfs/disk-io.c')
-rw-r--r--fs/btrfs/disk-io.c38
1 files changed, 34 insertions, 4 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index f724397b396b..db2095486a4f 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1229,14 +1229,18 @@ static void __setup_root(u32 nodesize, u32 leafsize, u32 sectorsize,
1229 atomic_set(&root->refs, 1); 1229 atomic_set(&root->refs, 1);
1230 root->log_transid = 0; 1230 root->log_transid = 0;
1231 root->last_log_commit = 0; 1231 root->last_log_commit = 0;
1232 extent_io_tree_init(&root->dirty_log_pages, 1232 if (fs_info)
1233 fs_info->btree_inode->i_mapping); 1233 extent_io_tree_init(&root->dirty_log_pages,
1234 fs_info->btree_inode->i_mapping);
1234 1235
1235 memset(&root->root_key, 0, sizeof(root->root_key)); 1236 memset(&root->root_key, 0, sizeof(root->root_key));
1236 memset(&root->root_item, 0, sizeof(root->root_item)); 1237 memset(&root->root_item, 0, sizeof(root->root_item));
1237 memset(&root->defrag_progress, 0, sizeof(root->defrag_progress)); 1238 memset(&root->defrag_progress, 0, sizeof(root->defrag_progress));
1238 memset(&root->root_kobj, 0, sizeof(root->root_kobj)); 1239 memset(&root->root_kobj, 0, sizeof(root->root_kobj));
1239 root->defrag_trans_start = fs_info->generation; 1240 if (fs_info)
1241 root->defrag_trans_start = fs_info->generation;
1242 else
1243 root->defrag_trans_start = 0;
1240 init_completion(&root->kobj_unregister); 1244 init_completion(&root->kobj_unregister);
1241 root->defrag_running = 0; 1245 root->defrag_running = 0;
1242 root->root_key.objectid = objectid; 1246 root->root_key.objectid = objectid;
@@ -1253,6 +1257,22 @@ static struct btrfs_root *btrfs_alloc_root(struct btrfs_fs_info *fs_info)
1253 return root; 1257 return root;
1254} 1258}
1255 1259
1260#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
1261/* Should only be used by the testing infrastructure */
1262struct btrfs_root *btrfs_alloc_dummy_root(void)
1263{
1264 struct btrfs_root *root;
1265
1266 root = btrfs_alloc_root(NULL);
1267 if (!root)
1268 return ERR_PTR(-ENOMEM);
1269 __setup_root(4096, 4096, 4096, 4096, root, NULL, 1);
1270 root->dummy_root = 1;
1271
1272 return root;
1273}
1274#endif
1275
1256struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans, 1276struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans,
1257 struct btrfs_fs_info *fs_info, 1277 struct btrfs_fs_info *fs_info,
1258 u64 objectid) 1278 u64 objectid)
@@ -3670,10 +3690,20 @@ int btrfs_set_buffer_uptodate(struct extent_buffer *buf)
3670 3690
3671void btrfs_mark_buffer_dirty(struct extent_buffer *buf) 3691void btrfs_mark_buffer_dirty(struct extent_buffer *buf)
3672{ 3692{
3673 struct btrfs_root *root = BTRFS_I(buf->pages[0]->mapping->host)->root; 3693 struct btrfs_root *root;
3674 u64 transid = btrfs_header_generation(buf); 3694 u64 transid = btrfs_header_generation(buf);
3675 int was_dirty; 3695 int was_dirty;
3676 3696
3697#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
3698 /*
3699 * This is a fast path so only do this check if we have sanity tests
3700 * enabled. Normal people shouldn't be marking dummy buffers as dirty
3701 * outside of the sanity tests.
3702 */
3703 if (unlikely(test_bit(EXTENT_BUFFER_DUMMY, &buf->bflags)))
3704 return;
3705#endif
3706 root = BTRFS_I(buf->pages[0]->mapping->host)->root;
3677 btrfs_assert_tree_locked(buf); 3707 btrfs_assert_tree_locked(buf);
3678 if (transid != root->fs_info->generation) 3708 if (transid != root->fs_info->generation)
3679 WARN(1, KERN_CRIT "btrfs transid mismatch buffer %llu, " 3709 WARN(1, KERN_CRIT "btrfs transid mismatch buffer %llu, "