Skip to content

Commit f8d59ec

Browse files
mssolakdave
authored andcommitted
btrfs: don't pass tree_id in btrfs_search_path_in_tree()
The 'tree_id' parameter in btrfs_search_path_in_tree() was only being used in order to fetch the root tree to be considered for the search. For this same reason this function was also requiring a 'struct btrfs_fs_info' parameter. This commit replaces these two parameters with a single 'struct btrfs_root' one, which identifies from which root tree the search should happen. This function only has one caller, the inode lookup ioctl, which knows how to provide the root tree for each case. In fact, if args->treeid == 0, then we don't even have to allocate a new root tree object, and we can reuse the one provided by the ioctl system call, thus avoiding an extra allocation. Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com> Reviewed-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 75d6b9d commit f8d59ec

1 file changed

Lines changed: 21 additions & 28 deletions

File tree

fs/btrfs/ioctl.c

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,13 +1664,11 @@ static noinline int btrfs_ioctl_tree_search_v2(struct btrfs_root *root,
16641664
}
16651665

16661666
/*
1667-
* Search INODE_REFs to identify path name of 'dirid' directory
1668-
* in a 'tree_id' tree. and sets path name to 'name'.
1667+
* Search for an INODE_REF in a 'root' tree which identifies the path name of
1668+
* 'dirid'. When found, it sets 'name' with the path name.
16691669
*/
1670-
static noinline int btrfs_search_path_in_tree(struct btrfs_fs_info *info,
1671-
u64 tree_id, u64 dirid, char *name)
1670+
static noinline int btrfs_search_path_in_tree(struct btrfs_root *root, u64 dirid, char *name)
16721671
{
1673-
struct btrfs_root *root;
16741672
struct btrfs_key key;
16751673
char *ptr;
16761674
int ret = -1;
@@ -1692,25 +1690,16 @@ static noinline int btrfs_search_path_in_tree(struct btrfs_fs_info *info,
16921690

16931691
ptr = &name[BTRFS_INO_LOOKUP_PATH_MAX - 1];
16941692

1695-
root = btrfs_get_fs_root(info, tree_id, true);
1696-
if (IS_ERR(root)) {
1697-
ret = PTR_ERR(root);
1698-
root = NULL;
1699-
goto out;
1700-
}
1701-
17021693
key.objectid = dirid;
17031694
key.type = BTRFS_INODE_REF_KEY;
17041695
key.offset = (u64)-1;
17051696

17061697
while (1) {
17071698
ret = btrfs_search_backwards(root, &key, path);
17081699
if (ret < 0)
1709-
goto out;
1710-
else if (ret > 0) {
1711-
ret = -ENOENT;
1712-
goto out;
1713-
}
1700+
return ret;
1701+
else if (ret > 0)
1702+
return -ENOENT;
17141703

17151704
l = path->nodes[0];
17161705
slot = path->slots[0];
@@ -1719,10 +1708,8 @@ static noinline int btrfs_search_path_in_tree(struct btrfs_fs_info *info,
17191708
len = btrfs_inode_ref_name_len(l, iref);
17201709
ptr -= len + 1;
17211710
total_len += len + 1;
1722-
if (ptr < name) {
1723-
ret = -ENAMETOOLONG;
1724-
goto out;
1725-
}
1711+
if (ptr < name)
1712+
return -ENAMETOOLONG;
17261713

17271714
*(ptr + len) = '/';
17281715
read_extent_buffer(l, ptr, (unsigned long)(iref + 1), len);
@@ -1737,10 +1724,8 @@ static noinline int btrfs_search_path_in_tree(struct btrfs_fs_info *info,
17371724
}
17381725
memmove(name, ptr, total_len);
17391726
name[total_len] = '\0';
1740-
ret = 0;
1741-
out:
1742-
btrfs_put_root(root);
1743-
return ret;
1727+
1728+
return 0;
17441729
}
17451730

17461731
static int btrfs_search_path_in_tree_user(struct mnt_idmap *idmap,
@@ -1884,6 +1869,7 @@ static int btrfs_search_path_in_tree_user(struct mnt_idmap *idmap,
18841869
static noinline int btrfs_ioctl_ino_lookup(struct btrfs_root *root,
18851870
void __user *argp)
18861871
{
1872+
bool new_root = false;
18871873
struct btrfs_ioctl_ino_lookup_args AUTO_KFREE(args);
18881874
int ret = 0;
18891875

@@ -1897,6 +1883,8 @@ static noinline int btrfs_ioctl_ino_lookup(struct btrfs_root *root,
18971883
*/
18981884
if (args->treeid == 0)
18991885
args->treeid = btrfs_root_id(root);
1886+
else
1887+
new_root = true;
19001888

19011889
if (args->objectid == BTRFS_FIRST_FREE_OBJECTID) {
19021890
args->name[0] = 0;
@@ -1908,9 +1896,14 @@ static noinline int btrfs_ioctl_ino_lookup(struct btrfs_root *root,
19081896
goto out;
19091897
}
19101898

1911-
ret = btrfs_search_path_in_tree(root->fs_info,
1912-
args->treeid, args->objectid,
1913-
args->name);
1899+
if (new_root) {
1900+
root = btrfs_get_fs_root(root->fs_info, args->treeid, true);
1901+
if (IS_ERR(root))
1902+
return PTR_ERR(root);
1903+
}
1904+
ret = btrfs_search_path_in_tree(root, args->objectid, args->name);
1905+
if (new_root)
1906+
btrfs_put_root(root);
19141907

19151908
out:
19161909
if (ret == 0 && copy_to_user(argp, args, sizeof(*args)))

0 commit comments

Comments
 (0)