for-5.16/bdev-size-2021-10-29

-----BEGIN PGP SIGNATURE-----
 
 iQJEBAABCAAuFiEEwPw5LcreJtl1+l5K99NY+ylx4KYFAmF8L70QHGF4Ym9lQGtl
 cm5lbC5kawAKCRD301j7KXHgpo9YEAC17yEJ0xwwtUUwZW8avzss4vdcIreFdiZu
 gaS+9Oi1bLxj0d2SjaZXJxjT9K+W2LftEsLuQ4oM6VHiLQkcEDbjJdVm3goftTt5
 aOvVormDdKbWNcGSbgxA/OcyUT39DH7y17NRVdqYzQSpnrhCod/1tb2ssck0OoYb
 VEyBKogMwYeYR55Z3I8yL5pNcEhR8TihZv3rL1iQ7DNpvh5I0I9naSEtGNC84aLP
 s4nwRIG+TYll+mg0sfSB29KF7xkoFQO7X7s1rnC/on+gsFEzbJcgkJPDIWeVLnLm
 ma8F1i+vJliCGaztyXoleAdg5QDiFmwTQwXRPAk2u8njJhcKi/RwIk2QYMZBZmEJ
 bB5EJnlnEaWxjgpCD7JDrtKgIgpbbQHc5QVHRZccsu43UqvDqOZIlvZNYY+h3ivz
 jT1zKuKDaTf8YWbfdOJwqm9e+qyR0AFm3rLMdHO58QEh1DBvSLIIdRCNE8wX7nFM
 Wx/GmQEkPqNTIZwJOQJMygK+sIuFUDybt3oAH2pjX1zyMx7kTJkrXvj0dhSS/B5u
 +gfMs3otWqxQ4P1qfnaUd9mYl8JabV7le2NHzhjdARm4NKFJEtcJe5BJBwiMbo0n
 vodqt7aUIAXwMrZXnWZL+w8CobhJBp8I5XHUgng147gDBuCjYQjBQT334auAXxgz
 MUCgbjBDqw==
 =Vadi
 -----END PGP SIGNATURE-----

Merge tag 'for-5.16/bdev-size-2021-10-29' of git://git.kernel.dk/linux-block

Pull bdev size cleanups from Jens Axboe:
 "Clean up the bdev size handling with new bdev_nr_bytes() helper"

* tag 'for-5.16/bdev-size-2021-10-29' of git://git.kernel.dk/linux-block: (34 commits)
  partitions/ibm: use bdev_nr_sectors instead of open coding it
  partitions/efi: use bdev_nr_bytes instead of open coding it
  block/ioctl: use bdev_nr_sectors and bdev_nr_bytes
  block: cache inode size in bdev
  udf: use sb_bdev_nr_blocks
  reiserfs: use sb_bdev_nr_blocks
  ntfs: use sb_bdev_nr_blocks
  jfs: use sb_bdev_nr_blocks
  ext4: use sb_bdev_nr_blocks
  block: add a sb_bdev_nr_blocks helper
  block: use bdev_nr_bytes instead of open coding it in blkdev_fallocate
  squashfs: use bdev_nr_bytes instead of open coding it
  reiserfs: use bdev_nr_bytes instead of open coding it
  pstore/blk: use bdev_nr_bytes instead of open coding it
  ntfs3: use bdev_nr_bytes instead of open coding it
  nilfs2: use bdev_nr_bytes instead of open coding it
  nfs/blocklayout: use bdev_nr_bytes instead of open coding it
  jfs: use bdev_nr_bytes instead of open coding it
  hfsplus: use bdev_nr_sectors instead of open coding it
  hfs: use bdev_nr_sectors instead of open coding it
  ...
This commit is contained in:
Linus Torvalds 2021-11-01 09:50:37 -07:00
commit 3f01727f75
62 changed files with 140 additions and 160 deletions

View File

@ -605,7 +605,7 @@ static long blkdev_fallocate(struct file *file, int mode, loff_t start,
return -EOPNOTSUPP; return -EOPNOTSUPP;
/* Don't go off the end of the device. */ /* Don't go off the end of the device. */
isize = i_size_read(bdev->bd_inode); isize = bdev_nr_bytes(bdev);
if (start >= isize) if (start >= isize)
return -EINVAL; return -EINVAL;
if (end >= isize) { if (end >= isize) {

View File

@ -58,6 +58,7 @@ void set_capacity(struct gendisk *disk, sector_t sectors)
spin_lock(&bdev->bd_size_lock); spin_lock(&bdev->bd_size_lock);
i_size_write(bdev->bd_inode, (loff_t)sectors << SECTOR_SHIFT); i_size_write(bdev->bd_inode, (loff_t)sectors << SECTOR_SHIFT);
bdev->bd_nr_sectors = sectors;
spin_unlock(&bdev->bd_size_lock); spin_unlock(&bdev->bd_size_lock);
} }
EXPORT_SYMBOL(set_capacity); EXPORT_SYMBOL(set_capacity);

View File

@ -132,7 +132,7 @@ static int blk_ioctl_discard(struct block_device *bdev, fmode_t mode,
if (len & 511) if (len & 511)
return -EINVAL; return -EINVAL;
if (start + len > i_size_read(bdev->bd_inode)) if (start + len > bdev_nr_bytes(bdev))
return -EINVAL; return -EINVAL;
err = truncate_bdev_range(bdev, mode, start, start + len - 1); err = truncate_bdev_range(bdev, mode, start, start + len - 1);
@ -164,7 +164,7 @@ static int blk_ioctl_zeroout(struct block_device *bdev, fmode_t mode,
return -EINVAL; return -EINVAL;
if (len & 511) if (len & 511)
return -EINVAL; return -EINVAL;
if (end >= (uint64_t)i_size_read(bdev->bd_inode)) if (end >= (uint64_t)bdev_nr_bytes(bdev))
return -EINVAL; return -EINVAL;
if (end < start) if (end < start)
return -EINVAL; return -EINVAL;
@ -543,7 +543,6 @@ long blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
struct block_device *bdev = I_BDEV(file->f_mapping->host); struct block_device *bdev = I_BDEV(file->f_mapping->host);
void __user *argp = (void __user *)arg; void __user *argp = (void __user *)arg;
fmode_t mode = file->f_mode; fmode_t mode = file->f_mode;
loff_t size;
int ret; int ret;
/* /*
@ -570,10 +569,9 @@ long blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
return put_long(argp, return put_long(argp,
(bdev->bd_disk->bdi->ra_pages * PAGE_SIZE) / 512); (bdev->bd_disk->bdi->ra_pages * PAGE_SIZE) / 512);
case BLKGETSIZE: case BLKGETSIZE:
size = i_size_read(bdev->bd_inode); if (bdev_nr_sectors(bdev) > ~0UL)
if ((size >> 9) > ~0UL)
return -EFBIG; return -EFBIG;
return put_ulong(argp, size >> 9); return put_ulong(argp, bdev_nr_sectors(bdev));
/* The data is compatible, but the command number is different */ /* The data is compatible, but the command number is different */
case BLKBSZGET: /* get block device soft block size (cf. BLKSSZGET) */ case BLKBSZGET: /* get block device soft block size (cf. BLKSSZGET) */
@ -581,7 +579,7 @@ long blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
case BLKBSZSET: case BLKBSZSET:
return blkdev_bszset(bdev, mode, argp); return blkdev_bszset(bdev, mode, argp);
case BLKGETSIZE64: case BLKGETSIZE64:
return put_u64(argp, i_size_read(bdev->bd_inode)); return put_u64(argp, bdev_nr_bytes(bdev));
/* Incompatible alignment on i386 */ /* Incompatible alignment on i386 */
case BLKTRACESETUP: case BLKTRACESETUP:
@ -615,7 +613,6 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
struct block_device *bdev = I_BDEV(file->f_mapping->host); struct block_device *bdev = I_BDEV(file->f_mapping->host);
struct gendisk *disk = bdev->bd_disk; struct gendisk *disk = bdev->bd_disk;
fmode_t mode = file->f_mode; fmode_t mode = file->f_mode;
loff_t size;
/* /*
* O_NDELAY can be altered using fcntl(.., F_SETFL, ..), so we have * O_NDELAY can be altered using fcntl(.., F_SETFL, ..), so we have
@ -641,10 +638,9 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
return compat_put_long(argp, return compat_put_long(argp,
(bdev->bd_disk->bdi->ra_pages * PAGE_SIZE) / 512); (bdev->bd_disk->bdi->ra_pages * PAGE_SIZE) / 512);
case BLKGETSIZE: case BLKGETSIZE:
size = i_size_read(bdev->bd_inode); if (bdev_nr_sectors(bdev) > ~0UL)
if ((size >> 9) > ~0UL)
return -EFBIG; return -EFBIG;
return compat_put_ulong(argp, size >> 9); return compat_put_ulong(argp, bdev_nr_sectors(bdev));
/* The data is compatible, but the command number is different */ /* The data is compatible, but the command number is different */
case BLKBSZGET_32: /* get the logical block size (cf. BLKSSZGET) */ case BLKBSZGET_32: /* get the logical block size (cf. BLKSSZGET) */
@ -652,7 +648,7 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
case BLKBSZSET_32: case BLKBSZSET_32:
return blkdev_bszset(bdev, mode, argp); return blkdev_bszset(bdev, mode, argp);
case BLKGETSIZE64_32: case BLKGETSIZE64_32:
return put_u64(argp, i_size_read(bdev->bd_inode)); return put_u64(argp, bdev_nr_bytes(bdev));
/* Incompatible alignment on i386 */ /* Incompatible alignment on i386 */
case BLKTRACESETUP32: case BLKTRACESETUP32:

View File

@ -91,6 +91,7 @@ static void bdev_set_nr_sectors(struct block_device *bdev, sector_t sectors)
{ {
spin_lock(&bdev->bd_size_lock); spin_lock(&bdev->bd_size_lock);
i_size_write(bdev->bd_inode, (loff_t)sectors << SECTOR_SHIFT); i_size_write(bdev->bd_inode, (loff_t)sectors << SECTOR_SHIFT);
bdev->bd_nr_sectors = sectors;
spin_unlock(&bdev->bd_size_lock); spin_unlock(&bdev->bd_size_lock);
} }

View File

@ -133,7 +133,7 @@ efi_crc32(const void *buf, unsigned long len)
*/ */
static u64 last_lba(struct gendisk *disk) static u64 last_lba(struct gendisk *disk)
{ {
return div_u64(disk->part0->bd_inode->i_size, return div_u64(bdev_nr_bytes(disk->part0),
queue_logical_block_size(disk->queue)) - 1ULL; queue_logical_block_size(disk->queue)) - 1ULL;
} }

View File

@ -198,7 +198,7 @@ static int find_lnx1_partitions(struct parsed_partitions *state,
char name[], char name[],
union label_t *label, union label_t *label,
sector_t labelsect, sector_t labelsect,
loff_t i_size, sector_t nr_sectors,
dasd_information2_t *info) dasd_information2_t *info)
{ {
loff_t offset, geo_size, size; loff_t offset, geo_size, size;
@ -213,14 +213,14 @@ static int find_lnx1_partitions(struct parsed_partitions *state,
} else { } else {
/* /*
* Formated w/o large volume support. If the sanity check * Formated w/o large volume support. If the sanity check
* 'size based on geo == size based on i_size' is true, then * 'size based on geo == size based on nr_sectors' is true, then
* we can safely assume that we know the formatted size of * we can safely assume that we know the formatted size of
* the disk, otherwise we need additional information * the disk, otherwise we need additional information
* that we can only get from a real DASD device. * that we can only get from a real DASD device.
*/ */
geo_size = geo->cylinders * geo->heads geo_size = geo->cylinders * geo->heads
* geo->sectors * secperblk; * geo->sectors * secperblk;
size = i_size >> 9; size = nr_sectors;
if (size != geo_size) { if (size != geo_size) {
if (!info) { if (!info) {
strlcat(state->pp_buf, "\n", PAGE_SIZE); strlcat(state->pp_buf, "\n", PAGE_SIZE);
@ -229,7 +229,7 @@ static int find_lnx1_partitions(struct parsed_partitions *state,
if (!strcmp(info->type, "ECKD")) if (!strcmp(info->type, "ECKD"))
if (geo_size < size) if (geo_size < size)
size = geo_size; size = geo_size;
/* else keep size based on i_size */ /* else keep size based on nr_sectors */
} }
} }
/* first and only partition starts in the first block after the label */ /* first and only partition starts in the first block after the label */
@ -293,7 +293,8 @@ int ibm_partition(struct parsed_partitions *state)
struct gendisk *disk = state->disk; struct gendisk *disk = state->disk;
struct block_device *bdev = disk->part0; struct block_device *bdev = disk->part0;
int blocksize, res; int blocksize, res;
loff_t i_size, offset, size; loff_t offset, size;
sector_t nr_sectors;
dasd_information2_t *info; dasd_information2_t *info;
struct hd_geometry *geo; struct hd_geometry *geo;
char type[5] = {0,}; char type[5] = {0,};
@ -308,8 +309,8 @@ int ibm_partition(struct parsed_partitions *state)
blocksize = bdev_logical_block_size(bdev); blocksize = bdev_logical_block_size(bdev);
if (blocksize <= 0) if (blocksize <= 0)
goto out_symbol; goto out_symbol;
i_size = i_size_read(bdev->bd_inode); nr_sectors = bdev_nr_sectors(bdev);
if (i_size == 0) if (nr_sectors == 0)
goto out_symbol; goto out_symbol;
info = kmalloc(sizeof(dasd_information2_t), GFP_KERNEL); info = kmalloc(sizeof(dasd_information2_t), GFP_KERNEL);
if (info == NULL) if (info == NULL)
@ -336,7 +337,7 @@ int ibm_partition(struct parsed_partitions *state)
label); label);
} else if (!strncmp(type, "LNX1", 4)) { } else if (!strncmp(type, "LNX1", 4)) {
res = find_lnx1_partitions(state, geo, blocksize, name, res = find_lnx1_partitions(state, geo, blocksize, name,
label, labelsect, i_size, label, labelsect, nr_sectors,
info); info);
} else if (!strncmp(type, "CMS1", 4)) { } else if (!strncmp(type, "CMS1", 4)) {
res = find_cms1_partitions(state, geo, blocksize, name, res = find_cms1_partitions(state, geo, blocksize, name,
@ -353,7 +354,7 @@ int ibm_partition(struct parsed_partitions *state)
res = 1; res = 1;
if (info->format == DASD_FORMAT_LDL) { if (info->format == DASD_FORMAT_LDL) {
strlcat(state->pp_buf, "(nonl)", PAGE_SIZE); strlcat(state->pp_buf, "(nonl)", PAGE_SIZE);
size = i_size >> 9; size = nr_sectors;
offset = (info->label_block + 1) * (blocksize >> 9); offset = (info->label_block + 1) * (blocksize >> 9);
put_partition(state, 1, offset, size-offset); put_partition(state, 1, offset, size-offset);
strlcat(state->pp_buf, "\n", PAGE_SIZE); strlcat(state->pp_buf, "\n", PAGE_SIZE);

View File

@ -1826,8 +1826,7 @@ static inline sector_t drbd_md_last_sector(struct drbd_backing_dev *bdev)
/* Returns the number of 512 byte sectors of the device */ /* Returns the number of 512 byte sectors of the device */
static inline sector_t drbd_get_capacity(struct block_device *bdev) static inline sector_t drbd_get_capacity(struct block_device *bdev)
{ {
/* return bdev ? get_capacity(bdev->bd_disk) : 0; */ return bdev ? bdev_nr_sectors(bdev) : 0;
return bdev ? i_size_read(bdev->bd_inode) >> 9 : 0;
} }
/** /**

View File

@ -1002,7 +1002,7 @@ static void calc_cached_dev_sectors(struct cache_set *c)
struct cached_dev *dc; struct cached_dev *dc;
list_for_each_entry(dc, &c->cached_devs, list) list_for_each_entry(dc, &c->cached_devs, list)
sectors += bdev_sectors(dc->bdev); sectors += bdev_nr_sectors(dc->bdev);
c->cached_dev_sectors = sectors; c->cached_dev_sectors = sectors;
} }

View File

@ -559,8 +559,4 @@ static inline unsigned int fract_exp_two(unsigned int x,
void bch_bio_map(struct bio *bio, void *base); void bch_bio_map(struct bio *bio, void *base);
int bch_bio_alloc_pages(struct bio *bio, gfp_t gfp_mask); int bch_bio_alloc_pages(struct bio *bio, gfp_t gfp_mask);
static inline sector_t bdev_sectors(struct block_device *bdev)
{
return bdev->bd_inode->i_size >> 9;
}
#endif /* _BCACHE_UTIL_H */ #endif /* _BCACHE_UTIL_H */

View File

@ -45,7 +45,7 @@ static uint64_t __calc_target_rate(struct cached_dev *dc)
* backing volume uses about 2% of the cache for dirty data. * backing volume uses about 2% of the cache for dirty data.
*/ */
uint32_t bdev_share = uint32_t bdev_share =
div64_u64(bdev_sectors(dc->bdev) << WRITEBACK_SHARE_SHIFT, div64_u64(bdev_nr_sectors(dc->bdev) << WRITEBACK_SHARE_SHIFT,
c->cached_dev_sectors); c->cached_dev_sectors);
uint64_t cache_dirty_target = uint64_t cache_dirty_target =

View File

@ -1525,7 +1525,7 @@ EXPORT_SYMBOL_GPL(dm_bufio_get_block_size);
sector_t dm_bufio_get_device_size(struct dm_bufio_client *c) sector_t dm_bufio_get_device_size(struct dm_bufio_client *c)
{ {
sector_t s = i_size_read(c->bdev->bd_inode) >> SECTOR_SHIFT; sector_t s = bdev_nr_sectors(c->bdev);
if (s >= c->start) if (s >= c->start)
s -= c->start; s -= c->start;
else else

View File

@ -334,7 +334,7 @@ static int __write_initial_superblock(struct dm_cache_metadata *cmd)
int r; int r;
struct dm_block *sblock; struct dm_block *sblock;
struct cache_disk_superblock *disk_super; struct cache_disk_superblock *disk_super;
sector_t bdev_size = i_size_read(cmd->bdev->bd_inode) >> SECTOR_SHIFT; sector_t bdev_size = bdev_nr_sectors(cmd->bdev);
/* FIXME: see if we can lose the max sectors limit */ /* FIXME: see if we can lose the max sectors limit */
if (bdev_size > DM_CACHE_METADATA_MAX_SECTORS) if (bdev_size > DM_CACHE_METADATA_MAX_SECTORS)

View File

@ -1940,7 +1940,7 @@ static void cache_dtr(struct dm_target *ti)
static sector_t get_dev_size(struct dm_dev *dev) static sector_t get_dev_size(struct dm_dev *dev)
{ {
return i_size_read(dev->bdev->bd_inode) >> SECTOR_SHIFT; return bdev_nr_sectors(dev->bdev);
} }
/*----------------------------------------------------------------*/ /*----------------------------------------------------------------*/

View File

@ -1514,7 +1514,7 @@ error:
static sector_t get_dev_size(struct dm_dev *dev) static sector_t get_dev_size(struct dm_dev *dev)
{ {
return i_size_read(dev->bdev->bd_inode) >> SECTOR_SHIFT; return bdev_nr_sectors(dev->bdev);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/

View File

@ -415,7 +415,7 @@ static int dust_message(struct dm_target *ti, unsigned int argc, char **argv,
char *result, unsigned int maxlen) char *result, unsigned int maxlen)
{ {
struct dust_device *dd = ti->private; struct dust_device *dd = ti->private;
sector_t size = i_size_read(dd->dev->bdev->bd_inode) >> SECTOR_SHIFT; sector_t size = bdev_nr_sectors(dd->dev->bdev);
bool invalid_msg = false; bool invalid_msg = false;
int r = -EINVAL; int r = -EINVAL;
unsigned long long tmp, block; unsigned long long tmp, block;
@ -544,8 +544,7 @@ static int dust_prepare_ioctl(struct dm_target *ti, struct block_device **bdev)
/* /*
* Only pass ioctls through if the device sizes match exactly. * Only pass ioctls through if the device sizes match exactly.
*/ */
if (dd->start || if (dd->start || ti->len != bdev_nr_sectors(dev->bdev))
ti->len != i_size_read(dev->bdev->bd_inode) >> SECTOR_SHIFT)
return 1; return 1;
return 0; return 0;

View File

@ -416,7 +416,7 @@ static int ebs_prepare_ioctl(struct dm_target *ti, struct block_device **bdev)
* Only pass ioctls through if the device sizes match exactly. * Only pass ioctls through if the device sizes match exactly.
*/ */
*bdev = dev->bdev; *bdev = dev->bdev;
return !!(ec->start || ti->len != i_size_read(dev->bdev->bd_inode) >> SECTOR_SHIFT); return !!(ec->start || ti->len != bdev_nr_sectors(dev->bdev));
} }
static void ebs_io_hints(struct dm_target *ti, struct queue_limits *limits) static void ebs_io_hints(struct dm_target *ti, struct queue_limits *limits)

View File

@ -1681,7 +1681,7 @@ static int era_message(struct dm_target *ti, unsigned argc, char **argv,
static sector_t get_dev_size(struct dm_dev *dev) static sector_t get_dev_size(struct dm_dev *dev)
{ {
return i_size_read(dev->bdev->bd_inode) >> SECTOR_SHIFT; return bdev_nr_sectors(dev->bdev);
} }
static int era_iterate_devices(struct dm_target *ti, static int era_iterate_devices(struct dm_target *ti,

View File

@ -168,7 +168,7 @@ static inline void dm_consecutive_chunk_count_dec(struct dm_exception *e)
*/ */
static inline sector_t get_dev_size(struct block_device *bdev) static inline sector_t get_dev_size(struct block_device *bdev)
{ {
return i_size_read(bdev->bd_inode) >> SECTOR_SHIFT; return bdev_nr_sectors(bdev);
} }
static inline chunk_t sector_to_chunk(struct dm_exception_store *store, static inline chunk_t sector_to_chunk(struct dm_exception_store *store,

View File

@ -456,8 +456,7 @@ static int flakey_prepare_ioctl(struct dm_target *ti, struct block_device **bdev
/* /*
* Only pass ioctls through if the device sizes match exactly. * Only pass ioctls through if the device sizes match exactly.
*/ */
if (fc->start || if (fc->start || ti->len != bdev_nr_sectors((*bdev)))
ti->len != i_size_read((*bdev)->bd_inode) >> SECTOR_SHIFT)
return 1; return 1;
return 0; return 0;
} }

View File

@ -4113,11 +4113,11 @@ static int dm_integrity_ctr(struct dm_target *ti, unsigned argc, char **argv)
} }
} }
ic->data_device_sectors = i_size_read(ic->dev->bdev->bd_inode) >> SECTOR_SHIFT; ic->data_device_sectors = bdev_nr_sectors(ic->dev->bdev);
if (!ic->meta_dev) if (!ic->meta_dev)
ic->meta_device_sectors = ic->data_device_sectors; ic->meta_device_sectors = ic->data_device_sectors;
else else
ic->meta_device_sectors = i_size_read(ic->meta_dev->bdev->bd_inode) >> SECTOR_SHIFT; ic->meta_device_sectors = bdev_nr_sectors(ic->meta_dev->bdev);
if (!journal_sectors) { if (!journal_sectors) {
journal_sectors = min((sector_t)DEFAULT_MAX_JOURNAL_SECTORS, journal_sectors = min((sector_t)DEFAULT_MAX_JOURNAL_SECTORS,
@ -4367,7 +4367,7 @@ try_smaller_buffer:
DEBUG_print(" journal_sections %u\n", (unsigned)le32_to_cpu(ic->sb->journal_sections)); DEBUG_print(" journal_sections %u\n", (unsigned)le32_to_cpu(ic->sb->journal_sections));
DEBUG_print(" journal_entries %u\n", ic->journal_entries); DEBUG_print(" journal_entries %u\n", ic->journal_entries);
DEBUG_print(" log2_interleave_sectors %d\n", ic->sb->log2_interleave_sectors); DEBUG_print(" log2_interleave_sectors %d\n", ic->sb->log2_interleave_sectors);
DEBUG_print(" data_device_sectors 0x%llx\n", i_size_read(ic->dev->bdev->bd_inode) >> SECTOR_SHIFT); DEBUG_print(" data_device_sectors 0x%llx\n", bdev_nr_sectors(ic->dev->bdev));
DEBUG_print(" initial_sectors 0x%x\n", ic->initial_sectors); DEBUG_print(" initial_sectors 0x%x\n", ic->initial_sectors);
DEBUG_print(" metadata_run 0x%x\n", ic->metadata_run); DEBUG_print(" metadata_run 0x%x\n", ic->metadata_run);
DEBUG_print(" log2_metadata_run %d\n", ic->log2_metadata_run); DEBUG_print(" log2_metadata_run %d\n", ic->log2_metadata_run);

View File

@ -135,8 +135,7 @@ static int linear_prepare_ioctl(struct dm_target *ti, struct block_device **bdev
/* /*
* Only pass ioctls through if the device sizes match exactly. * Only pass ioctls through if the device sizes match exactly.
*/ */
if (lc->start || if (lc->start || ti->len != bdev_nr_sectors(dev->bdev))
ti->len != i_size_read(dev->bdev->bd_inode) >> SECTOR_SHIFT)
return 1; return 1;
return 0; return 0;
} }

View File

@ -446,7 +446,7 @@ static int log_super(struct log_writes_c *lc)
static inline sector_t logdev_last_sector(struct log_writes_c *lc) static inline sector_t logdev_last_sector(struct log_writes_c *lc)
{ {
return i_size_read(lc->logdev->bdev->bd_inode) >> SECTOR_SHIFT; return bdev_nr_sectors(lc->logdev->bdev);
} }
static int log_writes_kthread(void *arg) static int log_writes_kthread(void *arg)
@ -851,7 +851,7 @@ static int log_writes_prepare_ioctl(struct dm_target *ti,
/* /*
* Only pass ioctls through if the device sizes match exactly. * Only pass ioctls through if the device sizes match exactly.
*/ */
if (ti->len != i_size_read(dev->bdev->bd_inode) >> SECTOR_SHIFT) if (ti->len != bdev_nr_sectors(dev->bdev))
return 1; return 1;
return 0; return 0;
} }

View File

@ -447,7 +447,7 @@ static int create_log_context(struct dm_dirty_log *log, struct dm_target *ti,
bdev_logical_block_size(lc->header_location. bdev_logical_block_size(lc->header_location.
bdev)); bdev));
if (buf_size > i_size_read(dev->bdev->bd_inode)) { if (buf_size > bdev_nr_bytes(dev->bdev)) {
DMWARN("log device %s too small: need %llu bytes", DMWARN("log device %s too small: need %llu bytes",
dev->name, (unsigned long long)buf_size); dev->name, (unsigned long long)buf_size);
kfree(lc); kfree(lc);

View File

@ -2061,7 +2061,7 @@ static int multipath_prepare_ioctl(struct dm_target *ti,
/* /*
* Only pass ioctls through if the device sizes match exactly. * Only pass ioctls through if the device sizes match exactly.
*/ */
if (!r && ti->len != i_size_read((*bdev)->bd_inode) >> SECTOR_SHIFT) if (!r && ti->len != bdev_nr_sectors((*bdev)))
return 1; return 1;
return r; return r;
} }

View File

@ -1261,7 +1261,7 @@ static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as,
md_rdev_init(jdev); md_rdev_init(jdev);
jdev->mddev = &rs->md; jdev->mddev = &rs->md;
jdev->bdev = rs->journal_dev.dev->bdev; 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) { if (jdev->sectors < MIN_RAID456_JOURNAL_SPACE) {
rs->ti->error = "No space for raid4/5/6 journal"; rs->ti->error = "No space for raid4/5/6 journal";
return -ENOSPC; return -ENOSPC;
@ -1607,7 +1607,7 @@ static int _check_data_dev_sectors(struct raid_set *rs)
rdev_for_each(rdev, &rs->md) rdev_for_each(rdev, &rs->md)
if (!test_bit(Journal, &rdev->flags) && rdev->bdev) { 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) { if (ds < rs->md.dev_sectors) {
rs->ti->error = "Component device(s) too small"; rs->ti->error = "Component device(s) too small";
return -EINVAL; return -EINVAL;
@ -2662,7 +2662,7 @@ static int rs_adjust_data_offsets(struct raid_set *rs)
* Make sure we got a minimum amount of free sectors per device * Make sure we got a minimum amount of free sectors per device
*/ */
if (rs->data_offset && 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" : rs->ti->error = data_offset ? "No space for forward reshape" :
"No space for backward reshape"; "No space for backward reshape";
return -ENOSPC; return -ENOSPC;

View File

@ -529,7 +529,7 @@ static int switch_prepare_ioctl(struct dm_target *ti, struct block_device **bdev
* Only pass ioctls through if the device sizes match exactly. * Only pass ioctls through if the device sizes match exactly.
*/ */
if (ti->len + sctx->path_list[path_nr].start != if (ti->len + sctx->path_list[path_nr].start !=
i_size_read((*bdev)->bd_inode) >> SECTOR_SHIFT) bdev_nr_sectors((*bdev)))
return 1; return 1;
return 0; return 0;
} }

View File

@ -227,8 +227,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
{ {
struct queue_limits *limits = data; struct queue_limits *limits = data;
struct block_device *bdev = dev->bdev; struct block_device *bdev = dev->bdev;
sector_t dev_size = sector_t dev_size = bdev_nr_sectors(bdev);
i_size_read(bdev->bd_inode) >> SECTOR_SHIFT;
unsigned short logical_block_size_sectors = unsigned short logical_block_size_sectors =
limits->logical_block_size >> SECTOR_SHIFT; limits->logical_block_size >> SECTOR_SHIFT;
char b[BDEVNAME_SIZE]; char b[BDEVNAME_SIZE];

View File

@ -549,7 +549,7 @@ static int __write_initial_superblock(struct dm_pool_metadata *pmd)
int r; int r;
struct dm_block *sblock; struct dm_block *sblock;
struct thin_disk_superblock *disk_super; struct thin_disk_superblock *disk_super;
sector_t bdev_size = i_size_read(pmd->bdev->bd_inode) >> SECTOR_SHIFT; sector_t bdev_size = bdev_nr_sectors(pmd->bdev);
if (bdev_size > THIN_METADATA_MAX_SECTORS) if (bdev_size > THIN_METADATA_MAX_SECTORS)
bdev_size = THIN_METADATA_MAX_SECTORS; bdev_size = THIN_METADATA_MAX_SECTORS;

View File

@ -3212,7 +3212,7 @@ static int metadata_pre_commit_callback(void *context)
static sector_t get_dev_size(struct block_device *bdev) static sector_t get_dev_size(struct block_device *bdev)
{ {
return i_size_read(bdev->bd_inode) >> SECTOR_SHIFT; return bdev_nr_sectors(bdev);
} }
static void warn_if_metadata_device_too_big(struct block_device *bdev) static void warn_if_metadata_device_too_big(struct block_device *bdev)

View File

@ -834,8 +834,7 @@ static int verity_prepare_ioctl(struct dm_target *ti, struct block_device **bdev
*bdev = v->data_dev->bdev; *bdev = v->data_dev->bdev;
if (v->data_start || if (v->data_start || ti->len != bdev_nr_sectors(v->data_dev->bdev))
ti->len != i_size_read(v->data_dev->bdev->bd_inode) >> SECTOR_SHIFT)
return 1; return 1;
return 0; return 0;
} }

View File

@ -2341,7 +2341,7 @@ static int writecache_ctr(struct dm_target *ti, unsigned argc, char **argv)
ti->error = "Cache data device lookup failed"; ti->error = "Cache data device lookup failed";
goto bad; goto bad;
} }
wc->memory_map_size = i_size_read(wc->ssd_dev->bdev->bd_inode); wc->memory_map_size = bdev_nr_bytes(wc->ssd_dev->bdev);
/* /*
* Parse the cache block size * Parse the cache block size

View File

@ -733,7 +733,7 @@ static int dmz_get_zoned_device(struct dm_target *ti, char *path,
dev->dev_idx = idx; dev->dev_idx = idx;
(void)bdevname(dev->bdev, dev->name); (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) { if (ti->begin) {
ti->error = "Partial mapping is not supported"; ti->error = "Partial mapping is not supported";
goto err; goto err;

View File

@ -888,8 +888,7 @@ static struct md_personality *find_pers(int level, char *clevel)
/* return the offset of the super block in 512byte sectors */ /* return the offset of the super block in 512byte sectors */
static inline sector_t calc_dev_sboffset(struct md_rdev *rdev) static inline sector_t calc_dev_sboffset(struct md_rdev *rdev)
{ {
sector_t num_sectors = i_size_read(rdev->bdev->bd_inode) / 512; return MD_NEW_SIZE_SECTORS(bdev_nr_sectors(rdev->bdev));
return MD_NEW_SIZE_SECTORS(num_sectors);
} }
static int alloc_disk_sb(struct md_rdev *rdev) static int alloc_disk_sb(struct md_rdev *rdev)
@ -1631,8 +1630,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
*/ */
switch(minor_version) { switch(minor_version) {
case 0: case 0:
sb_start = i_size_read(rdev->bdev->bd_inode) >> 9; sb_start = bdev_nr_sectors(rdev->bdev) - 8 * 2;
sb_start -= 8*2;
sb_start &= ~(sector_t)(4*2-1); sb_start &= ~(sector_t)(4*2-1);
break; break;
case 1: case 1:
@ -1787,10 +1785,9 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
else else
ret = 0; ret = 0;
} }
if (minor_version) { if (minor_version)
sectors = (i_size_read(rdev->bdev->bd_inode) >> 9); sectors = bdev_nr_sectors(rdev->bdev) - rdev->data_offset;
sectors -= rdev->data_offset; else
} else
sectors = rdev->sb_start; sectors = rdev->sb_start;
if (sectors < le64_to_cpu(sb->data_size)) if (sectors < le64_to_cpu(sb->data_size))
return -EINVAL; return -EINVAL;
@ -2168,8 +2165,7 @@ super_1_rdev_size_change(struct md_rdev *rdev, sector_t num_sectors)
return 0; /* too confusing */ return 0; /* too confusing */
if (rdev->sb_start < rdev->data_offset) { if (rdev->sb_start < rdev->data_offset) {
/* minor versions 1 and 2; superblock before data */ /* minor versions 1 and 2; superblock before data */
max_sectors = i_size_read(rdev->bdev->bd_inode) >> 9; max_sectors = bdev_nr_sectors(rdev->bdev) - rdev->data_offset;
max_sectors -= rdev->data_offset;
if (!num_sectors || num_sectors > max_sectors) if (!num_sectors || num_sectors > max_sectors)
num_sectors = max_sectors; num_sectors = max_sectors;
} else if (rdev->mddev->bitmap_info.offset) { } else if (rdev->mddev->bitmap_info.offset) {
@ -2178,7 +2174,7 @@ super_1_rdev_size_change(struct md_rdev *rdev, sector_t num_sectors)
} else { } else {
/* minor version 0; superblock after data */ /* minor version 0; superblock after data */
sector_t sb_start, bm_space; sector_t sb_start, bm_space;
sector_t dev_size = i_size_read(rdev->bdev->bd_inode) >> 9; sector_t dev_size = bdev_nr_sectors(rdev->bdev);
/* 8K is for superblock */ /* 8K is for superblock */
sb_start = dev_size - 8*2; sb_start = dev_size - 8*2;
@ -3391,7 +3387,7 @@ rdev_size_store(struct md_rdev *rdev, const char *buf, size_t len)
if (!sectors) if (!sectors)
return -EBUSY; return -EBUSY;
} else if (!sectors) } else if (!sectors)
sectors = (i_size_read(rdev->bdev->bd_inode) >> 9) - sectors = bdev_nr_sectors(rdev->bdev) -
rdev->data_offset; rdev->data_offset;
if (!my_mddev->pers->resize) if (!my_mddev->pers->resize)
/* Cannot change size for RAID0 or Linear etc */ /* Cannot change size for RAID0 or Linear etc */
@ -3718,7 +3714,7 @@ static struct md_rdev *md_import_device(dev_t newdev, int super_format, int supe
kobject_init(&rdev->kobj, &rdev_ktype); kobject_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) { if (!size) {
pr_warn("md: %s has zero or unknown size, marking faulty!\n", pr_warn("md: %s has zero or unknown size, marking faulty!\n",
bdevname(rdev->bdev,b)); bdevname(rdev->bdev,b));
@ -6896,7 +6892,7 @@ int md_add_new_disk(struct mddev *mddev, struct mdu_disk_info_s *info)
if (!mddev->persistent) { if (!mddev->persistent) {
pr_debug("md: nonpersistent superblock ...\n"); pr_debug("md: nonpersistent superblock ...\n");
rdev->sb_start = i_size_read(rdev->bdev->bd_inode) / 512; rdev->sb_start = bdev_nr_sectors(rdev->bdev);
} else } else
rdev->sb_start = calc_dev_sboffset(rdev); rdev->sb_start = calc_dev_sboffset(rdev);
rdev->sectors = rdev->sb_start; rdev->sectors = rdev->sb_start;
@ -6983,7 +6979,7 @@ static int hot_add_disk(struct mddev *mddev, dev_t dev)
if (mddev->persistent) if (mddev->persistent)
rdev->sb_start = calc_dev_sboffset(rdev); rdev->sb_start = calc_dev_sboffset(rdev);
else else
rdev->sb_start = i_size_read(rdev->bdev->bd_inode) / 512; rdev->sb_start = bdev_nr_sectors(rdev->bdev);
rdev->sectors = rdev->sb_start; rdev->sectors = rdev->sb_start;

View File

@ -87,7 +87,7 @@ int nvmet_bdev_ns_enable(struct nvmet_ns *ns)
ns->bdev = NULL; ns->bdev = NULL;
return ret; return ret;
} }
ns->size = i_size_read(ns->bdev->bd_inode); ns->size = bdev_nr_bytes(ns->bdev);
ns->blksize_shift = blksize_bits(bdev_logical_block_size(ns->bdev)); ns->blksize_shift = blksize_bits(bdev_logical_block_size(ns->bdev));
ns->pi_type = 0; ns->pi_type = 0;
@ -108,7 +108,7 @@ int nvmet_bdev_ns_enable(struct nvmet_ns *ns)
void nvmet_bdev_ns_revalidate(struct nvmet_ns *ns) void nvmet_bdev_ns_revalidate(struct nvmet_ns *ns)
{ {
ns->size = i_size_read(ns->bdev->bd_inode); ns->size = bdev_nr_bytes(ns->bdev);
} }
u16 blk_to_nvme_status(struct nvmet_req *req, blk_status_t blk_sts) u16 blk_to_nvme_status(struct nvmet_req *req, blk_status_t blk_sts)

View File

@ -232,9 +232,9 @@ static unsigned long long iblock_emulate_read_cap_with_block_size(
struct block_device *bd, struct block_device *bd,
struct request_queue *q) struct request_queue *q)
{ {
unsigned long long blocks_long = (div_u64(i_size_read(bd->bd_inode),
bdev_logical_block_size(bd)) - 1);
u32 block_size = bdev_logical_block_size(bd); u32 block_size = bdev_logical_block_size(bd);
unsigned long long blocks_long =
div_u64(bdev_nr_bytes(bd), block_size) - 1;
if (block_size == dev->dev_attrib.block_size) if (block_size == dev->dev_attrib.block_size)
return blocks_long; return blocks_long;

View File

@ -389,7 +389,7 @@ static int affs_fill_super(struct super_block *sb, void *data, int silent)
* blocks, we will have to change it. * blocks, we will have to change it.
*/ */
size = i_size_read(sb->s_bdev->bd_inode) >> 9; size = bdev_nr_sectors(sb->s_bdev);
pr_debug("initial blocksize=%d, #blocks=%d\n", 512, size); pr_debug("initial blocksize=%d, #blocks=%d\n", 512, size);
affs_set_blocksize(sb, PAGE_SIZE); affs_set_blocksize(sb, PAGE_SIZE);

View File

@ -283,8 +283,7 @@ static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,
} }
if (i_size_read(bdev->bd_inode) < if (bdev_nr_bytes(bdev) < btrfs_device_get_total_bytes(srcdev)) {
btrfs_device_get_total_bytes(srcdev)) {
btrfs_err(fs_info, btrfs_err(fs_info,
"target device is smaller than source device!"); "target device is smaller than source device!");
ret = -EINVAL; ret = -EINVAL;

View File

@ -3740,7 +3740,7 @@ struct btrfs_super_block *btrfs_read_dev_one_super(struct block_device *bdev,
else if (ret) else if (ret)
return ERR_PTR(ret); return ERR_PTR(ret);
if (bytenr + BTRFS_SUPER_INFO_SIZE >= i_size_read(bdev->bd_inode)) if (bytenr + BTRFS_SUPER_INFO_SIZE >= bdev_nr_bytes(bdev))
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
page = read_cache_page_gfp(mapping, bytenr >> PAGE_SHIFT, GFP_NOFS); page = read_cache_page_gfp(mapping, bytenr >> PAGE_SHIFT, GFP_NOFS);

View File

@ -1730,7 +1730,7 @@ static noinline int btrfs_ioctl_resize(struct file *file,
} }
if (!strcmp(sizestr, "max")) if (!strcmp(sizestr, "max"))
new_size = device->bdev->bd_inode->i_size; new_size = bdev_nr_bytes(device->bdev);
else { else {
if (sizestr[0] == '-') { if (sizestr[0] == '-') {
mod = -1; mod = -1;
@ -1771,7 +1771,7 @@ static noinline int btrfs_ioctl_resize(struct file *file,
ret = -EINVAL; ret = -EINVAL;
goto out_finish; goto out_finish;
} }
if (new_size > device->bdev->bd_inode->i_size) { if (new_size > bdev_nr_bytes(device->bdev)) {
ret = -EFBIG; ret = -EFBIG;
goto out_finish; goto out_finish;
} }

View File

@ -1286,7 +1286,7 @@ static struct btrfs_super_block *btrfs_read_disk_super(struct block_device *bdev
pgoff_t index; pgoff_t index;
/* make sure our super fits in the device */ /* 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))
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
/* make sure our super fits in the page */ /* make sure our super fits in the page */
@ -2610,8 +2610,8 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
device->io_width = fs_info->sectorsize; device->io_width = fs_info->sectorsize;
device->io_align = fs_info->sectorsize; device->io_align = fs_info->sectorsize;
device->sector_size = fs_info->sectorsize; device->sector_size = fs_info->sectorsize;
device->total_bytes = round_down(i_size_read(bdev->bd_inode), device->total_bytes =
fs_info->sectorsize); round_down(bdev_nr_bytes(bdev), fs_info->sectorsize);
device->disk_total_bytes = device->total_bytes; device->disk_total_bytes = device->total_bytes;
device->commit_total_bytes = device->total_bytes; device->commit_total_bytes = device->total_bytes;
set_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state); set_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state);
@ -7236,7 +7236,7 @@ static int read_one_dev(struct extent_buffer *leaf,
fill_device_from_item(leaf, dev_item, device); fill_device_from_item(leaf, dev_item, device);
if (device->bdev) { if (device->bdev) {
u64 max_total_bytes = i_size_read(device->bdev->bd_inode); u64 max_total_bytes = bdev_nr_bytes(device->bdev);
if (device->total_bytes > max_total_bytes) { if (device->total_bytes > max_total_bytes) {
btrfs_err(fs_info, btrfs_err(fs_info,

View File

@ -878,7 +878,7 @@ link_dev_buffers(struct page *page, struct buffer_head *head)
static sector_t blkdev_max_block(struct block_device *bdev, unsigned int size) static sector_t blkdev_max_block(struct block_device *bdev, unsigned int size)
{ {
sector_t retval = ~((sector_t)0); sector_t retval = ~((sector_t)0);
loff_t sz = i_size_read(bdev->bd_inode); loff_t sz = bdev_nr_bytes(bdev);
if (sz) { if (sz) {
unsigned int sizebits = blksize_bits(size); unsigned int sizebits = blksize_bits(size);
@ -897,7 +897,7 @@ init_page_buffers(struct page *page, struct block_device *bdev,
struct buffer_head *head = page_buffers(page); struct buffer_head *head = page_buffers(page);
struct buffer_head *bh = head; struct buffer_head *bh = head;
int uptodate = PageUptodate(page); int uptodate = PageUptodate(page);
sector_t end_block = blkdev_max_block(I_BDEV(bdev->bd_inode), size); sector_t end_block = blkdev_max_block(bdev, size);
do { do {
if (!buffer_mapped(bh)) { if (!buffer_mapped(bh)) {

View File

@ -209,7 +209,7 @@ static void *cramfs_blkdev_read(struct super_block *sb, unsigned int offset,
return read_buffers[i] + blk_offset; return read_buffers[i] + blk_offset;
} }
devsize = mapping->host->i_size >> PAGE_SHIFT; devsize = bdev_nr_bytes(sb->s_bdev) >> PAGE_SHIFT;
/* Ok, read in BLKS_PER_BUF pages completely first. */ /* Ok, read in BLKS_PER_BUF pages completely first. */
for (i = 0; i < BLKS_PER_BUF; i++) { for (i = 0; i < BLKS_PER_BUF; i++) {

View File

@ -4474,7 +4474,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
goto cantfind_ext4; goto cantfind_ext4;
/* check blocks count against device size */ /* check blocks count against device size */
blocks_count = sb->s_bdev->bd_inode->i_size >> sb->s_blocksize_bits; blocks_count = sb_bdev_nr_blocks(sb);
if (blocks_count && ext4_blocks_count(es) > blocks_count) { if (blocks_count && ext4_blocks_count(es) > blocks_count) {
ext4_msg(sb, KERN_WARNING, "bad geometry: block count %llu " ext4_msg(sb, KERN_WARNING, "bad geometry: block count %llu "
"exceeds size of device (%llu blocks)", "exceeds size of device (%llu blocks)",

View File

@ -1536,14 +1536,11 @@ static int fat_read_static_bpb(struct super_block *sb,
struct fat_bios_param_block *bpb) struct fat_bios_param_block *bpb)
{ {
static const char *notdos1x = "This doesn't look like a DOS 1.x volume"; static const char *notdos1x = "This doesn't look like a DOS 1.x volume";
sector_t bd_sects = bdev_nr_sectors(sb->s_bdev);
struct fat_floppy_defaults *fdefaults = NULL; struct fat_floppy_defaults *fdefaults = NULL;
int error = -EINVAL; int error = -EINVAL;
sector_t bd_sects;
unsigned i; unsigned i;
bd_sects = i_size_read(sb->s_bdev->bd_inode) / SECTOR_SIZE;
/* 16-bit DOS 1.x reliably wrote bootstrap short-jmp code */ /* 16-bit DOS 1.x reliably wrote bootstrap short-jmp code */
if (b->ignored[0] != 0xeb || b->ignored[2] != 0x90) { if (b->ignored[0] != 0xeb || b->ignored[2] != 0x90) {
if (!silent) if (!silent)

View File

@ -36,7 +36,7 @@ static int hfs_get_last_session(struct super_block *sb,
/* default values */ /* default values */
*start = 0; *start = 0;
*size = i_size_read(sb->s_bdev->bd_inode) >> 9; *size = bdev_nr_sectors(sb->s_bdev);
if (HFS_SB(sb)->session >= 0) { if (HFS_SB(sb)->session >= 0) {
struct cdrom_tocentry te; struct cdrom_tocentry te;

View File

@ -131,7 +131,7 @@ static int hfsplus_get_last_session(struct super_block *sb,
/* default values */ /* default values */
*start = 0; *start = 0;
*size = i_size_read(sb->s_bdev->bd_inode) >> 9; *size = bdev_nr_sectors(sb->s_bdev);
if (HFSPLUS_SB(sb)->session >= 0) { if (HFSPLUS_SB(sb)->session >= 0) {
struct cdrom_tocentry te; struct cdrom_tocentry te;

View File

@ -86,8 +86,7 @@ int jfs_extendfs(struct super_block *sb, s64 newLVSize, int newLogSize)
goto out; goto out;
} }
VolumeSize = i_size_read(sb->s_bdev->bd_inode) >> sb->s_blocksize_bits; VolumeSize = sb_bdev_nr_blocks(sb);
if (VolumeSize) { if (VolumeSize) {
if (newLVSize > VolumeSize) { if (newLVSize > VolumeSize) {
printk(KERN_WARNING "jfs_extendfs: invalid size\n"); printk(KERN_WARNING "jfs_extendfs: invalid size\n");
@ -199,7 +198,7 @@ int jfs_extendfs(struct super_block *sb, s64 newLVSize, int newLogSize)
txQuiesce(sb); txQuiesce(sb);
/* Reset size of direct inode */ /* 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) { if (sbi->mntflag & JFS_INLINELOG) {
/* /*

View File

@ -284,8 +284,7 @@ static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
} }
case Opt_resize_nosize: case Opt_resize_nosize:
{ {
*newLVSize = i_size_read(sb->s_bdev->bd_inode) >> *newLVSize = sb_bdev_nr_blocks(sb);
sb->s_blocksize_bits;
if (*newLVSize == 0) if (*newLVSize == 0)
pr_err("JFS: Cannot determine volume size\n"); pr_err("JFS: Cannot determine volume size\n");
break; break;
@ -551,7 +550,7 @@ static int jfs_fill_super(struct super_block *sb, void *data, int silent)
ret = -ENOMEM; ret = -ENOMEM;
goto out_unload; goto out_unload;
} }
inode->i_size = i_size_read(sb->s_bdev->bd_inode); inode->i_size = bdev_nr_bytes(sb->s_bdev);
inode->i_mapping->a_ops = &jfs_metapage_aops; inode->i_mapping->a_ops = &jfs_metapage_aops;
inode_fake_hash(inode); inode_fake_hash(inode);
mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS); mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS);

View File

@ -252,7 +252,7 @@ bl_parse_simple(struct nfs_server *server, struct pnfs_block_dev *d,
d->bdev = bdev; d->bdev = bdev;
d->len = i_size_read(d->bdev->bd_inode); d->len = bdev_nr_bytes(d->bdev);
d->map = bl_map_simple; d->map = bl_map_simple;
printk(KERN_INFO "pNFS: using block device %s\n", printk(KERN_INFO "pNFS: using block device %s\n",
@ -367,7 +367,7 @@ bl_parse_scsi(struct nfs_server *server, struct pnfs_block_dev *d,
return PTR_ERR(bdev); return PTR_ERR(bdev);
d->bdev = bdev; d->bdev = bdev;
d->len = i_size_read(d->bdev->bd_inode); d->len = bdev_nr_bytes(d->bdev);
d->map = bl_map_simple; d->map = bl_map_simple;
d->pr_key = v->scsi.pr_key; d->pr_key = v->scsi.pr_key;

View File

@ -1107,7 +1107,7 @@ static int nilfs_ioctl_set_alloc_range(struct inode *inode, void __user *argp)
goto out; goto out;
ret = -ERANGE; ret = -ERANGE;
if (range[1] > i_size_read(inode->i_sb->s_bdev->bd_inode)) if (range[1] > bdev_nr_bytes(inode->i_sb->s_bdev))
goto out; goto out;
segbytes = nilfs->ns_blocks_per_segment * nilfs->ns_blocksize; segbytes = nilfs->ns_blocks_per_segment * nilfs->ns_blocksize;

View File

@ -403,7 +403,7 @@ int nilfs_resize_fs(struct super_block *sb, __u64 newsize)
int ret; int ret;
ret = -ERANGE; ret = -ERANGE;
devsize = i_size_read(sb->s_bdev->bd_inode); devsize = bdev_nr_bytes(sb->s_bdev);
if (newsize > devsize) if (newsize > devsize)
goto out; goto out;

View File

@ -489,7 +489,7 @@ static int nilfs_load_super_block(struct the_nilfs *nilfs,
{ {
struct nilfs_super_block **sbp = nilfs->ns_sbp; struct nilfs_super_block **sbp = nilfs->ns_sbp;
struct buffer_head **sbh = nilfs->ns_sbh; struct buffer_head **sbh = nilfs->ns_sbh;
u64 sb2off = NILFS_SB2_OFFSET_BYTES(nilfs->ns_bdev->bd_inode->i_size); u64 sb2off = NILFS_SB2_OFFSET_BYTES(bdev_nr_bytes(nilfs->ns_bdev));
int valid[2], swp = 0; int valid[2], swp = 0;
sbp[0] = nilfs_read_super_block(sb, NILFS_SB_OFFSET_BYTES, blocksize, sbp[0] = nilfs_read_super_block(sb, NILFS_SB_OFFSET_BYTES, blocksize,

View File

@ -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).", ntfs_debug("Set device block size to %i bytes (block size bits %i).",
blocksize, sb->s_blocksize_bits); blocksize, sb->s_blocksize_bits);
/* Determine the size of the device in units of block_size bytes. */ /* 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) if (!silent)
ntfs_error(sb, "Unable to determine device size."); ntfs_error(sb, "Unable to determine device size.");
goto err_out_now; 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. */ /* Read the boot sector and return unlocked buffer head to it. */
if (!(bh = read_ntfs_boot_sector(sb, silent))) { if (!(bh = read_ntfs_boot_sector(sb, silent))) {
if (!silent) if (!silent)
@ -2816,8 +2815,7 @@ static int ntfs_fill_super(struct super_block *sb, void *opt, const int silent)
goto err_out_now; goto err_out_now;
} }
BUG_ON(blocksize != sb->s_blocksize); BUG_ON(blocksize != sb->s_blocksize);
vol->nr_blocks = i_size_read(sb->s_bdev->bd_inode) >> vol->nr_blocks = sb_bdev_nr_blocks(sb);
sb->s_blocksize_bits;
ntfs_debug("Changed device block size to %i bytes (block size " ntfs_debug("Changed device block size to %i bytes (block size "
"bits %i) to match volume sector size.", "bits %i) to match volume sector size.",
blocksize, sb->s_blocksize_bits); blocksize, sb->s_blocksize_bits);

View File

@ -921,7 +921,7 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)
/* Parse boot. */ /* Parse boot. */
err = ntfs_init_from_boot(sb, rq ? queue_logical_block_size(rq) : 512, err = ntfs_init_from_boot(sb, rq ? queue_logical_block_size(rq) : 512,
bdev->bd_inode->i_size); bdev_nr_bytes(bdev));
if (err) if (err)
goto out; goto out;

View File

@ -205,7 +205,6 @@ static ssize_t psblk_generic_blk_write(const char *buf, size_t bytes,
static int __register_pstore_blk(struct pstore_device_info *dev, static int __register_pstore_blk(struct pstore_device_info *dev,
const char *devpath) const char *devpath)
{ {
struct inode *inode;
int ret = -ENODEV; int ret = -ENODEV;
lockdep_assert_held(&pstore_blk_lock); lockdep_assert_held(&pstore_blk_lock);
@ -217,14 +216,13 @@ static int __register_pstore_blk(struct pstore_device_info *dev,
goto err; goto err;
} }
inode = file_inode(psblk_file); if (!S_ISBLK(file_inode(psblk_file)->i_mode)) {
if (!S_ISBLK(inode->i_mode)) {
pr_err("'%s' is not block device!\n", devpath); pr_err("'%s' is not block device!\n", devpath);
goto err_fput; goto err_fput;
} }
inode = I_BDEV(psblk_file->f_mapping->host)->bd_inode; dev->zone.total_size =
dev->zone.total_size = i_size_read(inode); bdev_nr_bytes(I_BDEV(psblk_file->f_mapping->host));
ret = __register_pstore_device(dev); ret = __register_pstore_device(dev);
if (ret) if (ret)

View File

@ -1199,9 +1199,7 @@ static int reiserfs_parse_options(struct super_block *s,
if (!strcmp(arg, "auto")) { if (!strcmp(arg, "auto")) {
/* From JFS code, to auto-get the size. */ /* From JFS code, to auto-get the size. */
*blocks = *blocks = sb_bdev_nr_blocks(s);
i_size_read(s->s_bdev->bd_inode) >> s->
s_blocksize_bits;
} else { } else {
*blocks = simple_strtoul(arg, &p, 0); *blocks = simple_strtoul(arg, &p, 0);
if (*p != '\0') { if (*p != '\0') {
@ -1986,9 +1984,7 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
* smaller than the filesystem. If the check fails then abort and * smaller than the filesystem. If the check fails then abort and
* scream, because bad stuff will happen otherwise. * scream, because bad stuff will happen otherwise.
*/ */
if (s->s_bdev && s->s_bdev->bd_inode if (bdev_nr_bytes(s->s_bdev) < sb_block_count(rs) * sb_blocksize(rs)) {
&& i_size_read(s->s_bdev->bd_inode) <
sb_block_count(rs) * sb_blocksize(rs)) {
SWARN(silent, s, "", "Filesystem cannot be " SWARN(silent, s, "", "Filesystem cannot be "
"mounted because it is bigger than the device"); "mounted because it is bigger than the device");
SWARN(silent, s, "", "You may need to run fsck " SWARN(silent, s, "", "You may need to run fsck "

View File

@ -16,6 +16,7 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/blkdev.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/fs_context.h> #include <linux/fs_context.h>
#include <linux/fs_parser.h> #include <linux/fs_parser.h>
@ -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 the /* Check the filesystem does not extend beyond the end of the
block device */ block device */
msblk->bytes_used = le64_to_cpu(sblk->bytes_used); msblk->bytes_used = le64_to_cpu(sblk->bytes_used);
if (msblk->bytes_used < 0 || msblk->bytes_used > if (msblk->bytes_used < 0 ||
i_size_read(sb->s_bdev->bd_inode)) msblk->bytes_used > bdev_nr_bytes(sb->s_bdev))
goto failed_mount; goto failed_mount;
/* Check block size for sanity */ /* Check block size for sanity */

View File

@ -47,8 +47,7 @@ unsigned int udf_get_last_session(struct super_block *sb)
unsigned long udf_get_last_block(struct super_block *sb) unsigned long udf_get_last_block(struct super_block *sb)
{ {
struct block_device *bdev = sb->s_bdev; struct cdrom_device_info *cdi = disk_to_cdi(sb->s_bdev->bd_disk);
struct cdrom_device_info *cdi = disk_to_cdi(bdev->bd_disk);
unsigned long lblock = 0; unsigned long lblock = 0;
/* /*
@ -56,7 +55,7 @@ unsigned long udf_get_last_block(struct super_block *sb)
* Try using the device size... * Try using the device size...
*/ */
if (!cdi || cdrom_get_last_written(cdi, &lblock) || lblock == 0) if (!cdi || cdrom_get_last_written(cdi, &lblock) || lblock == 0)
lblock = i_size_read(bdev->bd_inode) >> sb->s_blocksize_bits; lblock = sb_bdev_nr_blocks(sb);
if (lblock) if (lblock)
return lblock - 1; return lblock - 1;

View File

@ -1175,8 +1175,7 @@ static int udf_load_vat(struct super_block *sb, int p_index, int type1_index)
struct udf_inode_info *vati; struct udf_inode_info *vati;
uint32_t pos; uint32_t pos;
struct virtualAllocationTable20 *vat20; struct virtualAllocationTable20 *vat20;
sector_t blocks = i_size_read(sb->s_bdev->bd_inode) >> sector_t blocks = sb_bdev_nr_blocks(sb);
sb->s_blocksize_bits;
udf_find_vat_block(sb, p_index, type1_index, sbi->s_last_block); udf_find_vat_block(sb, p_index, type1_index, sbi->s_last_block);
if (!sbi->s_vat_inode && if (!sbi->s_vat_inode &&
@ -1838,8 +1837,7 @@ static int udf_check_anchor_block(struct super_block *sb, sector_t block,
int ret; int ret;
if (UDF_QUERY_FLAG(sb, UDF_FLAG_VARCONV) && if (UDF_QUERY_FLAG(sb, UDF_FLAG_VARCONV) &&
udf_fixed_to_variable(block) >= udf_fixed_to_variable(block) >= sb_bdev_nr_blocks(sb))
i_size_read(sb->s_bdev->bd_inode) >> sb->s_blocksize_bits)
return -EAGAIN; return -EAGAIN;
bh = udf_read_tagged(sb, block, block, &ident); bh = udf_read_tagged(sb, block, block, &ident);
@ -1901,8 +1899,7 @@ static int udf_scan_anchors(struct super_block *sb, sector_t *lastblock,
last[last_count++] = *lastblock - 152; last[last_count++] = *lastblock - 152;
for (i = 0; i < last_count; i++) { for (i = 0; i < last_count; i++) {
if (last[i] >= i_size_read(sb->s_bdev->bd_inode) >> if (last[i] >= sb_bdev_nr_blocks(sb))
sb->s_blocksize_bits)
continue; continue;
ret = udf_check_anchor_block(sb, last[i], fileset); ret = udf_check_anchor_block(sb, last[i], fileset);
if (ret != -EAGAIN) { if (ret != -EAGAIN) {

View File

@ -20,8 +20,26 @@ struct cgroup_subsys_state;
typedef void (bio_end_io_t) (struct bio *); typedef void (bio_end_io_t) (struct bio *);
struct bio_crypt_ctx; struct bio_crypt_ctx;
/*
* The basic unit of block I/O is a sector. It is used in a number of contexts
* in Linux (blk, bio, genhd). The size of one sector is 512 = 2**9
* bytes. Variables of type sector_t represent an offset or size that is a
* multiple of 512 bytes. Hence these two constants.
*/
#ifndef SECTOR_SHIFT
#define SECTOR_SHIFT 9
#endif
#ifndef SECTOR_SIZE
#define SECTOR_SIZE (1 << SECTOR_SHIFT)
#endif
#define PAGE_SECTORS_SHIFT (PAGE_SHIFT - SECTOR_SHIFT)
#define PAGE_SECTORS (1 << PAGE_SECTORS_SHIFT)
#define SECTOR_MASK (PAGE_SECTORS - 1)
struct block_device { struct block_device {
sector_t bd_start_sect; sector_t bd_start_sect;
sector_t bd_nr_sectors;
struct disk_stats __percpu *bd_stats; struct disk_stats __percpu *bd_stats;
unsigned long bd_stamp; unsigned long bd_stamp;
bool bd_read_only; /* read-only policy */ bool bd_read_only; /* read-only policy */

View File

@ -621,23 +621,6 @@ static inline struct request_queue *bdev_get_queue(struct block_device *bdev)
return bdev->bd_queue; /* this is never NULL */ return bdev->bd_queue; /* this is never NULL */
} }
/*
* The basic unit of block I/O is a sector. It is used in a number of contexts
* in Linux (blk, bio, genhd). The size of one sector is 512 = 2**9
* bytes. Variables of type sector_t represent an offset or size that is a
* multiple of 512 bytes. Hence these two constants.
*/
#ifndef SECTOR_SHIFT
#define SECTOR_SHIFT 9
#endif
#ifndef SECTOR_SIZE
#define SECTOR_SIZE (1 << SECTOR_SHIFT)
#endif
#define PAGE_SECTORS_SHIFT (PAGE_SHIFT - SECTOR_SHIFT)
#define PAGE_SECTORS (1 << PAGE_SECTORS_SHIFT)
#define SECTOR_MASK (PAGE_SECTORS - 1)
#ifdef CONFIG_BLK_DEV_ZONED #ifdef CONFIG_BLK_DEV_ZONED
/* Helper to convert BLK_ZONE_ZONE_XXX to its string format XXX */ /* Helper to convert BLK_ZONE_ZONE_XXX to its string format XXX */

View File

@ -245,7 +245,12 @@ static inline sector_t get_start_sect(struct block_device *bdev)
static inline sector_t bdev_nr_sectors(struct block_device *bdev) static inline sector_t bdev_nr_sectors(struct block_device *bdev)
{ {
return i_size_read(bdev->bd_inode) >> 9; return bdev->bd_nr_sectors;
}
static inline loff_t bdev_nr_bytes(struct block_device *bdev)
{
return bdev_nr_sectors(bdev) << SECTOR_SHIFT;
} }
static inline sector_t get_capacity(struct gendisk *disk) static inline sector_t get_capacity(struct gendisk *disk)
@ -253,6 +258,12 @@ static inline sector_t get_capacity(struct gendisk *disk)
return bdev_nr_sectors(disk->part0); return bdev_nr_sectors(disk->part0);
} }
static inline u64 sb_bdev_nr_blocks(struct super_block *sb)
{
return bdev_nr_sectors(sb->s_bdev) >>
(sb->s_blocksize_bits - SECTOR_SHIFT);
}
int bdev_disk_changed(struct gendisk *disk, bool invalidate); int bdev_disk_changed(struct gendisk *disk, bool invalidate);
void blk_drop_partitions(struct gendisk *disk); void blk_drop_partitions(struct gendisk *disk);