Commit a1fd0c35 authored by Omar Sandoval's avatar Omar Sandoval Committed by David Sterba

btrfs: allocate inode outside of btrfs_new_inode()

Instead of calling new_inode() and inode_init_owner() inside of
btrfs_new_inode(), do it in the callers. This allows us to pass in just
the inode instead of the mnt_userns and mode and removes the need for
memalloc_nofs_{save,restores}() since we do it before starting a
transaction. In create_subvol(), it also means we no longer have to look
up the inode again to instantiate it. This also paves the way for some
more cleanups in later patches.

This also removes the comments about Smack checking i_op, which are no
longer true since commit 5d6c3191 ("xattr: Add
__vfs_{get,set,remove}xattr helpers"). Now it checks inode->i_opflags &
IOP_XATTR, which is set based on sb->s_xattr.
Signed-off-by: default avatarOmar Sandoval <osandov@fb.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent b95b78e6
...@@ -3284,10 +3284,11 @@ int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, long nr, ...@@ -3284,10 +3284,11 @@ int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, long nr,
int btrfs_set_extent_delalloc(struct btrfs_inode *inode, u64 start, u64 end, int btrfs_set_extent_delalloc(struct btrfs_inode *inode, u64 start, u64 end,
unsigned int extra_bits, unsigned int extra_bits,
struct extent_state **cached_state); struct extent_state **cached_state);
struct inode *btrfs_new_subvol_inode(struct user_namespace *mnt_userns,
struct inode *dir);
int btrfs_create_subvol_root(struct btrfs_trans_handle *trans, int btrfs_create_subvol_root(struct btrfs_trans_handle *trans,
struct btrfs_root *new_root,
struct btrfs_root *parent_root, struct btrfs_root *parent_root,
struct user_namespace *mnt_userns); struct inode *inode);
void btrfs_set_delalloc_extent(struct inode *inode, struct extent_state *state, void btrfs_set_delalloc_extent(struct inode *inode, struct extent_state *state,
unsigned *bits); unsigned *bits);
void btrfs_clear_delalloc_extent(struct inode *inode, void btrfs_clear_delalloc_extent(struct inode *inode,
......
This diff is collapsed.
...@@ -587,6 +587,12 @@ static noinline int create_subvol(struct user_namespace *mnt_userns, ...@@ -587,6 +587,12 @@ static noinline int create_subvol(struct user_namespace *mnt_userns,
if (ret < 0) if (ret < 0)
goto out_root_item; goto out_root_item;
inode = btrfs_new_subvol_inode(mnt_userns, dir);
if (!inode) {
ret = -ENOMEM;
goto out_anon_dev;
}
btrfs_init_block_rsv(&block_rsv, BTRFS_BLOCK_RSV_TEMP); btrfs_init_block_rsv(&block_rsv, BTRFS_BLOCK_RSV_TEMP);
/* /*
* The same as the snapshot creation, please see the comment * The same as the snapshot creation, please see the comment
...@@ -594,13 +600,13 @@ static noinline int create_subvol(struct user_namespace *mnt_userns, ...@@ -594,13 +600,13 @@ static noinline int create_subvol(struct user_namespace *mnt_userns,
*/ */
ret = btrfs_subvolume_reserve_metadata(root, &block_rsv, 8, false); ret = btrfs_subvolume_reserve_metadata(root, &block_rsv, 8, false);
if (ret) if (ret)
goto out_anon_dev; goto out_inode;
trans = btrfs_start_transaction(root, 0); trans = btrfs_start_transaction(root, 0);
if (IS_ERR(trans)) { if (IS_ERR(trans)) {
ret = PTR_ERR(trans); ret = PTR_ERR(trans);
btrfs_subvolume_release_metadata(root, &block_rsv); btrfs_subvolume_release_metadata(root, &block_rsv);
goto out_anon_dev; goto out_inode;
} }
trans->block_rsv = &block_rsv; trans->block_rsv = &block_rsv;
trans->bytes_reserved = block_rsv.size; trans->bytes_reserved = block_rsv.size;
...@@ -683,16 +689,16 @@ static noinline int create_subvol(struct user_namespace *mnt_userns, ...@@ -683,16 +689,16 @@ static noinline int create_subvol(struct user_namespace *mnt_userns,
} }
/* anon_dev is owned by new_root now. */ /* anon_dev is owned by new_root now. */
anon_dev = 0; anon_dev = 0;
BTRFS_I(inode)->root = new_root;
/* ... and new_root is owned by inode now. */
ret = btrfs_record_root_in_trans(trans, new_root); ret = btrfs_record_root_in_trans(trans, new_root);
if (ret) { if (ret) {
btrfs_put_root(new_root);
btrfs_abort_transaction(trans, ret); btrfs_abort_transaction(trans, ret);
goto out; goto out;
} }
ret = btrfs_create_subvol_root(trans, new_root, root, mnt_userns); ret = btrfs_create_subvol_root(trans, root, inode);
btrfs_put_root(new_root);
if (ret) { if (ret) {
/* We potentially lose an unused inode item here */ /* We potentially lose an unused inode item here */
btrfs_abort_transaction(trans, ret); btrfs_abort_transaction(trans, ret);
...@@ -745,11 +751,11 @@ static noinline int create_subvol(struct user_namespace *mnt_userns, ...@@ -745,11 +751,11 @@ static noinline int create_subvol(struct user_namespace *mnt_userns,
ret = btrfs_commit_transaction(trans); ret = btrfs_commit_transaction(trans);
if (!ret) { if (!ret) {
inode = btrfs_lookup_dentry(dir, dentry);
if (IS_ERR(inode))
return PTR_ERR(inode);
d_instantiate(dentry, inode); d_instantiate(dentry, inode);
inode = NULL;
} }
out_inode:
iput(inode);
out_anon_dev: out_anon_dev:
if (anon_dev) if (anon_dev)
free_anon_bdev(anon_dev); free_anon_bdev(anon_dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment