aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2007-09-11 11:15:39 -0400
committerDavid Woodhouse <dwmw2@hera.kernel.org>2007-09-11 11:15:39 -0400
commit5ce14bbcdd1b5d9233d26a1e89faf3a26c820c58 (patch)
tree6e2a2964e9b01c03dd1b4d58c976d76664747b64 /fs
parent0e2752a72cb37075b24899f01e9bc6a589de3b6c (diff)
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>
Diffstat (limited to 'fs')
-rw-r--r--fs/btrfs/ctree.h3
-rw-r--r--fs/btrfs/disk-io.c9
-rw-r--r--fs/btrfs/root-tree.c16
-rw-r--r--fs/btrfs/transaction.c6
-rw-r--r--fs/btrfs/transaction.h3
5 files changed, 25 insertions, 12 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 03e1c4ad341b..6d6e94b63803 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1148,7 +1148,8 @@ int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
1148 *item); 1148 *item);
1149int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct 1149int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
1150 btrfs_root_item *item, struct btrfs_key *key); 1150 btrfs_root_item *item, struct btrfs_key *key);
1151int btrfs_find_dead_roots(struct btrfs_root *root); 1151int btrfs_find_dead_roots(struct btrfs_root *root, u64 objectid,
1152 struct btrfs_root *latest_root);
1152/* dir-item.c */ 1153/* dir-item.c */
1153int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root 1154int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
1154 *root, const char *name, int name_len, u64 dir, 1155 *root, const char *name, int name_len, u64 dir,
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 6c953a0e0aa3..4296839eea1a 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -426,6 +426,10 @@ struct btrfs_root *btrfs_read_fs_root(struct btrfs_fs_info *fs_info,
426 return ERR_PTR(ret); 426 return ERR_PTR(ret);
427 } 427 }
428 428
429 ret = btrfs_find_dead_roots(fs_info->tree_root,
430 root->root_key.objectid, root);
431 BUG_ON(ret);
432
429 return root; 433 return root;
430} 434}
431 435
@@ -522,11 +526,6 @@ struct btrfs_root *open_ctree(struct super_block *sb)
522 btrfs_read_block_groups(extent_root); 526 btrfs_read_block_groups(extent_root);
523 527
524 fs_info->generation = btrfs_super_generation(disk_super) + 1; 528 fs_info->generation = btrfs_super_generation(disk_super) + 1;
525 ret = btrfs_find_dead_roots(tree_root);
526 if (ret) {
527 mutex_unlock(&fs_info->fs_mutex);
528 goto fail_tree_root;
529 }
530 mutex_unlock(&fs_info->fs_mutex); 529 mutex_unlock(&fs_info->fs_mutex);
531 return tree_root; 530 return tree_root;
532 531
diff --git a/fs/btrfs/root-tree.c b/fs/btrfs/root-tree.c
index 402f67821c14..3b5926dfbeba 100644
--- a/fs/btrfs/root-tree.c
+++ b/fs/btrfs/root-tree.c
@@ -93,7 +93,8 @@ int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
93 return ret; 93 return ret;
94} 94}
95 95
96int btrfs_find_dead_roots(struct btrfs_root *root) 96int btrfs_find_dead_roots(struct btrfs_root *root, u64 objectid,
97 struct btrfs_root *latest)
97{ 98{
98 struct btrfs_root *dead_root; 99 struct btrfs_root *dead_root;
99 struct btrfs_item *item; 100 struct btrfs_item *item;
@@ -105,7 +106,7 @@ int btrfs_find_dead_roots(struct btrfs_root *root)
105 struct btrfs_leaf *leaf; 106 struct btrfs_leaf *leaf;
106 int slot; 107 int slot;
107 108
108 key.objectid = 0; 109 key.objectid = objectid;
109 key.flags = 0; 110 key.flags = 0;
110 btrfs_set_key_type(&key, BTRFS_ROOT_ITEM_KEY); 111 btrfs_set_key_type(&key, BTRFS_ROOT_ITEM_KEY);
111 key.offset = 0; 112 key.offset = 0;
@@ -131,15 +132,24 @@ int btrfs_find_dead_roots(struct btrfs_root *root)
131 btrfs_disk_key_to_cpu(&key, &item->key); 132 btrfs_disk_key_to_cpu(&key, &item->key);
132 if (btrfs_key_type(&key) != BTRFS_ROOT_ITEM_KEY) 133 if (btrfs_key_type(&key) != BTRFS_ROOT_ITEM_KEY)
133 goto next; 134 goto next;
135
136 if (key.objectid < objectid)
137 goto next;
138
139 if (key.objectid > objectid)
140 break;
141
134 ri = btrfs_item_ptr(leaf, slot, struct btrfs_root_item); 142 ri = btrfs_item_ptr(leaf, slot, struct btrfs_root_item);
135 if (btrfs_root_refs(ri) != 0) 143 if (btrfs_root_refs(ri) != 0)
136 goto next; 144 goto next;
145
137 dead_root = btrfs_read_fs_root_no_radix(root->fs_info, &key); 146 dead_root = btrfs_read_fs_root_no_radix(root->fs_info, &key);
138 if (IS_ERR(dead_root)) { 147 if (IS_ERR(dead_root)) {
139 ret = PTR_ERR(dead_root); 148 ret = PTR_ERR(dead_root);
140 goto err; 149 goto err;
141 } 150 }
142 ret = btrfs_add_dead_root(dead_root, 151
152 ret = btrfs_add_dead_root(dead_root, latest,
143 &root->fs_info->dead_roots); 153 &root->fs_info->dead_roots);
144 if (ret) 154 if (ret)
145 goto err; 155 goto err;
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 2b15daa3a9f2..29755593de65 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -239,7 +239,9 @@ struct dirty_root {
239 struct btrfs_root *latest_root; 239 struct btrfs_root *latest_root;
240}; 240};
241 241
242int btrfs_add_dead_root(struct btrfs_root *root, struct list_head *dead_list) 242int btrfs_add_dead_root(struct btrfs_root *root,
243 struct btrfs_root *latest,
244 struct list_head *dead_list)
243{ 245{
244 struct dirty_root *dirty; 246 struct dirty_root *dirty;
245 247
@@ -247,6 +249,7 @@ int btrfs_add_dead_root(struct btrfs_root *root, struct list_head *dead_list)
247 if (!dirty) 249 if (!dirty)
248 return -ENOMEM; 250 return -ENOMEM;
249 dirty->root = root; 251 dirty->root = root;
252 dirty->latest_root = latest;
250 list_add(&dirty->list, dead_list); 253 list_add(&dirty->list, dead_list);
251 return 0; 254 return 0;
252} 255}
@@ -412,7 +415,6 @@ static int drop_dirty_roots(struct btrfs_root *tree_root,
412 415
413 while(1) { 416 while(1) {
414 trans = btrfs_start_transaction(tree_root, 1); 417 trans = btrfs_start_transaction(tree_root, 1);
415
416 ret = btrfs_drop_snapshot(trans, dirty->root); 418 ret = btrfs_drop_snapshot(trans, dirty->root);
417 if (ret != -EAGAIN) { 419 if (ret != -EAGAIN) {
418 break; 420 break;
diff --git a/fs/btrfs/transaction.h b/fs/btrfs/transaction.h
index e451783a1a4d..4bc328cbb24c 100644
--- a/fs/btrfs/transaction.h
+++ b/fs/btrfs/transaction.h
@@ -78,7 +78,8 @@ void btrfs_transaction_flush_work(struct btrfs_root *root);
78void btrfs_transaction_queue_work(struct btrfs_root *root, int delay); 78void btrfs_transaction_queue_work(struct btrfs_root *root, int delay);
79void btrfs_init_transaction_sys(void); 79void btrfs_init_transaction_sys(void);
80void btrfs_exit_transaction_sys(void); 80void btrfs_exit_transaction_sys(void);
81int btrfs_add_dead_root(struct btrfs_root *root, struct list_head *dead_list); 81int btrfs_add_dead_root(struct btrfs_root *root, struct btrfs_root *latest,
82 struct list_head *dead_list);
82int btrfs_defrag_dirty_roots(struct btrfs_fs_info *info); 83int btrfs_defrag_dirty_roots(struct btrfs_fs_info *info);
83int btrfs_defrag_root(struct btrfs_root *root, int cacheonly); 84int btrfs_defrag_root(struct btrfs_root *root, int cacheonly);
84int btrfs_clean_old_snapshots(struct btrfs_root *root); 85int btrfs_clean_old_snapshots(struct btrfs_root *root);