Skip to content

Commit 186ddac

Browse files
YuKuai-huaweiAl Viro
authored andcommitted
block: move two helpers into bdev.c
disk_live() and block_size() access bd_inode directly, prepare to remove the field bd_inode from block_device, and only access bd_inode in block layer. Signed-off-by: Yu Kuai <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Jan Kara <[email protected]> Signed-off-by: Al Viro <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent c9600c6 commit 186ddac

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

block/bdev.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,6 +1257,18 @@ void bdev_statx_dioalign(struct inode *inode, struct kstat *stat)
12571257
blkdev_put_no_open(bdev);
12581258
}
12591259

1260+
bool disk_live(struct gendisk *disk)
1261+
{
1262+
return !inode_unhashed(disk->part0->bd_inode);
1263+
}
1264+
EXPORT_SYMBOL_GPL(disk_live);
1265+
1266+
unsigned int block_size(struct block_device *bdev)
1267+
{
1268+
return 1 << bdev->bd_inode->i_blkbits;
1269+
}
1270+
EXPORT_SYMBOL_GPL(block_size);
1271+
12601272
static int __init setup_bdev_allow_write_mounted(char *str)
12611273
{
12621274
if (kstrtobool(str, &bdev_allow_write_mounted))

include/linux/blkdev.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,6 @@ struct gendisk {
211211
struct blk_independent_access_ranges *ia_ranges;
212212
};
213213

214-
static inline bool disk_live(struct gendisk *disk)
215-
{
216-
return !inode_unhashed(disk->part0->bd_inode);
217-
}
218-
219214
/**
220215
* disk_openers - returns how many openers are there for a disk
221216
* @disk: disk to check
@@ -1364,11 +1359,6 @@ static inline unsigned int blksize_bits(unsigned int size)
13641359
return order_base_2(size >> SECTOR_SHIFT) + SECTOR_SHIFT;
13651360
}
13661361

1367-
static inline unsigned int block_size(struct block_device *bdev)
1368-
{
1369-
return 1 << bdev->bd_inode->i_blkbits;
1370-
}
1371-
13721362
int kblockd_schedule_work(struct work_struct *work);
13731363
int kblockd_mod_delayed_work_on(int cpu, struct delayed_work *dwork, unsigned long delay);
13741364

@@ -1536,6 +1526,8 @@ void blkdev_put_no_open(struct block_device *bdev);
15361526

15371527
struct block_device *I_BDEV(struct inode *inode);
15381528
struct block_device *file_bdev(struct file *bdev_file);
1529+
bool disk_live(struct gendisk *disk);
1530+
unsigned int block_size(struct block_device *bdev);
15391531

15401532
#ifdef CONFIG_BLOCK
15411533
void invalidate_bdev(struct block_device *bdev);

0 commit comments

Comments
 (0)