btrfs: Make btrfs_find_name_in_backref return btrfs_inode_ref struct
btrfs_find_name_in_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_ref 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
1dc990dfd3
commit
9bb8407f54
|
@ -2800,9 +2800,9 @@ btrfs_lookup_inode_extref(struct btrfs_trans_handle *trans,
|
||||||
u64 inode_objectid, u64 ref_objectid, int ins_len,
|
u64 inode_objectid, u64 ref_objectid, int ins_len,
|
||||||
int cow);
|
int cow);
|
||||||
|
|
||||||
int btrfs_find_name_in_backref(struct extent_buffer *leaf, int slot,
|
struct btrfs_inode_ref *btrfs_find_name_in_backref(struct extent_buffer *leaf,
|
||||||
const char *name,
|
int slot, const char *name,
|
||||||
int name_len, struct btrfs_inode_ref **ref_ret);
|
int name_len);
|
||||||
int btrfs_find_name_in_ext_backref(struct extent_buffer *leaf, int slot,
|
int btrfs_find_name_in_ext_backref(struct extent_buffer *leaf, int slot,
|
||||||
u64 ref_objectid, const char *name,
|
u64 ref_objectid, const char *name,
|
||||||
int name_len,
|
int name_len,
|
||||||
|
|
|
@ -8,9 +8,9 @@
|
||||||
#include "transaction.h"
|
#include "transaction.h"
|
||||||
#include "print-tree.h"
|
#include "print-tree.h"
|
||||||
|
|
||||||
int btrfs_find_name_in_backref(struct extent_buffer *leaf, int slot,
|
struct btrfs_inode_ref *btrfs_find_name_in_backref(struct extent_buffer *leaf,
|
||||||
const char *name,
|
int slot, const char *name,
|
||||||
int name_len, struct btrfs_inode_ref **ref_ret)
|
int name_len)
|
||||||
{
|
{
|
||||||
struct btrfs_inode_ref *ref;
|
struct btrfs_inode_ref *ref;
|
||||||
unsigned long ptr;
|
unsigned long ptr;
|
||||||
|
@ -28,13 +28,10 @@ int btrfs_find_name_in_backref(struct extent_buffer *leaf, int slot,
|
||||||
cur_offset += len + sizeof(*ref);
|
cur_offset += len + sizeof(*ref);
|
||||||
if (len != name_len)
|
if (len != name_len)
|
||||||
continue;
|
continue;
|
||||||
if (memcmp_extent_buffer(leaf, name, name_ptr, name_len) == 0) {
|
if (memcmp_extent_buffer(leaf, name, name_ptr, name_len) == 0)
|
||||||
if (ref_ret)
|
return ref;
|
||||||
*ref_ret = ref;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return 0;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int btrfs_find_name_in_ext_backref(struct extent_buffer *leaf, int slot,
|
int btrfs_find_name_in_ext_backref(struct extent_buffer *leaf, int slot,
|
||||||
|
@ -213,8 +210,10 @@ int btrfs_del_inode_ref(struct btrfs_trans_handle *trans,
|
||||||
} else if (ret < 0) {
|
} else if (ret < 0) {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
if (!btrfs_find_name_in_backref(path->nodes[0], path->slots[0],
|
|
||||||
name, name_len, &ref)) {
|
ref = btrfs_find_name_in_backref(path->nodes[0], path->slots[0], name,
|
||||||
|
name_len);
|
||||||
|
if (!ref) {
|
||||||
ret = -ENOENT;
|
ret = -ENOENT;
|
||||||
search_ext_refs = 1;
|
search_ext_refs = 1;
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -341,9 +340,9 @@ int btrfs_insert_inode_ref(struct btrfs_trans_handle *trans,
|
||||||
ins_len);
|
ins_len);
|
||||||
if (ret == -EEXIST) {
|
if (ret == -EEXIST) {
|
||||||
u32 old_size;
|
u32 old_size;
|
||||||
|
ref = btrfs_find_name_in_backref(path->nodes[0], path->slots[0],
|
||||||
if (btrfs_find_name_in_backref(path->nodes[0], path->slots[0],
|
name, name_len);
|
||||||
name, name_len, &ref))
|
if (ref)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
old_size = btrfs_item_size_nr(path->nodes[0], path->slots[0]);
|
old_size = btrfs_item_size_nr(path->nodes[0], path->slots[0]);
|
||||||
|
@ -359,7 +358,7 @@ int btrfs_insert_inode_ref(struct btrfs_trans_handle *trans,
|
||||||
if (ret == -EOVERFLOW) {
|
if (ret == -EOVERFLOW) {
|
||||||
if (btrfs_find_name_in_backref(path->nodes[0],
|
if (btrfs_find_name_in_backref(path->nodes[0],
|
||||||
path->slots[0],
|
path->slots[0],
|
||||||
name, name_len, &ref))
|
name, name_len))
|
||||||
ret = -EEXIST;
|
ret = -EEXIST;
|
||||||
else
|
else
|
||||||
ret = -EMLINK;
|
ret = -EMLINK;
|
||||||
|
|
|
@ -1271,8 +1271,8 @@ again:
|
||||||
parent_id, name,
|
parent_id, name,
|
||||||
namelen, NULL);
|
namelen, NULL);
|
||||||
else
|
else
|
||||||
ret = btrfs_find_name_in_backref(log_eb, log_slot, name,
|
ret = !!btrfs_find_name_in_backref(log_eb, log_slot,
|
||||||
namelen, NULL);
|
name, namelen);
|
||||||
|
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
struct inode *dir;
|
struct inode *dir;
|
||||||
|
@ -1338,8 +1338,8 @@ static int btrfs_inode_ref_exists(struct inode *inode, struct inode *dir,
|
||||||
path->slots[0], parent_id,
|
path->slots[0], parent_id,
|
||||||
name, namelen, NULL);
|
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, NULL);
|
name, namelen);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
btrfs_free_path(path);
|
btrfs_free_path(path);
|
||||||
|
|
Loading…
Reference in New Issue