Skip to content

Commit 6ab6ebb

Browse files
naotakdave
authored andcommitted
btrfs: split alloc_log_tree()
This is a preparation patch for the next patch. Split alloc_log_tree() into two parts. The first one allocating the tree structure, remains in alloc_log_tree() and the second part allocating the tree node, which is moved into btrfs_alloc_log_tree_node(). Also export the latter part is to be used in the next patch. Reviewed-by: Josef Bacik <[email protected]> Signed-off-by: Johannes Thumshirn <[email protected]> Signed-off-by: Naohiro Aota <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent f7ef528 commit 6ab6ebb

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

fs/btrfs/disk-io.c

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,6 @@ static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans,
12541254
struct btrfs_fs_info *fs_info)
12551255
{
12561256
struct btrfs_root *root;
1257-
struct extent_buffer *leaf;
12581257

12591258
root = btrfs_alloc_root(fs_info, BTRFS_TREE_LOG_OBJECTID, GFP_NOFS);
12601259
if (!root)
@@ -1264,6 +1263,14 @@ static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans,
12641263
root->root_key.type = BTRFS_ROOT_ITEM_KEY;
12651264
root->root_key.offset = BTRFS_TREE_LOG_OBJECTID;
12661265

1266+
return root;
1267+
}
1268+
1269+
int btrfs_alloc_log_tree_node(struct btrfs_trans_handle *trans,
1270+
struct btrfs_root *root)
1271+
{
1272+
struct extent_buffer *leaf;
1273+
12671274
/*
12681275
* DON'T set SHAREABLE bit for log trees.
12691276
*
@@ -1276,26 +1283,33 @@ static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans,
12761283

12771284
leaf = btrfs_alloc_tree_block(trans, root, 0, BTRFS_TREE_LOG_OBJECTID,
12781285
NULL, 0, 0, 0, BTRFS_NESTING_NORMAL);
1279-
if (IS_ERR(leaf)) {
1280-
btrfs_put_root(root);
1281-
return ERR_CAST(leaf);
1282-
}
1286+
if (IS_ERR(leaf))
1287+
return PTR_ERR(leaf);
12831288

12841289
root->node = leaf;
12851290

12861291
btrfs_mark_buffer_dirty(root->node);
12871292
btrfs_tree_unlock(root->node);
1288-
return root;
1293+
1294+
return 0;
12891295
}
12901296

12911297
int btrfs_init_log_root_tree(struct btrfs_trans_handle *trans,
12921298
struct btrfs_fs_info *fs_info)
12931299
{
12941300
struct btrfs_root *log_root;
1301+
int ret;
12951302

12961303
log_root = alloc_log_tree(trans, fs_info);
12971304
if (IS_ERR(log_root))
12981305
return PTR_ERR(log_root);
1306+
1307+
ret = btrfs_alloc_log_tree_node(trans, log_root);
1308+
if (ret) {
1309+
btrfs_put_root(log_root);
1310+
return ret;
1311+
}
1312+
12991313
WARN_ON(fs_info->log_root_tree);
13001314
fs_info->log_root_tree = log_root;
13011315
return 0;
@@ -1307,11 +1321,18 @@ int btrfs_add_log_tree(struct btrfs_trans_handle *trans,
13071321
struct btrfs_fs_info *fs_info = root->fs_info;
13081322
struct btrfs_root *log_root;
13091323
struct btrfs_inode_item *inode_item;
1324+
int ret;
13101325

13111326
log_root = alloc_log_tree(trans, fs_info);
13121327
if (IS_ERR(log_root))
13131328
return PTR_ERR(log_root);
13141329

1330+
ret = btrfs_alloc_log_tree_node(trans, log_root);
1331+
if (ret) {
1332+
btrfs_put_root(log_root);
1333+
return ret;
1334+
}
1335+
13151336
log_root->last_trans = trans->transid;
13161337
log_root->root_key.offset = root->root_key.objectid;
13171338

fs/btrfs/disk-io.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ blk_status_t btrfs_wq_submit_bio(struct inode *inode, struct bio *bio,
120120
extent_submit_bio_start_t *submit_bio_start);
121121
blk_status_t btrfs_submit_bio_done(void *private_data, struct bio *bio,
122122
int mirror_num);
123+
int btrfs_alloc_log_tree_node(struct btrfs_trans_handle *trans,
124+
struct btrfs_root *root);
123125
int btrfs_init_log_root_tree(struct btrfs_trans_handle *trans,
124126
struct btrfs_fs_info *fs_info);
125127
int btrfs_add_log_tree(struct btrfs_trans_handle *trans,

0 commit comments

Comments
 (0)