Skip to content

Commit

Permalink
btrfs-progs: reorder key initialization
Browse files Browse the repository at this point in the history
Use the objectid, type, offset natural order as it's more readable and
we're used to read keys like that.

Signed-off-by: David Sterba <[email protected]>
  • Loading branch information
kdave committed Apr 19, 2024
1 parent 6bc641b commit 247e2d2
Show file tree
Hide file tree
Showing 19 changed files with 44 additions and 43 deletions.
10 changes: 5 additions & 5 deletions check/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2785,8 +2785,8 @@ static int repair_inline_ram_bytes(struct btrfs_trans_handle *trans,
int ret;

key.objectid = rec->ino;
key.offset = 0;
key.type = BTRFS_EXTENT_DATA_KEY;
key.offset = 0;

ret = btrfs_search_slot(trans, root, &key, path, 0, 1);
if (ret > 0)
Expand Down Expand Up @@ -3018,8 +3018,8 @@ static int repair_inode_gen_original(struct btrfs_trans_handle *trans,
int ret;

key.objectid = rec->ino;
key.offset = 0;
key.type = BTRFS_INODE_ITEM_KEY;
key.offset = 0;

ret = btrfs_search_slot(trans, root, &key, path, 0, 1);
if (ret > 0) {
Expand Down Expand Up @@ -3920,12 +3920,12 @@ static int check_fs_roots(struct cache_tree *root_cache)
cache_tree_init(&wc.shared);

again:
key.offset = 0;
if (skip_root)
key.objectid = skip_root + 1;
else
key.objectid = 0;
key.type = BTRFS_ROOT_ITEM_KEY;
key.offset = 0;
ret = btrfs_search_slot(NULL, tree_root, &key, &path, 0, 0);
if (ret < 0) {
err = 1;
Expand Down Expand Up @@ -6937,8 +6937,8 @@ static int record_extent(struct btrfs_trans_handle *trans,
item_size += sizeof(*bi);

ins_key.objectid = rec->start;
ins_key.offset = rec->max_size;
ins_key.type = BTRFS_EXTENT_ITEM_KEY;
ins_key.offset = rec->max_size;

ret = btrfs_insert_empty_item(trans, extent_root, path,
&ins_key, item_size);
Expand Down Expand Up @@ -8935,9 +8935,9 @@ static int parse_tree_roots(struct list_head *normal_trees,
int slot;
int ret = 0;

key.offset = 0;
key.objectid = 0;
key.type = BTRFS_ROOT_ITEM_KEY;
key.offset = 0;
ret = btrfs_search_slot(NULL, gfs_info->tree_root, &key, &path, 0, 0);
if (ret < 0)
goto out;
Expand Down
12 changes: 6 additions & 6 deletions check/mode-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ int count_csum_range(u64 start, u64 len, u64 *found)
u16 csum_size = gfs_info->csum_size;

key.objectid = BTRFS_EXTENT_CSUM_OBJECTID;
key.offset = start;
key.type = BTRFS_EXTENT_CSUM_KEY;
key.offset = start;

ret = btrfs_search_slot(NULL, csum_root, &key, &path, 0, 0);
if (ret < 0)
Expand Down Expand Up @@ -417,8 +417,8 @@ static int get_highest_inode(struct btrfs_trans_handle *trans,
int ret;

key.objectid = BTRFS_LAST_FREE_OBJECTID;
key.offset = -1;
key.type = BTRFS_INODE_ITEM_KEY;
key.offset = -1;
ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
if (ret == 1) {
btrfs_item_key_to_cpu(path->nodes[0], &found_key,
Expand Down Expand Up @@ -745,8 +745,8 @@ static int find_file_type_dir_index(struct btrfs_root *root, u64 ino, u64 dirid,
int ret;

key.objectid = dirid;
key.offset = index;
key.type = BTRFS_DIR_INDEX_KEY;
key.offset = index;

ret = btrfs_search_slot(NULL, root, &key, &path, 0, 0);
if (ret > 0) {
Expand Down Expand Up @@ -798,8 +798,8 @@ static int find_file_type_dir_item(struct btrfs_root *root, u64 ino, u64 dirid,
int ret;

key.objectid = dirid;
key.offset = btrfs_name_hash(name, name_len);
key.type = BTRFS_DIR_INDEX_KEY;
key.offset = btrfs_name_hash(name, name_len);

ret = btrfs_search_slot(NULL, root, &key, &path, 0, 0);
if (ret > 0) {
Expand Down Expand Up @@ -1255,8 +1255,8 @@ static int fill_csum_tree_from_one_fs_root(struct btrfs_trans_handle *trans,
return -ENOMEM;

key.objectid = 0;
key.offset = 0;
key.type = 0;
key.offset = 0;
ret = btrfs_search_slot(NULL, cur_root, &key, &path, 0, 0);
if (ret < 0)
goto out;
Expand Down Expand Up @@ -1354,8 +1354,8 @@ static int fill_csum_tree_from_fs(struct btrfs_trans_handle *trans)
int ret = 0;

key.objectid = BTRFS_FS_TREE_OBJECTID;
key.offset = 0;
key.type = BTRFS_ROOT_ITEM_KEY;
key.offset = 0;
ret = btrfs_search_slot(NULL, tree_root, &key, &path, 0, 0);
if (ret < 0)
goto out;
Expand Down
8 changes: 4 additions & 4 deletions check/mode-lowmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -865,8 +865,8 @@ static int find_dir_index(struct btrfs_root *root, u64 dirid, u64 location_id,

/* search from the last index */
key.objectid = dirid;
key.offset = (u64)-1;
key.type = BTRFS_DIR_INDEX_KEY;
key.offset = (u64)-1;

ret = btrfs_search_slot(NULL, root, &key, &path, 0, 0);
if (ret < 0)
Expand Down Expand Up @@ -3935,8 +3935,8 @@ static int is_tree_reloc_root(struct extent_buffer *eb)
int ret = 0;

key.objectid = BTRFS_TREE_RELOC_OBJECTID;
key.offset = owner;
key.type = BTRFS_ROOT_ITEM_KEY;
key.offset = owner;

tree_reloc_root = btrfs_read_fs_root_no_cache(gfs_info, &key);
if (IS_ERR(tree_reloc_root))
Expand Down Expand Up @@ -5556,8 +5556,8 @@ int check_fs_roots_lowmem(void)
int err = 0;

key.objectid = BTRFS_FS_TREE_OBJECTID;
key.offset = 0;
key.type = BTRFS_ROOT_ITEM_KEY;
key.offset = 0;

ret = btrfs_search_slot(NULL, tree_root, &key, &path, 0, 0);
if (ret < 0) {
Expand Down Expand Up @@ -5670,8 +5670,8 @@ int check_chunks_and_extents_lowmem(void)
err |= ret;

key.objectid = BTRFS_EXTENT_TREE_OBJECTID;
key.offset = 0;
key.type = BTRFS_ROOT_ITEM_KEY;
key.offset = 0;

ret = btrfs_search_slot(NULL, gfs_info->tree_root, &key, &path, 0, 0);
if (ret) {
Expand Down
2 changes: 1 addition & 1 deletion check/qgroup-verify.c
Original file line number Diff line number Diff line change
Expand Up @@ -960,9 +960,9 @@ static int load_quota_info(struct btrfs_fs_info *info)
* items. The 2nd pass picks up relation items and glues them to their
* respective count structures.
*/
key.offset = 0;
key.objectid = search_relations ? 0 : BTRFS_QGROUP_RELATION_KEY;
key.type = 0;
key.offset = 0;

ret = btrfs_search_slot(NULL, root, &key, &path, 0, 0);
if (ret < 0) {
Expand Down
2 changes: 1 addition & 1 deletion check/repair.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ static int populate_used_from_extent_root(struct btrfs_root *root,
int slot;
int ret;

key.offset = 0;
key.objectid = 0;
key.type = BTRFS_EXTENT_ITEM_KEY;
key.offset = 0;
ret = btrfs_search_slot(NULL, root, &key, &path, 0, 0);
if (ret < 0)
return ret;
Expand Down
4 changes: 2 additions & 2 deletions cmds/filesystem-usage.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ static int load_chunk_info(int fd, struct array *chunkinfos)
sk->tree_id = BTRFS_CHUNK_TREE_OBJECTID;

sk->min_objectid = 0;
sk->max_objectid = (u64)-1;
sk->max_type = 0;
sk->min_type = (u8)-1;
sk->min_offset = 0;
sk->max_objectid = (u64)-1;
sk->max_type = 0;
sk->max_offset = (u64)-1;
sk->min_transid = 0;
sk->max_transid = (u64)-1;
Expand Down
2 changes: 1 addition & 1 deletion cmds/inspect-dump-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -580,9 +580,9 @@ static int cmd_inspect_dump_tree(const struct cmd_struct *cmd,
goto close_root;
}

key.offset = 0;
key.objectid = 0;
key.type = BTRFS_ROOT_ITEM_KEY;
key.offset = 0;
ret = btrfs_search_slot(NULL, tree_root_scan, &key, &path, 0, 0);
if (ret < 0) {
errno = -ret;
Expand Down
10 changes: 5 additions & 5 deletions cmds/inspect.c
Original file line number Diff line number Diff line change
Expand Up @@ -570,10 +570,10 @@ static int print_min_dev_size(int fd, u64 devid)
sk = btrfs_tree_search_sk(&args);
sk->tree_id = BTRFS_DEV_TREE_OBJECTID;
sk->min_objectid = devid;
sk->max_objectid = devid;
sk->max_type = BTRFS_DEV_EXTENT_KEY;
sk->min_type = BTRFS_DEV_EXTENT_KEY;
sk->min_offset = 0;
sk->max_objectid = devid;
sk->max_type = BTRFS_DEV_EXTENT_KEY;
sk->max_offset = (u64)-1;
sk->min_transid = 0;
sk->max_transid = (u64)-1;
Expand Down Expand Up @@ -980,10 +980,10 @@ static u64 fill_usage(int fd, u64 lstart)
sk = btrfs_tree_search_sk(&args);
sk->tree_id = BTRFS_EXTENT_TREE_OBJECTID;
sk->min_objectid = lstart;
sk->max_objectid = lstart;
sk->min_type = BTRFS_BLOCK_GROUP_ITEM_KEY;
sk->max_type = BTRFS_BLOCK_GROUP_ITEM_KEY;
sk->min_offset = 0;
sk->max_objectid = lstart;
sk->max_type = BTRFS_BLOCK_GROUP_ITEM_KEY;
sk->max_offset = (u64)-1;
sk->max_transid = (u64)-1;
sk->nr_items = 1;
Expand Down Expand Up @@ -1089,8 +1089,8 @@ static int cmd_inspect_list_chunks(const struct cmd_struct *cmd,
sk = btrfs_tree_search_sk(&args);
sk->tree_id = BTRFS_CHUNK_TREE_OBJECTID;
sk->min_objectid = BTRFS_FIRST_CHUNK_TREE_OBJECTID;
sk->max_objectid = BTRFS_FIRST_CHUNK_TREE_OBJECTID;
sk->min_type = BTRFS_CHUNK_ITEM_KEY;
sk->max_objectid = BTRFS_FIRST_CHUNK_TREE_OBJECTID;
sk->max_type = BTRFS_CHUNK_ITEM_KEY;
sk->max_offset = (u64)-1;
sk->max_transid = (u64)-1;
Expand Down
7 changes: 4 additions & 3 deletions cmds/qgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -1354,9 +1354,9 @@ static int __qgroups_search(int fd, struct btrfs_tree_search_args *args,
* record the mins in sk so we can make sure the
* next search doesn't repeat this root
*/
sk->min_objectid = key.objectid;
sk->min_type = key.type;
sk->min_offset = key.offset;
sk->min_objectid = key.objectid;
}
sk->nr_items = 4096;
/*
Expand Down Expand Up @@ -1410,10 +1410,11 @@ int btrfs_qgroup_query(int fd, u64 qgroupid, struct btrfs_qgroup_stats *stats)
memset(&args, 0, sizeof(args));
sk = btrfs_tree_search_sk(&args);
sk->tree_id = BTRFS_QUOTA_TREE_OBJECTID;
sk->min_objectid = 0;
sk->min_type = BTRFS_QGROUP_INFO_KEY;
sk->max_type = BTRFS_QGROUP_LIMIT_KEY;
sk->max_objectid = 0;
sk->min_offset = qgroupid;
sk->max_objectid = 0;
sk->max_type = BTRFS_QGROUP_LIMIT_KEY;
sk->max_offset = qgroupid;
sk->max_transid = (u64)-1;
sk->nr_items = 4096;
Expand Down
4 changes: 2 additions & 2 deletions cmds/rescue-chunk-recover.c
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,8 @@ static int check_chunk_by_metadata(struct recover_control *rc,
stripe = &chunk->stripes[i];

key.objectid = stripe->devid;
key.offset = stripe->offset;
key.type = BTRFS_DEV_EXTENT_KEY;
key.offset = stripe->offset;

ret = btrfs_search_slot(NULL, dev_root, &key, &path, 0, 0);
if (ret < 0) {
Expand Down Expand Up @@ -1016,8 +1016,8 @@ static int block_group_remove_all_extent_items(struct btrfs_trans_handle *trans,
root = btrfs_extent_root(fs_info, start);

key.objectid = start;
key.offset = 0;
key.type = BTRFS_EXTENT_ITEM_KEY;
key.offset = 0;
again:
ret = btrfs_search_slot(trans, root, &key, &path, -1, 1);
if (ret < 0)
Expand Down
2 changes: 1 addition & 1 deletion cmds/restore.c
Original file line number Diff line number Diff line change
Expand Up @@ -1167,9 +1167,9 @@ static int do_list_roots(struct btrfs_root *root)

root = root->fs_info->tree_root;

key.offset = 0;
key.objectid = 0;
key.type = BTRFS_ROOT_ITEM_KEY;
key.offset = 0;
ret = btrfs_search_slot(NULL, root, &key, &path, 0, 0);
if (ret < 0) {
error("failed search next root item: %d", ret);
Expand Down
2 changes: 1 addition & 1 deletion cmds/subvolume.c
Original file line number Diff line number Diff line change
Expand Up @@ -972,9 +972,9 @@ static u64 find_root_gen(int fd)
* them.
*/
sk->min_objectid = ino_args.treeid;
sk->min_type = BTRFS_ROOT_ITEM_KEY;
sk->max_objectid = ino_args.treeid;
sk->max_type = BTRFS_ROOT_ITEM_KEY;
sk->min_type = BTRFS_ROOT_ITEM_KEY;
sk->max_offset = (u64)-1;
sk->max_transid = (u64)-1;
sk->nr_items = 4096;
Expand Down
2 changes: 1 addition & 1 deletion common/extent-tree-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ static int __btrfs_record_file_extent(struct btrfs_trans_handle *trans,
}
btrfs_release_path(path);
ins_key.objectid = objectid;
ins_key.offset = file_pos;
ins_key.type = BTRFS_EXTENT_DATA_KEY;
ins_key.offset = file_pos;
ret = btrfs_insert_empty_item(trans, root, path, &ins_key, sizeof(*fi));
if (ret)
goto fail;
Expand Down
4 changes: 2 additions & 2 deletions common/fsfeatures.c
Original file line number Diff line number Diff line change
Expand Up @@ -730,10 +730,10 @@ int btrfs_tree_search2_ioctl_supported(int fd)
*/
sk->tree_id = BTRFS_ROOT_TREE_OBJECTID;
sk->min_objectid = BTRFS_EXTENT_TREE_OBJECTID;
sk->max_objectid = BTRFS_EXTENT_TREE_OBJECTID;
sk->min_type = BTRFS_ROOT_ITEM_KEY;
sk->max_type = BTRFS_ROOT_ITEM_KEY;
sk->min_offset = 0;
sk->max_objectid = BTRFS_EXTENT_TREE_OBJECTID;
sk->max_type = BTRFS_ROOT_ITEM_KEY;
sk->max_offset = (u64)-1;
sk->min_transid = 0;
sk->max_transid = (u64)-1;
Expand Down
4 changes: 2 additions & 2 deletions common/send-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ static int btrfs_read_root_item_raw(int mnt_fd, u64 root_id, size_t buf_len,
* them.
*/
sk->min_objectid = root_id;
sk->min_type = BTRFS_ROOT_ITEM_KEY;
sk->max_objectid = root_id;
sk->max_type = BTRFS_ROOT_ITEM_KEY;
sk->min_type = BTRFS_ROOT_ITEM_KEY;
sk->max_offset = (u64)-1;
sk->max_transid = (u64)-1;
sk->nr_items = 4096;
Expand Down Expand Up @@ -210,8 +210,8 @@ static int btrfs_subvolid_resolve_sub(int fd, char *path, size_t *path_len,
sk = btrfs_tree_search_sk(&args);
sk->tree_id = BTRFS_ROOT_TREE_OBJECTID;
sk->min_objectid = subvol_id;
sk->max_objectid = subvol_id;
sk->min_type = BTRFS_ROOT_BACKREF_KEY;
sk->max_objectid = subvol_id;
sk->max_type = BTRFS_ROOT_BACKREF_KEY;
sk->max_offset = (u64)-1;
sk->max_transid = (u64)-1;
Expand Down
2 changes: 1 addition & 1 deletion common/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ static int search_chunk_tree_for_fs_info(int fd,
sk = btrfs_tree_search_sk(&args);
sk->tree_id = BTRFS_CHUNK_TREE_OBJECTID;
sk->min_objectid = BTRFS_DEV_ITEMS_OBJECTID;
sk->max_objectid = BTRFS_DEV_ITEMS_OBJECTID;
sk->min_type = BTRFS_DEV_ITEM_KEY;
sk->max_objectid = BTRFS_DEV_ITEMS_OBJECTID;
sk->max_type = BTRFS_DEV_ITEM_KEY;
sk->min_transid = 0;
sk->max_transid = (u64)-1;
Expand Down
4 changes: 2 additions & 2 deletions convert/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1274,8 +1274,8 @@ static int do_convert(const char *devname, u32 convert_flags, u32 nodesize,
snprintf(subvol_name, sizeof(subvol_name), "%s_saved",
cctx.convert_ops->name);
key.objectid = CONV_IMAGE_SUBVOL_OBJECTID;
key.offset = (u64)-1;
key.type = BTRFS_ROOT_ITEM_KEY;
key.offset = (u64)-1;
image_root = btrfs_read_fs_root(root->fs_info, &key);
if (!image_root) {
error("unable to create image subvolume");
Expand Down Expand Up @@ -1486,8 +1486,8 @@ static int check_convert_image(struct btrfs_root *image_root, u64 ino,
int ret;

key.objectid = ino;
key.offset = 0;
key.type = BTRFS_EXTENT_DATA_KEY;
key.offset = 0;

ret = btrfs_search_slot(NULL, image_root, &key, &path, 0, 0);
/*
Expand Down
2 changes: 1 addition & 1 deletion convert/source-fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ int convert_insert_dirent(struct btrfs_trans_handle *trans,
struct btrfs_inode_item dummy_iitem = { 0 };
struct btrfs_key location = {
.objectid = objectid,
.offset = 0,
.type = BTRFS_INODE_ITEM_KEY,
.offset = 0,
};

ret = btrfs_insert_dir_item(trans, root, name, name_len,
Expand Down
Loading

0 comments on commit 247e2d2

Please sign in to comment.