btrfs: Use WARN_ON()'s return value in place of WARN_ON(1)
authorDulshani Gunawardhana <dulshani.gunawardhana89@gmail.com>
Thu, 31 Oct 2013 05:00:08 +0000 (10:30 +0530)
committerChris Mason <chris.mason@fusionio.com>
Tue, 12 Nov 2013 03:11:53 +0000 (22:11 -0500)
Use WARN_ON()'s return value in place of WARN_ON(1) for cleaner source
code that outputs a more descriptive warnings. Also fix the styling
warning of redundant braces that came up as a result of this fix.

Signed-off-by: Dulshani Gunawardhana <dulshani.gunawardhana89@gmail.com>
Reviewed-by: Zach Brown <zab@redhat.com>
Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
14 files changed:
fs/btrfs/backref.c
fs/btrfs/check-integrity.c
fs/btrfs/ctree.c
fs/btrfs/delayed-inode.c
fs/btrfs/disk-io.c
fs/btrfs/extent-tree.c
fs/btrfs/extent_io.c
fs/btrfs/file-item.c
fs/btrfs/inode-map.c
fs/btrfs/inode.c
fs/btrfs/relocation.c
fs/btrfs/send.c
fs/btrfs/tree-log.c
fs/btrfs/volumes.c

index 30d24cfb45d4c2cc5f7386ea426d5c58480ea096..3775947429b28ea07678c4f58877bfcbb5f8bed6 100644 (file)
@@ -326,8 +326,7 @@ static int __resolve_indirect_ref(struct btrfs_fs_info *fs_info,
 
        eb = path->nodes[level];
        while (!eb) {
-               if (!level) {
-                       WARN_ON(1);
+               if (WARN_ON(!level)) {
                        ret = 1;
                        goto out;
                }
index 656b07637e3931dc629d464b5d7927b4235e878e..e0aab44569741342e8a197fcbdfe4d7e6fbd6481 100644 (file)
@@ -2464,10 +2464,8 @@ static int btrfsic_process_written_superblock(
                }
        }
 
-       if (-1 == btrfsic_check_all_ref_blocks(state, superblock, 0)) {
-               WARN_ON(1);
+       if (WARN_ON(-1 == btrfsic_check_all_ref_blocks(state, superblock, 0)))
                btrfsic_dump_tree(state);
-       }
 
        return 0;
 }
@@ -2907,7 +2905,7 @@ static void btrfsic_cmp_log_and_dev_bytenr(struct btrfsic_state *state,
                btrfsic_release_block_ctx(&block_ctx);
        }
 
-       if (!match) {
+       if (WARN_ON(!match)) {
                printk(KERN_INFO "btrfs: attempt to write M-block which contains logical bytenr that doesn't map to dev+physical bytenr of submit_bio,"
                       " buffer->log_bytenr=%llu, submit_bio(bdev=%s,"
                       " phys_bytenr=%llu)!\n",
@@ -2924,7 +2922,6 @@ static void btrfsic_cmp_log_and_dev_bytenr(struct btrfsic_state *state,
                               bytenr, block_ctx.dev->name,
                               block_ctx.dev_bytenr, mirror_num);
                }
-               WARN_ON(1);
        }
 }
 
index a749121203df2b93381d49ddd42e8380fef59671..03c606cefd50ce23a57e8c001541eb4b36e4f5ee 100644 (file)
@@ -1285,11 +1285,10 @@ get_old_root(struct btrfs_root *root, u64 time_seq)
                free_extent_buffer(eb_root);
                blocksize = btrfs_level_size(root, old_root->level);
                old = read_tree_block(root, logical, blocksize, 0);
-               if (!old || !extent_buffer_uptodate(old)) {
+               if (WARN_ON(!old || !extent_buffer_uptodate(old))) {
                        free_extent_buffer(old);
                        pr_warn("btrfs: failed to read tree block %llu from get_old_root\n",
                                logical);
-                       WARN_ON(1);
                } else {
                        eb = btrfs_clone_extent_buffer(old);
                        free_extent_buffer(old);
@@ -3643,8 +3642,7 @@ static noinline int __push_leaf_left(struct btrfs_trans_handle *trans,
                ret = 1;
                goto out;
        }
-       if (!empty && push_items == btrfs_header_nritems(right))
-               WARN_ON(1);
+       WARN_ON(!empty && push_items == btrfs_header_nritems(right));
 
        /* push data from right to left */
        copy_extent_buffer(left, right,
index af2ecca8a109e887879e26209a3b854fda5261a8..2bb8e1a988a1f2b62923416be59201bf803a885f 100644 (file)
@@ -649,14 +649,13 @@ static int btrfs_delayed_inode_reserve_metadata(
                        goto out;
 
                ret = btrfs_block_rsv_migrate(src_rsv, dst_rsv, num_bytes);
-               if (!ret)
+               if (!WARN_ON(ret))
                        goto out;
 
                /*
                 * Ok this is a problem, let's just steal from the global rsv
                 * since this really shouldn't happen that often.
                 */
-               WARN_ON(1);
                ret = btrfs_block_rsv_migrate(&root->fs_info->global_block_rsv,
                                              dst_rsv, num_bytes);
                goto out;
index 22443fac9408da17ca065f38b23e7025e63cefd9..77fa2d99252f56ee47d4379149bb06b3d6815f34 100644 (file)
@@ -475,14 +475,8 @@ static int csum_dirty_buffer(struct btrfs_root *root, struct page *page)
        if (page != eb->pages[0])
                return 0;
        found_start = btrfs_header_bytenr(eb);
-       if (found_start != start) {
-               WARN_ON(1);
+       if (WARN_ON(found_start != start || !PageUptodate(page)))
                return 0;
-       }
-       if (!PageUptodate(page)) {
-               WARN_ON(1);
-               return 0;
-       }
        csum_tree_block(root, eb, 0);
        return 0;
 }
index 3aa52701d04a0fe53ff4a25b77563fdbba8e4780..2d58461bd035f6367ef5b74f4e5e9970cf6e1fbb 100644 (file)
@@ -1550,9 +1550,8 @@ again:
        if (ret && !insert) {
                err = -ENOENT;
                goto out;
-       } else if (ret) {
+       } else if (WARN_ON(ret)) {
                err = -EIO;
-               WARN_ON(1);
                goto out;
        }
 
@@ -5752,9 +5751,8 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
                        }
                        extent_slot = path->slots[0];
                }
-       } else if (ret == -ENOENT) {
+       } else if (WARN_ON(ret == -ENOENT)) {
                btrfs_print_leaf(extent_root, path->nodes[0]);
-               WARN_ON(1);
                btrfs_err(info,
                        "unable to find ref byte nr %llu parent %llu root %llu  owner %llu offset %llu",
                        bytenr, parent, root_objectid, owner_objectid,
@@ -8317,10 +8315,9 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info)
                                        struct btrfs_space_info,
                                        list);
                if (btrfs_test_opt(info->tree_root, ENOSPC_DEBUG)) {
-                       if (space_info->bytes_pinned > 0 ||
+                       if (WARN_ON(space_info->bytes_pinned > 0 ||
                            space_info->bytes_reserved > 0 ||
-                           space_info->bytes_may_use > 0) {
-                               WARN_ON(1);
+                           space_info->bytes_may_use > 0)) {
                                dump_space_info(space_info, 0, 0);
                        }
                }
index a93bab452183cec53a1c605d5a8ee64c017bba91..fb782ed624264a5761c8b0982c7cf7806bb7edca 100644 (file)
@@ -1739,10 +1739,8 @@ u64 count_range_bits(struct extent_io_tree *tree,
        u64 last = 0;
        int found = 0;
 
-       if (search_end <= cur_start) {
-               WARN_ON(1);
+       if (WARN_ON(search_end <= cur_start))
                return 0;
-       }
 
        spin_lock(&tree->lock);
        if (cur_start == 0 && bits == EXTENT_DIRTY) {
@@ -3568,9 +3566,8 @@ retry:
                         * but no sense in crashing the users box for something
                         * we can survive anyway.
                         */
-                       if (!eb) {
+                       if (WARN_ON(!eb)) {
                                spin_unlock(&mapping->private_lock);
-                               WARN_ON(1);
                                continue;
                        }
 
index ae8a5139e0eea5ec606068f30f3b3022a5933d54..6f384886028386f2f069756ef18e757b10ba9dbf 100644 (file)
@@ -849,10 +849,8 @@ insert:
        path->leave_spinning = 0;
        if (ret < 0)
                goto fail_unlock;
-       if (ret != 0) {
-               WARN_ON(1);
+       if (WARN_ON(ret != 0))
                goto fail_unlock;
-       }
        leaf = path->nodes[0];
 csum:
        item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_csum_item);
index ec08004a6a205a28c0bada26afd54ce2a12c9a5a..ab485e57b6fe6c7ea14f580976dd46c7efd88ffb 100644 (file)
@@ -78,10 +78,8 @@ again:
                            btrfs_transaction_in_commit(fs_info)) {
                                leaf = path->nodes[0];
 
-                               if (btrfs_header_nritems(leaf) == 0) {
-                                       WARN_ON(1);
+                               if (WARN_ON(btrfs_header_nritems(leaf) == 0))
                                        break;
-                               }
 
                                /*
                                 * Save the key so we can advances forward
index 17800221978f0cf08c9a4b36fb350bef806be11f..ddecc9c332f4eed81596bc9fe4d75dd0c9b5ada1 100644 (file)
@@ -2039,10 +2039,8 @@ static noinline int record_one_backref(u64 inum, u64 offset, u64 root_id,
                key.offset = offset;
 
        ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
-       if (ret < 0) {
-               WARN_ON(1);
+       if (WARN_ON(ret < 0))
                return ret;
-       }
        ret = 0;
 
        while (1) {
@@ -3182,8 +3180,7 @@ int btrfs_orphan_cleanup(struct btrfs_root *root)
 
                /* if we have links, this was a truncate, lets do that */
                if (inode->i_nlink) {
-                       if (!S_ISREG(inode->i_mode)) {
-                               WARN_ON(1);
+                       if (WARN_ON(!S_ISREG(inode->i_mode))) {
                                iput(inode);
                                continue;
                        }
@@ -8023,8 +8020,7 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,
                if (ret == -EEXIST) {
                        /* we shouldn't get
                         * eexist without a new_inode */
-                       if (!new_inode) {
-                               WARN_ON(1);
+                       if (WARN_ON(!new_inode)) {
                                return ret;
                        }
                } else {
index a5f6a8061b21c8b3e84e26ec14606c02d561640b..70eca79bae529de2b9dae700ce2555fdafd6ff88 100644 (file)
@@ -1777,8 +1777,7 @@ again:
                        new_ptr_gen = 0;
                }
 
-               if (new_bytenr > 0 && new_bytenr == old_bytenr) {
-                       WARN_ON(1);
+               if (WARN_ON(new_bytenr > 0 && new_bytenr == old_bytenr)) {
                        ret = level;
                        break;
                }
@@ -3545,10 +3544,8 @@ static int find_data_references(struct reloc_control *rc,
                                err = ret;
                                goto out;
                        }
-                       if (ret > 0) {
-                               WARN_ON(1);
+                       if (WARN_ON(ret > 0))
                                goto out;
-                       }
 
                        leaf = path->nodes[0];
                        nritems = btrfs_header_nritems(leaf);
@@ -3568,11 +3565,9 @@ static int find_data_references(struct reloc_control *rc,
                }
 
                btrfs_item_key_to_cpu(leaf, &key, path->slots[0]);
-               if (key.objectid != ref_objectid ||
-                   key.type != BTRFS_EXTENT_DATA_KEY) {
-                       WARN_ON(1);
+               if (WARN_ON(key.objectid != ref_objectid ||
+                   key.type != BTRFS_EXTENT_DATA_KEY))
                        break;
-               }
 
                fi = btrfs_item_ptr(leaf, path->slots[0],
                                    struct btrfs_file_extent_item);
index e26a3a62fd3f766882434de5a167f76059171da8..ec2f02435287f73ef53ccbd49c0808f03149b253 100644 (file)
@@ -564,10 +564,8 @@ static int begin_cmd(struct send_ctx *sctx, int cmd)
 {
        struct btrfs_cmd_header *hdr;
 
-       if (!sctx->send_buf) {
-               WARN_ON(1);
+       if (WARN_ON(!sctx->send_buf))
                return -EINVAL;
-       }
 
        BUG_ON(sctx->send_size);
 
index 7927a5fa755cfaaeaac6328013a80832000658a2..744553c83fe2ad79a5b07715167e6d887373bc8f 100644 (file)
@@ -2130,8 +2130,7 @@ static noinline int walk_down_log_tree(struct btrfs_trans_handle *trans,
                WARN_ON(*level >= BTRFS_MAX_LEVEL);
                cur = path->nodes[*level];
 
-               if (btrfs_header_level(cur) != *level)
-                       WARN_ON(1);
+               WARN_ON(btrfs_header_level(cur) != *level);
 
                if (path->slots[*level] >=
                    btrfs_header_nritems(cur))
@@ -2951,10 +2950,8 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans,
 
        /* find the first key from this transaction again */
        ret = btrfs_search_slot(NULL, root, &min_key, path, 0, 0);
-       if (ret != 0) {
-               WARN_ON(1);
+       if (WARN_ON(ret != 0))
                goto done;
-       }
 
        /*
         * we have a block from this transaction, log every item in it
index 716abee16a5ba74fecf679ffaa39c9505f943aba..3c16da51348fa28ee1e250d178ca9c06fee95af3 100644 (file)
@@ -2552,8 +2552,7 @@ again:
                failed = 0;
                retried = true;
                goto again;
-       } else if (failed && retried) {
-               WARN_ON(1);
+       } else if (WARN_ON(failed && retried)) {
                ret = -ENOSPC;
        }
 error:
@@ -5402,10 +5401,8 @@ static int bio_size_ok(struct block_device *bdev, struct bio *bio,
                .bi_rw = bio->bi_rw,
        };
 
-       if (bio->bi_vcnt == 0) {
-               WARN_ON(1);
+       if (WARN_ON(bio->bi_vcnt == 0))
                return 1;
-       }
 
        prev = &bio->bi_io_vec[bio->bi_vcnt - 1];
        if (bio_sectors(bio) > max_sectors)
@@ -5638,10 +5635,8 @@ struct btrfs_device *btrfs_alloc_device(struct btrfs_fs_info *fs_info,
        struct btrfs_device *dev;
        u64 tmp;
 
-       if (!devid && !fs_info) {
-               WARN_ON(1);
+       if (WARN_ON(!devid && !fs_info))
                return ERR_PTR(-EINVAL);
-       }
 
        dev = __alloc_device();
        if (IS_ERR(dev))