mirror of
https://github.com/kdave/btrfs-progs
synced 2025-02-02 19:01:47 +00:00
btrfs-progs: simplify struct subvol_uuid_search use
After removing uuid search fallback code the structure has become trivial and copies the fd that all callers have in their context. Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
22f5600649
commit
e491d9cf25
@ -71,8 +71,6 @@ struct btrfs_receive
|
||||
*/
|
||||
char cur_subvol_path[PATH_MAX];
|
||||
|
||||
struct subvol_uuid_search sus;
|
||||
|
||||
int honor_end_cmd;
|
||||
};
|
||||
|
||||
@ -270,11 +268,11 @@ static int process_snapshot(const char *path, const u8 *uuid, u64 ctransid,
|
||||
memset(&args_v2, 0, sizeof(args_v2));
|
||||
strncpy_null(args_v2.name, path);
|
||||
|
||||
parent_subvol = subvol_uuid_search(&rctx->sus, 0, parent_uuid,
|
||||
parent_subvol = subvol_uuid_search(rctx->mnt_fd, 0, parent_uuid,
|
||||
parent_ctransid, NULL,
|
||||
subvol_search_by_received_uuid);
|
||||
if (IS_ERR_OR_NULL(parent_subvol)) {
|
||||
parent_subvol = subvol_uuid_search(&rctx->sus, 0, parent_uuid,
|
||||
parent_subvol = subvol_uuid_search(rctx->mnt_fd, 0, parent_uuid,
|
||||
parent_ctransid, NULL,
|
||||
subvol_search_by_uuid);
|
||||
}
|
||||
@ -731,7 +729,7 @@ static int process_clone(const char *path, u64 offset, u64 len,
|
||||
BTRFS_UUID_SIZE) == 0) {
|
||||
subvol_path = rctx->cur_subvol_path;
|
||||
} else {
|
||||
si = subvol_uuid_search(&rctx->sus, 0, clone_uuid, clone_ctransid,
|
||||
si = subvol_uuid_search(rctx->mnt_fd, 0, clone_uuid, clone_ctransid,
|
||||
NULL,
|
||||
subvol_search_by_received_uuid);
|
||||
if (IS_ERR_OR_NULL(si)) {
|
||||
@ -1109,7 +1107,6 @@ static int do_receive(struct btrfs_receive *rctx, const char *tomnt,
|
||||
rctx->dest_dir_path++;
|
||||
}
|
||||
|
||||
rctx->sus.mnt_fd = rctx->mnt_fd;
|
||||
while (!end) {
|
||||
ret = btrfs_read_and_process_send_stream(r_fd, &send_ops,
|
||||
rctx,
|
||||
|
11
cmds/send.c
11
cmds/send.c
@ -57,15 +57,13 @@ struct btrfs_send {
|
||||
u64 clone_sources_count;
|
||||
|
||||
char *root_path;
|
||||
struct subvol_uuid_search sus;
|
||||
};
|
||||
|
||||
static int get_root_id(struct btrfs_send *sctx, const char *path, u64 *root_id)
|
||||
{
|
||||
struct subvol_info *si;
|
||||
|
||||
si = subvol_uuid_search(&sctx->sus, 0, NULL, 0, path,
|
||||
subvol_search_by_path);
|
||||
si = subvol_uuid_search(sctx->mnt_fd, 0, NULL, 0, path, subvol_search_by_path);
|
||||
if (IS_ERR_OR_NULL(si)) {
|
||||
if (!si)
|
||||
return -ENOENT;
|
||||
@ -83,12 +81,12 @@ static struct subvol_info *get_parent(struct btrfs_send *sctx, u64 root_id)
|
||||
struct subvol_info *si_tmp;
|
||||
struct subvol_info *si;
|
||||
|
||||
si_tmp = subvol_uuid_search(&sctx->sus, root_id, NULL, 0, NULL,
|
||||
si_tmp = subvol_uuid_search(sctx->mnt_fd, root_id, NULL, 0, NULL,
|
||||
subvol_search_by_root_id);
|
||||
if (IS_ERR_OR_NULL(si_tmp))
|
||||
return si_tmp;
|
||||
|
||||
si = subvol_uuid_search(&sctx->sus, 0, si_tmp->parent_uuid, 0, NULL,
|
||||
si = subvol_uuid_search(sctx->mnt_fd, 0, si_tmp->parent_uuid, 0, NULL,
|
||||
subvol_search_by_uuid);
|
||||
free(si_tmp->path);
|
||||
free(si_tmp);
|
||||
@ -136,7 +134,7 @@ static int find_good_parent(struct btrfs_send *sctx, u64 root_id, u64 *found)
|
||||
|
||||
free(parent2->path);
|
||||
free(parent2);
|
||||
parent2 = subvol_uuid_search(&sctx->sus,
|
||||
parent2 = subvol_uuid_search(sctx->mnt_fd,
|
||||
sctx->clone_sources[i], NULL, 0, NULL,
|
||||
subvol_search_by_root_id);
|
||||
if (IS_ERR_OR_NULL(parent2)) {
|
||||
@ -348,7 +346,6 @@ static int init_root_path(struct btrfs_send *sctx, const char *subvol)
|
||||
goto out;
|
||||
}
|
||||
|
||||
sctx->sus.mnt_fd = sctx->mnt_fd;
|
||||
if (ret < 0) {
|
||||
errno = -ret;
|
||||
error("failed to initialize subvol search: %m");
|
||||
|
@ -273,8 +273,7 @@ static int btrfs_subvolid_resolve_sub(int fd, char *path, size_t *path_len,
|
||||
return 0;
|
||||
}
|
||||
|
||||
void subvol_uuid_search_add(struct subvol_uuid_search *s,
|
||||
struct subvol_info *si)
|
||||
void subvol_uuid_search_add(int mnt_fd, struct subvol_info *si)
|
||||
{
|
||||
if (si) {
|
||||
free(si->path);
|
||||
@ -282,20 +281,20 @@ void subvol_uuid_search_add(struct subvol_uuid_search *s,
|
||||
}
|
||||
}
|
||||
|
||||
struct subvol_info *subvol_uuid_search(struct subvol_uuid_search *s,
|
||||
struct subvol_info *subvol_uuid_search(int mnt_fd,
|
||||
u64 root_id, const u8 *uuid, u64 transid,
|
||||
const char *path,
|
||||
enum subvol_search_type type)
|
||||
{
|
||||
struct subvol_info *si;
|
||||
|
||||
si = subvol_uuid_search2(s, root_id, uuid, transid, path, type);
|
||||
si = subvol_uuid_search2(mnt_fd, root_id, uuid, transid, path, type);
|
||||
if (IS_ERR(si))
|
||||
return NULL;
|
||||
return si;
|
||||
}
|
||||
|
||||
struct subvol_info *subvol_uuid_search2(struct subvol_uuid_search *s,
|
||||
struct subvol_info *subvol_uuid_search2(int mnt_fd,
|
||||
u64 root_id, const u8 *uuid, u64 transid,
|
||||
const char *path,
|
||||
enum subvol_search_type type)
|
||||
@ -306,16 +305,16 @@ struct subvol_info *subvol_uuid_search2(struct subvol_uuid_search *s,
|
||||
|
||||
switch (type) {
|
||||
case subvol_search_by_received_uuid:
|
||||
ret = btrfs_lookup_uuid_received_subvol_item(s->mnt_fd, uuid,
|
||||
ret = btrfs_lookup_uuid_received_subvol_item(mnt_fd, uuid,
|
||||
&root_id);
|
||||
break;
|
||||
case subvol_search_by_uuid:
|
||||
ret = btrfs_lookup_uuid_subvol_item(s->mnt_fd, uuid, &root_id);
|
||||
ret = btrfs_lookup_uuid_subvol_item(mnt_fd, uuid, &root_id);
|
||||
break;
|
||||
case subvol_search_by_root_id:
|
||||
break;
|
||||
case subvol_search_by_path:
|
||||
ret = btrfs_get_root_id_by_sub_path(s->mnt_fd, path, &root_id);
|
||||
ret = btrfs_get_root_id_by_sub_path(mnt_fd, path, &root_id);
|
||||
break;
|
||||
default:
|
||||
ret = -EINVAL;
|
||||
@ -325,7 +324,7 @@ struct subvol_info *subvol_uuid_search2(struct subvol_uuid_search *s,
|
||||
if (ret)
|
||||
goto out;
|
||||
|
||||
ret = btrfs_read_root_item(s->mnt_fd, root_id, &root_item);
|
||||
ret = btrfs_read_root_item(mnt_fd, root_id, &root_item);
|
||||
if (ret)
|
||||
goto out;
|
||||
|
||||
@ -354,7 +353,7 @@ struct subvol_info *subvol_uuid_search2(struct subvol_uuid_search *s,
|
||||
ret = -ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
ret = btrfs_subvolid_resolve(s->mnt_fd, info->path,
|
||||
ret = btrfs_subvolid_resolve(mnt_fd, info->path,
|
||||
PATH_MAX, root_id);
|
||||
}
|
||||
|
||||
|
@ -43,10 +43,6 @@ struct subvol_info {
|
||||
char *path;
|
||||
};
|
||||
|
||||
struct subvol_uuid_search {
|
||||
int mnt_fd;
|
||||
};
|
||||
|
||||
/*
|
||||
* Search for a subvolume by given type (received uuid, root id, path), returns
|
||||
* pointer to newly allocated struct subvol_info or NULL in case it's not found
|
||||
@ -58,16 +54,15 @@ struct subvol_uuid_search {
|
||||
* new code unless you need to keep backward compatibility with older
|
||||
* btrfs-progs.
|
||||
*/
|
||||
struct subvol_info *subvol_uuid_search(struct subvol_uuid_search *s,
|
||||
struct subvol_info *subvol_uuid_search(int mnt_fd,
|
||||
u64 root_id, const u8 *uuid, u64 transid,
|
||||
const char *path,
|
||||
enum subvol_search_type type);
|
||||
struct subvol_info *subvol_uuid_search2(struct subvol_uuid_search *s,
|
||||
struct subvol_info *subvol_uuid_search2(int mnt_fd,
|
||||
u64 root_id, const u8 *uuid, u64 transid,
|
||||
const char *path,
|
||||
enum subvol_search_type type);
|
||||
void subvol_uuid_search_add(struct subvol_uuid_search *s,
|
||||
struct subvol_info *si);
|
||||
void subvol_uuid_search_add(int mnt_fd, struct subvol_info *si);
|
||||
|
||||
int btrfs_subvolid_resolve(int fd, char *path, size_t path_len, u64 subvol_id);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user