btrfs: return bool from lock_extent_buffer_for_io
authorChristoph Hellwig <hch@lst.de>
Wed, 3 May 2023 15:24:30 +0000 (17:24 +0200)
committerDavid Sterba <dsterba@suse.com>
Mon, 19 Jun 2023 11:59:27 +0000 (13:59 +0200)
lock_extent_buffer_for_io never returns a negative error value, so switch
the return value to a simple bool.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: David Sterba <dsterba@suse.com>
[ keep noinline_for_stack ]
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/extent_io.c

index e35dfae..898c608 100644 (file)
@@ -1629,18 +1629,17 @@ static void end_extent_buffer_writeback(struct extent_buffer *eb)
  *
  * May try to flush write bio if we can't get the lock.
  *
- * Return  0 if the extent buffer doesn't need to be submitted.
- *           (E.g. the extent buffer is not dirty)
- * Return >0 is the extent buffer is submitted to bio.
- * Return <0 if something went wrong, no page is locked.
+ * Return %false if the extent buffer doesn't need to be submitted (e.g. the
+ * extent buffer is not dirty)
+ * Return %true is the extent buffer is submitted to bio.
  */
-static noinline_for_stack int lock_extent_buffer_for_io(struct extent_buffer *eb,
+static noinline_for_stack bool lock_extent_buffer_for_io(struct extent_buffer *eb,
                          struct btrfs_bio_ctrl *bio_ctrl)
 {
        struct btrfs_fs_info *fs_info = eb->fs_info;
        int i, num_pages;
        int flush = 0;
-       int ret = 0;
+       bool ret = false;
 
        if (!btrfs_try_tree_write_lock(eb)) {
                submit_write_bio(bio_ctrl, 0);
@@ -1651,7 +1650,7 @@ static noinline_for_stack int lock_extent_buffer_for_io(struct extent_buffer *eb
        if (test_bit(EXTENT_BUFFER_WRITEBACK, &eb->bflags)) {
                btrfs_tree_unlock(eb);
                if (bio_ctrl->wbc->sync_mode != WB_SYNC_ALL)
-                       return 0;
+                       return false;
                if (!flush) {
                        submit_write_bio(bio_ctrl, 0);
                        flush = 1;
@@ -1678,7 +1677,7 @@ static noinline_for_stack int lock_extent_buffer_for_io(struct extent_buffer *eb
                percpu_counter_add_batch(&fs_info->dirty_metadata_bytes,
                                         -eb->len,
                                         fs_info->dirty_metadata_batch);
-               ret = 1;
+               ret = true;
        } else {
                spin_unlock(&eb->refs_lock);
        }
@@ -2012,7 +2011,6 @@ static int submit_eb_subpage(struct page *page, struct btrfs_bio_ctrl *bio_ctrl)
        u64 page_start = page_offset(page);
        int bit_start = 0;
        int sectors_per_node = fs_info->nodesize >> fs_info->sectorsize_bits;
-       int ret;
 
        /* Lock and write each dirty extent buffers in the range */
        while (bit_start < fs_info->subpage_info->bitmap_nr_bits) {
@@ -2058,25 +2056,13 @@ static int submit_eb_subpage(struct page *page, struct btrfs_bio_ctrl *bio_ctrl)
                if (!eb)
                        continue;
 
-               ret = lock_extent_buffer_for_io(eb, bio_ctrl);
-               if (ret == 0) {
-                       free_extent_buffer(eb);
-                       continue;
+               if (lock_extent_buffer_for_io(eb, bio_ctrl)) {
+                       write_one_subpage_eb(eb, bio_ctrl);
+                       submitted++;
                }
-               if (ret < 0) {
-                       free_extent_buffer(eb);
-                       goto cleanup;
-               }
-               write_one_subpage_eb(eb, bio_ctrl);
                free_extent_buffer(eb);
-               submitted++;
        }
        return submitted;
-
-cleanup:
-       /* We hit error, end bio for the submitted extent buffers */
-       submit_write_bio(bio_ctrl, ret);
-       return ret;
 }
 
 /*
@@ -2155,8 +2141,7 @@ static int submit_eb_page(struct page *page, struct btrfs_bio_ctrl *bio_ctrl,
 
        *eb_context = eb;
 
-       ret = lock_extent_buffer_for_io(eb, bio_ctrl);
-       if (ret <= 0) {
+       if (!lock_extent_buffer_for_io(eb, bio_ctrl)) {
                btrfs_revert_meta_write_pointer(cache, eb);
                if (cache)
                        btrfs_put_block_group(cache);