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/transaction.c b/fs/btrfs/transaction.c
index 2b15daa..2975559 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -239,7 +239,9 @@
struct btrfs_root *latest_root;
};
-int btrfs_add_dead_root(struct btrfs_root *root, struct list_head *dead_list)
+int btrfs_add_dead_root(struct btrfs_root *root,
+ struct btrfs_root *latest,
+ struct list_head *dead_list)
{
struct dirty_root *dirty;
@@ -247,6 +249,7 @@
if (!dirty)
return -ENOMEM;
dirty->root = root;
+ dirty->latest_root = latest;
list_add(&dirty->list, dead_list);
return 0;
}
@@ -412,7 +415,6 @@
while(1) {
trans = btrfs_start_transaction(tree_root, 1);
-
ret = btrfs_drop_snapshot(trans, dirty->root);
if (ret != -EAGAIN) {
break;