aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs
diff options
context:
space:
mode:
authorArne Jansen <sensille@gmx.net>2011-09-13 06:44:20 -0400
committerJan Schmidt <list.btrfs@jan-o-sch.net>2012-07-10 09:14:43 -0400
commit20897f5c86b9d2b77baea1d48eda7fa4ac217279 (patch)
treed9c0e15de961c24baa043b7c4aca7cce9debb2ae /fs/btrfs
parentd13603ef6e14a12cd65a6975e8117c0fea7c7ddf (diff)
Btrfs: added helper to create new trees
This creates a brand new tree. Will be used to create the quota tree. Signed-off-by: Arne Jansen <sensille@gmx.net>
Diffstat (limited to 'fs/btrfs')
-rw-r--r--fs/btrfs/disk-io.c78
-rw-r--r--fs/btrfs/disk-io.h6
2 files changed, 83 insertions, 1 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 19a39e10d6f5..6fc243eccffa 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1225,6 +1225,82 @@ static struct btrfs_root *btrfs_alloc_root(struct btrfs_fs_info *fs_info)
1225 return root; 1225 return root;
1226} 1226}
1227 1227
1228struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans,
1229 struct btrfs_fs_info *fs_info,
1230 u64 objectid)
1231{
1232 struct extent_buffer *leaf;
1233 struct btrfs_root *tree_root = fs_info->tree_root;
1234 struct btrfs_root *root;
1235 struct btrfs_key key;
1236 int ret = 0;
1237 u64 bytenr;
1238
1239 root = btrfs_alloc_root(fs_info);
1240 if (!root)
1241 return ERR_PTR(-ENOMEM);
1242
1243 __setup_root(tree_root->nodesize, tree_root->leafsize,
1244 tree_root->sectorsize, tree_root->stripesize,
1245 root, fs_info, objectid);
1246 root->root_key.objectid = objectid;
1247 root->root_key.type = BTRFS_ROOT_ITEM_KEY;
1248 root->root_key.offset = 0;
1249
1250 leaf = btrfs_alloc_free_block(trans, root, root->leafsize,
1251 0, objectid, NULL, 0, 0, 0);
1252 if (IS_ERR(leaf)) {
1253 ret = PTR_ERR(leaf);
1254 goto fail;
1255 }
1256
1257 bytenr = leaf->start;
1258 memset_extent_buffer(leaf, 0, 0, sizeof(struct btrfs_header));
1259 btrfs_set_header_bytenr(leaf, leaf->start);
1260 btrfs_set_header_generation(leaf, trans->transid);
1261 btrfs_set_header_backref_rev(leaf, BTRFS_MIXED_BACKREF_REV);
1262 btrfs_set_header_owner(leaf, objectid);
1263 root->node = leaf;
1264
1265 write_extent_buffer(leaf, fs_info->fsid,
1266 (unsigned long)btrfs_header_fsid(leaf),
1267 BTRFS_FSID_SIZE);
1268 write_extent_buffer(leaf, fs_info->chunk_tree_uuid,
1269 (unsigned long)btrfs_header_chunk_tree_uuid(leaf),
1270 BTRFS_UUID_SIZE);
1271 btrfs_mark_buffer_dirty(leaf);
1272
1273 root->commit_root = btrfs_root_node(root);
1274 root->track_dirty = 1;
1275
1276
1277 root->root_item.flags = 0;
1278 root->root_item.byte_limit = 0;
1279 btrfs_set_root_bytenr(&root->root_item, leaf->start);
1280 btrfs_set_root_generation(&root->root_item, trans->transid);
1281 btrfs_set_root_level(&root->root_item, 0);
1282 btrfs_set_root_refs(&root->root_item, 1);
1283 btrfs_set_root_used(&root->root_item, leaf->len);
1284 btrfs_set_root_last_snapshot(&root->root_item, 0);
1285 btrfs_set_root_dirid(&root->root_item, 0);
1286 root->root_item.drop_level = 0;
1287
1288 key.objectid = objectid;
1289 key.type = BTRFS_ROOT_ITEM_KEY;
1290 key.offset = 0;
1291 ret = btrfs_insert_root(trans, tree_root, &key, &root->root_item);
1292 if (ret)
1293 goto fail;
1294
1295 btrfs_tree_unlock(leaf);
1296
1297fail:
1298 if (ret)
1299 return ERR_PTR(ret);
1300
1301 return root;
1302}
1303
1228static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans, 1304static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans,
1229 struct btrfs_fs_info *fs_info) 1305 struct btrfs_fs_info *fs_info)
1230{ 1306{
@@ -3260,7 +3336,7 @@ int btrfs_read_buffer(struct extent_buffer *buf, u64 parent_transid)
3260 return btree_read_extent_buffer_pages(root, buf, 0, parent_transid); 3336 return btree_read_extent_buffer_pages(root, buf, 0, parent_transid);
3261} 3337}
3262 3338
3263static int btree_lock_page_hook(struct page *page, void *data, 3339int btree_lock_page_hook(struct page *page, void *data,
3264 void (*flush_fn)(void *)) 3340 void (*flush_fn)(void *))
3265{ 3341{
3266 struct inode *inode = page->mapping->host; 3342 struct inode *inode = page->mapping->host;
diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h
index 05b3fab39f7e..95e147eea239 100644
--- a/fs/btrfs/disk-io.h
+++ b/fs/btrfs/disk-io.h
@@ -89,6 +89,12 @@ int btrfs_add_log_tree(struct btrfs_trans_handle *trans,
89int btrfs_cleanup_transaction(struct btrfs_root *root); 89int btrfs_cleanup_transaction(struct btrfs_root *root);
90void btrfs_cleanup_one_transaction(struct btrfs_transaction *trans, 90void btrfs_cleanup_one_transaction(struct btrfs_transaction *trans,
91 struct btrfs_root *root); 91 struct btrfs_root *root);
92void btrfs_abort_devices(struct btrfs_root *root);
93struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans,
94 struct btrfs_fs_info *fs_info,
95 u64 objectid);
96int btree_lock_page_hook(struct page *page, void *data,
97 void (*flush_fn)(void *));
92 98
93#ifdef CONFIG_DEBUG_LOCK_ALLOC 99#ifdef CONFIG_DEBUG_LOCK_ALLOC
94void btrfs_init_lockdep(void); 100void btrfs_init_lockdep(void);