mirror of
https://github.com/kdave/btrfs-progs
synced 2025-04-23 15:35:18 +00:00
btrfs-progs: Export btrfs_create_tree() and move it to disk-io.c
Just as how kernel uses it. This provides the basis for later uuid creation. Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
71ba47d26e
commit
680f4c8752
73
disk-io.c
73
disk-io.c
@ -1761,3 +1761,76 @@ int btrfs_set_buffer_uptodate(struct extent_buffer *eb)
|
|||||||
{
|
{
|
||||||
return set_extent_buffer_uptodate(eb);
|
return set_extent_buffer_uptodate(eb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans,
|
||||||
|
struct btrfs_fs_info *fs_info,
|
||||||
|
u64 objectid)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
|
||||||
|
leaf = btrfs_alloc_free_block(trans, root, fs_info->nodesize, objectid,
|
||||||
|
NULL, 0, 0, 0);
|
||||||
|
if (IS_ERR(leaf)) {
|
||||||
|
ret = PTR_ERR(leaf);
|
||||||
|
leaf = NULL;
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset_extent_buffer(leaf, 0, 0, sizeof(struct btrfs_header));
|
||||||
|
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);
|
||||||
|
root->node = leaf;
|
||||||
|
write_extent_buffer(leaf, fs_info->fs_devices->metadata_uuid,
|
||||||
|
btrfs_header_fsid(), BTRFS_FSID_SIZE);
|
||||||
|
write_extent_buffer(leaf, fs_info->chunk_tree_uuid,
|
||||||
|
btrfs_header_chunk_tree_uuid(leaf),
|
||||||
|
BTRFS_UUID_SIZE);
|
||||||
|
btrfs_mark_buffer_dirty(leaf);
|
||||||
|
|
||||||
|
extent_buffer_get(root->node);
|
||||||
|
root->commit_root = root->node;
|
||||||
|
root->track_dirty = 1;
|
||||||
|
|
||||||
|
root->root_item.flags = 0;
|
||||||
|
root->root_item.byte_limit = 0;
|
||||||
|
btrfs_set_root_bytenr(&root->root_item, leaf->start);
|
||||||
|
btrfs_set_root_generation(&root->root_item, trans->transid);
|
||||||
|
btrfs_set_root_level(&root->root_item, 0);
|
||||||
|
btrfs_set_root_refs(&root->root_item, 1);
|
||||||
|
btrfs_set_root_used(&root->root_item, leaf->len);
|
||||||
|
btrfs_set_root_last_snapshot(&root->root_item, 0);
|
||||||
|
btrfs_set_root_dirid(&root->root_item, 0);
|
||||||
|
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);
|
||||||
|
if (ret)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
return root;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
if (leaf)
|
||||||
|
free_extent_buffer(leaf);
|
||||||
|
|
||||||
|
kfree(root);
|
||||||
|
return ERR_PTR(ret);
|
||||||
|
}
|
||||||
|
@ -197,5 +197,8 @@ int write_tree_block(struct btrfs_trans_handle *trans,
|
|||||||
struct btrfs_fs_info *fs_info,
|
struct btrfs_fs_info *fs_info,
|
||||||
struct extent_buffer *eb);
|
struct extent_buffer *eb);
|
||||||
int write_and_map_eb(struct btrfs_fs_info *fs_info, struct extent_buffer *eb);
|
int write_and_map_eb(struct btrfs_fs_info *fs_info, struct extent_buffer *eb);
|
||||||
|
struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans,
|
||||||
|
struct btrfs_fs_info *fs_info,
|
||||||
|
u64 objectid);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1392,79 +1392,6 @@ out:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans,
|
|
||||||
struct btrfs_fs_info *fs_info,
|
|
||||||
u64 objectid)
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
|
|
||||||
leaf = btrfs_alloc_free_block(trans, root, fs_info->nodesize, objectid,
|
|
||||||
NULL, 0, 0, 0);
|
|
||||||
if (IS_ERR(leaf)) {
|
|
||||||
ret = PTR_ERR(leaf);
|
|
||||||
leaf = NULL;
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
memset_extent_buffer(leaf, 0, 0, sizeof(struct btrfs_header));
|
|
||||||
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);
|
|
||||||
root->node = leaf;
|
|
||||||
write_extent_buffer(leaf, fs_info->fs_devices->metadata_uuid,
|
|
||||||
btrfs_header_fsid(), BTRFS_FSID_SIZE);
|
|
||||||
write_extent_buffer(leaf, fs_info->chunk_tree_uuid,
|
|
||||||
btrfs_header_chunk_tree_uuid(leaf),
|
|
||||||
BTRFS_UUID_SIZE);
|
|
||||||
btrfs_mark_buffer_dirty(leaf);
|
|
||||||
|
|
||||||
extent_buffer_get(root->node);
|
|
||||||
root->commit_root = root->node;
|
|
||||||
root->track_dirty = 1;
|
|
||||||
|
|
||||||
root->root_item.flags = 0;
|
|
||||||
root->root_item.byte_limit = 0;
|
|
||||||
btrfs_set_root_bytenr(&root->root_item, leaf->start);
|
|
||||||
btrfs_set_root_generation(&root->root_item, trans->transid);
|
|
||||||
btrfs_set_root_level(&root->root_item, 0);
|
|
||||||
btrfs_set_root_refs(&root->root_item, 1);
|
|
||||||
btrfs_set_root_used(&root->root_item, leaf->len);
|
|
||||||
btrfs_set_root_last_snapshot(&root->root_item, 0);
|
|
||||||
btrfs_set_root_dirid(&root->root_item, 0);
|
|
||||||
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);
|
|
||||||
if (ret)
|
|
||||||
goto fail;
|
|
||||||
|
|
||||||
return root;
|
|
||||||
|
|
||||||
fail:
|
|
||||||
if (leaf)
|
|
||||||
free_extent_buffer(leaf);
|
|
||||||
|
|
||||||
kfree(root);
|
|
||||||
return ERR_PTR(ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define btrfs_set_fs_compat_ro(__fs_info, opt) \
|
#define btrfs_set_fs_compat_ro(__fs_info, opt) \
|
||||||
__btrfs_set_fs_compat_ro((__fs_info), BTRFS_FEATURE_COMPAT_RO_##opt)
|
__btrfs_set_fs_compat_ro((__fs_info), BTRFS_FEATURE_COMPAT_RO_##opt)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user