From e491d9cf25560dfcd26e733f12bf3fa2d7fc6f3b Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 30 Sep 2021 20:06:50 +0200 Subject: [PATCH] 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 --- cmds/receive.c | 9 +++------ cmds/send.c | 11 ++++------- common/send-utils.c | 19 +++++++++---------- common/send-utils.h | 11 +++-------- 4 files changed, 19 insertions(+), 31 deletions(-) diff --git a/cmds/receive.c b/cmds/receive.c index bdadc359..4d123a1f 100644 --- a/cmds/receive.c +++ b/cmds/receive.c @@ -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, diff --git a/cmds/send.c b/cmds/send.c index 45978dee..18102331 100644 --- a/cmds/send.c +++ b/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"); diff --git a/common/send-utils.c b/common/send-utils.c index dd9fce61..d3980436 100644 --- a/common/send-utils.c +++ b/common/send-utils.c @@ -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); } diff --git a/common/send-utils.h b/common/send-utils.h index fbf6c3b4..5ddd732c 100644 --- a/common/send-utils.h +++ b/common/send-utils.h @@ -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);