From 51e564543b6041f25368cccc8f8a87de9c08bb5c Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 3 Nov 2016 00:37:51 +0100 Subject: btrfs-progs: restore: use on-stack path buffer in copy_metadata We don't need to conserve stack space too much unlike kernel, also remove one error condition. Signed-off-by: David Sterba --- cmds-restore.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/cmds-restore.c b/cmds-restore.c index 46d94fac..c6a64e7a 100644 --- a/cmds-restore.c +++ b/cmds-restore.c @@ -558,44 +558,39 @@ out: static int copy_metadata(struct btrfs_root *root, int fd, struct btrfs_key *key) { - struct btrfs_path *path; + struct btrfs_path path; struct btrfs_inode_item *inode_item; int ret; - path = btrfs_alloc_path(); - if (!path) { - error("not enough memory"); - return -ENOMEM; - } - - ret = btrfs_lookup_inode(NULL, root, path, key, 0); + btrfs_init_path(&path); + ret = btrfs_lookup_inode(NULL, root, &path, key, 0); if (ret == 0) { struct btrfs_timespec *bts; struct timespec times[2]; - inode_item = btrfs_item_ptr(path->nodes[0], path->slots[0], + inode_item = btrfs_item_ptr(path.nodes[0], path.slots[0], struct btrfs_inode_item); - ret = fchown(fd, btrfs_inode_uid(path->nodes[0], inode_item), - btrfs_inode_gid(path->nodes[0], inode_item)); + ret = fchown(fd, btrfs_inode_uid(path.nodes[0], inode_item), + btrfs_inode_gid(path.nodes[0], inode_item)); if (ret) { error("failed to change owner: %s", strerror(errno)); goto out; } - ret = fchmod(fd, btrfs_inode_mode(path->nodes[0], inode_item)); + ret = fchmod(fd, btrfs_inode_mode(path.nodes[0], inode_item)); if (ret) { error("failed to change mode: %s", strerror(errno)); goto out; } bts = btrfs_inode_atime(inode_item); - times[0].tv_sec = btrfs_timespec_sec(path->nodes[0], bts); - times[0].tv_nsec = btrfs_timespec_nsec(path->nodes[0], bts); + times[0].tv_sec = btrfs_timespec_sec(path.nodes[0], bts); + times[0].tv_nsec = btrfs_timespec_nsec(path.nodes[0], bts); bts = btrfs_inode_mtime(inode_item); - times[1].tv_sec = btrfs_timespec_sec(path->nodes[0], bts); - times[1].tv_nsec = btrfs_timespec_nsec(path->nodes[0], bts); + times[1].tv_sec = btrfs_timespec_sec(path.nodes[0], bts); + times[1].tv_nsec = btrfs_timespec_nsec(path.nodes[0], bts); ret = futimens(fd, times); if (ret) { @@ -604,7 +599,7 @@ static int copy_metadata(struct btrfs_root *root, int fd, } } out: - btrfs_free_path(path); + btrfs_release_path(&path); return ret; } -- cgit v1.2.3