summaryrefslogtreecommitdiff
path: root/cmds-restore.c
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:33 +0100
commit61b72497bb3ef66065bfb38ea2450b37f79dc823 (patch)
treedee70476c13bb23d0010976ad51db4321d7a06cb /cmds-restore.c
parent69b7e72345062d0323b2e6da3398f910f2bb5ca3 (diff)
btrfs-progs: restore: use on-stack path buffer in search_dir
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>
Diffstat (limited to 'cmds-restore.c')
-rw-r--r--cmds-restore.c34
1 files changed, 14 insertions, 20 deletions
diff --git a/cmds-restore.c b/cmds-restore.c
index 60126aba..3c579524 100644
--- a/cmds-restore.c
+++ b/cmds-restore.c
@@ -912,7 +912,7 @@ static int search_dir(struct btrfs_root *root, struct btrfs_key *key,
const char *output_rootdir, const char *in_dir,
const regex_t *mreg)
{
- struct btrfs_path *path;
+ struct btrfs_path path;
struct extent_buffer *leaf;
struct btrfs_dir_item *dir_item;
struct btrfs_key found_key, location;
@@ -924,16 +924,10 @@ static int search_dir(struct btrfs_root *root, struct btrfs_key *key,
int loops = 0;
u8 type;
- path = btrfs_alloc_path();
- if (!path) {
- fprintf(stderr, "Ran out of memory\n");
- return -ENOMEM;
- }
-
+ btrfs_init_path(&path);
key->offset = 0;
key->type = BTRFS_DIR_INDEX_KEY;
-
- ret = btrfs_search_slot(NULL, root, key, path, 0, 0);
+ ret = btrfs_search_slot(NULL, root, key, &path, 0, 0);
if (ret < 0) {
fprintf(stderr, "Error searching %d\n", ret);
goto out;
@@ -941,12 +935,12 @@ static int search_dir(struct btrfs_root *root, struct btrfs_key *key,
ret = 0;
- leaf = path->nodes[0];
+ leaf = path.nodes[0];
while (!leaf) {
if (verbose > 1)
printf("No leaf after search, looking for the next "
"leaf\n");
- ret = next_leaf(root, path);
+ ret = next_leaf(root, &path);
if (ret < 0) {
fprintf(stderr, "Error getting next leaf %d\n",
ret);
@@ -959,7 +953,7 @@ static int search_dir(struct btrfs_root *root, struct btrfs_key *key,
ret = 0;
goto out;
}
- leaf = path->nodes[0];
+ leaf = path.nodes[0];
}
while (leaf) {
@@ -970,9 +964,9 @@ static int search_dir(struct btrfs_root *root, struct btrfs_key *key,
break;
}
- if (path->slots[0] >= btrfs_header_nritems(leaf)) {
+ if (path.slots[0] >= btrfs_header_nritems(leaf)) {
do {
- ret = next_leaf(root, path);
+ ret = next_leaf(root, &path);
if (ret < 0) {
fprintf(stderr, "Error searching %d\n",
ret);
@@ -986,11 +980,11 @@ static int search_dir(struct btrfs_root *root, struct btrfs_key *key,
ret = 0;
goto out;
}
- leaf = path->nodes[0];
+ leaf = path.nodes[0];
} while (!leaf);
continue;
}
- btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]);
+ btrfs_item_key_to_cpu(leaf, &found_key, path.slots[0]);
if (found_key.objectid != key->objectid) {
if (verbose > 1)
printf("Found objectid=%Lu, key=%Lu\n",
@@ -1003,7 +997,7 @@ static int search_dir(struct btrfs_root *root, struct btrfs_key *key,
found_key.type, key->type);
break;
}
- dir_item = btrfs_item_ptr(leaf, path->slots[0],
+ dir_item = btrfs_item_ptr(leaf, path.slots[0],
struct btrfs_dir_item);
name_ptr = (unsigned long)(dir_item + 1);
name_len = btrfs_dir_name_len(leaf, dir_item);
@@ -1135,12 +1129,12 @@ static int search_dir(struct btrfs_root *root, struct btrfs_key *key,
if (ret < 0) {
if (ignore_errors)
goto next;
- btrfs_free_path(path);
+ btrfs_release_path(&path);
return ret;
}
}
next:
- path->slots[0]++;
+ path.slots[0]++;
}
if (restore_metadata) {
@@ -1168,7 +1162,7 @@ next:
if (verbose)
printf("Done searching %s\n", in_dir);
out:
- btrfs_free_path(path);
+ btrfs_release_path(&path);
return ret;
}