aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Behrens <sbehrens@giantdisaster.de>2013-09-05 10:58:43 -0400
committerChris Mason <chris.mason@fusionio.com>2013-11-11 21:49:26 -0500
commit69e9c6c6dc87587d8846e447febedefe037c14f8 (patch)
tree557fc35afdf3bbee9ce0f46a2ce16ce1c386133c
parent5e01dc7b26d9f24f39abace5da98ccbd6a5ceb52 (diff)
Btrfs: eliminate the exceptional root_tree refs=0
The fact that btrfs_root_refs() returned 0 for the tree_root caused bugs in the past, therefore it is set to 1 with this patch and (hopefully) all affected code is adapted to this change. I verified this change by temporarily adding WARN_ON() checks everywhere where btrfs_root_refs() is used, checking whether the logic of the code is changed by btrfs_root_refs() returning 1 instead of 0 for root->root_key.objectid == BTRFS_ROOT_TREE_OBJECTID. With these added checks, I ran the xfstests './check -g auto'. The two roots chunk_root and log_root_tree that are only referenced by the superblock and the log_roots below the log_root_tree still have btrfs_root_refs() == 0, only the tree_root is changed. Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de> Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
-rw-r--r--fs/btrfs/disk-io.c1
-rw-r--r--fs/btrfs/inode-map.c3
-rw-r--r--fs/btrfs/inode.c21
3 files changed, 10 insertions, 15 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 62176ad89846..f724397b396b 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2670,6 +2670,7 @@ retry_root_backup:
2670 2670
2671 btrfs_set_root_node(&tree_root->root_item, tree_root->node); 2671 btrfs_set_root_node(&tree_root->root_item, tree_root->node);
2672 tree_root->commit_root = btrfs_root_node(tree_root); 2672 tree_root->commit_root = btrfs_root_node(tree_root);
2673 btrfs_set_root_refs(&tree_root->root_item, 1);
2673 2674
2674 location.objectid = BTRFS_EXTENT_TREE_OBJECTID; 2675 location.objectid = BTRFS_EXTENT_TREE_OBJECTID;
2675 location.type = BTRFS_ROOT_ITEM_KEY; 2676 location.type = BTRFS_ROOT_ITEM_KEY;
diff --git a/fs/btrfs/inode-map.c b/fs/btrfs/inode-map.c
index 2c66ddbbe670..d11e1c6610b6 100644
--- a/fs/btrfs/inode-map.c
+++ b/fs/btrfs/inode-map.c
@@ -412,8 +412,7 @@ int btrfs_save_ino_cache(struct btrfs_root *root,
412 return 0; 412 return 0;
413 413
414 /* Don't save inode cache if we are deleting this root */ 414 /* Don't save inode cache if we are deleting this root */
415 if (btrfs_root_refs(&root->root_item) == 0 && 415 if (btrfs_root_refs(&root->root_item) == 0)
416 root != root->fs_info->tree_root)
417 return 0; 416 return 0;
418 417
419 if (!btrfs_test_opt(root, INODE_MAP_CACHE)) 418 if (!btrfs_test_opt(root, INODE_MAP_CACHE))
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 51e3afa78354..dfc60aa40332 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -4472,8 +4472,10 @@ void btrfs_evict_inode(struct inode *inode)
4472 trace_btrfs_inode_evict(inode); 4472 trace_btrfs_inode_evict(inode);
4473 4473
4474 truncate_inode_pages(&inode->i_data, 0); 4474 truncate_inode_pages(&inode->i_data, 0);
4475 if (inode->i_nlink && (btrfs_root_refs(&root->root_item) != 0 || 4475 if (inode->i_nlink &&
4476 btrfs_is_free_space_inode(inode))) 4476 ((btrfs_root_refs(&root->root_item) != 0 &&
4477 root->root_key.objectid != BTRFS_ROOT_TREE_OBJECTID) ||
4478 btrfs_is_free_space_inode(inode)))
4477 goto no_delete; 4479 goto no_delete;
4478 4480
4479 if (is_bad_inode(inode)) { 4481 if (is_bad_inode(inode)) {
@@ -4490,7 +4492,8 @@ void btrfs_evict_inode(struct inode *inode)
4490 } 4492 }
4491 4493
4492 if (inode->i_nlink > 0) { 4494 if (inode->i_nlink > 0) {
4493 BUG_ON(btrfs_root_refs(&root->root_item) != 0); 4495 BUG_ON(btrfs_root_refs(&root->root_item) != 0 &&
4496 root->root_key.objectid != BTRFS_ROOT_TREE_OBJECTID);
4494 goto no_delete; 4497 goto no_delete;
4495 } 4498 }
4496 4499
@@ -4731,14 +4734,7 @@ static void inode_tree_del(struct inode *inode)
4731 } 4734 }
4732 spin_unlock(&root->inode_lock); 4735 spin_unlock(&root->inode_lock);
4733 4736
4734 /* 4737 if (empty && btrfs_root_refs(&root->root_item) == 0) {
4735 * Free space cache has inodes in the tree root, but the tree root has a
4736 * root_refs of 0, so this could end up dropping the tree root as a
4737 * snapshot, so we need the extra !root->fs_info->tree_root check to
4738 * make sure we don't drop it.
4739 */
4740 if (empty && btrfs_root_refs(&root->root_item) == 0 &&
4741 root != root->fs_info->tree_root) {
4742 synchronize_srcu(&root->fs_info->subvol_srcu); 4738 synchronize_srcu(&root->fs_info->subvol_srcu);
4743 spin_lock(&root->inode_lock); 4739 spin_lock(&root->inode_lock);
4744 empty = RB_EMPTY_ROOT(&root->inode_tree); 4740 empty = RB_EMPTY_ROOT(&root->inode_tree);
@@ -7857,8 +7853,7 @@ int btrfs_drop_inode(struct inode *inode)
7857 return 1; 7853 return 1;
7858 7854
7859 /* the snap/subvol tree is on deleting */ 7855 /* the snap/subvol tree is on deleting */
7860 if (btrfs_root_refs(&root->root_item) == 0 && 7856 if (btrfs_root_refs(&root->root_item) == 0)
7861 root != root->fs_info->tree_root)
7862 return 1; 7857 return 1;
7863 else 7858 else
7864 return generic_drop_inode(inode); 7859 return generic_drop_inode(inode);