From: fdmanana@kernel.org
To: linux-btrfs@vger.kernel.org
Subject: [PATCH v2 7/8] btrfs: export comp_keys() from ctree.c as btrfs_comp_keys()
Date: Wed, 27 Sep 2023 12:09:27 +0100 [thread overview]
Message-ID: <222b6f1bd38e4317f1d26e47a79da563db359927.1695812791.git.fdmanana@suse.com> (raw)
In-Reply-To: <cover.1695812791.git.fdmanana@suse.com>
From: Filipe Manana <fdmanana@suse.com>
Export comp_keys() out of ctree.c, as btrfs_comp_keys(), so that in a
later patch we can move out defrag specific code from ctree.c into
defrag.c.
Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
fs/btrfs/ctree.c | 44 +++++++-------------------------------------
fs/btrfs/ctree.h | 31 +++++++++++++++++++++++++++++++
2 files changed, 38 insertions(+), 37 deletions(-)
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 005f0e1f98b3..b25b42ebcc2b 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -743,36 +743,6 @@ static int close_blocks(u64 blocknr, u64 other, u32 blocksize)
return 0;
}
-#ifdef __LITTLE_ENDIAN
-
-/*
- * Compare two keys, on little-endian the disk order is same as CPU order and
- * we can avoid the conversion.
- */
-static int comp_keys(const struct btrfs_disk_key *disk_key,
- const struct btrfs_key *k2)
-{
- const struct btrfs_key *k1 = (const struct btrfs_key *)disk_key;
-
- return btrfs_comp_cpu_keys(k1, k2);
-}
-
-#else
-
-/*
- * compare two keys in a memcmp fashion
- */
-static int comp_keys(const struct btrfs_disk_key *disk,
- const struct btrfs_key *k2)
-{
- struct btrfs_key k1;
-
- btrfs_disk_key_to_cpu(&k1, disk);
-
- return btrfs_comp_cpu_keys(&k1, k2);
-}
-#endif
-
/*
* same as comp_keys only with two btrfs_key's
*/
@@ -845,7 +815,7 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans,
int close = 1;
btrfs_node_key(parent, &disk_key, i);
- if (!progress_passed && comp_keys(&disk_key, progress) < 0)
+ if (!progress_passed && btrfs_comp_keys(&disk_key, progress) < 0)
continue;
progress_passed = 1;
@@ -958,7 +928,7 @@ int btrfs_bin_search(struct extent_buffer *eb, int first_slot,
tmp = &unaligned;
}
- ret = comp_keys(tmp, key);
+ ret = btrfs_comp_keys(tmp, key);
if (ret < 0)
low = mid + 1;
@@ -1995,7 +1965,7 @@ static int search_leaf(struct btrfs_trans_handle *trans,
* the extent buffer's header and we have recently accessed
* the header's level field.
*/
- ret = comp_keys(&first_key, key);
+ ret = btrfs_comp_keys(&first_key, key);
if (ret < 0) {
/*
* The first key is smaller than the key we want
@@ -2504,7 +2474,7 @@ static int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path)
*/
if (path->slots[0] < btrfs_header_nritems(path->nodes[0])) {
btrfs_item_key(path->nodes[0], &found_key, path->slots[0]);
- ret = comp_keys(&found_key, &orig_key);
+ ret = btrfs_comp_keys(&found_key, &orig_key);
if (ret == 0) {
if (path->slots[0] > 0) {
path->slots[0]--;
@@ -2519,7 +2489,7 @@ static int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path)
}
btrfs_item_key(path->nodes[0], &found_key, 0);
- ret = comp_keys(&found_key, &key);
+ ret = btrfs_comp_keys(&found_key, &key);
/*
* We might have had an item with the previous key in the tree right
* before we released our path. And after we released our path, that
@@ -2710,7 +2680,7 @@ void btrfs_set_item_key_safe(struct btrfs_trans_handle *trans,
slot = path->slots[0];
if (slot > 0) {
btrfs_item_key(eb, &disk_key, slot - 1);
- if (unlikely(comp_keys(&disk_key, new_key) >= 0)) {
+ if (unlikely(btrfs_comp_keys(&disk_key, new_key) >= 0)) {
btrfs_print_leaf(eb);
btrfs_crit(fs_info,
"slot %u key (%llu %u %llu) new key (%llu %u %llu)",
@@ -2724,7 +2694,7 @@ void btrfs_set_item_key_safe(struct btrfs_trans_handle *trans,
}
if (slot < btrfs_header_nritems(eb) - 1) {
btrfs_item_key(eb, &disk_key, slot + 1);
- if (unlikely(comp_keys(&disk_key, new_key) <= 0)) {
+ if (unlikely(btrfs_comp_keys(&disk_key, new_key) <= 0)) {
btrfs_print_leaf(eb);
btrfs_crit(fs_info,
"slot %u key (%llu %u %llu) new key (%llu %u %llu)",
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index c685952a544c..7b69abb5009c 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -9,6 +9,7 @@
#include <linux/pagemap.h>
#include "locking.h"
#include "fs.h"
+#include "accessors.h"
struct btrfs_trans_handle;
struct btrfs_transaction;
@@ -461,6 +462,36 @@ int btrfs_bin_search(struct extent_buffer *eb, int first_slot,
const struct btrfs_key *key, int *slot);
int __pure btrfs_comp_cpu_keys(const struct btrfs_key *k1, const struct btrfs_key *k2);
+
+#ifdef __LITTLE_ENDIAN
+
+/*
+ * Compare two keys, on little-endian the disk order is same as CPU order and
+ * we can avoid the conversion.
+ */
+static inline int btrfs_comp_keys(const struct btrfs_disk_key *disk_key,
+ const struct btrfs_key *k2)
+{
+ const struct btrfs_key *k1 = (const struct btrfs_key *)disk_key;
+
+ return btrfs_comp_cpu_keys(k1, k2);
+}
+
+#else
+
+/* Compare two keys in a memcmp fashion. */
+static inline int btrfs_comp_keys(const struct btrfs_disk_key *disk,
+ const struct btrfs_key *k2)
+{
+ struct btrfs_key k1;
+
+ btrfs_disk_key_to_cpu(&k1, disk);
+
+ return btrfs_comp_cpu_keys(&k1, k2);
+}
+
+#endif
+
int btrfs_previous_item(struct btrfs_root *root,
struct btrfs_path *path, u64 min_objectid,
int type);
--
2.40.1
next prev parent reply other threads:[~2023-09-27 11:09 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-26 12:45 [PATCH 0/8] btrfs: some fixes and cleanups around btrfs_cow_block() fdmanana
2023-09-26 12:45 ` [PATCH 1/8] btrfs: error out when COWing block using a stale transaction fdmanana
2023-09-26 17:31 ` David Sterba
2023-09-26 17:57 ` Filipe Manana
2023-09-26 18:18 ` Filipe Manana
2023-09-26 12:45 ` [PATCH 2/8] btrfs: error when COWing block from a root that is being deleted fdmanana
2023-09-26 12:45 ` [PATCH 3/8] btrfs: error out when reallocating block for defrag using a stale transaction fdmanana
2023-09-26 17:41 ` David Sterba
2023-09-26 12:45 ` [PATCH 4/8] btrfs: remove noinline attribute from btrfs_cow_block() fdmanana
2023-09-26 12:45 ` [PATCH 5/8] btrfs: use round_down() to align block offset at btrfs_cow_block() fdmanana
2023-09-26 12:45 ` [PATCH 6/8] btrfs: rename and export __btrfs_cow_block() fdmanana
2023-09-26 12:45 ` [PATCH 7/8] btrfs: export comp_keys() from ctree.c as btrfs_comp_keys() fdmanana
2023-09-26 12:45 ` [PATCH 8/8] btrfs: move btrfs_realloc_node() from ctree.c into defrag.h fdmanana
2023-09-27 11:09 ` [PATCH v2 0/8] btrfs: some fixes and cleanups around btrfs_cow_block() fdmanana
2023-09-27 11:09 ` [PATCH v2 1/8] btrfs: error out when COWing block using a stale transaction fdmanana
2023-09-27 11:09 ` [PATCH v2 2/8] btrfs: error when COWing block from a root that is being deleted fdmanana
2023-09-27 11:09 ` [PATCH v2 3/8] btrfs: error out when reallocating block for defrag using a stale transaction fdmanana
2023-09-27 11:09 ` [PATCH v2 4/8] btrfs: remove noinline attribute from btrfs_cow_block() fdmanana
2023-09-27 11:09 ` [PATCH v2 5/8] btrfs: use round_down() to align block offset at btrfs_cow_block() fdmanana
2023-09-27 11:09 ` [PATCH v2 6/8] btrfs: rename and export __btrfs_cow_block() fdmanana
2023-09-27 11:09 ` fdmanana [this message]
2023-09-27 11:09 ` [PATCH v2 8/8] btrfs: move btrfs_realloc_node() from ctree.c into defrag.c fdmanana
2023-09-29 14:35 ` David Sterba
2023-09-29 14:33 ` [PATCH v2 0/8] btrfs: some fixes and cleanups around btrfs_cow_block() 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=222b6f1bd38e4317f1d26e47a79da563db359927.1695812791.git.fdmanana@suse.com \
--to=fdmanana@kernel.org \
--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).