diff options
author | David Sterba <dsterba@suse.com> | 2016-11-03 00:37:51 +0100 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2016-11-09 13:47:33 +0100 |
commit | 6dfe365b4bc52f199c98f676a3184886d1e39f61 (patch) | |
tree | 60cff5a819620c0d5380d316b7aac10ecee5ca4f | |
parent | 61b72497bb3ef66065bfb38ea2450b37f79dc823 (diff) |
btrfs-progs: restore: use on-stack path buffer in do_list_roots
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-restore.c | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/cmds-restore.c b/cmds-restore.c index 3c579524..1b95e7a2 100644 --- a/cmds-restore.c +++ b/cmds-restore.c @@ -1171,7 +1171,7 @@ static int do_list_roots(struct btrfs_root *root) struct btrfs_key key; struct btrfs_key found_key; struct btrfs_disk_key disk_key; - struct btrfs_path *path; + struct btrfs_path path; struct extent_buffer *leaf; struct btrfs_root_item ri; unsigned long offset; @@ -1179,38 +1179,33 @@ static int do_list_roots(struct btrfs_root *root) int ret; root = root->fs_info->tree_root; - path = btrfs_alloc_path(); - if (!path) { - fprintf(stderr, "Failed to alloc path\n"); - return -ENOMEM; - } + btrfs_init_path(&path); key.offset = 0; key.objectid = 0; key.type = BTRFS_ROOT_ITEM_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, "Failed to do search %d\n", ret); - btrfs_free_path(path); + btrfs_release_path(&path); return -1; } - leaf = path->nodes[0]; + leaf = path.nodes[0]; while (1) { - slot = path->slots[0]; + slot = path.slots[0]; if (slot >= btrfs_header_nritems(leaf)) { - ret = btrfs_next_leaf(root, path); + ret = btrfs_next_leaf(root, &path); if (ret) break; - leaf = path->nodes[0]; - slot = path->slots[0]; + leaf = path.nodes[0]; + slot = path.slots[0]; } btrfs_item_key(leaf, &disk_key, slot); btrfs_disk_key_to_cpu(&found_key, &disk_key); if (found_key.type != BTRFS_ROOT_ITEM_KEY) { - path->slots[0]++; + path.slots[0]++; continue; } @@ -1220,9 +1215,9 @@ static int do_list_roots(struct btrfs_root *root) btrfs_print_key(&disk_key); printf(" %Lu level %d\n", btrfs_root_bytenr(&ri), btrfs_root_level(&ri)); - path->slots[0]++; + path.slots[0]++; } - btrfs_free_path(path); + btrfs_release_path(&path); return 0; } |