From: Christoph Hellwig <hch@lst.de> Date: 2021-10-15 13:27:13
Add a helpe to query the size of a block device in bytes. This
will be used to remove open coded access to ->bd_inode.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
include/linux/genhd.h | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
From: Christoph Hellwig <hch@lst.de> Date: 2021-10-15 13:27:26
Ensure these are always available for inlines in the various block layer
headers.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
include/linux/blk_types.h | 17 +++++++++++++++++
include/linux/blkdev.h | 17 -----------------
2 files changed, 17 insertions(+), 17 deletions(-)
@@ -334,7 +334,7 @@ static int __write_initial_superblock(struct dm_cache_metadata *cmd)intr;structdm_block*sblock;structcache_disk_superblock*disk_super;-sector_tbdev_size=i_size_read(cmd->bdev->bd_inode)>>SECTOR_SHIFT;+sector_tbdev_size=bdev_nr_sectors(cmd->bdev);/* FIXME: see if we can lose the max sectors limit */if(bdev_size>DM_CACHE_METADATA_MAX_SECTORS)
@@ -1261,7 +1261,7 @@ static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as,md_rdev_init(jdev);jdev->mddev=&rs->md;jdev->bdev=rs->journal_dev.dev->bdev;-jdev->sectors=to_sector(i_size_read(jdev->bdev->bd_inode));+jdev->sectors=bdev_nr_sectors(jdev->bdev);if(jdev->sectors<MIN_RAID456_JOURNAL_SPACE){rs->ti->error="No space for raid4/5/6 journal";return-ENOSPC;
@@ -1607,7 +1607,7 @@ static int _check_data_dev_sectors(struct raid_set *rs)rdev_for_each(rdev,&rs->md)if(!test_bit(Journal,&rdev->flags)&&rdev->bdev){-ds=min(ds,to_sector(i_size_read(rdev->bdev->bd_inode)));+ds=min(ds,bdev_nr_sectors(rdev->bdev));if(ds<rs->md.dev_sectors){rs->ti->error="Component device(s) too small";return-EINVAL;
@@ -2662,7 +2662,7 @@ static int rs_adjust_data_offsets(struct raid_set *rs)*Makesurewegotaminimumamountoffreesectorsperdevice*/if(rs->data_offset&&-to_sector(i_size_read(rdev->bdev->bd_inode))-rs->md.dev_sectors<MIN_FREE_RESHAPE_SPACE){+bdev_nr_sectors(rdev->bdev)-rs->md.dev_sectors<MIN_FREE_RESHAPE_SPACE){rs->ti->error=data_offset?"No space for forward reshape":"No space for backward reshape";return-ENOSPC;
@@ -733,7 +733,7 @@ static int dmz_get_zoned_device(struct dm_target *ti, char *path,dev->dev_idx=idx;(void)bdevname(dev->bdev,dev->name);-dev->capacity=i_size_read(bdev->bd_inode)>>SECTOR_SHIFT;+dev->capacity=bdev_nr_sectors(bdev);if(ti->begin){ti->error="Partial mapping is not supported";gotoerr;
From: Christoph Hellwig <hch@lst.de> Date: 2021-10-15 13:27:31
Use the proper helper to read the block device size.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Kees Cook <redacted>
Acked-by: Song Liu <song@kernel.org>
---
drivers/md/md.c | 26 +++++++++++---------------
1 file changed, 11 insertions(+), 15 deletions(-)
@@ -890,8 +890,7 @@ static struct md_personality *find_pers(int level, char *clevel)/* return the offset of the super block in 512byte sectors */staticinlinesector_tcalc_dev_sboffset(structmd_rdev*rdev){-sector_tnum_sectors=i_size_read(rdev->bdev->bd_inode)/512;-returnMD_NEW_SIZE_SECTORS(num_sectors);+returnMD_NEW_SIZE_SECTORS(bdev_nr_sectors(rdev->bdev));}staticintalloc_disk_sb(structmd_rdev*rdev)
@@ -1633,8 +1632,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_*/switch(minor_version){case0:-sb_start=i_size_read(rdev->bdev->bd_inode)>>9;-sb_start-=8*2;+sb_start=bdev_nr_sectors(rdev->bdev)-8*2;sb_start&=~(sector_t)(4*2-1);break;case1:
@@ -1789,10 +1787,9 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_elseret=0;}-if(minor_version){-sectors=(i_size_read(rdev->bdev->bd_inode)>>9);-sectors-=rdev->data_offset;-}else+if(minor_version)+sectors=bdev_nr_sectors(rdev->bdev)-rdev->data_offset;+elsesectors=rdev->sb_start;if(sectors<le64_to_cpu(sb->data_size))return-EINVAL;
@@ -2170,8 +2167,7 @@ super_1_rdev_size_change(struct md_rdev *rdev, sector_t num_sectors)return0;/* too confusing */if(rdev->sb_start<rdev->data_offset){/* minor versions 1 and 2; superblock before data */-max_sectors=i_size_read(rdev->bdev->bd_inode)>>9;-max_sectors-=rdev->data_offset;+max_sectors=bdev_nr_sectors(rdev->bdev)-rdev->data_offset;if(!num_sectors||num_sectors>max_sectors)num_sectors=max_sectors;}elseif(rdev->mddev->bitmap_info.offset){
@@ -2180,7 +2176,7 @@ super_1_rdev_size_change(struct md_rdev *rdev, sector_t num_sectors)}else{/* minor version 0; superblock after data */sector_tsb_start,bm_space;-sector_tdev_size=i_size_read(rdev->bdev->bd_inode)>>9;+sector_tdev_size=bdev_nr_sectors(rdev->bdev);/* 8K is for superblock */sb_start=dev_size-8*2;
@@ -3384,7 +3380,7 @@ rdev_size_store(struct md_rdev *rdev, const char *buf, size_t len)if(!sectors)return-EBUSY;}elseif(!sectors)-sectors=(i_size_read(rdev->bdev->bd_inode)>>9)-+sectors=bdev_nr_sectors(rdev->bdev)-rdev->data_offset;if(!my_mddev->pers->resize)/* Cannot change size for RAID0 or Linear etc */
@@ -3711,7 +3707,7 @@ static struct md_rdev *md_import_device(dev_t newdev, int super_format, int supekobject_init(&rdev->kobj,&rdev_ktype);-size=i_size_read(rdev->bdev->bd_inode)>>BLOCK_SIZE_BITS;+size=bdev_nr_bytes(rdev->bdev)>>BLOCK_SIZE_BITS;if(!size){pr_warn("md: %s has zero or unknown size, marking faulty!\n",bdevname(rdev->bdev,b));
From: Christoph Hellwig <hch@lst.de> Date: 2021-10-15 13:27:52
Use the proper helper to read the block device size.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
---
fs/buffer.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
@@ -232,9 +232,9 @@ static unsigned long long iblock_emulate_read_cap_with_block_size(structblock_device*bd,structrequest_queue*q){-unsignedlonglongblocks_long=(div_u64(i_size_read(bd->bd_inode),-bdev_logical_block_size(bd))-1);u32block_size=bdev_logical_block_size(bd);+unsignedlonglongblocks_long=+div_u64(bdev_nr_bytes(bd),block_size)-1;if(block_size==dev->dev_attrib.block_size)returnblocks_long;
From: Christoph Hellwig <hch@lst.de> Date: 2021-10-15 13:27:58
No need to convert from bdev to inode and back.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Kees Cook <redacted>
Reviewed-by: Jan Kara <jack@suse.cz>
---
fs/buffer.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
@@ -283,8 +283,7 @@ static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,}-if(i_size_read(bdev->bd_inode)<-btrfs_device_get_total_bytes(srcdev)){+if(bdev_nr_bytes(bdev)<btrfs_device_get_total_bytes(srcdev)){btrfs_err(fs_info,"target device is smaller than source device!");ret=-EINVAL;
@@ -1286,7 +1286,7 @@ static struct btrfs_super_block *btrfs_read_disk_super(struct block_device *bdevpgoff_tindex;/* make sure our super fits in the device */-if(bytenr+PAGE_SIZE>=i_size_read(bdev->bd_inode))+if(bytenr+PAGE_SIZE>=bdev_nr_bytes(bdev))returnERR_PTR(-EINVAL);/* make sure our super fits in the page */
@@ -1536,14 +1536,11 @@ static int fat_read_static_bpb(struct super_block *sb,structfat_bios_param_block*bpb){staticconstchar*notdos1x="This doesn't look like a DOS 1.x volume";-+sector_tbd_sects=bdev_nr_sectors(sb->s_bdev);structfat_floppy_defaults*fdefaults=NULL;interror=-EINVAL;-sector_tbd_sects;unsignedi;-bd_sects=i_size_read(sb->s_bdev->bd_inode)/SECTOR_SIZE;-/* 16-bit DOS 1.x reliably wrote bootstrap short-jmp code */if(b->ignored[0]!=0xeb||b->ignored[2]!=0x90){if(!silent)
@@ -199,7 +199,7 @@ int jfs_extendfs(struct super_block *sb, s64 newLVSize, int newLogSize)txQuiesce(sb);/* Reset size of direct inode */-sbi->direct_inode->i_size=i_size_read(sb->s_bdev->bd_inode);+sbi->direct_inode->i_size=bdev_nr_bytes(sb->s_bdev);if(sbi->mntflag&JFS_INLINELOG){/*
From: Christoph Hellwig <hch@lst.de> Date: 2021-10-15 13:30:02
Use the proper helper to read the block device size and remove two
cargo culted checks that can't be false.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Jan Kara <jack@suse.cz>
---
fs/reiserfs/super.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
@@ -1986,9 +1986,7 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)*smallerthanthefilesystem.Ifthecheckfailsthenabortand*scream,becausebadstuffwillhappenotherwise.*/-if(s->s_bdev&&s->s_bdev->bd_inode-&&i_size_read(s->s_bdev->bd_inode)<-sb_block_count(rs)*sb_blocksize(rs)){+if(bdev_nr_bytes(s->s_bdev)<sb_block_count(rs)*sb_blocksize(rs)){SWARN(silent,s,"","Filesystem cannot be ""mounted because it is bigger than the device");SWARN(silent,s,"","You may need to run fsck "
@@ -217,14 +216,13 @@ static int __register_pstore_blk(struct pstore_device_info *dev,gotoerr;}-inode=file_inode(psblk_file);-if(!S_ISBLK(inode->i_mode)){+if(!S_ISBLK(file_inode(psblk_file)->i_mode)){pr_err("'%s' is not block device!\n",devpath);gotoerr_fput;}-inode=I_BDEV(psblk_file->f_mapping->host)->bd_inode;-dev->zone.total_size=i_size_read(inode);+dev->zone.total_size=+bdev_nr_bytes(I_BDEV(psblk_file->f_mapping->host));ret=__register_pstore_device(dev);if(ret)
@@ -179,8 +180,8 @@ static int squashfs_fill_super(struct super_block *sb, struct fs_context *fc)/* Check the filesystem does not extend beyond the end of theblockdevice*/msblk->bytes_used=le64_to_cpu(sblk->bytes_used);-if(msblk->bytes_used<0||msblk->bytes_used>-i_size_read(sb->s_bdev->bd_inode))+if(msblk->bytes_used<0||+msblk->bytes_used>bdev_nr_bytes(sb->s_bdev))gotofailed_mount;/* Check block size for sanity */
From: Christoph Hellwig <hch@lst.de> Date: 2021-10-15 13:30:39
Use the proper helper to read the block device size.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
---
block/fops.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
@@ -548,7 +548,7 @@ static long blkdev_fallocate(struct file *file, int mode, loff_t start,return-EOPNOTSUPP;/* Don't go off the end of the device. */-isize=i_size_read(bdev->bd_inode);+isize=bdev_nr_bytes(bdev);if(start>=isize)return-EINVAL;if(end>=isize){
From: Christoph Hellwig <hch@lst.de> Date: 2021-10-15 13:30:46
Add a helper to return the size of sb->s_bdev in sb->s_blocksize_bits
based unites. Note that SECTOR_SHIFT has to be open coded due to
include dependency issues for now, but I have a plan to sort that out
eventually.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
include/linux/genhd.h | 6 ++++++
1 file changed, 6 insertions(+)
From: Christoph Hellwig <hch@lst.de> Date: 2021-10-15 13:31:29
Use the sb_bdev_nr_blocks helper instead of open coding it.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Kees Cook <redacted>
Reviewed-by: Jan Kara <jack@suse.cz>
Acked-by: Theodore Ts'o <tytso@mit.edu>
---
fs/ext4/super.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: Christoph Hellwig <hch@lst.de> Date: 2021-10-15 13:31:32
Use the sb_bdev_nr_blocks helper instead of open coding it and clean up
ntfs_fill_super a bit by moving an assignment a little earlier that has
no negative side effects.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Kees Cook <redacted>
---
fs/ntfs/super.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
@@ -2772,13 +2772,12 @@ static int ntfs_fill_super(struct super_block *sb, void *opt, const int silent)ntfs_debug("Set device block size to %i bytes (block size bits %i).",blocksize,sb->s_blocksize_bits);/* Determine the size of the device in units of block_size bytes. */-if(!i_size_read(sb->s_bdev->bd_inode)){+vol->nr_blocks=sb_bdev_nr_blocks(sb);+if(!vol->nr_blocks){if(!silent)ntfs_error(sb,"Unable to determine device size.");gotoerr_out_now;}-vol->nr_blocks=i_size_read(sb->s_bdev->bd_inode)>>-sb->s_blocksize_bits;/* Read the boot sector and return unlocked buffer head to it. */if(!(bh=read_ntfs_boot_sector(sb,silent))){if(!silent)
@@ -2816,8 +2815,7 @@ static int ntfs_fill_super(struct super_block *sb, void *opt, const int silent)gotoerr_out_now;}BUG_ON(blocksize!=sb->s_blocksize);-vol->nr_blocks=i_size_read(sb->s_bdev->bd_inode)>>-sb->s_blocksize_bits;+vol->nr_blocks=sb_bdev_nr_blocks(sb);ntfs_debug("Changed device block size to %i bytes (block size ""bits %i) to match volume sector size.",blocksize,sb->s_blocksize_bits);
From: Christoph Hellwig <hch@lst.de> Date: 2021-10-15 13:31:33
Use the sb_bdev_nr_blocks helper instead of open coding it.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Kees Cook <redacted>
Reviewed-by: Jan Kara <jack@suse.cz>
---
fs/reiserfs/super.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
@@ -1199,9 +1199,7 @@ static int reiserfs_parse_options(struct super_block *s,if(!strcmp(arg,"auto")){/* From JFS code, to auto-get the size. */-*blocks=-i_size_read(s->s_bdev->bd_inode)>>s->-s_blocksize_bits;+*blocks=sb_bdev_nr_blocks(s);}else{*blocks=simple_strtoul(arg,&p,0);if(*p!='\0'){
From: Christoph Hellwig <hch@lst.de> Date: 2021-10-15 13:31:33
Use the sb_bdev_nr_blocks helper instead of open coding it.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Kees Cook <redacted>
Reviewed-by: Jan Kara <jack@suse.cz>
---
fs/udf/lowlevel.c | 5 ++---
fs/udf/super.c | 9 +++------
2 files changed, 5 insertions(+), 9 deletions(-)
@@ -1175,8 +1175,7 @@ static int udf_load_vat(struct super_block *sb, int p_index, int type1_index)structudf_inode_info*vati;uint32_tpos;structvirtualAllocationTable20*vat20;-sector_tblocks=i_size_read(sb->s_bdev->bd_inode)>>-sb->s_blocksize_bits;+sector_tblocks=sb_bdev_nr_blocks(sb);udf_find_vat_block(sb,p_index,type1_index,sbi->s_last_block);if(!sbi->s_vat_inode&&
From: David Sterba <hidden> Date: 2021-10-15 13:53:20
On Fri, Oct 15, 2021 at 03:26:25PM +0200, Christoph Hellwig wrote:
Use the proper helper to read the block device size.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Anand Jain <redacted>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
From: Anton Altaparmakov <hidden> Date: 2021-10-15 14:37:02
Hi Christoph,
Looks good, thank you.
Best regards,
Anton
On 15 Oct 2021, at 14:26, Christoph Hellwig [off-list ref] wrote:
Use the sb_bdev_nr_blocks helper instead of open coding it and clean up
ntfs_fill_super a bit by moving an assignment a little earlier that has
no negative side effects.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Kees Cook <redacted>
@@ -2772,13 +2772,12 @@ static int ntfs_fill_super(struct super_block *sb, void *opt, const int silent)
ntfs_debug("Set device block size to %i bytes (block size bits %i).",
blocksize, sb->s_blocksize_bits);
/* Determine the size of the device in units of block_size bytes. */
- if (!i_size_read(sb->s_bdev->bd_inode)) {
+ vol->nr_blocks = sb_bdev_nr_blocks(sb);
+ if (!vol->nr_blocks) {
if (!silent)
ntfs_error(sb, "Unable to determine device size.");
goto err_out_now;
}
- vol->nr_blocks = i_size_read(sb->s_bdev->bd_inode) >>
- sb->s_blocksize_bits;
/* Read the boot sector and return unlocked buffer head to it. */
if (!(bh = read_ntfs_boot_sector(sb, silent))) {
if (!silent)
@@ -2816,8 +2815,7 @@ static int ntfs_fill_super(struct super_block *sb, void *opt, const int silent)
--
Anton Altaparmakov <anton at tuxera.com> (replace at with @)
Lead in File System Development, Tuxera Inc., http://www.tuxera.com/
Linux NTFS maintainer
From: Anton Altaparmakov <hidden> Date: 2021-10-15 14:38:25
Hi Christoph,
On 15 Oct 2021, at 14:26, Christoph Hellwig [off-list ref] wrote:
Add a helpe to query the size of a block device in bytes. This
will be used to remove open coded access to ->bd_inode.
Matthew already pointed out the return type for bdev_nr_bytes() but also your commit message has a typo: "Add a helpe" -> "Add a helper".
Best regards,
Anton
On Fri, Oct 15, 2021 at 02:37:41PM +0000, Anton Altaparmakov wrote:
Hi Christoph,
quoted
On 15 Oct 2021, at 14:26, Christoph Hellwig [off-list ref] wrote:
Add a helpe to query the size of a block device in bytes. This
will be used to remove open coded access to ->bd_inode.
Matthew already pointed out the return type for bdev_nr_bytes() but also your commit message has a typo: "Add a helpe" -> "Add a helper".
Right. With these fixed, I'm a fan. :)
Reviewed-by: Kees Cook <redacted>
-Kees
--
Kees Cook
@@ -232,9 +232,9 @@ static unsigned long long iblock_emulate_read_cap_with_block_size(structblock_device*bd,structrequest_queue*q){-unsignedlonglongblocks_long=(div_u64(i_size_read(bd->bd_inode),-bdev_logical_block_size(bd))-1);u32block_size=bdev_logical_block_size(bd);+unsignedlonglongblocks_long=+div_u64(bdev_nr_bytes(bd),block_size)-1;if(block_size==dev->dev_attrib.block_size)returnblocks_long;
On Fri, Oct 15, 2021 at 03:26:35PM +0200, Christoph Hellwig wrote:
Use the proper helper to read the block device size and remove two
cargo culted checks that can't be false.
Signed-off-by: Christoph Hellwig <hch@lst.de>
On Fri, Oct 15, 2021 at 03:26:38PM +0200, Christoph Hellwig wrote:
Add a helper to return the size of sb->s_bdev in sb->s_blocksize_bits
based unites. Note that SECTOR_SHIFT has to be open coded due to
include dependency issues for now, but I have a plan to sort that out
eventually.
Signed-off-by: Christoph Hellwig <hch@lst.de>
You can adjust this changelog to remove the note about SECTOR_SHIFT
now. :)
Reviewed-by: Kees Cook <redacted>
--
Kees Cook
Use the equivalent block layer helper instead.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Kees Cook <redacted>
Acked-by: Coly Li <redacted>
---
Add a helper to return the size of sb->s_bdev in sb->s_blocksize_bits
based unites. Note that SECTOR_SHIFT has to be open coded due to
include dependency issues for now, but I have a plan to sort that out
eventually.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Use the sb_bdev_nr_blocks helper instead of open coding it.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Kees Cook <redacted>
Reviewed-by: Jan Kara <jack@suse.cz>
Acked-by: Theodore Ts'o <tytso@mit.edu>
Use the proper helper to read the block device size and remove two
cargo culted checks that can't be false.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Jan Kara <jack@suse.cz>