Btrfs: Find and remove dead roots the first time a root is loaded.

Dead roots are trees left over after a crash, and they were either in the
process of being removed or were waiting to be removed when the box crashed.
Before, a search of the entire tree of root pointers was done on mount
looking for dead roots.  Now, the search is done the first time we load
a root.

This makes mount faster when there are a large number of snapshots, and it
enables the block accounting code to properly update the block counts on
the latest root as old versions of the root are reaped after a crash.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 6c953a0..4296839 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -426,6 +426,10 @@
 		return ERR_PTR(ret);
 	}
 
+	ret = btrfs_find_dead_roots(fs_info->tree_root,
+				    root->root_key.objectid, root);
+	BUG_ON(ret);
+
 	return root;
 }
 
@@ -522,11 +526,6 @@
 	btrfs_read_block_groups(extent_root);
 
 	fs_info->generation = btrfs_super_generation(disk_super) + 1;
-	ret = btrfs_find_dead_roots(tree_root);
-	if (ret) {
-		mutex_unlock(&fs_info->fs_mutex);
-		goto fail_tree_root;
-	}
 	mutex_unlock(&fs_info->fs_mutex);
 	return tree_root;