]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
btrfs: add unlikely annotations to branches leading to EIO
authorDavid Sterba <dsterba@suse.com>
Wed, 17 Sep 2025 17:53:55 +0000 (19:53 +0200)
committerDavid Sterba <dsterba@suse.com>
Tue, 23 Sep 2025 06:49:26 +0000 (08:49 +0200)
The unlikely() annotation is a static prediction hint that compiler may
use to reorder code out of hot path. We use it elsewhere (namely
tree-checker.c) for error branches that almost never happen, where
EIO is one of them.

Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
19 files changed:
fs/btrfs/backref.c
fs/btrfs/bio.c
fs/btrfs/defrag.c
fs/btrfs/dev-replace.c
fs/btrfs/disk-io.c
fs/btrfs/extent-tree.c
fs/btrfs/extent_io.c
fs/btrfs/extent_map.c
fs/btrfs/file.c
fs/btrfs/free-space-tree.c
fs/btrfs/inode.c
fs/btrfs/qgroup.c
fs/btrfs/raid56.c
fs/btrfs/relocation.c
fs/btrfs/scrub.c
fs/btrfs/send.c
fs/btrfs/zlib.c
fs/btrfs/zoned.c
fs/btrfs/zstd.c

index 650083e0f1cb8bdb754183f1cc0a8b96c890c2b9..2ab550a1e715a746a10b7b65848fc3cdad6e9c59 100644 (file)
@@ -859,7 +859,7 @@ static int add_missing_keys(struct btrfs_fs_info *fs_info,
                        free_pref(ref);
                        return PTR_ERR(eb);
                }
-               if (!extent_buffer_uptodate(eb)) {
+               if (unlikely(!extent_buffer_uptodate(eb))) {
                        free_pref(ref);
                        free_extent_buffer(eb);
                        return -EIO;
@@ -1614,7 +1614,7 @@ again:
                                        ret = PTR_ERR(eb);
                                        goto out;
                                }
-                               if (!extent_buffer_uptodate(eb)) {
+                               if (unlikely(!extent_buffer_uptodate(eb))) {
                                        free_extent_buffer(eb);
                                        ret = -EIO;
                                        goto out;
index db2deaa4aad4e2f10d4d18dbd47d2cd627144b66..21df48e6c4fa2091889cab6fae80f8a730e9380a 100644 (file)
@@ -849,8 +849,8 @@ int btrfs_repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 start,
        if (ret < 0)
                goto out_counter_dec;
 
-       if (!smap.dev->bdev ||
-           !test_bit(BTRFS_DEV_STATE_WRITEABLE, &smap.dev->dev_state)) {
+       if (unlikely(!smap.dev->bdev ||
+                    !test_bit(BTRFS_DEV_STATE_WRITEABLE, &smap.dev->dev_state))) {
                ret = -EIO;
                goto out_counter_dec;
        }
index 84ba9906f0d818ad009268a8613af1eed575b53c..7b277934f66f9229bf8bd55b23a525791128670f 100644 (file)
@@ -924,7 +924,7 @@ again:
                        folio_put(folio);
                        goto again;
                }
-               if (!folio_test_uptodate(folio)) {
+               if (unlikely(!folio_test_uptodate(folio))) {
                        folio_unlock(folio);
                        folio_put(folio);
                        return ERR_PTR(-EIO);
index b37e9a893b918ae46de9fd7a9068b11c0fcf129f..a4eaef60549eed494ca5f917cd8d3241de376597 100644 (file)
@@ -177,8 +177,7 @@ no_valid_dev_replace_entry_found:
                 * allow 'btrfs dev replace_cancel' if src/tgt device is
                 * missing
                 */
-               if (!dev_replace->srcdev &&
-                   !btrfs_test_opt(fs_info, DEGRADED)) {
+               if (unlikely(!dev_replace->srcdev && !btrfs_test_opt(fs_info, DEGRADED))) {
                        ret = -EIO;
                        btrfs_warn(fs_info,
                           "cannot mount because device replace operation is ongoing and");
@@ -186,8 +185,7 @@ no_valid_dev_replace_entry_found:
                           "srcdev (devid %llu) is missing, need to run 'btrfs dev scan'?",
                           src_devid);
                }
-               if (!dev_replace->tgtdev &&
-                   !btrfs_test_opt(fs_info, DEGRADED)) {
+               if (unlikely(!dev_replace->tgtdev && !btrfs_test_opt(fs_info, DEGRADED))) {
                        ret = -EIO;
                        btrfs_warn(fs_info,
                           "cannot mount because device replace operation is ongoing and");
index dbc72135b5e7a0f9e762d1d81eb1df0545ec5378..21c2a19d690f5815757a870452422073f1e21077 100644 (file)
@@ -370,21 +370,21 @@ int btrfs_validate_extent_buffer(struct extent_buffer *eb,
        ASSERT(check);
 
        found_start = btrfs_header_bytenr(eb);
-       if (found_start != eb->start) {
+       if (unlikely(found_start != eb->start)) {
                btrfs_err_rl(fs_info,
                        "bad tree block start, mirror %u want %llu have %llu",
                             eb->read_mirror, eb->start, found_start);
                ret = -EIO;
                goto out;
        }
-       if (check_tree_block_fsid(eb)) {
+       if (unlikely(check_tree_block_fsid(eb))) {
                btrfs_err_rl(fs_info, "bad fsid on logical %llu mirror %u",
                             eb->start, eb->read_mirror);
                ret = -EIO;
                goto out;
        }
        found_level = btrfs_header_level(eb);
-       if (found_level >= BTRFS_MAX_LEVEL) {
+       if (unlikely(found_level >= BTRFS_MAX_LEVEL)) {
                btrfs_err(fs_info,
                        "bad tree block level, mirror %u level %d on logical %llu",
                        eb->read_mirror, btrfs_header_level(eb), eb->start);
@@ -410,7 +410,7 @@ int btrfs_validate_extent_buffer(struct extent_buffer *eb,
                }
        }
 
-       if (found_level != check->level) {
+       if (unlikely(found_level != check->level)) {
                btrfs_err(fs_info,
                "level verify failed on logical %llu mirror %u wanted %u found %u",
                          eb->start, eb->read_mirror, check->level, found_level);
@@ -1046,7 +1046,7 @@ static struct btrfs_root *read_tree_root_path(struct btrfs_root *tree_root,
                root->node = NULL;
                goto fail;
        }
-       if (!btrfs_buffer_uptodate(root->node, generation, false)) {
+       if (unlikely(!btrfs_buffer_uptodate(root->node, generation, false))) {
                ret = -EIO;
                goto fail;
        }
@@ -2058,7 +2058,7 @@ static int btrfs_replay_log(struct btrfs_fs_info *fs_info,
        u64 bytenr = btrfs_super_log_root(disk_super);
        int level = btrfs_super_log_root_level(disk_super);
 
-       if (fs_devices->rw_devices == 0) {
+       if (unlikely(fs_devices->rw_devices == 0)) {
                btrfs_warn(fs_info, "log replay required on RO media");
                return -EIO;
        }
@@ -2079,7 +2079,7 @@ static int btrfs_replay_log(struct btrfs_fs_info *fs_info,
                btrfs_put_root(log_tree_root);
                return ret;
        }
-       if (!extent_buffer_uptodate(log_tree_root->node)) {
+       if (unlikely(!extent_buffer_uptodate(log_tree_root->node))) {
                btrfs_err(fs_info, "failed to read log tree");
                btrfs_put_root(log_tree_root);
                return -EIO;
@@ -2641,7 +2641,7 @@ static int load_super_root(struct btrfs_root *root, u64 bytenr, u64 gen, int lev
                root->node = NULL;
                return ret;
        }
-       if (!extent_buffer_uptodate(root->node)) {
+       if (unlikely(!extent_buffer_uptodate(root->node))) {
                free_extent_buffer(root->node);
                root->node = NULL;
                return -EIO;
@@ -3469,7 +3469,7 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
         * below in btrfs_init_dev_replace().
         */
        btrfs_free_extra_devids(fs_devices);
-       if (!fs_devices->latest_dev->bdev) {
+       if (unlikely(!fs_devices->latest_dev->bdev)) {
                btrfs_err(fs_info, "failed to read devices");
                ret = -EIO;
                goto fail_tree_roots;
@@ -3963,7 +3963,7 @@ static int barrier_all_devices(struct btrfs_fs_info *info)
         * Checks last_flush_error of disks in order to determine the device
         * state.
         */
-       if (errors_wait && !btrfs_check_rw_degradable(info, NULL))
+       if (unlikely(errors_wait && !btrfs_check_rw_degradable(info, NULL)))
                return -EIO;
 
        return 0;
@@ -4076,7 +4076,7 @@ int write_all_supers(struct btrfs_fs_info *fs_info, int max_mirrors)
                if (ret)
                        total_errors++;
        }
-       if (total_errors > max_errors) {
+       if (unlikely(total_errors > max_errors)) {
                btrfs_err(fs_info, "%d errors while writing supers",
                          total_errors);
                mutex_unlock(&fs_info->fs_devices->device_list_mutex);
@@ -4101,7 +4101,7 @@ int write_all_supers(struct btrfs_fs_info *fs_info, int max_mirrors)
                        total_errors++;
        }
        mutex_unlock(&fs_info->fs_devices->device_list_mutex);
-       if (total_errors > max_errors) {
+       if (unlikely(total_errors > max_errors)) {
                btrfs_handle_fs_error(fs_info, -EIO,
                                      "%d errors while writing supers",
                                      total_errors);
index 5982683d8e45944ef748695e1ca928dd69f9a053..6a258bd8693e021e44a92728128b2afe1952e62e 100644 (file)
@@ -5638,7 +5638,7 @@ static int maybe_drop_reference(struct btrfs_trans_handle *trans, struct btrfs_r
                ref.parent = path->nodes[level]->start;
        } else {
                ASSERT(btrfs_root_id(root) == btrfs_header_owner(path->nodes[level]));
-               if (btrfs_root_id(root) != btrfs_header_owner(path->nodes[level])) {
+               if (unlikely(btrfs_root_id(root) != btrfs_header_owner(path->nodes[level]))) {
                        btrfs_err(root->fs_info, "mismatched block owner");
                        return -EIO;
                }
@@ -5774,7 +5774,7 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans,
 
        level--;
        ASSERT(level == btrfs_header_level(next));
-       if (level != btrfs_header_level(next)) {
+       if (unlikely(level != btrfs_header_level(next))) {
                btrfs_err(root->fs_info, "mismatched level");
                ret = -EIO;
                goto out_unlock;
index 4342d654a95403e8fc31598dc2e189f9e0a1552a..c123a3ef154ae5fb5575b78c55608a8f9ac78fc7 100644 (file)
@@ -3880,7 +3880,7 @@ int read_extent_buffer_pages(struct extent_buffer *eb, int mirror_num,
                return ret;
 
        wait_on_bit_io(&eb->bflags, EXTENT_BUFFER_READING, TASK_UNINTERRUPTIBLE);
-       if (!test_bit(EXTENT_BUFFER_UPTODATE, &eb->bflags))
+       if (unlikely(!test_bit(EXTENT_BUFFER_UPTODATE, &eb->bflags)))
                return -EIO;
        return 0;
 }
index ac28eee7ae32c5ffebb788da42716cd11e31eb44..c1e5c7c158b80acbdb4e99abb17071bac651a740 100644 (file)
@@ -1057,7 +1057,7 @@ int btrfs_split_extent_map(struct btrfs_inode *inode, u64 start, u64 len, u64 pr
        btrfs_lock_extent(&inode->io_tree, start, start + len - 1, NULL);
        write_lock(&em_tree->lock);
        em = btrfs_lookup_extent_mapping(em_tree, start, len);
-       if (!em) {
+       if (unlikely(!em)) {
                ret = -EIO;
                goto out_unlock;
        }
index 4daec404fec6211788cd0ebf605667953cbb2448..e7765578349b6d07610da317c17098e97ecba7b4 100644 (file)
@@ -815,7 +815,7 @@ static int prepare_uptodate_folio(struct inode *inode, struct folio *folio, u64
        if (ret)
                return ret;
        folio_lock(folio);
-       if (!folio_test_uptodate(folio)) {
+       if (unlikely(!folio_test_uptodate(folio))) {
                folio_unlock(folio);
                return -EIO;
        }
index eba7f22ae49c6795f50c00cffc2197767fe8330a..2fee9f3b60d4394a0b981df5a7b6e199c7020db7 100644 (file)
@@ -137,12 +137,12 @@ static int btrfs_search_prev_slot(struct btrfs_trans_handle *trans,
        if (ret < 0)
                return ret;
 
-       if (ret == 0) {
+       if (unlikely(ret == 0)) {
                DEBUG_WARN();
                return -EIO;
        }
 
-       if (p->slots[0] == 0) {
+       if (unlikely(p->slots[0] == 0)) {
                DEBUG_WARN("no previous slot found");
                return -EIO;
        }
@@ -293,7 +293,7 @@ int btrfs_convert_free_space_to_bitmaps(struct btrfs_trans_handle *trans,
        expected_extent_count = btrfs_free_space_extent_count(leaf, info);
        btrfs_release_path(path);
 
-       if (extent_count != expected_extent_count) {
+       if (unlikely(extent_count != expected_extent_count)) {
                btrfs_err(fs_info,
                          "incorrect extent count for %llu; counted %u, expected %u",
                          block_group->start, extent_count,
@@ -465,7 +465,7 @@ int btrfs_convert_free_space_to_extents(struct btrfs_trans_handle *trans,
                start_bit = find_next_bit_le(bitmap, nrbits, end_bit);
        }
 
-       if (extent_count != expected_extent_count) {
+       if (unlikely(extent_count != expected_extent_count)) {
                btrfs_err(fs_info,
                          "incorrect extent count for %llu; counted %u, expected %u",
                          block_group->start, extent_count,
@@ -1611,7 +1611,7 @@ static int load_free_space_bitmaps(struct btrfs_caching_control *caching_ctl,
                extent_count++;
        }
 
-       if (extent_count != expected_extent_count) {
+       if (unlikely(extent_count != expected_extent_count)) {
                btrfs_err(fs_info,
                          "incorrect extent count for %llu; counted %u, expected %u",
                          block_group->start, extent_count,
@@ -1672,7 +1672,7 @@ static int load_free_space_extents(struct btrfs_caching_control *caching_ctl,
                extent_count++;
        }
 
-       if (extent_count != expected_extent_count) {
+       if (unlikely(extent_count != expected_extent_count)) {
                btrfs_err(fs_info,
                          "incorrect extent count for %llu; counted %u, expected %u",
                          block_group->start, extent_count,
index 3e0b699c938d62b061637276e4da4226909a53d3..6403312505c4d1ac1fea61da89cf6012fb756661 100644 (file)
@@ -3104,7 +3104,7 @@ int btrfs_finish_one_ordered(struct btrfs_ordered_extent *ordered_extent)
        if (!freespace_inode)
                btrfs_lockdep_acquire(fs_info, btrfs_ordered_extent);
 
-       if (test_bit(BTRFS_ORDERED_IOERR, &ordered_extent->flags)) {
+       if (unlikely(test_bit(BTRFS_ORDERED_IOERR, &ordered_extent->flags))) {
                ret = -EIO;
                goto out;
        }
@@ -3370,7 +3370,7 @@ int btrfs_check_block_csum(struct btrfs_fs_info *fs_info, phys_addr_t paddr, u8
                           const u8 * const csum_expected)
 {
        btrfs_calculate_block_csum(fs_info, paddr, csum);
-       if (memcmp(csum, csum_expected, fs_info->csum_size))
+       if (unlikely(memcmp(csum, csum_expected, fs_info->csum_size) != 0))
                return -EIO;
        return 0;
 }
@@ -4842,7 +4842,7 @@ again:
                        folio_put(folio);
                        goto again;
                }
-               if (!folio_test_uptodate(folio)) {
+               if (unlikely(!folio_test_uptodate(folio))) {
                        ret = -EIO;
                        goto out_unlock;
                }
@@ -4986,7 +4986,7 @@ again:
                        folio_put(folio);
                        goto again;
                }
-               if (!folio_test_uptodate(folio)) {
+               if (unlikely(!folio_test_uptodate(folio))) {
                        ret = -EIO;
                        goto out_unlock;
                }
@@ -7179,7 +7179,7 @@ not_found:
 insert:
        ret = 0;
        btrfs_release_path(path);
-       if (em->start > start || btrfs_extent_map_end(em) <= start) {
+       if (unlikely(em->start > start || btrfs_extent_map_end(em) <= start)) {
                btrfs_err(fs_info,
                          "bad extent! em: [%llu %llu] passed [%llu %llu]",
                          em->start, em->len, start, len);
@@ -9298,7 +9298,7 @@ static ssize_t btrfs_encoded_read_inline(
        ret = btrfs_lookup_file_extent(NULL, root, path, btrfs_ino(inode),
                                       extent_start, 0);
        if (ret) {
-               if (ret > 0) {
+               if (unlikely(ret > 0)) {
                        /* The extent item disappeared? */
                        return -EIO;
                }
index 8154393449b8413911ca4981a8b9d69e5bb04c43..4c6097b7e56afbc81350455494c49fe4272bbde2 100644 (file)
@@ -2538,7 +2538,7 @@ static int qgroup_trace_subtree_swap(struct btrfs_trans_handle *trans,
                return -EUCLEAN;
        }
 
-       if (!extent_buffer_uptodate(src_eb) || !extent_buffer_uptodate(dst_eb)) {
+       if (unlikely(!extent_buffer_uptodate(src_eb) || !extent_buffer_uptodate(dst_eb))) {
                ret = -EIO;
                goto out;
        }
@@ -4843,7 +4843,7 @@ int btrfs_qgroup_trace_subtree_after_cow(struct btrfs_trans_handle *trans,
                reloc_eb = NULL;
                goto free_out;
        }
-       if (!extent_buffer_uptodate(reloc_eb)) {
+       if (unlikely(!extent_buffer_uptodate(reloc_eb))) {
                ret = -EIO;
                goto free_out;
        }
index c90612f6cc1b0a4ccabb03efccdcc3ab62f59012..0135dceb7baaa0908b3c238dc7c787e93371213a 100644 (file)
@@ -1167,7 +1167,7 @@ static int rbio_add_io_sector(struct btrfs_raid_bio *rbio,
                /* Check if we have reached tolerance early. */
                found_errors = get_rbio_veritical_errors(rbio, sector_nr,
                                                         NULL, NULL);
-               if (found_errors > rbio->bioc->max_errors)
+               if (unlikely(found_errors > rbio->bioc->max_errors))
                        return -EIO;
                return 0;
        }
@@ -1847,7 +1847,7 @@ static int recover_vertical(struct btrfs_raid_bio *rbio, int sector_nr,
        if (!found_errors)
                return 0;
 
-       if (found_errors > rbio->bioc->max_errors)
+       if (unlikely(found_errors > rbio->bioc->max_errors))
                return -EIO;
 
        /*
@@ -2399,7 +2399,7 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
                int found_errors;
 
                found_errors = get_rbio_veritical_errors(rbio, sectornr, NULL, NULL);
-               if (found_errors > rbio->bioc->max_errors) {
+               if (unlikely(found_errors > rbio->bioc->max_errors)) {
                        ret = -EIO;
                        break;
                }
@@ -2688,7 +2688,7 @@ static int recover_scrub_rbio(struct btrfs_raid_bio *rbio)
 
                found_errors = get_rbio_veritical_errors(rbio, sector_nr,
                                                         &faila, &failb);
-               if (found_errors > rbio->bioc->max_errors) {
+               if (unlikely(found_errors > rbio->bioc->max_errors)) {
                        ret = -EIO;
                        goto out;
                }
@@ -2712,7 +2712,7 @@ static int recover_scrub_rbio(struct btrfs_raid_bio *rbio)
                 * data, so the capability of the repair is declined.  (In the
                 * case of RAID5, we can not repair anything.)
                 */
-               if (dfail > rbio->bioc->max_errors - 1) {
+               if (unlikely(dfail > rbio->bioc->max_errors - 1)) {
                        ret = -EIO;
                        goto out;
                }
@@ -2729,7 +2729,7 @@ static int recover_scrub_rbio(struct btrfs_raid_bio *rbio)
                 * scrubbing parity, luckily, use the other one to repair the
                 * data, or we can not repair the data stripe.
                 */
-               if (failp != rbio->scrubp) {
+               if (unlikely(failp != rbio->scrubp)) {
                        ret = -EIO;
                        goto out;
                }
@@ -2820,7 +2820,7 @@ static void scrub_rbio(struct btrfs_raid_bio *rbio)
                int found_errors;
 
                found_errors = get_rbio_veritical_errors(rbio, sector_nr, NULL, NULL);
-               if (found_errors > rbio->bioc->max_errors) {
+               if (unlikely(found_errors > rbio->bioc->max_errors)) {
                        ret = -EIO;
                        break;
                }
index 94cd55e97f5bd9da7115e73f2ae25c868c2114f7..7027572cb6c16aff4defdec0ed7985b07f6e0ddf 100644 (file)
@@ -2270,7 +2270,7 @@ static int do_relocation(struct btrfs_trans_handle *trans,
 
                bytenr = btrfs_node_blockptr(upper->eb, slot);
                if (lowest) {
-                       if (bytenr != node->bytenr) {
+                       if (unlikely(bytenr != node->bytenr)) {
                                btrfs_err(root->fs_info,
                "lowest leaf/node mismatch: bytenr %llu node->bytenr %llu slot %d upper %llu",
                                          bytenr, node->bytenr, slot,
@@ -2447,7 +2447,7 @@ static int get_tree_block_key(struct btrfs_fs_info *fs_info,
        eb = read_tree_block(fs_info, block->bytenr, &check);
        if (IS_ERR(eb))
                return PTR_ERR(eb);
-       if (!extent_buffer_uptodate(eb)) {
+       if (unlikely(!extent_buffer_uptodate(eb))) {
                free_extent_buffer(eb);
                return -EIO;
        }
@@ -2832,7 +2832,7 @@ again:
        if (!folio_test_uptodate(folio)) {
                btrfs_read_folio(NULL, folio);
                folio_lock(folio);
-               if (!folio_test_uptodate(folio)) {
+               if (unlikely(!folio_test_uptodate(folio))) {
                        ret = -EIO;
                        goto release_folio;
                }
index 641d7975b93634799489009afa58c7f97d3b08a0..4691d0bdb2e86c3c00ca93e1df822f905f0b2ec8 100644 (file)
@@ -1987,7 +1987,7 @@ static int flush_scrub_stripes(struct scrub_ctx *sctx)
                 * metadata, we should immediately abort.
                 */
                for (int i = 0; i < nr_stripes; i++) {
-                       if (stripe_has_metadata_error(&sctx->stripes[i])) {
+                       if (unlikely(stripe_has_metadata_error(&sctx->stripes[i]))) {
                                ret = -EIO;
                                goto out;
                        }
@@ -2181,7 +2181,7 @@ static int scrub_raid56_parity_stripe(struct scrub_ctx *sctx,
                 * As we may hit an empty data stripe while it's missing.
                 */
                bitmap_and(&error, &error, &has_extent, stripe->nr_sectors);
-               if (!bitmap_empty(&error, stripe->nr_sectors)) {
+               if (unlikely(!bitmap_empty(&error, stripe->nr_sectors))) {
                        btrfs_err(fs_info,
 "scrub: unrepaired sectors detected, full stripe %llu data stripe %u errors %*pbl",
                                  full_stripe_start, i, stripe->nr_sectors,
@@ -2875,8 +2875,8 @@ skip_unfreeze:
                btrfs_put_block_group(cache);
                if (ret)
                        break;
-               if (sctx->is_dev_replace &&
-                   atomic64_read(&dev_replace->num_write_errors) > 0) {
+               if (unlikely(sctx->is_dev_replace &&
+                            atomic64_read(&dev_replace->num_write_errors) > 0)) {
                        ret = -EIO;
                        break;
                }
@@ -2904,7 +2904,7 @@ static int scrub_one_super(struct scrub_ctx *sctx, struct btrfs_device *dev,
        if (ret < 0)
                return ret;
        ret = btrfs_check_super_csum(fs_info, sb);
-       if (ret != 0) {
+       if (unlikely(ret != 0)) {
                btrfs_err_rl(fs_info,
                  "scrub: super block at physical %llu devid %llu has bad csum",
                        physical, dev->devid);
@@ -3080,8 +3080,8 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start,
        }
 
        mutex_lock(&fs_info->scrub_lock);
-       if (!test_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &dev->dev_state) ||
-           test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &dev->dev_state)) {
+       if (unlikely(!test_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &dev->dev_state) ||
+                    test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &dev->dev_state))) {
                mutex_unlock(&fs_info->scrub_lock);
                mutex_unlock(&fs_info->fs_devices->device_list_mutex);
                ret = -EIO;
index be830d295a6bd82dca79e8e3852b28164b8b95d6..9230e5066fc6b7a877493ff729af10271539e4ed 100644 (file)
@@ -646,7 +646,7 @@ static int write_buf(struct file *filp, const void *buf, u32 len, loff_t *off)
                ret = kernel_write(filp, buf + pos, len - pos, off);
                if (ret < 0)
                        return ret;
-               if (ret == 0)
+               if (unlikely(ret == 0))
                        return -EIO;
                pos += ret;
        }
@@ -1723,7 +1723,7 @@ static int read_symlink(struct btrfs_root *root,
        ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
        if (ret < 0)
                return ret;
-       if (ret) {
+       if (unlikely(ret)) {
                /*
                 * An empty symlink inode. Can happen in rare error paths when
                 * creating a symlink (transaction committed before the inode
@@ -5199,7 +5199,7 @@ static int put_file_data(struct send_ctx *sctx, u64 offset, u32 len)
                if (!folio_test_uptodate(folio)) {
                        btrfs_read_folio(NULL, folio);
                        folio_lock(folio);
-                       if (!folio_test_uptodate(folio)) {
+                       if (unlikely(!folio_test_uptodate(folio))) {
                                folio_unlock(folio);
                                btrfs_err(fs_info,
                        "send: IO error at offset %llu for inode %llu root %llu",
@@ -6961,7 +6961,7 @@ static int changed_ref(struct send_ctx *sctx,
 {
        int ret = 0;
 
-       if (sctx->cur_ino != sctx->cmp_key->objectid) {
+       if (unlikely(sctx->cur_ino != sctx->cmp_key->objectid)) {
                inconsistent_snapshot_error(sctx, result, "reference");
                return -EIO;
        }
@@ -6989,7 +6989,7 @@ static int changed_xattr(struct send_ctx *sctx,
 {
        int ret = 0;
 
-       if (sctx->cur_ino != sctx->cmp_key->objectid) {
+       if (unlikely(sctx->cur_ino != sctx->cmp_key->objectid)) {
                inconsistent_snapshot_error(sctx, result, "xattr");
                return -EIO;
        }
index 493e5872c6a33d4fd39d5cc7548ca486486dc405..6caba8be7c845ce05354a035bce8dc68ed9a4ba7 100644 (file)
@@ -291,7 +291,7 @@ int zlib_compress_folios(struct list_head *ws, struct btrfs_inode *inode,
                ret = zlib_deflate(&workspace->strm, Z_FINISH);
                if (ret == Z_STREAM_END)
                        break;
-               if (ret != Z_OK && ret != Z_BUF_ERROR) {
+               if (unlikely(ret != Z_OK && ret != Z_BUF_ERROR)) {
                        zlib_deflateEnd(&workspace->strm);
                        ret = -EIO;
                        goto out;
index 39c1f36df8f7b363eb048beef7e9dea552d6a06d..e3341a84f4ab3958d3c0d717c55eac4d6a825cc1 100644 (file)
@@ -274,7 +274,7 @@ static int btrfs_get_dev_zones(struct btrfs_device *device, u64 pos,
                return ret;
        }
        *nr_zones = ret;
-       if (!ret)
+       if (unlikely(!ret))
                return -EIO;
 
        /* Populate cache */
@@ -503,7 +503,7 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device, bool populate_cache)
                sector = zones[nr_zones - 1].start + zones[nr_zones - 1].len;
        }
 
-       if (nreported != zone_info->nr_zones) {
+       if (unlikely(nreported != zone_info->nr_zones)) {
                btrfs_err(device->fs_info,
                                 "inconsistent number of zones on %s (%u/%u)",
                                 rcu_dereference(device->name), nreported,
@@ -513,7 +513,7 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device, bool populate_cache)
        }
 
        if (max_active_zones) {
-               if (nactive > max_active_zones) {
+               if (unlikely(nactive > max_active_zones)) {
                        if (bdev_max_active_zones(bdev) == 0) {
                                max_active_zones = 0;
                                zone_info->max_active_zones = 0;
@@ -901,7 +901,7 @@ int btrfs_sb_log_location_bdev(struct block_device *bdev, int mirror, int rw,
                                  zones);
        if (ret < 0)
                return ret;
-       if (ret != BTRFS_NR_SB_LOG_ZONES)
+       if (unlikely(ret != BTRFS_NR_SB_LOG_ZONES))
                return -EIO;
 
        return sb_log_location(bdev, zones, rw, bytenr_ret);
@@ -1357,7 +1357,7 @@ static int btrfs_load_zone_info(struct btrfs_fs_info *fs_info, int zone_idx,
                return 0;
        }
 
-       if (zone.type == BLK_ZONE_TYPE_CONVENTIONAL) {
+       if (unlikely(zone.type == BLK_ZONE_TYPE_CONVENTIONAL)) {
                btrfs_err(fs_info,
                "zoned: unexpected conventional zone %llu on device %s (devid %llu)",
                        zone.start << SECTOR_SHIFT, rcu_dereference(device->name),
@@ -1399,7 +1399,7 @@ static int btrfs_load_block_group_single(struct btrfs_block_group *bg,
                                         struct zone_info *info,
                                         unsigned long *active)
 {
-       if (info->alloc_offset == WP_MISSING_DEV) {
+       if (unlikely(info->alloc_offset == WP_MISSING_DEV)) {
                btrfs_err(bg->fs_info,
                        "zoned: cannot recover write pointer for zone %llu",
                        info->physical);
@@ -1428,13 +1428,13 @@ static int btrfs_load_block_group_dup(struct btrfs_block_group *bg,
 
        bg->zone_capacity = min_not_zero(zone_info[0].capacity, zone_info[1].capacity);
 
-       if (zone_info[0].alloc_offset == WP_MISSING_DEV) {
+       if (unlikely(zone_info[0].alloc_offset == WP_MISSING_DEV)) {
                btrfs_err(bg->fs_info,
                          "zoned: cannot recover write pointer for zone %llu",
                          zone_info[0].physical);
                return -EIO;
        }
-       if (zone_info[1].alloc_offset == WP_MISSING_DEV) {
+       if (unlikely(zone_info[1].alloc_offset == WP_MISSING_DEV)) {
                btrfs_err(bg->fs_info,
                          "zoned: cannot recover write pointer for zone %llu",
                          zone_info[1].physical);
@@ -1447,14 +1447,14 @@ static int btrfs_load_block_group_dup(struct btrfs_block_group *bg,
        if (zone_info[1].alloc_offset == WP_CONVENTIONAL)
                zone_info[1].alloc_offset = last_alloc;
 
-       if (zone_info[0].alloc_offset != zone_info[1].alloc_offset) {
+       if (unlikely(zone_info[0].alloc_offset != zone_info[1].alloc_offset)) {
                btrfs_err(bg->fs_info,
                          "zoned: write pointer offset mismatch of zones in DUP profile");
                return -EIO;
        }
 
        if (test_bit(0, active) != test_bit(1, active)) {
-               if (!btrfs_zone_activate(bg))
+               if (unlikely(!btrfs_zone_activate(bg)))
                        return -EIO;
        } else if (test_bit(0, active)) {
                set_bit(BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE, &bg->runtime_flags);
@@ -1489,16 +1489,16 @@ static int btrfs_load_block_group_raid1(struct btrfs_block_group *bg,
                if (zone_info[i].alloc_offset == WP_CONVENTIONAL)
                        zone_info[i].alloc_offset = last_alloc;
 
-               if ((zone_info[0].alloc_offset != zone_info[i].alloc_offset) &&
-                   !btrfs_test_opt(fs_info, DEGRADED)) {
+               if (unlikely((zone_info[0].alloc_offset != zone_info[i].alloc_offset) &&
+                            !btrfs_test_opt(fs_info, DEGRADED))) {
                        btrfs_err(fs_info,
                        "zoned: write pointer offset mismatch of zones in %s profile",
                                  btrfs_bg_type_to_raid_name(map->type));
                        return -EIO;
                }
                if (test_bit(0, active) != test_bit(i, active)) {
-                       if (!btrfs_test_opt(fs_info, DEGRADED) &&
-                           !btrfs_zone_activate(bg)) {
+                       if (unlikely(!btrfs_test_opt(fs_info, DEGRADED) &&
+                                    !btrfs_zone_activate(bg))) {
                                return -EIO;
                        }
                } else {
@@ -1554,7 +1554,7 @@ static int btrfs_load_block_group_raid0(struct btrfs_block_group *bg,
                }
 
                if (test_bit(0, active) != test_bit(i, active)) {
-                       if (!btrfs_zone_activate(bg))
+                       if (unlikely(!btrfs_zone_activate(bg)))
                                return -EIO;
                } else {
                        if (test_bit(0, active))
@@ -1586,7 +1586,7 @@ static int btrfs_load_block_group_raid10(struct btrfs_block_group *bg,
                        continue;
 
                if (test_bit(0, active) != test_bit(i, active)) {
-                       if (!btrfs_zone_activate(bg))
+                       if (unlikely(!btrfs_zone_activate(bg)))
                                return -EIO;
                } else {
                        if (test_bit(0, active))
@@ -1643,7 +1643,7 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new)
                return 0;
 
        /* Sanity check */
-       if (!IS_ALIGNED(length, fs_info->zone_size)) {
+       if (unlikely(!IS_ALIGNED(length, fs_info->zone_size))) {
                btrfs_err(fs_info,
                "zoned: block group %llu len %llu unaligned to zone size %llu",
                          logical, length, fs_info->zone_size);
@@ -1756,7 +1756,7 @@ out:
                return -EINVAL;
        }
 
-       if (cache->alloc_offset > cache->zone_capacity) {
+       if (unlikely(cache->alloc_offset > cache->zone_capacity)) {
                btrfs_err(fs_info,
 "zoned: invalid write pointer %llu (larger than zone capacity %llu) in block group %llu",
                          cache->alloc_offset, cache->zone_capacity,
@@ -2087,7 +2087,7 @@ static int read_zone_info(struct btrfs_fs_info *fs_info, u64 logical,
 
        ret = btrfs_map_block(fs_info, BTRFS_MAP_GET_READ_MIRRORS, logical,
                              &mapped_length, &bioc, NULL, NULL);
-       if (ret || !bioc || mapped_length < PAGE_SIZE) {
+       if (unlikely(ret || !bioc || mapped_length < PAGE_SIZE)) {
                ret = -EIO;
                goto out_put_bioc;
        }
index 8f7c8d27c9ca8de01d2c27754221655c23af1b0c..c9cddcfa337b912a973cf1e2df500fe85ba0b04e 100644 (file)
@@ -654,7 +654,7 @@ int zstd_decompress_bio(struct list_head *ws, struct compressed_bio *cb)
                if (workspace->in_buf.pos == workspace->in_buf.size) {
                        kunmap_local(workspace->in_buf.src);
                        folio_in_index++;
-                       if (folio_in_index >= total_folios_in) {
+                       if (unlikely(folio_in_index >= total_folios_in)) {
                                workspace->in_buf.src = NULL;
                                ret = -EIO;
                                goto done;