From: Josef Bacik <josef@toxicpanda.com>
To: linux-btrfs@vger.kernel.org, kernel-team@fb.com
Subject: [PATCH 14/38] btrfs-progs: move btrfs_set_item_key_unsafe to check/
Date: Wed, 23 Aug 2023 10:32:40 -0400 [thread overview]
Message-ID: <3c55d9a5d40e799d82bea269de589a41e44a6b56.1692800904.git.josef@toxicpanda.com> (raw)
In-Reply-To: <cover.1692800904.git.josef@toxicpanda.com>
This helper exists for check and for btrfs-corrupt-block. Move the
helper and the btrfs_fixup_low_keys helper into check/repair.[ch] so we
can keep the kernel-shared sources close to the upstream kernel.
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
btrfs-corrupt-block.c | 1 +
check/repair.c | 47 +++++++++++++++++++++++++++++++++++++++++++
check/repair.h | 5 +++++
kernel-shared/ctree.c | 40 +++++++++---------------------------
kernel-shared/ctree.h | 5 -----
5 files changed, 62 insertions(+), 36 deletions(-)
diff --git a/btrfs-corrupt-block.c b/btrfs-corrupt-block.c
index 3c742cc8..3e741c08 100644
--- a/btrfs-corrupt-block.c
+++ b/btrfs-corrupt-block.c
@@ -35,6 +35,7 @@
#include "common/messages.h"
#include "common/string-utils.h"
#include "cmds/commands.h"
+#include "check/repair.h"
#define FIELD_BUF_LEN 80
diff --git a/check/repair.c b/check/repair.c
index eacf4506..d8900c41 100644
--- a/check/repair.c
+++ b/check/repair.c
@@ -33,6 +33,53 @@
int opt_check_repair = 0;
+/*
+ * adjust the pointers going up the tree, starting at level
+ * making sure the right key of each node is points to 'key'.
+ * This is used after shifting pointers to the left, so it stops
+ * fixing up pointers when a given leaf/node is not in slot 0 of the
+ * higher levels
+ */
+void btrfs_fixup_low_keys(struct btrfs_path *path, struct btrfs_disk_key *key,
+ int level)
+{
+ int i;
+ struct extent_buffer *t;
+
+ for (i = level; i < BTRFS_MAX_LEVEL; i++) {
+ int tslot = path->slots[i];
+ if (!path->nodes[i])
+ break;
+ t = path->nodes[i];
+ btrfs_set_node_key(t, key, tslot);
+ btrfs_mark_buffer_dirty(path->nodes[i]);
+ if (tslot != 0)
+ break;
+ }
+}
+
+/*
+ * update an item key without the safety checks. This is meant to be called by
+ * fsck only.
+ */
+void btrfs_set_item_key_unsafe(struct btrfs_root *root,
+ struct btrfs_path *path,
+ struct btrfs_key *new_key)
+{
+ struct btrfs_disk_key disk_key;
+ struct extent_buffer *eb;
+ int slot;
+
+ eb = path->nodes[0];
+ slot = path->slots[0];
+
+ btrfs_cpu_key_to_disk(&disk_key, new_key);
+ btrfs_set_item_key(eb, &disk_key, slot);
+ btrfs_mark_buffer_dirty(eb);
+ if (slot == 0)
+ btrfs_fixup_low_keys(path, &disk_key, 1);
+}
+
int btrfs_add_corrupt_extent_record(struct btrfs_fs_info *info,
struct btrfs_key *first_key,
u64 start, u64 len, int level)
diff --git a/check/repair.h b/check/repair.h
index 3c44a498..81440a87 100644
--- a/check/repair.h
+++ b/check/repair.h
@@ -45,5 +45,10 @@ int btrfs_mark_used_blocks(struct btrfs_fs_info *fs_info,
struct extent_io_tree *tree);
enum btrfs_tree_block_status btrfs_check_block_for_repair(struct extent_buffer *eb,
struct btrfs_key *first_key);
+void btrfs_set_item_key_unsafe(struct btrfs_root *root,
+ struct btrfs_path *path,
+ struct btrfs_key *new_key);
+void btrfs_fixup_low_keys(struct btrfs_path *path, struct btrfs_disk_key *key,
+ int level);
#endif
diff --git a/kernel-shared/ctree.c b/kernel-shared/ctree.c
index bbbb2cc3..8eba7812 100644
--- a/kernel-shared/ctree.c
+++ b/kernel-shared/ctree.c
@@ -1485,8 +1485,8 @@ again:
* fixing up pointers when a given leaf/node is not in slot 0 of the
* higher levels
*/
-void btrfs_fixup_low_keys( struct btrfs_path *path, struct btrfs_disk_key *key,
- int level)
+static void fixup_low_keys(struct btrfs_path *path, struct btrfs_disk_key *key,
+ int level)
{
int i;
struct extent_buffer *t;
@@ -1532,29 +1532,7 @@ void btrfs_set_item_key_safe(struct btrfs_fs_info *fs_info,
btrfs_set_item_key(eb, &disk_key, slot);
btrfs_mark_buffer_dirty(eb);
if (slot == 0)
- btrfs_fixup_low_keys(path, &disk_key, 1);
-}
-
-/*
- * update an item key without the safety checks. This is meant to be called by
- * fsck only.
- */
-void btrfs_set_item_key_unsafe(struct btrfs_root *root,
- struct btrfs_path *path,
- struct btrfs_key *new_key)
-{
- struct btrfs_disk_key disk_key;
- struct extent_buffer *eb;
- int slot;
-
- eb = path->nodes[0];
- slot = path->slots[0];
-
- btrfs_cpu_key_to_disk(&disk_key, new_key);
- btrfs_set_item_key(eb, &disk_key, slot);
- btrfs_mark_buffer_dirty(eb);
- if (slot == 0)
- btrfs_fixup_low_keys(path, &disk_key, 1);
+ fixup_low_keys(path, &disk_key, 1);
}
/*
@@ -2213,7 +2191,7 @@ static int push_leaf_left(struct btrfs_trans_handle *trans, struct btrfs_root
btrfs_mark_buffer_dirty(right);
btrfs_item_key(right, &disk_key, 0);
- btrfs_fixup_low_keys(path, &disk_key, 1);
+ fixup_low_keys(path, &disk_key, 1);
/* then fixup the leaf pointer in the path */
if (path->slots[0] < push_items) {
@@ -2439,7 +2417,7 @@ again:
path->nodes[0] = right;
path->slots[0] = 0;
if (path->slots[1] == 0)
- btrfs_fixup_low_keys(path, &disk_key, 1);
+ fixup_low_keys(path, &disk_key, 1);
}
btrfs_mark_buffer_dirty(right);
return ret;
@@ -2644,7 +2622,7 @@ void btrfs_truncate_item(struct btrfs_path *path, u32 new_size, int from_end)
btrfs_set_disk_key_offset(&disk_key, offset + size_diff);
btrfs_set_item_key(leaf, &disk_key, slot);
if (slot == 0)
- btrfs_fixup_low_keys(path, &disk_key, 1);
+ fixup_low_keys(path, &disk_key, 1);
}
btrfs_set_item_size(leaf, slot, new_size);
@@ -2808,7 +2786,7 @@ int btrfs_insert_empty_items(struct btrfs_trans_handle *trans,
ret = 0;
if (slot == 0) {
btrfs_cpu_key_to_disk(&disk_key, cpu_key);
- btrfs_fixup_low_keys(path, &disk_key, 1);
+ fixup_low_keys(path, &disk_key, 1);
}
if (btrfs_leaf_free_space(leaf) < 0) {
@@ -2881,7 +2859,7 @@ int btrfs_del_ptr(struct btrfs_root *root, struct btrfs_path *path,
struct btrfs_disk_key disk_key;
btrfs_node_key(parent, &disk_key, 0);
- btrfs_fixup_low_keys(path, &disk_key, level + 1);
+ fixup_low_keys(path, &disk_key, level + 1);
}
btrfs_mark_buffer_dirty(parent);
return ret;
@@ -2979,7 +2957,7 @@ int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
struct btrfs_disk_key disk_key;
btrfs_item_key(leaf, &disk_key, 0);
- btrfs_fixup_low_keys(path, &disk_key, 1);
+ fixup_low_keys(path, &disk_key, 1);
}
/* delete the leaf if it is mostly empty */
diff --git a/kernel-shared/ctree.h b/kernel-shared/ctree.h
index 0d9b75bf..3e00d69b 100644
--- a/kernel-shared/ctree.h
+++ b/kernel-shared/ctree.h
@@ -1052,14 +1052,9 @@ static inline int btrfs_next_item(struct btrfs_root *root,
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);
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);
int btrfs_super_csum_size(const struct btrfs_super_block *sb);
const char *btrfs_super_csum_name(u16 csum_type);
--
2.41.0
next prev parent reply other threads:[~2023-08-23 14:33 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-23 14:32 [PATCH 00/38] btrfs-progs: sync ctree.c into btrfs-progs Josef Bacik
2023-08-23 14:32 ` [PATCH 01/38] btrfs-progs: stop using add_root_to_dirty_list in check Josef Bacik
2023-08-23 14:32 ` [PATCH 02/38] btrfs-progs: remove useless add_root_to_dirty_list call in mkfs Josef Bacik
2023-08-29 6:32 ` Qu Wenruo
2023-08-29 6:42 ` Qu Wenruo
2023-08-23 14:32 ` [PATCH 03/38] btrfs-progs: remove add_root_to_dirty_list call when creating free space tree Josef Bacik
2023-08-23 14:32 ` [PATCH 04/38] btrfs-progs: make add_root_to_dirty_list static and unexport it Josef Bacik
2023-08-23 14:32 ` [PATCH 05/38] btrfs-progs: pass btrfs_trans_handle through btrfs_clear_buffer_dirty Josef Bacik
2023-08-23 14:32 ` [PATCH 06/38] btrfs-progs: update read_node_slot to match the kernel definition Josef Bacik
2023-08-23 14:32 ` [PATCH 07/38] btrfs-progs: update btrfs_bin_search " Josef Bacik
2023-08-23 14:32 ` [PATCH 08/38] btrfs-progs: update btrfs_set_item_key_safe to match " Josef Bacik
2023-08-23 14:32 ` [PATCH 09/38] btrfs-progs: update btrfs_print_leaf to match the " Josef Bacik
2023-08-23 14:32 ` [PATCH 10/38] btrfs-progs: update btrfs_truncate_item " Josef Bacik
2023-08-23 14:32 ` [PATCH 11/38] btrfs-progs: update btrfs_extend_item " Josef Bacik
2023-08-23 14:32 ` [PATCH 12/38] btrfs-progs: sync memcpy_extent_buffer from the kernel Josef Bacik
2023-08-23 14:32 ` [PATCH 13/38] btrfs-progs: drop btrfs_init_path Josef Bacik
2023-08-23 17:25 ` David Sterba
2023-08-23 14:32 ` Josef Bacik [this message]
2023-08-23 14:32 ` [PATCH 15/38] btrfs-progs: move btrfs_record_file_extent and code into a new file Josef Bacik
2023-08-23 14:32 ` [PATCH 16/38] btrfs-progs: make a local copy of btrfs_next_sibling_block in print-tree.c Josef Bacik
2023-08-23 14:32 ` [PATCH 17/38] btrfs-progs: don't set the ->commit_root in btrfs_create_tree Josef Bacik
2023-08-23 14:32 ` [PATCH 18/38] btrfs-progs: remove btrfs_create_root Josef Bacik
2023-08-23 14:32 ` [PATCH 19/38] btrfs-progs: move btrfs_uuid_tree_add into mkfs/main.c Josef Bacik
2023-08-23 14:32 ` [PATCH 20/38] btrfs-progs: make btrfs_del_ptr a void Josef Bacik
2023-08-23 14:32 ` [PATCH 21/38] btrfs-progs: replace blocksize with parent argument for btrfs_alloc_tree_block Josef Bacik
2023-08-23 14:32 ` [PATCH 22/38] btrfs-progs: use path->search_for_extension Josef Bacik
2023-08-23 14:32 ` [PATCH 23/38] btrfs-progs: init new tree blocks in btrfs_alloc_tree_block Josef Bacik
2023-08-23 14:32 ` [PATCH 24/38] btrfs-progs: add dwarves to the package list for ci Josef Bacik
2023-08-23 14:32 ` [PATCH 25/38] btrfs-progs: add kerncompat helpers for ctree.c sync Josef Bacik
2023-08-23 14:32 ` [PATCH 26/38] btrfs-progs: add trans_lock to fs_info Josef Bacik
2023-08-23 14:32 ` [PATCH 27/38] btrfs-progs: add commit_root_sem to btrfs_fs_info Josef Bacik
2023-08-23 14:32 ` [PATCH 28/38] btrfs-progs: update btrfs_cow_block to match the in-kernel definition Josef Bacik
2023-08-23 14:32 ` [PATCH 29/38] btrfs-progs: update btrfs_insert_empty_items to match the kernel Josef Bacik
2023-08-23 14:32 ` [PATCH 30/38] btrfs-progs: update btrfs_insert_empty_item " Josef Bacik
2023-08-23 14:32 ` [PATCH 31/38] btrfs-progs: update btrfs_del_ptr " Josef Bacik
2023-08-23 14:32 ` [PATCH 32/38] btrfs-progs: update btrfs_insert_item " Josef Bacik
2023-08-23 14:32 ` [PATCH 33/38] btrfs-progs: update btrfs_leaf_free_space " Josef Bacik
2023-08-23 14:33 ` [PATCH 34/38] btrfs-progs: use btrfs_tree_parent_check for btrfs_read_extent_buffer Josef Bacik
2023-08-23 14:33 ` [PATCH 35/38] btrfs-progs: update read_tree_block to take a btrfs_parent_tree_check Josef Bacik
2023-08-23 14:33 ` [PATCH 36/38] btrfs-progs: inline btrfs_name_hash and btrfs_extref_hash Josef Bacik
2023-08-23 14:33 ` [PATCH 37/38] btrfs-progs: update btrfs_split_item to match the in-kernel definition Josef Bacik
2023-08-23 14:33 ` [PATCH 38/38] btrfs-progs: sync ctree.c from kernel Josef Bacik
2023-08-23 17:41 ` [PATCH 00/38] btrfs-progs: sync ctree.c into btrfs-progs David Sterba
2023-08-25 21:35 ` David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3c55d9a5d40e799d82bea269de589a41e44a6b56.1692800904.git.josef@toxicpanda.com \
--to=josef@toxicpanda.com \
--cc=kernel-team@fb.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).