btrfs-progs: restore: use on-stack path buffer in set_file_xattrs

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 951e6276e6
commit e79daa7a82

View File

@ -461,7 +461,7 @@ static int set_file_xattrs(struct btrfs_root *root, u64 inode,
int fd, const char *file_name) int fd, const char *file_name)
{ {
struct btrfs_key key; struct btrfs_key key;
struct btrfs_path *path; struct btrfs_path path;
struct extent_buffer *leaf; struct extent_buffer *leaf;
struct btrfs_dir_item *di; struct btrfs_dir_item *di;
u32 name_len = 0; u32 name_len = 0;
@ -472,23 +472,19 @@ static int set_file_xattrs(struct btrfs_root *root, u64 inode,
char *data = NULL; char *data = NULL;
int ret = 0; int ret = 0;
btrfs_init_path(&path);
key.objectid = inode; key.objectid = inode;
key.type = BTRFS_XATTR_ITEM_KEY; key.type = BTRFS_XATTR_ITEM_KEY;
key.offset = 0; key.offset = 0;
ret = btrfs_search_slot(NULL, root, &key, &path, 0, 0);
path = btrfs_alloc_path();
if (!path)
return -ENOMEM;
ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
if (ret < 0) if (ret < 0)
goto out; goto out;
leaf = path->nodes[0]; leaf = path.nodes[0];
while (1) { while (1) {
if (path->slots[0] >= btrfs_header_nritems(leaf)) { if (path.slots[0] >= btrfs_header_nritems(leaf)) {
do { do {
ret = next_leaf(root, path); ret = next_leaf(root, &path);
if (ret < 0) { if (ret < 0) {
error("searching for extended attributes: %d\n", error("searching for extended attributes: %d\n",
ret); ret);
@ -498,17 +494,17 @@ static int set_file_xattrs(struct btrfs_root *root, u64 inode,
ret = 0; ret = 0;
goto out; goto out;
} }
leaf = path->nodes[0]; leaf = path.nodes[0];
} while (!leaf); } while (!leaf);
continue; continue;
} }
btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); btrfs_item_key_to_cpu(leaf, &key, path.slots[0]);
if (key.type != BTRFS_XATTR_ITEM_KEY || key.objectid != inode) if (key.type != BTRFS_XATTR_ITEM_KEY || key.objectid != inode)
break; break;
cur = 0; cur = 0;
total_len = btrfs_item_size_nr(leaf, path->slots[0]); total_len = btrfs_item_size_nr(leaf, path.slots[0]);
di = btrfs_item_ptr(leaf, path->slots[0], di = btrfs_item_ptr(leaf, path.slots[0],
struct btrfs_dir_item); struct btrfs_dir_item);
while (cur < total_len) { while (cur < total_len) {
@ -548,11 +544,11 @@ static int set_file_xattrs(struct btrfs_root *root, u64 inode,
cur += len; cur += len;
di = (struct btrfs_dir_item *)((char *)di + len); di = (struct btrfs_dir_item *)((char *)di + len);
} }
path->slots[0]++; path.slots[0]++;
} }
ret = 0; ret = 0;
out: out:
btrfs_free_path(path); btrfs_release_path(&path);
free(name); free(name);
free(data); free(data);