2
0
mirror of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git synced 2025-09-04 20:19:47 +08:00

btrfs: return a btrfs_inode from read_one_inode()

All callers of read_one_inode() are mostly interested in the btrfs_inode
structure rather than the VFS inode, so make read_one_inode() return
the btrfs_inode instead, avoiding lots of BTRFS_I() calls.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Filipe Manana 2025-03-06 17:11:00 +00:00 committed by David Sterba
parent a488d8ac2c
commit b4c50cbb01

View File

@ -616,7 +616,7 @@ static int read_alloc_one_name(struct extent_buffer *eb, void *start, int len,
* simple helper to read an inode off the disk from a given root * simple helper to read an inode off the disk from a given root
* This can only be called for subvolume roots and not for the log * This can only be called for subvolume roots and not for the log
*/ */
static noinline struct inode *read_one_inode(struct btrfs_root *root, static noinline struct btrfs_inode *read_one_inode(struct btrfs_root *root,
u64 objectid) u64 objectid)
{ {
struct btrfs_inode *inode; struct btrfs_inode *inode;
@ -624,7 +624,7 @@ static noinline struct inode *read_one_inode(struct btrfs_root *root,
inode = btrfs_iget_logging(objectid, root); inode = btrfs_iget_logging(objectid, root);
if (IS_ERR(inode)) if (IS_ERR(inode))
return NULL; return NULL;
return &inode->vfs_inode; return inode;
} }
/* replays a single extent in 'eb' at 'slot' with 'key' into the /* replays a single extent in 'eb' at 'slot' with 'key' into the
@ -652,7 +652,7 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans,
u64 start = key->offset; u64 start = key->offset;
u64 nbytes = 0; u64 nbytes = 0;
struct btrfs_file_extent_item *item; struct btrfs_file_extent_item *item;
struct inode *inode = NULL; struct btrfs_inode *inode = NULL;
unsigned long size; unsigned long size;
int ret = 0; int ret = 0;
@ -691,8 +691,7 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans,
* file. This must be done before the btrfs_drop_extents run * file. This must be done before the btrfs_drop_extents run
* so we don't try to drop this extent. * so we don't try to drop this extent.
*/ */
ret = btrfs_lookup_file_extent(trans, root, path, ret = btrfs_lookup_file_extent(trans, root, path, btrfs_ino(inode), start, 0);
btrfs_ino(BTRFS_I(inode)), start, 0);
if (ret == 0 && if (ret == 0 &&
(found_type == BTRFS_FILE_EXTENT_REG || (found_type == BTRFS_FILE_EXTENT_REG ||
@ -726,7 +725,7 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans,
drop_args.start = start; drop_args.start = start;
drop_args.end = extent_end; drop_args.end = extent_end;
drop_args.drop_cache = true; drop_args.drop_cache = true;
ret = btrfs_drop_extents(trans, root, BTRFS_I(inode), &drop_args); ret = btrfs_drop_extents(trans, root, inode, &drop_args);
if (ret) if (ret)
goto out; goto out;
@ -904,16 +903,15 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans,
goto out; goto out;
} }
ret = btrfs_inode_set_file_extent_range(BTRFS_I(inode), start, ret = btrfs_inode_set_file_extent_range(inode, start, extent_end - start);
extent_end - start);
if (ret) if (ret)
goto out; goto out;
update_inode: update_inode:
btrfs_update_inode_bytes(BTRFS_I(inode), nbytes, drop_args.bytes_found); btrfs_update_inode_bytes(inode, nbytes, drop_args.bytes_found);
ret = btrfs_update_inode(trans, BTRFS_I(inode)); ret = btrfs_update_inode(trans, inode);
out: out:
iput(inode); iput(&inode->vfs_inode);
return ret; return ret;
} }
@ -950,7 +948,7 @@ static noinline int drop_one_dir_item(struct btrfs_trans_handle *trans,
struct btrfs_dir_item *di) struct btrfs_dir_item *di)
{ {
struct btrfs_root *root = dir->root; struct btrfs_root *root = dir->root;
struct inode *inode; struct btrfs_inode *inode;
struct fscrypt_str name; struct fscrypt_str name;
struct extent_buffer *leaf; struct extent_buffer *leaf;
struct btrfs_key location; struct btrfs_key location;
@ -975,10 +973,10 @@ static noinline int drop_one_dir_item(struct btrfs_trans_handle *trans,
if (ret) if (ret)
goto out; goto out;
ret = unlink_inode_for_log_replay(trans, dir, BTRFS_I(inode), &name); ret = unlink_inode_for_log_replay(trans, dir, inode, &name);
out: out:
kfree(name.name); kfree(name.name);
iput(inode); iput(&inode->vfs_inode);
return ret; return ret;
} }
@ -1151,7 +1149,7 @@ again:
u32 item_size; u32 item_size;
u32 cur_offset = 0; u32 cur_offset = 0;
unsigned long base; unsigned long base;
struct inode *victim_parent; struct btrfs_inode *victim_parent;
leaf = path->nodes[0]; leaf = path->nodes[0];
@ -1191,10 +1189,10 @@ again:
btrfs_release_path(path); btrfs_release_path(path);
ret = unlink_inode_for_log_replay(trans, ret = unlink_inode_for_log_replay(trans,
BTRFS_I(victim_parent), victim_parent,
inode, &victim_name); inode, &victim_name);
} }
iput(victim_parent); iput(&victim_parent->vfs_inode);
kfree(victim_name.name); kfree(victim_name.name);
if (ret) if (ret)
return ret; return ret;
@ -1328,7 +1326,7 @@ again:
ret = !!btrfs_find_name_in_backref(log_eb, log_slot, &name); ret = !!btrfs_find_name_in_backref(log_eb, log_slot, &name);
if (!ret) { if (!ret) {
struct inode *dir; struct btrfs_inode *dir;
btrfs_release_path(path); btrfs_release_path(path);
dir = read_one_inode(root, parent_id); dir = read_one_inode(root, parent_id);
@ -1337,10 +1335,9 @@ again:
kfree(name.name); kfree(name.name);
goto out; goto out;
} }
ret = unlink_inode_for_log_replay(trans, BTRFS_I(dir), ret = unlink_inode_for_log_replay(trans, dir, inode, &name);
inode, &name);
kfree(name.name); kfree(name.name);
iput(dir); iput(&dir->vfs_inode);
if (ret) if (ret)
goto out; goto out;
goto again; goto again;
@ -1372,8 +1369,8 @@ static noinline int add_inode_ref(struct btrfs_trans_handle *trans,
struct extent_buffer *eb, int slot, struct extent_buffer *eb, int slot,
struct btrfs_key *key) struct btrfs_key *key)
{ {
struct inode *dir = NULL; struct btrfs_inode *dir = NULL;
struct inode *inode = NULL; struct btrfs_inode *inode = NULL;
unsigned long ref_ptr; unsigned long ref_ptr;
unsigned long ref_end; unsigned long ref_end;
struct fscrypt_str name = { 0 }; struct fscrypt_str name = { 0 };
@ -1438,8 +1435,8 @@ static noinline int add_inode_ref(struct btrfs_trans_handle *trans,
if (ret) if (ret)
goto out; goto out;
ret = inode_in_dir(root, path, btrfs_ino(BTRFS_I(dir)), ret = inode_in_dir(root, path, btrfs_ino(dir), btrfs_ino(inode),
btrfs_ino(BTRFS_I(inode)), ref_index, &name); ref_index, &name);
if (ret < 0) { if (ret < 0) {
goto out; goto out;
} else if (ret == 0) { } else if (ret == 0) {
@ -1450,8 +1447,7 @@ static noinline int add_inode_ref(struct btrfs_trans_handle *trans,
* overwrite any existing back reference, and we don't * overwrite any existing back reference, and we don't
* want to create dangling pointers in the directory. * want to create dangling pointers in the directory.
*/ */
ret = __add_inode_ref(trans, root, path, log, ret = __add_inode_ref(trans, root, path, log, dir, inode,
BTRFS_I(dir), BTRFS_I(inode),
inode_objectid, parent_objectid, inode_objectid, parent_objectid,
ref_index, &name); ref_index, &name);
if (ret) { if (ret) {
@ -1461,12 +1457,11 @@ static noinline int add_inode_ref(struct btrfs_trans_handle *trans,
} }
/* insert our name */ /* insert our name */
ret = btrfs_add_link(trans, BTRFS_I(dir), BTRFS_I(inode), ret = btrfs_add_link(trans, dir, inode, &name, 0, ref_index);
&name, 0, ref_index);
if (ret) if (ret)
goto out; goto out;
ret = btrfs_update_inode(trans, BTRFS_I(inode)); ret = btrfs_update_inode(trans, inode);
if (ret) if (ret)
goto out; goto out;
} }
@ -1476,7 +1471,7 @@ static noinline int add_inode_ref(struct btrfs_trans_handle *trans,
kfree(name.name); kfree(name.name);
name.name = NULL; name.name = NULL;
if (log_ref_ver) { if (log_ref_ver) {
iput(dir); iput(&dir->vfs_inode);
dir = NULL; dir = NULL;
} }
} }
@ -1489,8 +1484,7 @@ static noinline int add_inode_ref(struct btrfs_trans_handle *trans,
* dir index entries exist for a name but there is no inode reference * dir index entries exist for a name but there is no inode reference
* item with the same name. * item with the same name.
*/ */
ret = unlink_old_inode_refs(trans, root, path, BTRFS_I(inode), eb, slot, ret = unlink_old_inode_refs(trans, root, path, inode, eb, slot, key);
key);
if (ret) if (ret)
goto out; goto out;
@ -1499,8 +1493,10 @@ static noinline int add_inode_ref(struct btrfs_trans_handle *trans,
out: out:
btrfs_release_path(path); btrfs_release_path(path);
kfree(name.name); kfree(name.name);
iput(dir); if (dir)
iput(inode); iput(&dir->vfs_inode);
if (inode)
iput(&inode->vfs_inode);
return ret; return ret;
} }
@ -1672,12 +1668,13 @@ static noinline int fixup_inode_link_counts(struct btrfs_trans_handle *trans,
{ {
int ret; int ret;
struct btrfs_key key; struct btrfs_key key;
struct inode *inode;
key.objectid = BTRFS_TREE_LOG_FIXUP_OBJECTID; key.objectid = BTRFS_TREE_LOG_FIXUP_OBJECTID;
key.type = BTRFS_ORPHAN_ITEM_KEY; key.type = BTRFS_ORPHAN_ITEM_KEY;
key.offset = (u64)-1; key.offset = (u64)-1;
while (1) { while (1) {
struct btrfs_inode *inode;
ret = btrfs_search_slot(trans, root, &key, path, -1, 1); ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
if (ret < 0) if (ret < 0)
break; break;
@ -1705,8 +1702,8 @@ static noinline int fixup_inode_link_counts(struct btrfs_trans_handle *trans,
break; break;
} }
ret = fixup_inode_link_count(trans, inode); ret = fixup_inode_link_count(trans, &inode->vfs_inode);
iput(inode); iput(&inode->vfs_inode);
if (ret) if (ret)
break; break;
@ -1734,12 +1731,14 @@ static noinline int link_to_fixup_dir(struct btrfs_trans_handle *trans,
{ {
struct btrfs_key key; struct btrfs_key key;
int ret = 0; int ret = 0;
struct inode *inode; struct btrfs_inode *inode;
struct inode *vfs_inode;
inode = read_one_inode(root, objectid); inode = read_one_inode(root, objectid);
if (!inode) if (!inode)
return -EIO; return -EIO;
vfs_inode = &inode->vfs_inode;
key.objectid = BTRFS_TREE_LOG_FIXUP_OBJECTID; key.objectid = BTRFS_TREE_LOG_FIXUP_OBJECTID;
key.type = BTRFS_ORPHAN_ITEM_KEY; key.type = BTRFS_ORPHAN_ITEM_KEY;
key.offset = objectid; key.offset = objectid;
@ -1748,15 +1747,15 @@ static noinline int link_to_fixup_dir(struct btrfs_trans_handle *trans,
btrfs_release_path(path); btrfs_release_path(path);
if (ret == 0) { if (ret == 0) {
if (!inode->i_nlink) if (!vfs_inode->i_nlink)
set_nlink(inode, 1); set_nlink(vfs_inode, 1);
else else
inc_nlink(inode); inc_nlink(vfs_inode);
ret = btrfs_update_inode(trans, BTRFS_I(inode)); ret = btrfs_update_inode(trans, inode);
} else if (ret == -EEXIST) { } else if (ret == -EEXIST) {
ret = 0; ret = 0;
} }
iput(inode); iput(vfs_inode);
return ret; return ret;
} }
@ -1772,8 +1771,8 @@ static noinline int insert_one_name(struct btrfs_trans_handle *trans,
const struct fscrypt_str *name, const struct fscrypt_str *name,
struct btrfs_key *location) struct btrfs_key *location)
{ {
struct inode *inode; struct btrfs_inode *inode;
struct inode *dir; struct btrfs_inode *dir;
int ret; int ret;
inode = read_one_inode(root, location->objectid); inode = read_one_inode(root, location->objectid);
@ -1782,17 +1781,16 @@ static noinline int insert_one_name(struct btrfs_trans_handle *trans,
dir = read_one_inode(root, dirid); dir = read_one_inode(root, dirid);
if (!dir) { if (!dir) {
iput(inode); iput(&inode->vfs_inode);
return -EIO; return -EIO;
} }
ret = btrfs_add_link(trans, BTRFS_I(dir), BTRFS_I(inode), name, ret = btrfs_add_link(trans, dir, inode, name, 1, index);
1, index);
/* FIXME, put inode into FIXUP list */ /* FIXME, put inode into FIXUP list */
iput(inode); iput(&inode->vfs_inode);
iput(dir); iput(&dir->vfs_inode);
return ret; return ret;
} }
@ -1854,7 +1852,7 @@ static noinline int replay_one_name(struct btrfs_trans_handle *trans,
bool index_dst_matches = false; bool index_dst_matches = false;
struct btrfs_key log_key; struct btrfs_key log_key;
struct btrfs_key search_key; struct btrfs_key search_key;
struct inode *dir; struct btrfs_inode *dir;
u8 log_flags; u8 log_flags;
bool exists; bool exists;
int ret; int ret;
@ -1884,9 +1882,8 @@ static noinline int replay_one_name(struct btrfs_trans_handle *trans,
ret = PTR_ERR(dir_dst_di); ret = PTR_ERR(dir_dst_di);
goto out; goto out;
} else if (dir_dst_di) { } else if (dir_dst_di) {
ret = delete_conflicting_dir_entry(trans, BTRFS_I(dir), path, ret = delete_conflicting_dir_entry(trans, dir, path, dir_dst_di,
dir_dst_di, &log_key, &log_key, log_flags, exists);
log_flags, exists);
if (ret < 0) if (ret < 0)
goto out; goto out;
dir_dst_matches = (ret == 1); dir_dst_matches = (ret == 1);
@ -1901,9 +1898,8 @@ static noinline int replay_one_name(struct btrfs_trans_handle *trans,
ret = PTR_ERR(index_dst_di); ret = PTR_ERR(index_dst_di);
goto out; goto out;
} else if (index_dst_di) { } else if (index_dst_di) {
ret = delete_conflicting_dir_entry(trans, BTRFS_I(dir), path, ret = delete_conflicting_dir_entry(trans, dir, path, index_dst_di,
index_dst_di, &log_key, &log_key, log_flags, exists);
log_flags, exists);
if (ret < 0) if (ret < 0)
goto out; goto out;
index_dst_matches = (ret == 1); index_dst_matches = (ret == 1);
@ -1958,11 +1954,11 @@ static noinline int replay_one_name(struct btrfs_trans_handle *trans,
out: out:
if (!ret && update_size) { if (!ret && update_size) {
btrfs_i_size_write(BTRFS_I(dir), dir->i_size + name.len * 2); btrfs_i_size_write(dir, dir->vfs_inode.i_size + name.len * 2);
ret = btrfs_update_inode(trans, BTRFS_I(dir)); ret = btrfs_update_inode(trans, dir);
} }
kfree(name.name); kfree(name.name);
iput(dir); iput(&dir->vfs_inode);
if (!ret && name_added) if (!ret && name_added)
ret = 1; ret = 1;
return ret; return ret;
@ -2119,16 +2115,16 @@ static noinline int check_item_in_log(struct btrfs_trans_handle *trans,
struct btrfs_root *log, struct btrfs_root *log,
struct btrfs_path *path, struct btrfs_path *path,
struct btrfs_path *log_path, struct btrfs_path *log_path,
struct inode *dir, struct btrfs_inode *dir,
struct btrfs_key *dir_key) struct btrfs_key *dir_key)
{ {
struct btrfs_root *root = BTRFS_I(dir)->root; struct btrfs_root *root = dir->root;
int ret; int ret;
struct extent_buffer *eb; struct extent_buffer *eb;
int slot; int slot;
struct btrfs_dir_item *di; struct btrfs_dir_item *di;
struct fscrypt_str name = { 0 }; struct fscrypt_str name = { 0 };
struct inode *inode = NULL; struct btrfs_inode *inode = NULL;
struct btrfs_key location; struct btrfs_key location;
/* /*
@ -2175,9 +2171,8 @@ static noinline int check_item_in_log(struct btrfs_trans_handle *trans,
if (ret) if (ret)
goto out; goto out;
inc_nlink(inode); inc_nlink(&inode->vfs_inode);
ret = unlink_inode_for_log_replay(trans, BTRFS_I(dir), BTRFS_I(inode), ret = unlink_inode_for_log_replay(trans, dir, inode, &name);
&name);
/* /*
* Unlike dir item keys, dir index keys can only have one name (entry) in * Unlike dir item keys, dir index keys can only have one name (entry) in
* them, as there are no key collisions since each key has a unique offset * them, as there are no key collisions since each key has a unique offset
@ -2187,7 +2182,8 @@ out:
btrfs_release_path(path); btrfs_release_path(path);
btrfs_release_path(log_path); btrfs_release_path(log_path);
kfree(name.name); kfree(name.name);
iput(inode); if (inode)
iput(&inode->vfs_inode);
return ret; return ret;
} }
@ -2311,7 +2307,7 @@ static noinline int replay_dir_deletes(struct btrfs_trans_handle *trans,
struct btrfs_key dir_key; struct btrfs_key dir_key;
struct btrfs_key found_key; struct btrfs_key found_key;
struct btrfs_path *log_path; struct btrfs_path *log_path;
struct inode *dir; struct btrfs_inode *dir;
dir_key.objectid = dirid; dir_key.objectid = dirid;
dir_key.type = BTRFS_DIR_INDEX_KEY; dir_key.type = BTRFS_DIR_INDEX_KEY;
@ -2388,7 +2384,7 @@ static noinline int replay_dir_deletes(struct btrfs_trans_handle *trans,
out: out:
btrfs_release_path(path); btrfs_release_path(path);
btrfs_free_path(log_path); btrfs_free_path(log_path);
iput(dir); iput(&dir->vfs_inode);
return ret; return ret;
} }
@ -2482,7 +2478,7 @@ static int replay_one_buffer(struct btrfs_root *log, struct extent_buffer *eb,
*/ */
if (S_ISREG(mode)) { if (S_ISREG(mode)) {
struct btrfs_drop_extents_args drop_args = { 0 }; struct btrfs_drop_extents_args drop_args = { 0 };
struct inode *inode; struct btrfs_inode *inode;
u64 from; u64 from;
inode = read_one_inode(root, key.objectid); inode = read_one_inode(root, key.objectid);
@ -2490,22 +2486,20 @@ static int replay_one_buffer(struct btrfs_root *log, struct extent_buffer *eb,
ret = -EIO; ret = -EIO;
break; break;
} }
from = ALIGN(i_size_read(inode), from = ALIGN(i_size_read(&inode->vfs_inode),
root->fs_info->sectorsize); root->fs_info->sectorsize);
drop_args.start = from; drop_args.start = from;
drop_args.end = (u64)-1; drop_args.end = (u64)-1;
drop_args.drop_cache = true; drop_args.drop_cache = true;
ret = btrfs_drop_extents(wc->trans, root, ret = btrfs_drop_extents(wc->trans, root, inode,
BTRFS_I(inode),
&drop_args); &drop_args);
if (!ret) { if (!ret) {
inode_sub_bytes(inode, inode_sub_bytes(&inode->vfs_inode,
drop_args.bytes_found); drop_args.bytes_found);
/* Update the inode's nbytes. */ /* Update the inode's nbytes. */
ret = btrfs_update_inode(wc->trans, ret = btrfs_update_inode(wc->trans, inode);
BTRFS_I(inode));
} }
iput(inode); iput(&inode->vfs_inode);
if (ret) if (ret)
break; break;
} }