Similar to the file_inode() helper, provide a helper to lookup the inode for a raw block device itself.
Unified · Split
| @@ -156,11 +156,16 @@ blkdev_get_block(struct inode *inode, sector_t iblock, · 155 unmodified lines | |||
| 156 | return 0; | 156 | return 0; |
| 157 | } | 157 | } |
| 158 | 158 | ||
| 159 | static struct inode *bdev_file_inode(struct file *file) | ||
| 160 | { | ||
| 161 | return file->f_mapping->host; | ||
| 162 | } | ||
| 163 | |||
| 159 | static ssize_t | 164 | static ssize_t |
| 160 | blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, loff_t offset) | 165 | blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, loff_t offset) |
| 161 | { | 166 | { |
| 162 | struct file *file = iocb->ki_filp; | 167 | struct file *file = iocb->ki_filp; |
| 163 | struct inode *inode = file->f_mapping->host; | 168 | struct inode *inode = bdev_file_inode(file); |
| 164 | 169 | ||
| 165 | if (IS_DAX(inode)) | 170 | if (IS_DAX(inode)) |
| 166 | return dax_do_io(iocb, inode, iter, offset, blkdev_get_block, | 171 | return dax_do_io(iocb, inode, iter, offset, blkdev_get_block, |
| @@ -338,7 +343,7 @@ static int blkdev_write_end(struct file *file, struct address_space *mapping, · 171 unmodified lines | |||
| 338 | */ | 343 | */ |
| 339 | static loff_t block_llseek(struct file *file, loff_t offset, int whence) | 344 | static loff_t block_llseek(struct file *file, loff_t offset, int whence) |
| 340 | { | 345 | { |
| 341 | struct inode *bd_inode = file->f_mapping->host; | 346 | struct inode *bd_inode = bdev_file_inode(file); |
| 342 | loff_t retval; | 347 | loff_t retval; |
| 343 | 348 | ||
| 344 | mutex_lock(&bd_inode->i_mutex); | 349 | mutex_lock(&bd_inode->i_mutex); |
| @@ -349,7 +354,7 @@ static loff_t block_llseek(struct file *file, loff_t offset, int whence) · 4 unmodified lines | |||
| 349 | 354 | ||
| 350 | int blkdev_fsync(struct file *filp, loff_t start, loff_t end, int datasync) | 355 | int blkdev_fsync(struct file *filp, loff_t start, loff_t end, int datasync) |
| 351 | { | 356 | { |
| 352 | struct inode *bd_inode = filp->f_mapping->host; | 357 | struct inode *bd_inode = bdev_file_inode(filp); |
| 353 | struct block_device *bdev = I_BDEV(bd_inode); | 358 | struct block_device *bdev = I_BDEV(bd_inode); |
| 354 | int error; | 359 | int error; |
| 355 | 360 | ||
| @@ -1605,14 +1610,14 @@ EXPORT_SYMBOL(blkdev_put); · 1249 unmodified lines | |||
| 1605 | 1610 | ||
| 1606 | static int blkdev_close(struct inode * inode, struct file * filp) | 1611 | static int blkdev_close(struct inode * inode, struct file * filp) |
| 1607 | { | 1612 | { |
| 1608 | struct block_device *bdev = I_BDEV(filp->f_mapping->host); | 1613 | struct block_device *bdev = I_BDEV(bdev_file_inode(filp)); |
| 1609 | blkdev_put(bdev, filp->f_mode); | 1614 | blkdev_put(bdev, filp->f_mode); |
| 1610 | return 0; | 1615 | return 0; |
| 1611 | } | 1616 | } |
| 1612 | 1617 | ||
| 1613 | static long block_ioctl(struct file *file, unsigned cmd, unsigned long arg) | 1618 | static long block_ioctl(struct file *file, unsigned cmd, unsigned long arg) |
| 1614 | { | 1619 | { |
| 1615 | struct block_device *bdev = I_BDEV(file->f_mapping->host); | 1620 | struct block_device *bdev = I_BDEV(bdev_file_inode(file)); |
| 1616 | fmode_t mode = file->f_mode; | 1621 | fmode_t mode = file->f_mode; |
| 1617 | 1622 | ||
| 1618 | /* | 1623 | /* |
| @@ -1637,7 +1642,7 @@ static long block_ioctl(struct file *file, unsigned cmd, unsigned long arg) · 18 unmodified lines | |||
| 1637 | ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from) | 1642 | ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from) |
| 1638 | { | 1643 | { |
| 1639 | struct file *file = iocb->ki_filp; | 1644 | struct file *file = iocb->ki_filp; |
| 1640 | struct inode *bd_inode = file->f_mapping->host; | 1645 | struct inode *bd_inode = bdev_file_inode(file); |
| 1641 | loff_t size = i_size_read(bd_inode); | 1646 | loff_t size = i_size_read(bd_inode); |
| 1642 | struct blk_plug plug; | 1647 | struct blk_plug plug; |
| 1643 | ssize_t ret; | 1648 | ssize_t ret; |
| @@ -1669,7 +1674,7 @@ EXPORT_SYMBOL_GPL(blkdev_write_iter); · 25 unmodified lines | |||
| 1669 | ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to) | 1674 | ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to) |
| 1670 | { | 1675 | { |
| 1671 | struct file *file = iocb->ki_filp; | 1676 | struct file *file = iocb->ki_filp; |
| 1672 | struct inode *bd_inode = file->f_mapping->host; | 1677 | struct inode *bd_inode = bdev_file_inode(file); |
| 1673 | loff_t size = i_size_read(bd_inode); | 1678 | loff_t size = i_size_read(bd_inode); |
| 1674 | loff_t pos = iocb->ki_pos; | 1679 | loff_t pos = iocb->ki_pos; |
| 1675 | 1680 | ||