mirror of
https://github.com/kdave/btrfs-progs
synced 2025-02-19 19:26:51 +00:00
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:
parent
8bb13015bd
commit
a1f2dd12ad
@ -233,17 +233,17 @@ static int cmd_inspect_logical_resolve(const struct cmd_struct *cmd,
|
|||||||
u64 offset = inodes->val[i+1];
|
u64 offset = inodes->val[i+1];
|
||||||
u64 root = inodes->val[i+2];
|
u64 root = inodes->val[i+2];
|
||||||
int path_fd;
|
int path_fd;
|
||||||
char *name;
|
|
||||||
DIR *dirs = NULL;
|
DIR *dirs = NULL;
|
||||||
|
|
||||||
if (getpath) {
|
if (getpath) {
|
||||||
char mount_path[PATH_MAX];
|
char mount_path[PATH_MAX];
|
||||||
name = btrfs_list_path_for_root(fd, root);
|
char name[PATH_MAX];
|
||||||
if (IS_ERR(name)) {
|
|
||||||
ret = PTR_ERR(name);
|
ret = btrfs_subvolid_resolve(fd, name, sizeof(name), root);
|
||||||
|
if (ret < 0)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
|
||||||
if (!name) {
|
if (name[0] == 0) {
|
||||||
path_ptr[-1] = '\0';
|
path_ptr[-1] = '\0';
|
||||||
path_fd = fd;
|
path_fd = fd;
|
||||||
strncpy(mount_path, full_path, PATH_MAX);
|
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];
|
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
|
* path to the subvolume pointed by root, but the
|
||||||
* subvolume can be mounted in a directory name
|
* subvolume can be mounted in a directory name
|
||||||
* different from the subvolume name. In this
|
* different from the subvolume name. In this
|
||||||
|
@ -588,7 +588,6 @@ int subvol_uuid_search_init(int mnt_fd, struct subvol_uuid_search *s)
|
|||||||
int root_item_valid = 0;
|
int root_item_valid = 0;
|
||||||
unsigned long off = 0;
|
unsigned long off = 0;
|
||||||
int i;
|
int i;
|
||||||
char *path;
|
|
||||||
|
|
||||||
s->mnt_fd = mnt_fd;
|
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)
|
} else if (btrfs_search_header_type(sh)
|
||||||
== BTRFS_ROOT_BACKREF_KEY ||
|
== BTRFS_ROOT_BACKREF_KEY ||
|
||||||
root_item_valid) {
|
root_item_valid) {
|
||||||
|
char path_buf[PATH_MAX];
|
||||||
|
char *path;
|
||||||
|
|
||||||
if (!root_item_valid)
|
if (!root_item_valid)
|
||||||
goto skip;
|
goto skip;
|
||||||
|
|
||||||
path = btrfs_list_path_for_root(mnt_fd,
|
ret = btrfs_subvolid_resolve(mnt_fd, path_buf,
|
||||||
btrfs_search_header_objectid(sh));
|
sizeof(path_buf),
|
||||||
if (!path)
|
btrfs_search_header_objectid(sh));
|
||||||
path = strdup("");
|
if (ret < 0) {
|
||||||
if (IS_ERR(path)) {
|
errno = -ret;
|
||||||
ret = PTR_ERR(path);
|
|
||||||
fprintf(stderr, "ERROR: unable to "
|
fprintf(stderr, "ERROR: unable to "
|
||||||
"resolve path "
|
"resolve path "
|
||||||
"for root %llu\n",
|
"for root %llu: %m\n",
|
||||||
btrfs_search_header_objectid(sh));
|
btrfs_search_header_objectid(sh));
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
path = strdup(path_buf);
|
||||||
|
|
||||||
si = calloc(1, sizeof(*si));
|
si = calloc(1, sizeof(*si));
|
||||||
si->root_id = btrfs_search_header_objectid(sh);
|
si->root_id = btrfs_search_header_objectid(sh);
|
||||||
|
Loading…
Reference in New Issue
Block a user