On Thu, Jan 23, 2020 at 05:18:49PM +0900, Johannes Thumshirn wrote:
> if (btrfs_super_bytenr(super_tmp) != dev_bytenr ||
> btrfs_super_magic(super_tmp) != BTRFS_MAGIC ||
> memcmp(device->uuid, super_tmp->dev_item.uuid, BTRFS_UUID_SIZE) ||
> btrfs_super_nodesize(super_tmp) != state->metablock_size ||
> btrfs_super_sectorsize(super_tmp) != state->datablock_size) {
> - brelse(bh);
> + btrfs_release_disk_super(page);
> return 0;
> }
>
> @@ -795,7 +813,7 @@ static int btrfsic_process_superblock_dev_mirror(
> superblock_tmp = btrfsic_block_alloc();
> if (NULL == superblock_tmp) {
> pr_info("btrfsic: error, kmalloc failed!\n");
> - brelse(bh);
> + btrfs_release_disk_super(page);
> return -1;
> }
> /* for superblock, only the dev_bytenr makes sense */
> @@ -880,7 +898,7 @@ static int btrfsic_process_superblock_dev_mirror(
> mirror_num)) {
> pr_info("btrfsic: btrfsic_map_block(bytenr @%llu, mirror %d) failed!\n",
> next_bytenr, mirror_num);
> - brelse(bh);
> + btrfs_release_disk_super(page);
> return -1;
> }
>
> @@ -890,7 +908,7 @@ static int btrfsic_process_superblock_dev_mirror(
> mirror_num, NULL);
> if (NULL == next_block) {
> btrfsic_release_block_ctx(&tmp_next_block_ctx);
> - brelse(bh);
> + btrfs_release_disk_super(page);
> return -1;
> }
>
> @@ -902,7 +920,7 @@ static int btrfsic_process_superblock_dev_mirror(
> BTRFSIC_GENERATION_UNKNOWN);
> btrfsic_release_block_ctx(&tmp_next_block_ctx);
> if (NULL == l) {
> - brelse(bh);
> + btrfs_release_disk_super(page);
> return -1;
> }
> }
> @@ -910,7 +928,7 @@ static int btrfsic_process_superblock_dev_mirror(
> if (state->print_mask & BTRFSIC_PRINT_MASK_INITIAL_ALL_TREES)
> btrfsic_dump_tree_sub(state, superblock_tmp, 0);
>
> - brelse(bh);
> + btrfs_release_disk_super(page);
This could be the cleaned up to merge all error exits to jump to this
common block. Integrity checker is an old code so nobody cared enough to
clean it up, but it would be good to do it now when there are pople
looking at the code.
As mentioned before, btrfs_release_disk_super should be opencoded so
this would make it more straightfowrard to have only one place instad of
each error exit brelse replaced by put_page/kunmap.
> return 0;
> }