btrfs-progs: check: use on-stack path buffer in add_missing_dir_index

We don't need to conserve stack space too much unlike kernel, also
remove one error condition.

Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2016-11-03 00:37:51 +01:00
parent 5b3c976bc2
commit f26af74da4

View file

@ -2186,7 +2186,7 @@ static int add_missing_dir_index(struct btrfs_root *root,
struct inode_record *rec, struct inode_record *rec,
struct inode_backref *backref) struct inode_backref *backref)
{ {
struct btrfs_path *path; struct btrfs_path path;
struct btrfs_trans_handle *trans; struct btrfs_trans_handle *trans;
struct btrfs_dir_item *dir_item; struct btrfs_dir_item *dir_item;
struct extent_buffer *leaf; struct extent_buffer *leaf;
@ -2197,27 +2197,22 @@ static int add_missing_dir_index(struct btrfs_root *root,
u32 data_size = sizeof(*dir_item) + backref->namelen; u32 data_size = sizeof(*dir_item) + backref->namelen;
int ret; int ret;
path = btrfs_alloc_path();
if (!path)
return -ENOMEM;
trans = btrfs_start_transaction(root, 1); trans = btrfs_start_transaction(root, 1);
if (IS_ERR(trans)) { if (IS_ERR(trans))
btrfs_free_path(path);
return PTR_ERR(trans); return PTR_ERR(trans);
}
fprintf(stderr, "repairing missing dir index item for inode %llu\n", fprintf(stderr, "repairing missing dir index item for inode %llu\n",
(unsigned long long)rec->ino); (unsigned long long)rec->ino);
btrfs_init_path(&path);
key.objectid = backref->dir; key.objectid = backref->dir;
key.type = BTRFS_DIR_INDEX_KEY; key.type = BTRFS_DIR_INDEX_KEY;
key.offset = backref->index; key.offset = backref->index;
ret = btrfs_insert_empty_item(trans, root, &path, &key, data_size);
ret = btrfs_insert_empty_item(trans, root, path, &key, data_size);
BUG_ON(ret); BUG_ON(ret);
leaf = path->nodes[0]; leaf = path.nodes[0];
dir_item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_dir_item); dir_item = btrfs_item_ptr(leaf, path.slots[0], struct btrfs_dir_item);
disk_key.objectid = cpu_to_le64(rec->ino); disk_key.objectid = cpu_to_le64(rec->ino);
disk_key.type = BTRFS_INODE_ITEM_KEY; disk_key.type = BTRFS_INODE_ITEM_KEY;
@ -2230,7 +2225,7 @@ static int add_missing_dir_index(struct btrfs_root *root,
name_ptr = (unsigned long)(dir_item + 1); name_ptr = (unsigned long)(dir_item + 1);
write_extent_buffer(leaf, backref->name, name_ptr, backref->namelen); write_extent_buffer(leaf, backref->name, name_ptr, backref->namelen);
btrfs_mark_buffer_dirty(leaf); btrfs_mark_buffer_dirty(leaf);
btrfs_free_path(path); btrfs_release_path(&path);
btrfs_commit_transaction(trans, root); btrfs_commit_transaction(trans, root);
backref->found_dir_index = 1; backref->found_dir_index = 1;