Btrfs-progs: move btrfs_fsck_reinit_root to cmds-check.c
authorEric Sandeen <sandeen@redhat.com>
Fri, 26 Apr 2013 21:06:05 +0000 (16:06 -0500)
committerDavid Sterba <dsterba@suse.cz>
Fri, 9 Aug 2013 12:32:28 +0000 (14:32 +0200)
cmds-check.c contains the only caller of btrfs_fsck_reinit_root;
moving it to the caller's source file gets ctree.c a little
closer to kernelspace, although it does require exporting
add_root_to_dirty_list(), which is not done in kernelspace.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
cmds-check.c
ctree.c
ctree.h

index 8015288..d034446 100644 (file)
@@ -5328,6 +5328,53 @@ out:
        return ret;
 }
 
+static int btrfs_fsck_reinit_root(struct btrfs_trans_handle *trans,
+                          struct btrfs_root *root, int overwrite)
+{
+       struct extent_buffer *c;
+       struct extent_buffer *old = root->node;
+       int level;
+       struct btrfs_disk_key disk_key = {0,0,0};
+
+       level = 0;
+
+       if (overwrite) {
+               c = old;
+               extent_buffer_get(c);
+               goto init;
+       }
+       c = btrfs_alloc_free_block(trans, root,
+                                  btrfs_level_size(root, 0),
+                                  root->root_key.objectid,
+                                  &disk_key, level, 0, 0);
+       if (IS_ERR(c)) {
+               c = old;
+               extent_buffer_get(c);
+       }
+init:
+       memset_extent_buffer(c, 0, 0, sizeof(struct btrfs_header));
+       btrfs_set_header_level(c, level);
+       btrfs_set_header_bytenr(c, c->start);
+       btrfs_set_header_generation(c, trans->transid);
+       btrfs_set_header_backref_rev(c, BTRFS_MIXED_BACKREF_REV);
+       btrfs_set_header_owner(c, root->root_key.objectid);
+
+       write_extent_buffer(c, root->fs_info->fsid,
+                           (unsigned long)btrfs_header_fsid(c),
+                           BTRFS_FSID_SIZE);
+
+       write_extent_buffer(c, root->fs_info->chunk_tree_uuid,
+                           (unsigned long)btrfs_header_chunk_tree_uuid(c),
+                           BTRFS_UUID_SIZE);
+
+       btrfs_mark_buffer_dirty(c);
+
+       free_extent_buffer(old);
+       root->node = c;
+       add_root_to_dirty_list(root);
+       return 0;
+}
+
 static int pin_down_tree_blocks(struct btrfs_fs_info *fs_info,
                                struct extent_buffer *eb, int tree_root)
 {
diff --git a/ctree.c b/ctree.c
index b07961b..d491cdd 100644 (file)
--- a/ctree.c
+++ b/ctree.c
@@ -67,7 +67,7 @@ void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p)
        memset(p, 0, sizeof(*p));
 }
 
-static void add_root_to_dirty_list(struct btrfs_root *root)
+void add_root_to_dirty_list(struct btrfs_root *root)
 {
        if (root->track_dirty && list_empty(&root->dirty_list)) {
                list_add(&root->dirty_list,
@@ -137,53 +137,6 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans,
        return 0;
 }
 
-int btrfs_fsck_reinit_root(struct btrfs_trans_handle *trans,
-                          struct btrfs_root *root, int overwrite)
-{
-       struct extent_buffer *c;
-       struct extent_buffer *old = root->node;
-       int level;
-       struct btrfs_disk_key disk_key = {0,0,0};
-
-       level = 0;
-
-       if (overwrite) {
-               c = old;
-               extent_buffer_get(c);
-               goto init;
-       }
-       c = btrfs_alloc_free_block(trans, root,
-                                  btrfs_level_size(root, 0),
-                                  root->root_key.objectid,
-                                  &disk_key, level, 0, 0);
-       if (IS_ERR(c)) {
-               c = old;
-               extent_buffer_get(c);
-       }
-init:
-       memset_extent_buffer(c, 0, 0, sizeof(struct btrfs_header));
-       btrfs_set_header_level(c, level);
-       btrfs_set_header_bytenr(c, c->start);
-       btrfs_set_header_generation(c, trans->transid);
-       btrfs_set_header_backref_rev(c, BTRFS_MIXED_BACKREF_REV);
-       btrfs_set_header_owner(c, root->root_key.objectid);
-
-       write_extent_buffer(c, root->fs_info->fsid,
-                           (unsigned long)btrfs_header_fsid(c),
-                           BTRFS_FSID_SIZE);
-
-       write_extent_buffer(c, root->fs_info->chunk_tree_uuid,
-                           (unsigned long)btrfs_header_chunk_tree_uuid(c),
-                           BTRFS_UUID_SIZE);
-
-       btrfs_mark_buffer_dirty(c);
-
-       free_extent_buffer(old);
-       root->node = c;
-       add_root_to_dirty_list(root);
-       return 0;
-}
-
 /*
  * check if the tree block can be shared by multiple trees
  */
diff --git a/ctree.h b/ctree.h
index 0b0d701..d4c5a28 100644 (file)
--- a/ctree.h
+++ b/ctree.h
@@ -2152,8 +2152,6 @@ int btrfs_check_node(struct btrfs_root *root,
 int btrfs_check_leaf(struct btrfs_root *root,
                      struct btrfs_disk_key *parent_key,
                      struct extent_buffer *buf);
-int btrfs_fsck_reinit_root(struct btrfs_trans_handle *trans,
-                          struct btrfs_root *root, int overwrite);
 void reada_for_search(struct btrfs_root *root, struct btrfs_path *path,
                             int level, int slot, u64 objectid);
 struct extent_buffer *read_node_slot(struct btrfs_root *root,
@@ -2195,6 +2193,7 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans,
                       int start_slot, int cache_only, u64 *last_ret,
                       struct btrfs_key *progress);
 void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
+void add_root_to_dirty_list(struct btrfs_root *root);
 struct btrfs_path *btrfs_alloc_path(void);
 void btrfs_free_path(struct btrfs_path *p);
 void btrfs_init_path(struct btrfs_path *p);