btrfs-progs: open code btrfs_list_get_path_rootid

The function btrfs_list_get_path_rootid is exported to libbtrfs so it
needs to stay, but we can inline the implementation.

Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2021-09-08 11:16:43 +02:00
parent 400b66689e
commit 419cb3011c
4 changed files with 40 additions and 15 deletions

View File

@ -1528,10 +1528,14 @@ int btrfs_list_subvols_print(int fd, struct btrfs_list_filter_set *filter_set,
int ret = 0;
u64 top_id = 0;
if (full_path)
ret = btrfs_list_get_path_rootid(fd, &top_id);
if (ret)
if (full_path) {
ret = lookup_path_rootid(fd, &top_id);
if (ret) {
errno = -ret;
error("cannot resolve rootid for path: %m");
return ret;
}
}
ret = btrfs_list_subvols(fd, &root_lookup);
if (ret)
@ -1560,9 +1564,12 @@ int btrfs_get_toplevel_subvol(int fd, struct root_info *the_ri)
struct root_info *ri;
u64 root_id;
ret = btrfs_list_get_path_rootid(fd, &root_id);
if (ret)
ret = lookup_path_rootid(fd, &root_id);
if (ret) {
errno = -ret;
error("cannot resolve rootid for path: %m");
return ret;
}
ret = btrfs_list_subvols(fd, &rl);
if (ret)
@ -1591,9 +1598,12 @@ int btrfs_get_subvol(int fd, struct root_info *the_ri)
struct root_info *ri;
u64 root_id;
ret = btrfs_list_get_path_rootid(fd, &root_id);
if (ret)
ret = lookup_path_rootid(fd, &root_id);
if (ret) {
errno = -ret;
error("cannot resolve rootid for path: %m");
return ret;
}
ret = btrfs_list_subvols(fd, &rl);
if (ret)
@ -1809,9 +1819,12 @@ char *btrfs_list_path_for_root(int fd, u64 root)
int ret;
u64 top_id;
ret = btrfs_list_get_path_rootid(fd, &top_id);
if (ret)
ret = lookup_path_rootid(fd, &top_id);
if (ret) {
errno = -ret;
error("cannot resolve rootid for path: %m");
return ERR_PTR(ret);
}
ret = list_subvol_search(fd, &root_lookup);
if (ret < 0)

View File

@ -1064,9 +1064,12 @@ static int do_receive(struct btrfs_receive *rctx, const char *tomnt,
* subvolume we're sitting in so that we can adjust the paths of any
* subvols we want to receive in.
*/
ret = btrfs_list_get_path_rootid(rctx->mnt_fd, &subvol_id);
if (ret)
ret = lookup_path_rootid(rctx->mnt_fd, &subvol_id);
if (ret) {
errno = -ret;
error("cannot resolve rootid for path: %m");
goto out;
}
root_subvol_path[0] = 0;
ret = btrfs_subvolid_resolve(rctx->mnt_fd, root_subvol_path,

View File

@ -674,9 +674,12 @@ static int cmd_subvol_list(const struct cmd_struct *cmd, int argc, char **argv)
btrfs_list_setup_filter(&filter_set, BTRFS_LIST_FILTER_FLAGS,
flags);
ret = btrfs_list_get_path_rootid(fd, &top_id);
if (ret)
ret = lookup_path_rootid(fd, &top_id);
if (ret) {
errno = -ret;
error("cannot resolve rootid for path: %m");
goto out;
}
if (is_list_all)
btrfs_list_setup_filter(&filter_set,

View File

@ -25,6 +25,8 @@
#include "kernel-shared/ctree.h"
#include "common/send-utils.h"
#include "common/messages.h"
#include "common/utils.h"
#include "ioctl.h"
#include "btrfs-list.h"
@ -44,7 +46,11 @@ static int btrfs_get_root_id_by_sub_path(int mnt_fd, const char *sub_path,
return ret;
}
ret = btrfs_list_get_path_rootid(subvol_fd, root_id);
ret = lookup_path_rootid(subvol_fd, root_id);
if (ret) {
errno = -ret;
error("cannot resolve rootid for path: %m");
}
close(subvol_fd);
return ret;
}