summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.com>2016-11-03 00:37:51 +0100
committerDavid Sterba <dsterba@suse.com>2016-11-09 13:47:32 +0100
commitf26af74da43185897092adc054cf49b691936695 (patch)
tree839f359f5a37834ff6a5f140ef195c38c689127c
parent5b3c976bc202f2b41b7c7c92be1c326adb1511d6 (diff)
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>
-rw-r--r--cmds-check.c21
1 files changed, 8 insertions, 13 deletions
diff --git a/cmds-check.c b/cmds-check.c
index a37c5f51..24c729be 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -2186,7 +2186,7 @@ static int add_missing_dir_index(struct btrfs_root *root,
struct inode_record *rec,
struct inode_backref *backref)
{
- struct btrfs_path *path;
+ struct btrfs_path path;
struct btrfs_trans_handle *trans;
struct btrfs_dir_item *dir_item;
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;
int ret;
- path = btrfs_alloc_path();
- if (!path)
- return -ENOMEM;
-
trans = btrfs_start_transaction(root, 1);
- if (IS_ERR(trans)) {
- btrfs_free_path(path);
+ if (IS_ERR(trans))
return PTR_ERR(trans);
- }
fprintf(stderr, "repairing missing dir index item for inode %llu\n",
(unsigned long long)rec->ino);
+
+ btrfs_init_path(&path);
key.objectid = backref->dir;
key.type = BTRFS_DIR_INDEX_KEY;
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);
- leaf = path->nodes[0];
- dir_item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_dir_item);
+ leaf = path.nodes[0];
+ dir_item = btrfs_item_ptr(leaf, path.slots[0], struct btrfs_dir_item);
disk_key.objectid = cpu_to_le64(rec->ino);
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);
write_extent_buffer(leaf, backref->name, name_ptr, backref->namelen);
btrfs_mark_buffer_dirty(leaf);
- btrfs_free_path(path);
+ btrfs_release_path(&path);
btrfs_commit_transaction(trans, root);
backref->found_dir_index = 1;