mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/kdave/btrfs-progs.git
synced 2024-11-23 12:14:24 +08:00
btrfs-progs: make btrfs_create_tree take a key for the root key
We're going to start create global roots from mkfs, and we need to have a offset set for the root key. Make the btrfs_create_tree() take a key for the root_key instead of just the objectid so we can setup these new style roots properly. Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
5fb27deaf1
commit
02fb308bdc
@ -2426,25 +2426,22 @@ int btrfs_delete_and_free_root(struct btrfs_trans_handle *trans,
|
||||
|
||||
struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans,
|
||||
struct btrfs_fs_info *fs_info,
|
||||
u64 objectid)
|
||||
struct btrfs_key *key)
|
||||
{
|
||||
struct extent_buffer *leaf;
|
||||
struct btrfs_root *tree_root = fs_info->tree_root;
|
||||
struct btrfs_root *root;
|
||||
struct btrfs_key key;
|
||||
int ret = 0;
|
||||
|
||||
root = kzalloc(sizeof(*root), GFP_KERNEL);
|
||||
if (!root)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
btrfs_setup_root(root, fs_info, objectid);
|
||||
root->root_key.objectid = objectid;
|
||||
root->root_key.type = BTRFS_ROOT_ITEM_KEY;
|
||||
root->root_key.offset = 0;
|
||||
btrfs_setup_root(root, fs_info, key->objectid);
|
||||
memcpy(&root->root_key, key, sizeof(struct btrfs_key));
|
||||
|
||||
leaf = btrfs_alloc_free_block(trans, root, fs_info->nodesize, objectid,
|
||||
NULL, 0, 0, 0);
|
||||
leaf = btrfs_alloc_free_block(trans, root, fs_info->nodesize,
|
||||
root->root_key.objectid, NULL, 0, 0, 0);
|
||||
if (IS_ERR(leaf)) {
|
||||
ret = PTR_ERR(leaf);
|
||||
leaf = NULL;
|
||||
@ -2455,7 +2452,7 @@ struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans,
|
||||
btrfs_set_header_bytenr(leaf, leaf->start);
|
||||
btrfs_set_header_generation(leaf, trans->transid);
|
||||
btrfs_set_header_backref_rev(leaf, BTRFS_MIXED_BACKREF_REV);
|
||||
btrfs_set_header_owner(leaf, objectid);
|
||||
btrfs_set_header_owner(leaf, root->root_key.objectid);
|
||||
root->node = leaf;
|
||||
write_extent_buffer(leaf, fs_info->fs_devices->metadata_uuid,
|
||||
btrfs_header_fsid(), BTRFS_FSID_SIZE);
|
||||
@ -2480,10 +2477,8 @@ struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans,
|
||||
memset(root->root_item.uuid, 0, BTRFS_UUID_SIZE);
|
||||
root->root_item.drop_level = 0;
|
||||
|
||||
key.objectid = objectid;
|
||||
key.type = BTRFS_ROOT_ITEM_KEY;
|
||||
key.offset = 0;
|
||||
ret = btrfs_insert_root(trans, tree_root, &key, &root->root_item);
|
||||
ret = btrfs_insert_root(trans, tree_root, &root->root_key,
|
||||
&root->root_item);
|
||||
if (ret)
|
||||
goto fail;
|
||||
|
||||
|
@ -220,7 +220,7 @@ int write_and_map_eb(struct btrfs_fs_info *fs_info, struct extent_buffer *eb);
|
||||
int btrfs_fs_roots_compare_roots(struct rb_node *node1, struct rb_node *node2);
|
||||
struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans,
|
||||
struct btrfs_fs_info *fs_info,
|
||||
u64 objectid);
|
||||
struct btrfs_key *key);
|
||||
int btrfs_delete_and_free_root(struct btrfs_trans_handle *trans,
|
||||
struct btrfs_root *root);
|
||||
struct btrfs_root *btrfs_csum_root(struct btrfs_fs_info *fs_info, u64 bytenr);
|
||||
|
@ -1475,14 +1475,17 @@ int btrfs_create_free_space_tree(struct btrfs_fs_info *fs_info)
|
||||
struct btrfs_root *free_space_root;
|
||||
struct btrfs_block_group *block_group;
|
||||
u64 start = BTRFS_SUPER_INFO_OFFSET + BTRFS_SUPER_INFO_SIZE;
|
||||
struct btrfs_key root_key = {
|
||||
.objectid = BTRFS_FREE_SPACE_TREE_OBJECTID,
|
||||
.type = BTRFS_ROOT_ITEM_KEY,
|
||||
};
|
||||
int ret;
|
||||
|
||||
trans = btrfs_start_transaction(tree_root, 0);
|
||||
if (IS_ERR(trans))
|
||||
return PTR_ERR(trans);
|
||||
|
||||
free_space_root = btrfs_create_tree(trans, fs_info,
|
||||
BTRFS_FREE_SPACE_TREE_OBJECTID);
|
||||
free_space_root = btrfs_create_tree(trans, fs_info, &root_key);
|
||||
if (IS_ERR(free_space_root)) {
|
||||
ret = PTR_ERR(free_space_root);
|
||||
goto abort;
|
||||
|
13
mkfs/main.c
13
mkfs/main.c
@ -717,12 +717,15 @@ static int create_data_reloc_tree(struct btrfs_trans_handle *trans)
|
||||
struct btrfs_inode_item *inode;
|
||||
struct btrfs_root *root;
|
||||
struct btrfs_path path;
|
||||
struct btrfs_key key;
|
||||
struct btrfs_key key = {
|
||||
.objectid = BTRFS_DATA_RELOC_TREE_OBJECTID,
|
||||
.type = BTRFS_ROOT_ITEM_KEY,
|
||||
};
|
||||
u64 ino = BTRFS_FIRST_FREE_OBJECTID;
|
||||
char *name = "..";
|
||||
int ret;
|
||||
|
||||
root = btrfs_create_tree(trans, fs_info, BTRFS_DATA_RELOC_TREE_OBJECTID);
|
||||
root = btrfs_create_tree(trans, fs_info, &key);
|
||||
if (IS_ERR(root)) {
|
||||
ret = PTR_ERR(root);
|
||||
goto out;
|
||||
@ -782,10 +785,14 @@ static int create_uuid_tree(struct btrfs_trans_handle *trans)
|
||||
{
|
||||
struct btrfs_fs_info *fs_info = trans->fs_info;
|
||||
struct btrfs_root *root;
|
||||
struct btrfs_key key = {
|
||||
.objectid = BTRFS_UUID_TREE_OBJECTID,
|
||||
.type = BTRFS_ROOT_ITEM_KEY,
|
||||
};
|
||||
int ret = 0;
|
||||
|
||||
ASSERT(fs_info->uuid_root == NULL);
|
||||
root = btrfs_create_tree(trans, fs_info, BTRFS_UUID_TREE_OBJECTID);
|
||||
root = btrfs_create_tree(trans, fs_info, &key);
|
||||
if (IS_ERR(root)) {
|
||||
ret = PTR_ERR(root);
|
||||
goto out;
|
||||
|
Loading…
Reference in New Issue
Block a user