Skip to content

Commit 5c8fd99

Browse files
josefbacikkdave
authored andcommitted
btrfs: make inodes hold a ref on their roots
If we make sure all the inodes have refs on their root we don't have to worry about the root disappearing while we have open inodes. Signed-off-by: Josef Bacik <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 8c38938 commit 5c8fd99

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

fs/btrfs/disk-io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2096,7 +2096,7 @@ static void btrfs_init_btree_inode(struct btrfs_fs_info *fs_info)
20962096

20972097
BTRFS_I(inode)->io_tree.ops = &btree_extent_io_ops;
20982098

2099-
BTRFS_I(inode)->root = fs_info->tree_root;
2099+
BTRFS_I(inode)->root = btrfs_grab_root(fs_info->tree_root);
21002100
memset(&BTRFS_I(inode)->location, 0, sizeof(struct btrfs_key));
21012101
set_bit(BTRFS_INODE_DUMMY, &BTRFS_I(inode)->runtime_flags);
21022102
btrfs_insert_inode_hash(inode);

fs/btrfs/inode.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5235,7 +5235,8 @@ static int btrfs_init_locked_inode(struct inode *inode, void *p)
52355235
inode->i_ino = args->location->objectid;
52365236
memcpy(&BTRFS_I(inode)->location, args->location,
52375237
sizeof(*args->location));
5238-
BTRFS_I(inode)->root = args->root;
5238+
BTRFS_I(inode)->root = btrfs_grab_root(args->root);
5239+
BUG_ON(args->root && !BTRFS_I(inode)->root);
52395240
return 0;
52405241
}
52415242

@@ -5316,7 +5317,7 @@ static struct inode *new_simple_dir(struct super_block *s,
53165317
if (!inode)
53175318
return ERR_PTR(-ENOMEM);
53185319

5319-
BTRFS_I(inode)->root = root;
5320+
BTRFS_I(inode)->root = btrfs_grab_root(root);
53205321
memcpy(&BTRFS_I(inode)->location, key, sizeof(*key));
53215322
set_bit(BTRFS_INODE_DUMMY, &BTRFS_I(inode)->runtime_flags);
53225323

@@ -5884,7 +5885,7 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans,
58845885
*/
58855886
BTRFS_I(inode)->index_cnt = 2;
58865887
BTRFS_I(inode)->dir_index = *index;
5887-
BTRFS_I(inode)->root = root;
5888+
BTRFS_I(inode)->root = btrfs_grab_root(root);
58885889
BTRFS_I(inode)->generation = trans->transid;
58895890
inode->i_generation = BTRFS_I(inode)->generation;
58905891

@@ -8926,6 +8927,7 @@ void btrfs_destroy_inode(struct inode *inode)
89268927
inode_tree_del(inode);
89278928
btrfs_drop_extent_cache(BTRFS_I(inode), 0, (u64)-1, 0);
89288929
btrfs_inode_clear_file_extent_range(BTRFS_I(inode), 0, (u64)-1);
8930+
btrfs_put_root(BTRFS_I(inode)->root);
89298931
}
89308932

89318933
int btrfs_drop_inode(struct inode *inode)

0 commit comments

Comments
 (0)