From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH v2 1/5] btrfs-progs: Export btrfs_create_tree() and move it to disk-io.c
Date: Thu, 3 Jan 2019 15:32:17 +0800 [thread overview]
Message-ID: <20190103073221.10525-2-wqu@suse.com> (raw)
In-Reply-To: <20190103073221.10525-1-wqu@suse.com>
Just as how kernel uses it.
This provides the basis for later uuid creation.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
disk-io.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++
disk-io.h | 4 ++-
free-space-tree.c | 72 -----------------------------------------------
3 files changed, 75 insertions(+), 73 deletions(-)
diff --git a/disk-io.c b/disk-io.c
index 5fafa144c0d3..0668031b974b 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -1723,3 +1723,75 @@ int btrfs_set_buffer_uptodate(struct extent_buffer *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->fsid, 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);
+}
diff --git a/disk-io.h b/disk-io.h
index 05cbbce6ea4a..c4a6a020dd88 100644
--- a/disk-io.h
+++ b/disk-io.h
@@ -197,5 +197,7 @@ int write_tree_block(struct btrfs_trans_handle *trans,
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
diff --git a/free-space-tree.c b/free-space-tree.c
index 6ef57928f1a9..5089fef0652c 100644
--- a/free-space-tree.c
+++ b/free-space-tree.c
@@ -1420,78 +1420,6 @@ out:
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->fsid, 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) \
__btrfs_set_fs_compat_ro((__fs_info), BTRFS_FEATURE_COMPAT_RO_##opt)
--
2.20.1
next prev parent reply other threads:[~2019-01-03 7:32 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-03 7:32 [PATCH v2 0/5] Fix incorrectly created uuid tree Qu Wenruo
2019-01-03 7:32 ` Qu Wenruo [this message]
2019-01-03 7:32 ` [PATCH v2 2/5] btrfs-progs: mkfs: Create data reloc tree from scratch Qu Wenruo
2019-01-03 7:32 ` [PATCH v2 3/5] btrfs-progs: uuid: Port kernel btrfs_uuid_tree_lookup() Qu Wenruo
2019-01-03 7:32 ` [PATCH v2 4/5] btrfs-progs: uuid: Port btrfs_uuid_tree_add() function Qu Wenruo
2019-01-03 7:32 ` [PATCH v2 5/5] btrfs-progs: Create uuid tree with proper contents Qu Wenruo
2019-01-10 21:04 ` [PATCH v2 0/5] Fix incorrectly created uuid tree David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190103073221.10525-2-wqu@suse.com \
--to=wqu@suse.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).