]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
btrfs: export comp_keys() from ctree.c as btrfs_comp_keys()
authorFilipe Manana <fdmanana@suse.com>
Wed, 27 Sep 2023 11:09:27 +0000 (12:09 +0100)
committerDavid Sterba <dsterba@suse.com>
Thu, 12 Oct 2023 14:44:14 +0000 (16:44 +0200)
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>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/ctree.c
fs/btrfs/ctree.h

index 85a228e8b46b9907ac4c6617d1e215ea13c9e650..abc1ad957f1153a044dde14cfbe5b88414b429e7 100644 (file)
@@ -749,36 +749,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
  */
@@ -851,7 +821,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;
@@ -964,7 +934,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;
@@ -2001,7 +1971,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
@@ -2510,7 +2480,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]--;
@@ -2525,7 +2495,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
@@ -2716,7 +2686,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)",
@@ -2730,7 +2700,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)",
index 9075b7162be315b44ed0702ded63cbc9b0ae4035..f84266f61767cc73b636d4d21dd42e44034388e8 100644 (file)
@@ -9,6 +9,7 @@
 #include <linux/pagemap.h>
 #include "locking.h"
 #include "fs.h"
+#include "accessors.h"
 
 struct btrfs_trans_handle;
 struct btrfs_transaction;
@@ -464,6 +465,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);