@@ -2456,7 +2456,7 @@ static int reset_nlink(struct btrfs_trans_handle *trans,
list_for_each_entry(backref, &rec->backrefs, list) {
ret = btrfs_add_link(trans, root, rec->ino, backref->dir,
backref->name, backref->namelen,
- backref->filetype, &backref->index, 1, 0);
+ backref->filetype, &backref->index, 0);
if (ret < 0)
goto out;
}
@@ -464,7 +464,7 @@ int link_inode_to_lostfound(struct btrfs_trans_handle *trans,
goto out;
}
ret = btrfs_add_link(trans, root, ino, lost_found_ino,
- namebuf, name_len, filetype, NULL, 1, 0);
+ namebuf, name_len, filetype, NULL, 0);
/*
* Add ".INO" suffix several times to handle case where
* "FILENAME.INO" is already taken by another file.
@@ -481,7 +481,7 @@ int link_inode_to_lostfound(struct btrfs_trans_handle *trans,
".%llu", ino);
name_len += count_digits(ino) + 1;
ret = btrfs_add_link(trans, root, ino, lost_found_ino, namebuf,
- name_len, filetype, NULL, 1, 0);
+ name_len, filetype, NULL, 0);
}
if (ret < 0) {
errno = -ret;
@@ -1042,7 +1042,7 @@ static int repair_ternary_lowmem(struct btrfs_root *root, u64 dir_ino, u64 ino,
if (ret)
goto out;
ret = btrfs_add_link(trans, root, ino, dir_ino, name, name_len,
- filetype, &index, 1, 1);
+ filetype, &index, 1);
goto out;
}
out:
@@ -841,7 +841,7 @@ static int create_image(struct btrfs_root *root,
goto out;
}
ret = btrfs_add_link(trans, root, ino, BTRFS_FIRST_FREE_OBJECTID, name,
- strlen(name), BTRFS_FT_REG_FILE, NULL, 1, 0);
+ strlen(name), BTRFS_FT_REG_FILE, NULL, 0);
if (ret < 0) {
errno = -ret;
error("failed to link ino %llu to '/%s' in root %llu: %m",
@@ -1227,7 +1227,7 @@ int btrfs_change_inode_flags(struct btrfs_trans_handle *trans,
struct btrfs_root *root, u64 ino, u64 flags);
int btrfs_add_link(struct btrfs_trans_handle *trans, struct btrfs_root *root,
u64 ino, u64 parent_ino, char *name, int namelen,
- u8 type, u64 *index, int add_backref, int ignore_existed);
+ u8 type, u64 *index, int ignore_existed);
int btrfs_unlink(struct btrfs_trans_handle *trans, struct btrfs_root *root,
u64 ino, u64 parent_ino, u64 index, const char *name,
int namelen, int add_orphan);
@@ -178,7 +178,7 @@ out:
*/
int btrfs_add_link(struct btrfs_trans_handle *trans, struct btrfs_root *root,
u64 ino, u64 parent_ino, char *name, int namelen,
- u8 type, u64 *index, int add_backref, int ignore_existed)
+ u8 type, u64 *index, int ignore_existed)
{
struct btrfs_path *path;
struct btrfs_key key;
@@ -205,33 +205,31 @@ int btrfs_add_link(struct btrfs_trans_handle *trans, struct btrfs_root *root,
goto out;
/* Add inode ref */
- if (add_backref) {
- ret = btrfs_insert_inode_ref(trans, root, name, namelen,
- ino, parent_ino, ret_index);
- if (ret < 0 && !(ignore_existed && ret == -EEXIST))
- goto out;
+ ret = btrfs_insert_inode_ref(trans, root, name, namelen,
+ ino, parent_ino, ret_index);
+ if (ret < 0 && !(ignore_existed && ret == -EEXIST))
+ goto out;
- /* do not update nlinks if existed */
- if (!ret) {
- /* Update nlinks for the inode */
- key.objectid = ino;
- key.type = BTRFS_INODE_ITEM_KEY;
- key.offset = 0;
- ret = btrfs_search_slot(trans, root, &key, path, 1, 1);
- if (ret) {
- if (ret > 0)
- ret = -ENOENT;
- goto out;
- }
- inode_item = btrfs_item_ptr(path->nodes[0],
- path->slots[0], struct btrfs_inode_item);
- nlink = btrfs_inode_nlink(path->nodes[0], inode_item);
- nlink++;
- btrfs_set_inode_nlink(path->nodes[0], inode_item,
- nlink);
- btrfs_mark_buffer_dirty(path->nodes[0]);
- btrfs_release_path(path);
+ /* do not update nlinks if existed */
+ if (!ret) {
+ /* Update nlinks for the inode */
+ key.objectid = ino;
+ key.type = BTRFS_INODE_ITEM_KEY;
+ key.offset = 0;
+ ret = btrfs_search_slot(trans, root, &key, path, 1, 1);
+ if (ret) {
+ if (ret > 0)
+ ret = -ENOENT;
+ goto out;
}
+ inode_item = btrfs_item_ptr(path->nodes[0],
+ path->slots[0], struct btrfs_inode_item);
+ nlink = btrfs_inode_nlink(path->nodes[0], inode_item);
+ nlink++;
+ btrfs_set_inode_nlink(path->nodes[0], inode_item,
+ nlink);
+ btrfs_mark_buffer_dirty(path->nodes[0]);
+ btrfs_release_path(path);
}
/* Add dir_item and dir_index */
@@ -582,7 +580,7 @@ int btrfs_mkdir(struct btrfs_trans_handle *trans, struct btrfs_root *root,
if (ret)
goto out;
ret = btrfs_add_link(trans, root, ret_ino, parent_ino, name, namelen,
- BTRFS_FT_DIR, NULL, 1, 0);
+ BTRFS_FT_DIR, NULL, 0);
if (ret)
goto out;
out:
The function btrfs_add_link() has a parameter @add_backref, to indicate if the operation should add an INODE_REF for the child inode. However all call sites are passing 1 for @add_backref, and in fact if intentionally passing 0 for @add_backref for most cases, it would only lead to missing INODE_REF and cause inconsistency. And for call sites that want to ignore existing INODE_REF, they would have already pass 1 for @ignore_existed. So we can safely remmove the @add_backref parameter. Signed-off-by: Qu Wenruo <wqu@suse.com> --- check/main.c | 2 +- check/mode-common.c | 4 ++-- check/mode-lowmem.c | 2 +- convert/main.c | 2 +- kernel-shared/ctree.h | 2 +- kernel-shared/inode.c | 52 +++++++++++++++++++++---------------------- 6 files changed, 31 insertions(+), 33 deletions(-)