From 8ea15251e76f4727bbb4da4216e24ca13d7efa7a Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Wed, 23 Aug 2023 10:32:34 -0400 Subject: [PATCH] btrfs-progs: update btrfs_set_item_key_safe to match kernel definition In the kernel we just pass the btrfs_fs_info, and we const'ify the new_key. Update the btrfs-progs definition to make syncing ctree.c easier. Signed-off-by: Josef Bacik Signed-off-by: David Sterba --- kernel-shared/ctree.c | 12 +++++------- kernel-shared/ctree.h | 5 +++-- kernel-shared/file-item.c | 3 +-- tune/change-csum.c | 8 +------- 4 files changed, 10 insertions(+), 18 deletions(-) diff --git a/kernel-shared/ctree.c b/kernel-shared/ctree.c index 6a232a07..0186ae21 100644 --- a/kernel-shared/ctree.c +++ b/kernel-shared/ctree.c @@ -1514,8 +1514,9 @@ void btrfs_fixup_low_keys( struct btrfs_path *path, struct btrfs_disk_key *key, * This function isn't completely safe. It's the caller's responsibility * that the new key won't break the order */ -int btrfs_set_item_key_safe(struct btrfs_root *root, struct btrfs_path *path, - struct btrfs_key *new_key) +void btrfs_set_item_key_safe(struct btrfs_fs_info *fs_info, + struct btrfs_path *path, + const struct btrfs_key *new_key) { struct btrfs_disk_key disk_key; struct extent_buffer *eb; @@ -1525,13 +1526,11 @@ int btrfs_set_item_key_safe(struct btrfs_root *root, struct btrfs_path *path, slot = path->slots[0]; if (slot > 0) { btrfs_item_key(eb, &disk_key, slot - 1); - if (btrfs_comp_keys(&disk_key, new_key) >= 0) - return -1; + BUG_ON(btrfs_comp_keys(&disk_key, new_key) >= 0); } if (slot < btrfs_header_nritems(eb) - 1) { btrfs_item_key(eb, &disk_key, slot + 1); - if (btrfs_comp_keys(&disk_key, new_key) <= 0) - return -1; + BUG_ON(btrfs_comp_keys(&disk_key, new_key) <= 0); } btrfs_cpu_key_to_disk(&disk_key, new_key); @@ -1539,7 +1538,6 @@ int btrfs_set_item_key_safe(struct btrfs_root *root, struct btrfs_path *path, btrfs_mark_buffer_dirty(eb); if (slot == 0) btrfs_fixup_low_keys(path, &disk_key, 1); - return 0; } /* diff --git a/kernel-shared/ctree.h b/kernel-shared/ctree.h index 499833bc..a49e6ca9 100644 --- a/kernel-shared/ctree.h +++ b/kernel-shared/ctree.h @@ -1063,8 +1063,9 @@ int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path); int btrfs_leaf_free_space(struct extent_buffer *leaf); void btrfs_fixup_low_keys(struct btrfs_path *path, struct btrfs_disk_key *key, int level); -int btrfs_set_item_key_safe(struct btrfs_root *root, struct btrfs_path *path, - struct btrfs_key *new_key); +void btrfs_set_item_key_safe(struct btrfs_fs_info *fs_info, + struct btrfs_path *path, + const struct btrfs_key *new_key); void btrfs_set_item_key_unsafe(struct btrfs_root *root, struct btrfs_path *path, struct btrfs_key *new_key); diff --git a/kernel-shared/file-item.c b/kernel-shared/file-item.c index 1a2f5f14..30a89094 100644 --- a/kernel-shared/file-item.c +++ b/kernel-shared/file-item.c @@ -379,8 +379,7 @@ static noinline int truncate_one_csum(struct btrfs_root *root, BUG_ON(ret); key->offset = end_byte; - ret = btrfs_set_item_key_safe(root, path, key); - BUG_ON(ret); + btrfs_set_item_key_safe(root->fs_info, path, key); } else { BUG(); } diff --git a/tune/change-csum.c b/tune/change-csum.c index 17372890..9edddb05 100644 --- a/tune/change-csum.c +++ b/tune/change-csum.c @@ -459,13 +459,7 @@ static int change_csum_objectids(struct btrfs_fs_info *fs_info) btrfs_item_key_to_cpu(path.nodes[0], &found_key, i); found_key.objectid = BTRFS_EXTENT_CSUM_OBJECTID; path.slots[0] = i; - ret = btrfs_set_item_key_safe(csum_root, &path, &found_key); - if (ret < 0) { - errno = -ret; - error("failed to set item key for data csum at logical %llu: %m", - found_key.offset); - goto out; - } + btrfs_set_item_key_safe(fs_info, &path, &found_key); } btrfs_release_path(&path); }