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>
This commit is contained in:
parent
9bb8407f54
commit
6ff49c6ad2
|
@ -2803,11 +2803,9 @@ btrfs_lookup_inode_extref(struct btrfs_trans_handle *trans,
|
||||||
struct btrfs_inode_ref *btrfs_find_name_in_backref(struct extent_buffer *leaf,
|
struct btrfs_inode_ref *btrfs_find_name_in_backref(struct extent_buffer *leaf,
|
||||||
int slot, const char *name,
|
int slot, const char *name,
|
||||||
int name_len);
|
int name_len);
|
||||||
int btrfs_find_name_in_ext_backref(struct extent_buffer *leaf, int slot,
|
struct btrfs_inode_extref *btrfs_find_name_in_ext_backref(
|
||||||
u64 ref_objectid, const char *name,
|
struct extent_buffer *leaf, int slot, u64 ref_objectid,
|
||||||
int name_len,
|
const char *name, int name_len);
|
||||||
struct btrfs_inode_extref **extref_ret);
|
|
||||||
|
|
||||||
/* file-item.c */
|
/* file-item.c */
|
||||||
struct btrfs_dio_private;
|
struct btrfs_dio_private;
|
||||||
int btrfs_del_csums(struct btrfs_trans_handle *trans,
|
int btrfs_del_csums(struct btrfs_trans_handle *trans,
|
||||||
|
|
|
@ -34,10 +34,9 @@ struct btrfs_inode_ref *btrfs_find_name_in_backref(struct extent_buffer *leaf,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int btrfs_find_name_in_ext_backref(struct extent_buffer *leaf, int slot,
|
struct btrfs_inode_extref *btrfs_find_name_in_ext_backref(
|
||||||
u64 ref_objectid,
|
struct extent_buffer *leaf, int slot, u64 ref_objectid,
|
||||||
const char *name, int name_len,
|
const char *name, int name_len)
|
||||||
struct btrfs_inode_extref **extref_ret)
|
|
||||||
{
|
{
|
||||||
struct btrfs_inode_extref *extref;
|
struct btrfs_inode_extref *extref;
|
||||||
unsigned long ptr;
|
unsigned long ptr;
|
||||||
|
@ -62,15 +61,12 @@ int btrfs_find_name_in_ext_backref(struct extent_buffer *leaf, int slot,
|
||||||
|
|
||||||
if (ref_name_len == name_len &&
|
if (ref_name_len == name_len &&
|
||||||
btrfs_inode_extref_parent(leaf, extref) == ref_objectid &&
|
btrfs_inode_extref_parent(leaf, extref) == ref_objectid &&
|
||||||
(memcmp_extent_buffer(leaf, name, name_ptr, name_len) == 0)) {
|
(memcmp_extent_buffer(leaf, name, name_ptr, name_len) == 0))
|
||||||
if (extref_ret)
|
return extref;
|
||||||
*extref_ret = extref;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
cur_offset += ref_name_len + sizeof(*extref);
|
cur_offset += ref_name_len + sizeof(*extref);
|
||||||
}
|
}
|
||||||
return 0;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns NULL if no extref found */
|
/* Returns NULL if no extref found */
|
||||||
|
@ -84,7 +80,6 @@ btrfs_lookup_inode_extref(struct btrfs_trans_handle *trans,
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct btrfs_key key;
|
struct btrfs_key key;
|
||||||
struct btrfs_inode_extref *extref;
|
|
||||||
|
|
||||||
key.objectid = inode_objectid;
|
key.objectid = inode_objectid;
|
||||||
key.type = BTRFS_INODE_EXTREF_KEY;
|
key.type = BTRFS_INODE_EXTREF_KEY;
|
||||||
|
@ -95,11 +90,9 @@ btrfs_lookup_inode_extref(struct btrfs_trans_handle *trans,
|
||||||
return ERR_PTR(ret);
|
return ERR_PTR(ret);
|
||||||
if (ret > 0)
|
if (ret > 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (!btrfs_find_name_in_ext_backref(path->nodes[0], path->slots[0],
|
return btrfs_find_name_in_ext_backref(path->nodes[0], path->slots[0],
|
||||||
ref_objectid, name, name_len,
|
ref_objectid, name, name_len);
|
||||||
&extref))
|
|
||||||
return NULL;
|
|
||||||
return extref;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int btrfs_del_inode_extref(struct btrfs_trans_handle *trans,
|
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,
|
||||||
* This should always succeed so error here will make the FS
|
* This should always succeed so error here will make the FS
|
||||||
* readonly.
|
* readonly.
|
||||||
*/
|
*/
|
||||||
if (!btrfs_find_name_in_ext_backref(path->nodes[0], path->slots[0],
|
extref = btrfs_find_name_in_ext_backref(path->nodes[0], path->slots[0],
|
||||||
ref_objectid,
|
ref_objectid, name, name_len);
|
||||||
name, name_len, &extref)) {
|
if (!extref) {
|
||||||
btrfs_handle_fs_error(root->fs_info, -ENOENT, NULL);
|
btrfs_handle_fs_error(root->fs_info, -ENOENT, NULL);
|
||||||
ret = -EROFS;
|
ret = -EROFS;
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -284,7 +277,7 @@ static int btrfs_insert_inode_extref(struct btrfs_trans_handle *trans,
|
||||||
if (btrfs_find_name_in_ext_backref(path->nodes[0],
|
if (btrfs_find_name_in_ext_backref(path->nodes[0],
|
||||||
path->slots[0],
|
path->slots[0],
|
||||||
ref_objectid,
|
ref_objectid,
|
||||||
name, name_len, NULL))
|
name, name_len))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
btrfs_extend_item(path, ins_len);
|
btrfs_extend_item(path, ins_len);
|
||||||
|
|
|
@ -968,7 +968,7 @@ static noinline int backref_in_log(struct btrfs_root *log,
|
||||||
if (btrfs_find_name_in_ext_backref(path->nodes[0],
|
if (btrfs_find_name_in_ext_backref(path->nodes[0],
|
||||||
path->slots[0],
|
path->slots[0],
|
||||||
ref_objectid,
|
ref_objectid,
|
||||||
name, namelen, NULL))
|
name, namelen))
|
||||||
match = 1;
|
match = 1;
|
||||||
|
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -1267,9 +1267,9 @@ again:
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (key->type == BTRFS_INODE_EXTREF_KEY)
|
if (key->type == BTRFS_INODE_EXTREF_KEY)
|
||||||
ret = btrfs_find_name_in_ext_backref(log_eb, log_slot,
|
ret = !!btrfs_find_name_in_ext_backref(log_eb, log_slot,
|
||||||
parent_id, name,
|
parent_id, name,
|
||||||
namelen, NULL);
|
namelen);
|
||||||
else
|
else
|
||||||
ret = !!btrfs_find_name_in_backref(log_eb, log_slot,
|
ret = !!btrfs_find_name_in_backref(log_eb, log_slot,
|
||||||
name, namelen);
|
name, namelen);
|
||||||
|
@ -1334,9 +1334,8 @@ static int btrfs_inode_ref_exists(struct inode *inode, struct inode *dir,
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
if (key.type == BTRFS_INODE_EXTREF_KEY)
|
if (key.type == BTRFS_INODE_EXTREF_KEY)
|
||||||
ret = btrfs_find_name_in_ext_backref(path->nodes[0],
|
ret = !!btrfs_find_name_in_ext_backref(path->nodes[0],
|
||||||
path->slots[0], parent_id,
|
path->slots[0], parent_id, name, namelen);
|
||||||
name, namelen, NULL);
|
|
||||||
else
|
else
|
||||||
ret = !!btrfs_find_name_in_backref(path->nodes[0], path->slots[0],
|
ret = !!btrfs_find_name_in_backref(path->nodes[0], path->slots[0],
|
||||||
name, namelen);
|
name, namelen);
|
||||||
|
|
Loading…
Reference in New Issue