btrfs: rename the functions to search for bits in extent ranges
authorFilipe Manana <fdmanana@suse.com>
Thu, 3 Apr 2025 14:19:49 +0000 (15:19 +0100)
committerDavid Sterba <dsterba@suse.com>
Thu, 15 May 2025 12:30:44 +0000 (14:30 +0200)
These functions are exported so they should have a 'btrfs_' prefix by
convention, to make it clear they are btrfs specific and to avoid
collisions with functions from elsewhere in the kernel.

So add a 'btrfs_' prefix to their name to make it clear they are from
btrfs.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
12 files changed:
fs/btrfs/block-group.c
fs/btrfs/dev-replace.c
fs/btrfs/disk-io.c
fs/btrfs/extent-io-tree.c
fs/btrfs/extent-io-tree.h
fs/btrfs/extent-tree.c
fs/btrfs/file-item.c
fs/btrfs/free-space-cache.c
fs/btrfs/relocation.c
fs/btrfs/tests/extent-io-tests.c
fs/btrfs/transaction.c
fs/btrfs/volumes.c

index 944c355bf051017f9d3249a9a28d02bb86fca74f..91807d2943669947d5edcd0e6ca2011ac7bcf3d8 100644 (file)
@@ -525,9 +525,9 @@ int btrfs_add_new_free_space(struct btrfs_block_group *block_group, u64 start,
                *total_added_ret = 0;
 
        while (start < end) {
-               if (!find_first_extent_bit(&info->excluded_extents, start,
-                                          &extent_start, &extent_end,
-                                          EXTENT_DIRTY, NULL))
+               if (!btrfs_find_first_extent_bit(&info->excluded_extents, start,
+                                                &extent_start, &extent_end,
+                                                EXTENT_DIRTY, NULL))
                        break;
 
                if (extent_start <= start) {
index db94c7f2246124c9d17b9d85568660abbe25b24c..55608ac8dbe02a47a4dfd1cb95f80dc36cb82f2e 100644 (file)
@@ -794,9 +794,9 @@ static int btrfs_set_target_alloc_state(struct btrfs_device *srcdev,
 
        lockdep_assert_held(&srcdev->fs_info->chunk_mutex);
 
-       while (find_first_extent_bit(&srcdev->alloc_state, start,
-                                    &found_start, &found_end,
-                                    CHUNK_ALLOCATED, &cached_state)) {
+       while (btrfs_find_first_extent_bit(&srcdev->alloc_state, start,
+                                          &found_start, &found_end,
+                                          CHUNK_ALLOCATED, &cached_state)) {
                ret = btrfs_set_extent_bit(&tgtdev->alloc_state, found_start,
                                           found_end, CHUNK_ALLOCATED, NULL);
                if (ret)
index cd99fab7af7a8d735e6570ae9df3bd5237eeeba1..2586dd05483a177501693f34725d31e20d3581f9 100644 (file)
@@ -4237,8 +4237,9 @@ static void warn_about_uncommitted_trans(struct btrfs_fs_info *fs_info)
                u64 found_end;
 
                found = true;
-               while (find_first_extent_bit(&trans->dirty_pages, cur,
-                       &found_start, &found_end, EXTENT_DIRTY, &cached)) {
+               while (btrfs_find_first_extent_bit(&trans->dirty_pages, cur,
+                                                  &found_start, &found_end,
+                                                  EXTENT_DIRTY, &cached)) {
                        dirty_bytes += found_end + 1 - found_start;
                        cur = found_end + 1;
                }
@@ -4691,8 +4692,8 @@ static void btrfs_destroy_marked_extents(struct btrfs_fs_info *fs_info,
        u64 start = 0;
        u64 end;
 
-       while (find_first_extent_bit(dirty_pages, start, &start, &end,
-                                    mark, NULL)) {
+       while (btrfs_find_first_extent_bit(dirty_pages, start, &start, &end,
+                                          mark, NULL)) {
                btrfs_clear_extent_bits(dirty_pages, start, end, mark);
                while (start <= end) {
                        eb = find_extent_buffer(fs_info, start);
@@ -4726,8 +4727,8 @@ static void btrfs_destroy_pinned_extent(struct btrfs_fs_info *fs_info,
                 * the same extent range.
                 */
                mutex_lock(&fs_info->unused_bg_unpin_mutex);
-               if (!find_first_extent_bit(unpin, 0, &start, &end,
-                                          EXTENT_DIRTY, &cached_state)) {
+               if (!btrfs_find_first_extent_bit(unpin, 0, &start, &end,
+                                                EXTENT_DIRTY, &cached_state)) {
                        mutex_unlock(&fs_info->unused_bg_unpin_mutex);
                        break;
                }
index 49a9202dc5d0880e50ebecfd471830ebf0b710cc..245b78c65edd474a9dab60e9f864957a12e2ac2b 100644 (file)
@@ -869,9 +869,9 @@ static struct extent_state *find_first_extent_bit_state(struct extent_io_tree *t
  * Return true if we find something, and update @start_ret and @end_ret.
  * Return false if we found nothing.
  */
-bool find_first_extent_bit(struct extent_io_tree *tree, u64 start,
-                          u64 *start_ret, u64 *end_ret, u32 bits,
-                          struct extent_state **cached_state)
+bool btrfs_find_first_extent_bit(struct extent_io_tree *tree, u64 start,
+                                u64 *start_ret, u64 *end_ret, u32 bits,
+                                struct extent_state **cached_state)
 {
        struct extent_state *state;
        bool ret = false;
@@ -930,8 +930,8 @@ out:
  * then walk down the tree until we find a non-contiguous area.  The area
  * returned will be the full contiguous area with the bits set.
  */
-int find_contiguous_extent_bit(struct extent_io_tree *tree, u64 start,
-                              u64 *start_ret, u64 *end_ret, u32 bits)
+int btrfs_find_contiguous_extent_bit(struct extent_io_tree *tree, u64 start,
+                                    u64 *start_ret, u64 *end_ret, u32 bits)
 {
        struct extent_state *state;
        int ret = 1;
@@ -1495,8 +1495,8 @@ out:
  * spans (last_range_end, end of device]. In this case it's up to the caller to
  * trim @end_ret to the appropriate size.
  */
-void find_first_clear_extent_bit(struct extent_io_tree *tree, u64 start,
-                                u64 *start_ret, u64 *end_ret, u32 bits)
+void btrfs_find_first_clear_extent_bit(struct extent_io_tree *tree, u64 start,
+                                      u64 *start_ret, u64 *end_ret, u32 bits)
 {
        struct extent_state *state;
        struct extent_state *prev = NULL, *next = NULL;
index e092d776a7557bf9a2f9956a102671900a612523..60fedf1b855e0ca89abe22b85543643cf354947c 100644 (file)
@@ -214,13 +214,13 @@ int convert_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
                       u32 bits, u32 clear_bits,
                       struct extent_state **cached_state);
 
-bool find_first_extent_bit(struct extent_io_tree *tree, u64 start,
-                          u64 *start_ret, u64 *end_ret, u32 bits,
-                          struct extent_state **cached_state);
-void find_first_clear_extent_bit(struct extent_io_tree *tree, u64 start,
-                                u64 *start_ret, u64 *end_ret, u32 bits);
-int find_contiguous_extent_bit(struct extent_io_tree *tree, u64 start,
-                              u64 *start_ret, u64 *end_ret, u32 bits);
+bool btrfs_find_first_extent_bit(struct extent_io_tree *tree, u64 start,
+                                u64 *start_ret, u64 *end_ret, u32 bits,
+                                struct extent_state **cached_state);
+void btrfs_find_first_clear_extent_bit(struct extent_io_tree *tree, u64 start,
+                                      u64 *start_ret, u64 *end_ret, u32 bits);
+int btrfs_find_contiguous_extent_bit(struct extent_io_tree *tree, u64 start,
+                                    u64 *start_ret, u64 *end_ret, u32 bits);
 bool btrfs_find_delalloc_range(struct extent_io_tree *tree, u64 *start,
                               u64 *end, u64 max_bytes,
                               struct extent_state **cached_state);
index 06eb0d724f3dd8a52b952d10fb31778357886909..7ca5cfaccbfd66e7826308395f4770fe15a78e51 100644 (file)
@@ -2829,8 +2829,8 @@ int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans)
                struct extent_state *cached_state = NULL;
 
                mutex_lock(&fs_info->unused_bg_unpin_mutex);
-               if (!find_first_extent_bit(unpin, 0, &start, &end,
-                                          EXTENT_DIRTY, &cached_state)) {
+               if (!btrfs_find_first_extent_bit(unpin, 0, &start, &end,
+                                                EXTENT_DIRTY, &cached_state)) {
                        mutex_unlock(&fs_info->unused_bg_unpin_mutex);
                        break;
                }
@@ -6391,9 +6391,9 @@ static int btrfs_trim_free_extents(struct btrfs_device *device, u64 *trimmed)
                if (ret)
                        break;
 
-               find_first_clear_extent_bit(&device->alloc_state, start,
-                                           &start, &end,
-                                           CHUNK_TRIMMED | CHUNK_ALLOCATED);
+               btrfs_find_first_clear_extent_bit(&device->alloc_state, start,
+                                                 &start, &end,
+                                                 CHUNK_TRIMMED | CHUNK_ALLOCATED);
 
                /* Check if there are any CHUNK_* bits left */
                if (start > device->total_bytes) {
index 87e956cd35202987f2889834f99855419d7f4b11..d2ea830ad2448261d43e4fc7e8592fc19e28aa9c 100644 (file)
@@ -55,8 +55,8 @@ void btrfs_inode_safe_disk_i_size_write(struct btrfs_inode *inode, u64 new_i_siz
                goto out_unlock;
        }
 
-       ret = find_contiguous_extent_bit(inode->file_extent_tree, 0, &start,
-                                        &end, EXTENT_DIRTY);
+       ret = btrfs_find_contiguous_extent_bit(inode->file_extent_tree, 0, &start,
+                                              &end, EXTENT_DIRTY);
        if (!ret && start == 0)
                i_size = min(i_size, end + 1);
        else
index ba3c8ba26c434690abbbd4ead08d750edf7ff2c4..3f91f653c1fa4d76ca05ca50cba722e0422d4be4 100644 (file)
@@ -1219,9 +1219,9 @@ static noinline_for_stack int write_pinned_extent_entries(
        start = block_group->start;
 
        while (start < block_group->start + block_group->length) {
-               if (!find_first_extent_bit(unpin, start,
-                                          &extent_start, &extent_end,
-                                          EXTENT_DIRTY, NULL))
+               if (!btrfs_find_first_extent_bit(unpin, start,
+                                                &extent_start, &extent_end,
+                                                EXTENT_DIRTY, NULL))
                        return 0;
 
                /* This pinned extent is out of our range */
index ec31cefd0dc1783bd0bd935dfc57e9e753b141db..b996fb0ee374d572b2a1d352e4ee3f573d23a92e 100644 (file)
@@ -3433,9 +3433,9 @@ next:
                        goto next;
                }
 
-               block_found = find_first_extent_bit(&rc->processed_blocks,
-                                                   key.objectid, &start, &end,
-                                                   EXTENT_DIRTY, NULL);
+               block_found = btrfs_find_first_extent_bit(&rc->processed_blocks,
+                                                         key.objectid, &start, &end,
+                                                         EXTENT_DIRTY, NULL);
 
                if (block_found && start <= key.objectid) {
                        btrfs_release_path(path);
index 2d56c1ff715edf7bbcf5a52a0850b2f526ba2cd4..3d59e002c161b1d694b92f2952621f52582a44b7 100644 (file)
@@ -567,7 +567,7 @@ static int test_find_first_clear_extent_bit(void)
        extent_io_tree_init(NULL, &tree, IO_TREE_SELFTEST);
 
        /* Test correct handling of empty tree */
-       find_first_clear_extent_bit(&tree, 0, &start, &end, CHUNK_TRIMMED);
+       btrfs_find_first_clear_extent_bit(&tree, 0, &start, &end, CHUNK_TRIMMED);
        if (start != 0 || end != -1) {
                test_err(
        "error getting a range from completely empty tree: start %llu end %llu",
@@ -581,8 +581,8 @@ static int test_find_first_clear_extent_bit(void)
        btrfs_set_extent_bit(&tree, SZ_1M, SZ_4M - 1,
                             CHUNK_TRIMMED | CHUNK_ALLOCATED, NULL);
 
-       find_first_clear_extent_bit(&tree, SZ_512K, &start, &end,
-                                   CHUNK_TRIMMED | CHUNK_ALLOCATED);
+       btrfs_find_first_clear_extent_bit(&tree, SZ_512K, &start, &end,
+                                         CHUNK_TRIMMED | CHUNK_ALLOCATED);
 
        if (start != 0 || end != SZ_1M - 1) {
                test_err("error finding beginning range: start %llu end %llu",
@@ -597,8 +597,8 @@ static int test_find_first_clear_extent_bit(void)
        /*
         * Request first hole starting at 12M, we should get 4M-32M
         */
-       find_first_clear_extent_bit(&tree, 12 * SZ_1M, &start, &end,
-                                   CHUNK_TRIMMED | CHUNK_ALLOCATED);
+       btrfs_find_first_clear_extent_bit(&tree, 12 * SZ_1M, &start, &end,
+                                         CHUNK_TRIMMED | CHUNK_ALLOCATED);
 
        if (start != SZ_4M || end != SZ_32M - 1) {
                test_err("error finding trimmed range: start %llu end %llu",
@@ -610,8 +610,8 @@ static int test_find_first_clear_extent_bit(void)
         * Search in the middle of allocated range, should get the next one
         * available, which happens to be unallocated -> 4M-32M
         */
-       find_first_clear_extent_bit(&tree, SZ_2M, &start, &end,
-                                   CHUNK_TRIMMED | CHUNK_ALLOCATED);
+       btrfs_find_first_clear_extent_bit(&tree, SZ_2M, &start, &end,
+                                         CHUNK_TRIMMED | CHUNK_ALLOCATED);
 
        if (start != SZ_4M || end != SZ_32M - 1) {
                test_err("error finding next unalloc range: start %llu end %llu",
@@ -624,8 +624,8 @@ static int test_find_first_clear_extent_bit(void)
         * being unset in this range, we should get the entry in range 64M-72M
         */
        btrfs_set_extent_bit(&tree, SZ_64M, SZ_64M + SZ_8M - 1, CHUNK_ALLOCATED, NULL);
-       find_first_clear_extent_bit(&tree, SZ_64M + SZ_1M, &start, &end,
-                                   CHUNK_TRIMMED);
+       btrfs_find_first_clear_extent_bit(&tree, SZ_64M + SZ_1M, &start, &end,
+                                         CHUNK_TRIMMED);
 
        if (start != SZ_64M || end != SZ_64M + SZ_8M - 1) {
                test_err("error finding exact range: start %llu end %llu",
@@ -633,8 +633,8 @@ static int test_find_first_clear_extent_bit(void)
                goto out;
        }
 
-       find_first_clear_extent_bit(&tree, SZ_64M - SZ_8M, &start, &end,
-                                   CHUNK_TRIMMED);
+       btrfs_find_first_clear_extent_bit(&tree, SZ_64M - SZ_8M, &start, &end,
+                                         CHUNK_TRIMMED);
 
        /*
         * Search in the middle of set range whose immediate neighbour doesn't
@@ -650,7 +650,7 @@ static int test_find_first_clear_extent_bit(void)
         * Search beyond any known range, shall return after last known range
         * and end should be -1
         */
-       find_first_clear_extent_bit(&tree, -1, &start, &end, CHUNK_TRIMMED);
+       btrfs_find_first_clear_extent_bit(&tree, -1, &start, &end, CHUNK_TRIMMED);
        if (start != SZ_64M + SZ_8M || end != -1) {
                test_err(
                "error handling beyond end of range search: start %llu end %llu",
index 3d272c140303ecb20e66024aeddba89da25ff9c4..8fa9af18e4833fd874902bfc3cebb1b4385bfd92 100644 (file)
@@ -1128,8 +1128,8 @@ int btrfs_write_marked_extents(struct btrfs_fs_info *fs_info,
        u64 start = 0;
        u64 end;
 
-       while (find_first_extent_bit(dirty_pages, start, &start, &end,
-                                    mark, &cached_state)) {
+       while (btrfs_find_first_extent_bit(dirty_pages, start, &start, &end,
+                                          mark, &cached_state)) {
                bool wait_writeback = false;
 
                ret = convert_extent_bit(dirty_pages, start, end,
@@ -1181,8 +1181,8 @@ static int __btrfs_wait_marked_extents(struct btrfs_fs_info *fs_info,
        u64 end;
        int ret = 0;
 
-       while (find_first_extent_bit(dirty_pages, start, &start, &end,
-                                    EXTENT_NEED_WAIT, &cached_state)) {
+       while (btrfs_find_first_extent_bit(dirty_pages, start, &start, &end,
+                                          EXTENT_NEED_WAIT, &cached_state)) {
                /*
                 * Ignore -ENOMEM errors returned by clear_extent_bit().
                 * When committing the transaction, we'll remove any entries
index f3b22cefb359efbb1bc332e8881699035c7847f3..8eb20fba052e79efd2a080deb9da65d7e376d94d 100644 (file)
@@ -1511,9 +1511,9 @@ static bool contains_pending_extent(struct btrfs_device *device, u64 *start,
 
        lockdep_assert_held(&device->fs_info->chunk_mutex);
 
-       if (find_first_extent_bit(&device->alloc_state, *start,
-                                 &physical_start, &physical_end,
-                                 CHUNK_ALLOCATED, NULL)) {
+       if (btrfs_find_first_extent_bit(&device->alloc_state, *start,
+                                       &physical_start, &physical_end,
+                                       CHUNK_ALLOCATED, NULL)) {
 
                if (in_range(physical_start, *start, len) ||
                    in_range(*start, physical_start,