Message ID | 20200212071704.17505-9-johannes.thumshirn@wdc.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | btrfs: remove buffer heads form superblock handling | expand |
On Wed, Feb 12, 2020 at 04:17:04PM +0900, Johannes Thumshirn wrote: > @@ -762,29 +761,45 @@ static int btrfsic_process_superblock_dev_mirror( > struct btrfs_fs_info *fs_info = state->fs_info; > struct btrfs_super_block *super_tmp; > u64 dev_bytenr; > - struct buffer_head *bh; > struct btrfsic_block *superblock_tmp; > int pass; > struct block_device *const superblock_bdev = device->bdev; > + struct page *page; > + struct bio bio; > + struct bio_vec bio_vec; > + struct address_space *mapping = superblock_bdev->bd_inode->i_mapping; > + int ret; > > /* super block bytenr is always the unmapped device bytenr */ > dev_bytenr = btrfs_sb_offset(superblock_mirror_num); > if (dev_bytenr + BTRFS_SUPER_INFO_SIZE > device->commit_total_bytes) > return -1; > - bh = __bread(superblock_bdev, dev_bytenr / BTRFS_BDEV_BLOCKSIZE, > - BTRFS_SUPER_INFO_SIZE); > - if (NULL == bh) > + > + page = find_or_create_page(mapping, dev_bytenr >> PAGE_SHIFT, GFP_NOFS); > + if (!page) > + return -1; > + > + bio_init(&bio, &bio_vec, 1); > + bio.bi_iter.bi_sector = dev_bytenr >> SECTOR_SHIFT; > + bio_set_dev(&bio, superblock_bdev); > + bio_set_op_attrs(&bio, REQ_OP_READ, 0); > + bio_add_page(&bio, page, BTRFS_SUPER_INFO_SIZE, 0); > + > + ret = submit_bio_wait(&bio); > + if (ret) > return -1; > - super_tmp = (struct btrfs_super_block *) > - (bh->b_data + (dev_bytenr & (BTRFS_BDEV_BLOCKSIZE - 1))); > + > + unlock_page(page); > + > + super_tmp = kmap(page); I beleve the same reasoning applies here regarding kmap, it's the bdev mapping and we won't get a highmem page. > > 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); > - return 0; > + ret = 0; > + goto out_unmap; > } > > superblock_tmp =
On 12/02/2020 18:06, David Sterba wrote: > On Wed, Feb 12, 2020 at 04:17:04PM +0900, Johannes Thumshirn wrote: >> @@ -762,29 +761,45 @@ static int btrfsic_process_superblock_dev_mirror( >> struct btrfs_fs_info *fs_info = state->fs_info; >> struct btrfs_super_block *super_tmp; >> u64 dev_bytenr; >> - struct buffer_head *bh; >> struct btrfsic_block *superblock_tmp; >> int pass; >> struct block_device *const superblock_bdev = device->bdev; >> + struct page *page; >> + struct bio bio; >> + struct bio_vec bio_vec; >> + struct address_space *mapping = superblock_bdev->bd_inode->i_mapping; >> + int ret; >> >> /* super block bytenr is always the unmapped device bytenr */ >> dev_bytenr = btrfs_sb_offset(superblock_mirror_num); >> if (dev_bytenr + BTRFS_SUPER_INFO_SIZE > device->commit_total_bytes) >> return -1; >> - bh = __bread(superblock_bdev, dev_bytenr / BTRFS_BDEV_BLOCKSIZE, >> - BTRFS_SUPER_INFO_SIZE); >> - if (NULL == bh) >> + >> + page = find_or_create_page(mapping, dev_bytenr >> PAGE_SHIFT, GFP_NOFS); >> + if (!page) >> + return -1; >> + >> + bio_init(&bio, &bio_vec, 1); >> + bio.bi_iter.bi_sector = dev_bytenr >> SECTOR_SHIFT; >> + bio_set_dev(&bio, superblock_bdev); >> + bio_set_op_attrs(&bio, REQ_OP_READ, 0); >> + bio_add_page(&bio, page, BTRFS_SUPER_INFO_SIZE, 0); >> + >> + ret = submit_bio_wait(&bio); >> + if (ret) >> return -1; >> - super_tmp = (struct btrfs_super_block *) >> - (bh->b_data + (dev_bytenr & (BTRFS_BDEV_BLOCKSIZE - 1))); >> + >> + unlock_page(page); >> + >> + super_tmp = kmap(page); > > I beleve the same reasoning applies here regarding kmap, it's the bdev > mapping and we won't get a highmem page. > Ah damn it my bad and __bio_add_page() as well. Can I send you a follow-on patch to fold in?
diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c index 4f6db2fe482a..e10a27d6db08 100644 --- a/fs/btrfs/check-integrity.c +++ b/fs/btrfs/check-integrity.c @@ -77,7 +77,6 @@ #include <linux/sched.h> #include <linux/slab.h> -#include <linux/buffer_head.h> #include <linux/mutex.h> #include <linux/genhd.h> #include <linux/blkdev.h> @@ -762,29 +761,45 @@ static int btrfsic_process_superblock_dev_mirror( struct btrfs_fs_info *fs_info = state->fs_info; struct btrfs_super_block *super_tmp; u64 dev_bytenr; - struct buffer_head *bh; struct btrfsic_block *superblock_tmp; int pass; struct block_device *const superblock_bdev = device->bdev; + struct page *page; + struct bio bio; + struct bio_vec bio_vec; + struct address_space *mapping = superblock_bdev->bd_inode->i_mapping; + int ret; /* super block bytenr is always the unmapped device bytenr */ dev_bytenr = btrfs_sb_offset(superblock_mirror_num); if (dev_bytenr + BTRFS_SUPER_INFO_SIZE > device->commit_total_bytes) return -1; - bh = __bread(superblock_bdev, dev_bytenr / BTRFS_BDEV_BLOCKSIZE, - BTRFS_SUPER_INFO_SIZE); - if (NULL == bh) + + page = find_or_create_page(mapping, dev_bytenr >> PAGE_SHIFT, GFP_NOFS); + if (!page) + return -1; + + bio_init(&bio, &bio_vec, 1); + bio.bi_iter.bi_sector = dev_bytenr >> SECTOR_SHIFT; + bio_set_dev(&bio, superblock_bdev); + bio_set_op_attrs(&bio, REQ_OP_READ, 0); + bio_add_page(&bio, page, BTRFS_SUPER_INFO_SIZE, 0); + + ret = submit_bio_wait(&bio); + if (ret) return -1; - super_tmp = (struct btrfs_super_block *) - (bh->b_data + (dev_bytenr & (BTRFS_BDEV_BLOCKSIZE - 1))); + + unlock_page(page); + + super_tmp = kmap(page); 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); - return 0; + ret = 0; + goto out_unmap; } superblock_tmp = @@ -795,8 +810,8 @@ 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); - return -1; + ret = -1; + goto out_unmap; } /* for superblock, only the dev_bytenr makes sense */ superblock_tmp->dev_bytenr = dev_bytenr; @@ -880,8 +895,8 @@ 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); - return -1; + ret = -1; + goto out_unmap; } next_block = btrfsic_block_lookup_or_add( @@ -890,8 +905,8 @@ static int btrfsic_process_superblock_dev_mirror( mirror_num, NULL); if (NULL == next_block) { btrfsic_release_block_ctx(&tmp_next_block_ctx); - brelse(bh); - return -1; + ret = -1; + goto out_unmap; } next_block->disk_key = tmp_disk_key; @@ -902,16 +917,18 @@ static int btrfsic_process_superblock_dev_mirror( BTRFSIC_GENERATION_UNKNOWN); btrfsic_release_block_ctx(&tmp_next_block_ctx); if (NULL == l) { - brelse(bh); - return -1; + ret = -1; + goto out_unmap; } } } if (state->print_mask & BTRFSIC_PRINT_MASK_INITIAL_ALL_TREES) btrfsic_dump_tree_sub(state, superblock_tmp, 0); - brelse(bh); - return 0; +out_unmap: + kunmap(page); + put_page(page); + return ret; } static struct btrfsic_stack_frame *btrfsic_stack_frame_alloc(void)