btrfs: convert ASSERT(0) with handled errors to DEBUG_WARN()
authorDavid Sterba <dsterba@suse.com>
Thu, 17 Apr 2025 09:17:03 +0000 (11:17 +0200)
committerDavid Sterba <dsterba@suse.com>
Thu, 15 May 2025 12:30:47 +0000 (14:30 +0200)
The use of ASSERT(0) is maybe useful for some cases but more like a
notice for developers. Assertions can be compiled in independently so
convert it to a debugging helper.

The difference is that it's just a warning and will not end up in BUG().
The converted cases are in connection with proper error handling.

Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/backref.c
fs/btrfs/dev-replace.c
fs/btrfs/extent_io.c
fs/btrfs/free-space-tree.c
fs/btrfs/relocation.c
fs/btrfs/send.c
fs/btrfs/volumes.c
fs/btrfs/zoned.c

index e76e1845cfce14da32d86238df9d6699d0a4b93c..6ee0259048cd3ec08606d805a71afbb7a3b31edd 100644 (file)
@@ -3617,7 +3617,7 @@ int btrfs_backref_finish_upper_links(struct btrfs_backref_cache *cache,
 
                /* Sanity check, we shouldn't have any unchecked nodes */
                if (!upper->checked) {
-                       ASSERT(0);
+                       DEBUG_WARN("we should not have any unchecked nodes");
                        return -EUCLEAN;
                }
 
index 483e71e09181ff9202bae812ec8f83cf66915d2e..5c26f0fcf0d500e080f826f8195ad48107ea672a 100644 (file)
@@ -637,7 +637,7 @@ static int btrfs_dev_replace_start(struct btrfs_fs_info *fs_info,
                break;
        case BTRFS_IOCTL_DEV_REPLACE_STATE_STARTED:
        case BTRFS_IOCTL_DEV_REPLACE_STATE_SUSPENDED:
-               ASSERT(0);
+               DEBUG_WARN("unexpected STARTED ot SUSPENDED dev-replace state");
                ret = BTRFS_IOCTL_DEV_REPLACE_RESULT_ALREADY_STARTED;
                up_write(&dev_replace->rwsem);
                goto leave;
index 22456f456303ed0a7bd465c9a41784a7da67b279..da836fc32f24a26943350197c5daec44cb711824 100644 (file)
@@ -3274,7 +3274,7 @@ reallocate:
                 * using 0-order folios.
                 */
                if (unlikely(ret == -EAGAIN)) {
-                       ASSERT(0);
+                       DEBUG_WARN("folio order mismatch between new eb and filemap");
                        goto reallocate;
                }
                attached++;
index 39c6b96a4c25a87dd792cde637305b2976383075..ef62f3a69267f311e12575e2e3a0e0401a454ceb 100644 (file)
@@ -117,7 +117,7 @@ struct btrfs_free_space_info *search_free_space_info(
        if (ret != 0) {
                btrfs_warn(fs_info, "missing free space info for %llu",
                           block_group->start);
-               ASSERT(0);
+               DEBUG_WARN();
                return ERR_PTR(-ENOENT);
        }
 
@@ -141,12 +141,12 @@ static int btrfs_search_prev_slot(struct btrfs_trans_handle *trans,
                return ret;
 
        if (ret == 0) {
-               ASSERT(0);
+               DEBUG_WARN();
                return -EIO;
        }
 
        if (p->slots[0] == 0) {
-               ASSERT(0);
+               DEBUG_WARN("no previous slot found");
                return -EIO;
        }
        p->slots[0]--;
@@ -293,7 +293,7 @@ int convert_free_space_to_bitmaps(struct btrfs_trans_handle *trans,
                          "incorrect extent count for %llu; counted %u, expected %u",
                          block_group->start, extent_count,
                          expected_extent_count);
-               ASSERT(0);
+               DEBUG_WARN();
                ret = -EIO;
                goto out;
        }
@@ -455,7 +455,7 @@ int convert_free_space_to_extents(struct btrfs_trans_handle *trans,
                          "incorrect extent count for %llu; counted %u, expected %u",
                          block_group->start, extent_count,
                          expected_extent_count);
-               ASSERT(0);
+               DEBUG_WARN();
                ret = -EIO;
                goto out;
        }
@@ -843,7 +843,7 @@ int remove_from_free_space_tree(struct btrfs_trans_handle *trans,
 
        block_group = btrfs_lookup_block_group(trans->fs_info, start);
        if (!block_group) {
-               ASSERT(0);
+               DEBUG_WARN("no block group found for start=%llu", start);
                ret = -ENOENT;
                goto out;
        }
@@ -1036,7 +1036,7 @@ int add_to_free_space_tree(struct btrfs_trans_handle *trans,
 
        block_group = btrfs_lookup_block_group(trans->fs_info, start);
        if (!block_group) {
-               ASSERT(0);
+               DEBUG_WARN("no block group found for start=%llu", start);
                ret = -ENOENT;
                goto out;
        }
@@ -1555,7 +1555,7 @@ static int load_free_space_bitmaps(struct btrfs_caching_control *caching_ctl,
                          "incorrect extent count for %llu; counted %u, expected %u",
                          block_group->start, extent_count,
                          expected_extent_count);
-               ASSERT(0);
+               DEBUG_WARN();
                ret = -EIO;
                goto out;
        }
@@ -1619,7 +1619,7 @@ static int load_free_space_extents(struct btrfs_caching_control *caching_ctl,
                          "incorrect extent count for %llu; counted %u, expected %u",
                          block_group->start, extent_count,
                          expected_extent_count);
-               ASSERT(0);
+               DEBUG_WARN();
                ret = -EIO;
                goto out;
        }
index 6ba9fcb53c33c00f83c2558913bca1835c614f94..97c223aa90b650bd1b68b17a44ddad0e9e8dd6cc 100644 (file)
@@ -1931,11 +1931,11 @@ static int record_reloc_root_in_trans(struct btrfs_trans_handle *trans,
         * reloc root without a corresponding root this could return ENOENT.
         */
        if (IS_ERR(root)) {
-               ASSERT(0);
+               DEBUG_WARN("error %ld reading root for reloc root", PTR_ERR(root));
                return PTR_ERR(root);
        }
        if (root->reloc_root != reloc_root) {
-               ASSERT(0);
+               DEBUG_WARN("unexpected reloc root found");
                btrfs_err(fs_info,
                          "root %llu has two reloc roots associated with it",
                          reloc_root->root_key.offset);
index 116d67ab93dcdb4f8dc18936907ce92661dcfb3d..095bdd11398d66df4f6cc952e9fbc9a1e1e6549a 100644 (file)
@@ -383,11 +383,11 @@ static void inconsistent_snapshot_error(struct send_ctx *sctx,
                result_string = "updated";
                break;
        case BTRFS_COMPARE_TREE_SAME:
-               ASSERT(0);
+               DEBUG_WARN("no change between trees");
                result_string = "unchanged";
                break;
        default:
-               ASSERT(0);
+               DEBUG_WARN("unexpected comparison result %d", result);
                result_string = "unexpected";
        }
 
index b8ac5630fcd6cfa5664226610aa2a2265ba6fdca..97a3831a3f9ab967773c4acea964840bf0b20ec7 100644 (file)
@@ -3252,7 +3252,8 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans, u64 chunk_offset)
                 * user having built with ASSERT enabled, so if ASSERT doesn't
                 * do anything we still error out.
                 */
-               ASSERT(0);
+               DEBUG_WARN("errr %ld reading chunk map at offset %llu",
+                          PTR_ERR(map), chunk_offset);
                return PTR_ERR(map);
        }
 
@@ -5574,7 +5575,7 @@ struct btrfs_block_group *btrfs_create_chunk(struct btrfs_trans_handle *trans,
        lockdep_assert_held(&info->chunk_mutex);
 
        if (!alloc_profile_is_valid(type, 0)) {
-               ASSERT(0);
+               DEBUG_WARN("invalid alloc profile for type %llu", type);
                return ERR_PTR(-EINVAL);
        }
 
@@ -5586,7 +5587,7 @@ struct btrfs_block_group *btrfs_create_chunk(struct btrfs_trans_handle *trans,
 
        if (!(type & BTRFS_BLOCK_GROUP_TYPE_MASK)) {
                btrfs_err(info, "invalid chunk type 0x%llx requested", type);
-               ASSERT(0);
+               DEBUG_WARN();
                return ERR_PTR(-EINVAL);
        }
 
index 7b30700ec9304fb8027bc7e752e5a7c0f7bcbfae..7fc2f73dc8d8a6260b793bb99ad93a7df86b08b2 100644 (file)
@@ -989,7 +989,7 @@ int btrfs_advance_sb_log(struct btrfs_device *device, int mirror)
        }
 
        /* All the zones are FULL. Should not reach here. */
-       ASSERT(0);
+       DEBUG_WARN("unexpected state, all zones full");
        return -EIO;
 }