Skip to content

Commit

Permalink
Merge branch 'misc-next' into for-next-next-v6.11-20240907
Browse files Browse the repository at this point in the history
  • Loading branch information
kdave committed Sep 7, 2024
2 parents 83970f7 + 4e7847f commit 5224b44
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 169 deletions.
1 change: 1 addition & 0 deletions fs/btrfs/Kconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# SPDX-License-Identifier: GPL-2.0
# misc-next marker

config BTRFS_FS
tristate "Btrfs filesystem support"
Expand Down
12 changes: 10 additions & 2 deletions fs/btrfs/extent-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -5149,8 +5149,16 @@ struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans,
parent = ins.objectid;
flags |= BTRFS_BLOCK_FLAG_FULL_BACKREF;
owning_root = reloc_src_root;
} else
BUG_ON(parent > 0);
} else {
if (unlikely(parent > 0)) {
/*
* Other roots than reloc tree don't expect start
* offset of a parent block.
*/
ret = -EUCLEAN;
goto out_free_reserved;
}
}

if (root_objectid != BTRFS_TREE_LOG_OBJECTID) {
struct btrfs_delayed_extent_op *extent_op;
Expand Down
143 changes: 81 additions & 62 deletions fs/btrfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -3786,14 +3786,44 @@ static int btrfs_init_file_extent_tree(struct btrfs_inode *inode)
return 0;
}

static int btrfs_add_inode_to_root(struct btrfs_inode *inode, bool prealloc)
{
struct btrfs_root *root = inode->root;
struct btrfs_inode *existing;
const u64 ino = btrfs_ino(inode);
int ret;

if (inode_unhashed(&inode->vfs_inode))
return 0;

if (prealloc) {
ret = xa_reserve(&root->inodes, ino, GFP_NOFS);
if (ret)
return ret;
}

existing = xa_store(&root->inodes, ino, inode, GFP_ATOMIC);

if (xa_is_err(existing)) {
ret = xa_err(existing);
ASSERT(ret != -EINVAL);
ASSERT(ret != -ENOMEM);
return ret;
} else if (existing) {
WARN_ON(!(existing->vfs_inode.i_state & (I_WILL_FREE | I_FREEING)));
}

return 0;
}

/*
* read an inode from the btree into the in-memory inode
* Read a locked inode from the btree into the in-memory inode.
* On failure clean up the inode.
*/
static int btrfs_read_locked_inode(struct inode *inode,
struct btrfs_path *in_path)
struct btrfs_path *path)
{
struct btrfs_fs_info *fs_info = inode_to_fs_info(inode);
struct btrfs_path *path = in_path;
struct extent_buffer *leaf;
struct btrfs_inode_item *inode_item;
struct btrfs_root *root = BTRFS_I(inode)->root;
Expand All @@ -3807,25 +3837,25 @@ static int btrfs_read_locked_inode(struct inode *inode,

ret = btrfs_init_file_extent_tree(BTRFS_I(inode));
if (ret)
return ret;
goto out;

ret = btrfs_fill_inode(inode, &rdev);
if (!ret)
filled = true;

if (!path) {
path = btrfs_alloc_path();
if (!path)
return -ENOMEM;
}
ASSERT(path);

btrfs_get_inode_key(BTRFS_I(inode), &location);

ret = btrfs_lookup_inode(NULL, root, path, &location, 0);
if (ret) {
if (path != in_path)
btrfs_free_path(path);
return ret;
/*
* ret > 0 can come from btrfs_search_slot called by
* btrfs_lookup_inode(), this means the inode was not found.
*/
if (ret > 0)
ret = -ENOENT;
goto out;
}

leaf = path->nodes[0];
Expand Down Expand Up @@ -3960,8 +3990,6 @@ static int btrfs_read_locked_inode(struct inode *inode,
btrfs_ino(BTRFS_I(inode)),
btrfs_root_id(root), ret);
}
if (path != in_path)
btrfs_free_path(path);

if (!maybe_acls)
cache_no_acl(inode);
Expand All @@ -3988,7 +4016,15 @@ static int btrfs_read_locked_inode(struct inode *inode,
}

btrfs_sync_inode_flags_to_i_flags(inode);

ret = btrfs_add_inode_to_root(BTRFS_I(inode), true);
if (ret)
goto out;

return 0;
out:
iget_failed(inode);
return ret;
}

/*
Expand Down Expand Up @@ -5500,35 +5536,7 @@ static int fixup_tree_root_location(struct btrfs_fs_info *fs_info,
return err;
}

static int btrfs_add_inode_to_root(struct btrfs_inode *inode, bool prealloc)
{
struct btrfs_root *root = inode->root;
struct btrfs_inode *existing;
const u64 ino = btrfs_ino(inode);
int ret;

if (inode_unhashed(&inode->vfs_inode))
return 0;

if (prealloc) {
ret = xa_reserve(&root->inodes, ino, GFP_NOFS);
if (ret)
return ret;
}

existing = xa_store(&root->inodes, ino, inode, GFP_ATOMIC);

if (xa_is_err(existing)) {
ret = xa_err(existing);
ASSERT(ret != -EINVAL);
ASSERT(ret != -ENOMEM);
return ret;
} else if (existing) {
WARN_ON(!(existing->vfs_inode.i_state & (I_WILL_FREE | I_FREEING)));
}

return 0;
}

static void btrfs_del_inode_from_root(struct btrfs_inode *inode)
{
Expand Down Expand Up @@ -5591,9 +5599,8 @@ static struct inode *btrfs_iget_locked(u64 ino, struct btrfs_root *root)

/*
* Get an inode object given its inode number and corresponding root.
* Path can be preallocated to prevent recursing back to iget through
* allocator. NULL is also valid but may require an additional allocation
* later.
* Path is preallocated to prevent recursing back to iget through
* allocator.
*/
struct inode *btrfs_iget_path(u64 ino, struct btrfs_root *root,
struct btrfs_path *path)
Expand All @@ -5609,30 +5616,42 @@ struct inode *btrfs_iget_path(u64 ino, struct btrfs_root *root,
return inode;

ret = btrfs_read_locked_inode(inode, path);
/*
* ret > 0 can come from btrfs_search_slot called by
* btrfs_read_locked_inode(), this means the inode item was not found.
*/
if (ret > 0)
ret = -ENOENT;
if (ret < 0)
goto error;

ret = btrfs_add_inode_to_root(BTRFS_I(inode), true);
if (ret < 0)
goto error;
if (ret)
return ERR_PTR(ret);

unlock_new_inode(inode);

return inode;
error:
iget_failed(inode);
return ERR_PTR(ret);
}

/*
* Get an inode object given its inode number and corresponding root.
*/
struct inode *btrfs_iget(u64 ino, struct btrfs_root *root)
{
return btrfs_iget_path(ino, root, NULL);
struct inode *inode;
struct btrfs_path *path;
int ret;

inode = btrfs_iget_locked(ino, root);
if (!inode)
return ERR_PTR(-ENOMEM);

if (!(inode->i_state & I_NEW))
return inode;

path = btrfs_alloc_path();
if (!path)
return ERR_PTR(-ENOMEM);

ret = btrfs_read_locked_inode(inode, path);

btrfs_free_path(path);

if (ret)
return ERR_PTR(ret);

unlock_new_inode(inode);
return inode;
}

static struct inode *new_simple_dir(struct inode *dir,
Expand Down
Loading

0 comments on commit 5224b44

Please sign in to comment.