Skip to content

Commit ead083a

Browse files
author
Al Viro
committed
set_blocksize(): switch to passing struct file *
Signed-off-by: Al Viro <[email protected]>
1 parent b85c429 commit ead083a

File tree

9 files changed

+28
-23
lines changed

9 files changed

+28
-23
lines changed

block/bdev.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,11 @@ static void set_init_blocksize(struct block_device *bdev)
144144
bdev->bd_inode->i_blkbits = blksize_bits(bsize);
145145
}
146146

147-
int set_blocksize(struct block_device *bdev, int size)
147+
int set_blocksize(struct file *file, int size)
148148
{
149+
struct inode *inode = file->f_mapping->host;
150+
struct block_device *bdev = I_BDEV(inode);
151+
149152
/* Size must be a power of two, and between 512 and PAGE_SIZE */
150153
if (size > PAGE_SIZE || size < 512 || !is_power_of_2(size))
151154
return -EINVAL;
@@ -155,9 +158,9 @@ int set_blocksize(struct block_device *bdev, int size)
155158
return -EINVAL;
156159

157160
/* Don't change the size if it is same as current */
158-
if (bdev->bd_inode->i_blkbits != blksize_bits(size)) {
161+
if (inode->i_blkbits != blksize_bits(size)) {
159162
sync_blockdev(bdev);
160-
bdev->bd_inode->i_blkbits = blksize_bits(size);
163+
inode->i_blkbits = blksize_bits(size);
161164
kill_bdev(bdev);
162165
}
163166
return 0;
@@ -167,7 +170,7 @@ EXPORT_SYMBOL(set_blocksize);
167170

168171
int sb_set_blocksize(struct super_block *sb, int size)
169172
{
170-
if (set_blocksize(sb->s_bdev, size))
173+
if (set_blocksize(sb->s_bdev_file, size))
171174
return 0;
172175
/* If we get here, we know size is power of two
173176
* and it's value is between 512 and PAGE_SIZE */

block/ioctl.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -473,11 +473,14 @@ static int compat_hdio_getgeo(struct block_device *bdev,
473473
#endif
474474

475475
/* set the logical block size */
476-
static int blkdev_bszset(struct block_device *bdev, blk_mode_t mode,
476+
static int blkdev_bszset(struct file *file, blk_mode_t mode,
477477
int __user *argp)
478478
{
479+
// this one might be file_inode(file)->i_rdev - a rare valid
480+
// use of file_inode() for those.
481+
dev_t dev = I_BDEV(file->f_mapping->host)->bd_dev;
482+
struct file *excl_file;
479483
int ret, n;
480-
struct file *file;
481484

482485
if (!capable(CAP_SYS_ADMIN))
483486
return -EACCES;
@@ -487,13 +490,13 @@ static int blkdev_bszset(struct block_device *bdev, blk_mode_t mode,
487490
return -EFAULT;
488491

489492
if (mode & BLK_OPEN_EXCL)
490-
return set_blocksize(bdev, n);
493+
return set_blocksize(file, n);
491494

492-
file = bdev_file_open_by_dev(bdev->bd_dev, mode, &bdev, NULL);
493-
if (IS_ERR(file))
495+
excl_file = bdev_file_open_by_dev(dev, mode, &dev, NULL);
496+
if (IS_ERR(excl_file))
494497
return -EBUSY;
495-
ret = set_blocksize(bdev, n);
496-
fput(file);
498+
ret = set_blocksize(excl_file, n);
499+
fput(excl_file);
497500
return ret;
498501
}
499502

@@ -621,7 +624,7 @@ long blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
621624
case BLKBSZGET: /* get block device soft block size (cf. BLKSSZGET) */
622625
return put_int(argp, block_size(bdev));
623626
case BLKBSZSET:
624-
return blkdev_bszset(bdev, mode, argp);
627+
return blkdev_bszset(file, mode, argp);
625628
case BLKGETSIZE64:
626629
return put_u64(argp, bdev_nr_bytes(bdev));
627630

@@ -681,7 +684,7 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
681684
case BLKBSZGET_32: /* get the logical block size (cf. BLKSSZGET) */
682685
return put_int(argp, bdev_logical_block_size(bdev));
683686
case BLKBSZSET_32:
684-
return blkdev_bszset(bdev, mode, argp);
687+
return blkdev_bszset(file, mode, argp);
685688
case BLKGETSIZE64_32:
686689
return put_u64(argp, bdev_nr_bytes(bdev));
687690

drivers/block/pktcdvd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2215,7 +2215,7 @@ static int pkt_open_dev(struct pktcdvd_device *pd, bool write)
22152215
}
22162216
dev_info(ddev, "%lukB available on disc\n", lba << 1);
22172217
}
2218-
set_blocksize(file_bdev(bdev_file), CD_FRAMESIZE);
2218+
set_blocksize(bdev_file, CD_FRAMESIZE);
22192219

22202220
return 0;
22212221

fs/btrfs/dev-replace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,
316316
set_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state);
317317
set_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state);
318318
device->dev_stats_valid = 1;
319-
set_blocksize(device->bdev, BTRFS_BDEV_BLOCKSIZE);
319+
set_blocksize(bdev_file, BTRFS_BDEV_BLOCKSIZE);
320320
device->fs_devices = fs_devices;
321321

322322
ret = btrfs_get_dev_zone_info(device, false);

fs/btrfs/volumes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ btrfs_get_bdev_and_sb(const char *device_path, blk_mode_t flags, void *holder,
483483
if (flush)
484484
sync_blockdev(bdev);
485485
if (holder) {
486-
ret = set_blocksize(bdev, BTRFS_BDEV_BLOCKSIZE);
486+
ret = set_blocksize(*bdev_file, BTRFS_BDEV_BLOCKSIZE);
487487
if (ret) {
488488
fput(*bdev_file);
489489
goto error;
@@ -2717,7 +2717,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
27172717
set_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state);
27182718
clear_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state);
27192719
device->dev_stats_valid = 1;
2720-
set_blocksize(device->bdev, BTRFS_BDEV_BLOCKSIZE);
2720+
set_blocksize(device->bdev_file, BTRFS_BDEV_BLOCKSIZE);
27212721

27222722
if (seeding_dev) {
27232723
btrfs_clear_sb_rdonly(sb);

fs/ext4/super.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5873,7 +5873,7 @@ static struct file *ext4_get_journal_blkdev(struct super_block *sb,
58735873

58745874
sb_block = EXT4_MIN_BLOCK_SIZE / blocksize;
58755875
offset = EXT4_MIN_BLOCK_SIZE % blocksize;
5876-
set_blocksize(bdev, blocksize);
5876+
set_blocksize(bdev_file, blocksize);
58775877
bh = __bread(bdev, sb_block, blocksize);
58785878
if (!bh) {
58795879
ext4_msg(sb, KERN_ERR, "couldn't read superblock of "

fs/reiserfs/journal.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2626,8 +2626,7 @@ static int journal_init_dev(struct super_block *super,
26262626
MAJOR(jdev), MINOR(jdev), result);
26272627
return result;
26282628
} else if (jdev != super->s_dev)
2629-
set_blocksize(file_bdev(journal->j_bdev_file),
2630-
super->s_blocksize);
2629+
set_blocksize(journal->j_bdev_file, super->s_blocksize);
26312630

26322631
return 0;
26332632
}
@@ -2643,7 +2642,7 @@ static int journal_init_dev(struct super_block *super,
26432642
return result;
26442643
}
26452644

2646-
set_blocksize(file_bdev(journal->j_bdev_file), super->s_blocksize);
2645+
set_blocksize(journal->j_bdev_file, super->s_blocksize);
26472646
reiserfs_info(super,
26482647
"journal_init_dev: journal device: %pg\n",
26492648
file_bdev(journal->j_bdev_file));

fs/xfs/xfs_buf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2043,7 +2043,7 @@ xfs_setsize_buftarg(
20432043
btp->bt_meta_sectorsize = sectorsize;
20442044
btp->bt_meta_sectormask = sectorsize - 1;
20452045

2046-
if (set_blocksize(btp->bt_bdev, sectorsize)) {
2046+
if (set_blocksize(btp->bt_bdev_file, sectorsize)) {
20472047
xfs_warn(btp->bt_mount,
20482048
"Cannot set_blocksize to %u on device %pg",
20492049
sectorsize, btp->bt_bdev);

include/linux/blkdev.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,7 @@ static inline void bio_end_io_acct(struct bio *bio, unsigned long start_time)
14741474
}
14751475

14761476
int bdev_read_only(struct block_device *bdev);
1477-
int set_blocksize(struct block_device *bdev, int size);
1477+
int set_blocksize(struct file *file, int size);
14781478

14791479
int lookup_bdev(const char *pathname, dev_t *dev);
14801480

0 commit comments

Comments
 (0)