btrfs-progs: use btrfs_subvolid_resolve instead of btrfs_list_path_for_root

The btrfs_list_* functions come with some overhead and for simple path
resolution we can use btrfs_subvolid_resolve.

Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2021-09-29 16:55:46 +02:00
parent 8bb13015bd
commit a1f2dd12ad
2 changed files with 17 additions and 15 deletions

View File

@ -233,17 +233,17 @@ static int cmd_inspect_logical_resolve(const struct cmd_struct *cmd,
u64 offset = inodes->val[i+1];
u64 root = inodes->val[i+2];
int path_fd;
char *name;
DIR *dirs = NULL;
if (getpath) {
char mount_path[PATH_MAX];
name = btrfs_list_path_for_root(fd, root);
if (IS_ERR(name)) {
ret = PTR_ERR(name);
char name[PATH_MAX];
ret = btrfs_subvolid_resolve(fd, name, sizeof(name), root);
if (ret < 0)
goto out;
}
if (!name) {
if (name[0] == 0) {
path_ptr[-1] = '\0';
path_fd = fd;
strncpy(mount_path, full_path, PATH_MAX);
@ -253,7 +253,7 @@ static int cmd_inspect_logical_resolve(const struct cmd_struct *cmd,
char subvolid[PATH_MAX];
/*
* btrfs_list_path_for_root returns the full
* btrfs_subvolid_resolve returns the full
* path to the subvolume pointed by root, but the
* subvolume can be mounted in a directory name
* different from the subvolume name. In this

View File

@ -588,7 +588,6 @@ int subvol_uuid_search_init(int mnt_fd, struct subvol_uuid_search *s)
int root_item_valid = 0;
unsigned long off = 0;
int i;
char *path;
s->mnt_fd = mnt_fd;
@ -658,21 +657,24 @@ int subvol_uuid_search_init(int mnt_fd, struct subvol_uuid_search *s)
} else if (btrfs_search_header_type(sh)
== BTRFS_ROOT_BACKREF_KEY ||
root_item_valid) {
char path_buf[PATH_MAX];
char *path;
if (!root_item_valid)
goto skip;
path = btrfs_list_path_for_root(mnt_fd,
btrfs_search_header_objectid(sh));
if (!path)
path = strdup("");
if (IS_ERR(path)) {
ret = PTR_ERR(path);
ret = btrfs_subvolid_resolve(mnt_fd, path_buf,
sizeof(path_buf),
btrfs_search_header_objectid(sh));
if (ret < 0) {
errno = -ret;
fprintf(stderr, "ERROR: unable to "
"resolve path "
"for root %llu\n",
"for root %llu: %m\n",
btrfs_search_header_objectid(sh));
goto out;
}
path = strdup(path_buf);
si = calloc(1, sizeof(*si));
si->root_id = btrfs_search_header_objectid(sh);