Skip to content

Commit 6ff49c6

Browse files
lorddoskiaskdave
authored andcommitted
btrfs: Make btrfs_find_name_in_ext_backref return struct btrfs_inode_extref
btrfs_find_name_in_ext_backref returns either 0/1 depending on whether it found a backref for the given name. If it returns true then the actual inode_ref struct is returned in one of its parameters. That's pointless, instead refactor the function such that it returns either a pointer to the btrfs_inode_extref or NULL it it didn't find anything. This streamlines the function calling convention. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 9bb8407 commit 6ff49c6

3 files changed

Lines changed: 22 additions & 32 deletions

File tree

‎fs/btrfs/ctree.h‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2803,11 +2803,9 @@ btrfs_lookup_inode_extref(struct btrfs_trans_handle *trans,
28032803
struct btrfs_inode_ref *btrfs_find_name_in_backref(struct extent_buffer *leaf,
28042804
int slot, const char *name,
28052805
int name_len);
2806-
int btrfs_find_name_in_ext_backref(struct extent_buffer *leaf, int slot,
2807-
u64 ref_objectid, const char *name,
2808-
int name_len,
2809-
struct btrfs_inode_extref **extref_ret);
2810-
2806+
struct btrfs_inode_extref *btrfs_find_name_in_ext_backref(
2807+
struct extent_buffer *leaf, int slot, u64 ref_objectid,
2808+
const char *name, int name_len);
28112809
/* file-item.c */
28122810
struct btrfs_dio_private;
28132811
int btrfs_del_csums(struct btrfs_trans_handle *trans,

‎fs/btrfs/inode-item.c‎

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@ struct btrfs_inode_ref *btrfs_find_name_in_backref(struct extent_buffer *leaf,
3434
return NULL;
3535
}
3636

37-
int btrfs_find_name_in_ext_backref(struct extent_buffer *leaf, int slot,
38-
u64 ref_objectid,
39-
const char *name, int name_len,
40-
struct btrfs_inode_extref **extref_ret)
37+
struct btrfs_inode_extref *btrfs_find_name_in_ext_backref(
38+
struct extent_buffer *leaf, int slot, u64 ref_objectid,
39+
const char *name, int name_len)
4140
{
4241
struct btrfs_inode_extref *extref;
4342
unsigned long ptr;
@@ -62,15 +61,12 @@ int btrfs_find_name_in_ext_backref(struct extent_buffer *leaf, int slot,
6261

6362
if (ref_name_len == name_len &&
6463
btrfs_inode_extref_parent(leaf, extref) == ref_objectid &&
65-
(memcmp_extent_buffer(leaf, name, name_ptr, name_len) == 0)) {
66-
if (extref_ret)
67-
*extref_ret = extref;
68-
return 1;
69-
}
64+
(memcmp_extent_buffer(leaf, name, name_ptr, name_len) == 0))
65+
return extref;
7066

7167
cur_offset += ref_name_len + sizeof(*extref);
7268
}
73-
return 0;
69+
return NULL;
7470
}
7571

7672
/* Returns NULL if no extref found */
@@ -84,7 +80,6 @@ btrfs_lookup_inode_extref(struct btrfs_trans_handle *trans,
8480
{
8581
int ret;
8682
struct btrfs_key key;
87-
struct btrfs_inode_extref *extref;
8883

8984
key.objectid = inode_objectid;
9085
key.type = BTRFS_INODE_EXTREF_KEY;
@@ -95,11 +90,9 @@ btrfs_lookup_inode_extref(struct btrfs_trans_handle *trans,
9590
return ERR_PTR(ret);
9691
if (ret > 0)
9792
return NULL;
98-
if (!btrfs_find_name_in_ext_backref(path->nodes[0], path->slots[0],
99-
ref_objectid, name, name_len,
100-
&extref))
101-
return NULL;
102-
return extref;
93+
return btrfs_find_name_in_ext_backref(path->nodes[0], path->slots[0],
94+
ref_objectid, name, name_len);
95+
10396
}
10497

10598
static int btrfs_del_inode_extref(struct btrfs_trans_handle *trans,
@@ -139,9 +132,9 @@ static int btrfs_del_inode_extref(struct btrfs_trans_handle *trans,
139132
* This should always succeed so error here will make the FS
140133
* readonly.
141134
*/
142-
if (!btrfs_find_name_in_ext_backref(path->nodes[0], path->slots[0],
143-
ref_objectid,
144-
name, name_len, &extref)) {
135+
extref = btrfs_find_name_in_ext_backref(path->nodes[0], path->slots[0],
136+
ref_objectid, name, name_len);
137+
if (!extref) {
145138
btrfs_handle_fs_error(root->fs_info, -ENOENT, NULL);
146139
ret = -EROFS;
147140
goto out;
@@ -284,7 +277,7 @@ static int btrfs_insert_inode_extref(struct btrfs_trans_handle *trans,
284277
if (btrfs_find_name_in_ext_backref(path->nodes[0],
285278
path->slots[0],
286279
ref_objectid,
287-
name, name_len, NULL))
280+
name, name_len))
288281
goto out;
289282

290283
btrfs_extend_item(path, ins_len);

‎fs/btrfs/tree-log.c‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ static noinline int backref_in_log(struct btrfs_root *log,
968968
if (btrfs_find_name_in_ext_backref(path->nodes[0],
969969
path->slots[0],
970970
ref_objectid,
971-
name, namelen, NULL))
971+
name, namelen))
972972
match = 1;
973973

974974
goto out;
@@ -1267,9 +1267,9 @@ static int unlink_old_inode_refs(struct btrfs_trans_handle *trans,
12671267
goto out;
12681268

12691269
if (key->type == BTRFS_INODE_EXTREF_KEY)
1270-
ret = btrfs_find_name_in_ext_backref(log_eb, log_slot,
1271-
parent_id, name,
1272-
namelen, NULL);
1270+
ret = !!btrfs_find_name_in_ext_backref(log_eb, log_slot,
1271+
parent_id, name,
1272+
namelen);
12731273
else
12741274
ret = !!btrfs_find_name_in_backref(log_eb, log_slot,
12751275
name, namelen);
@@ -1334,9 +1334,8 @@ static int btrfs_inode_ref_exists(struct inode *inode, struct inode *dir,
13341334
goto out;
13351335
}
13361336
if (key.type == BTRFS_INODE_EXTREF_KEY)
1337-
ret = btrfs_find_name_in_ext_backref(path->nodes[0],
1338-
path->slots[0], parent_id,
1339-
name, namelen, NULL);
1337+
ret = !!btrfs_find_name_in_ext_backref(path->nodes[0],
1338+
path->slots[0], parent_id, name, namelen);
13401339
else
13411340
ret = !!btrfs_find_name_in_backref(path->nodes[0], path->slots[0],
13421341
name, namelen);

0 commit comments

Comments
 (0)