Commit 4e762d86 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe

block: always use I_BDEV on file->f_mapping->host to find the bdev

Always use I_BDEV(file->f_mapping->host) to find the bdev for a file to
free up file->private_data for other uses.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarHannes Reinecke <hare@suse.de>
Acked-by: default avatarChristian Brauner <brauner@kernel.org>
Link: https://lore.kernel.org/r/20230608110258.189493-29-hch@lst.deSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 05bdb996
...@@ -54,7 +54,7 @@ static bool blkdev_dio_unaligned(struct block_device *bdev, loff_t pos, ...@@ -54,7 +54,7 @@ static bool blkdev_dio_unaligned(struct block_device *bdev, loff_t pos,
static ssize_t __blkdev_direct_IO_simple(struct kiocb *iocb, static ssize_t __blkdev_direct_IO_simple(struct kiocb *iocb,
struct iov_iter *iter, unsigned int nr_pages) struct iov_iter *iter, unsigned int nr_pages)
{ {
struct block_device *bdev = iocb->ki_filp->private_data; struct block_device *bdev = I_BDEV(iocb->ki_filp->f_mapping->host);
struct bio_vec inline_vecs[DIO_INLINE_BIO_VECS], *vecs; struct bio_vec inline_vecs[DIO_INLINE_BIO_VECS], *vecs;
loff_t pos = iocb->ki_pos; loff_t pos = iocb->ki_pos;
bool should_dirty = false; bool should_dirty = false;
...@@ -170,7 +170,7 @@ static void blkdev_bio_end_io(struct bio *bio) ...@@ -170,7 +170,7 @@ static void blkdev_bio_end_io(struct bio *bio)
static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
unsigned int nr_pages) unsigned int nr_pages)
{ {
struct block_device *bdev = iocb->ki_filp->private_data; struct block_device *bdev = I_BDEV(iocb->ki_filp->f_mapping->host);
struct blk_plug plug; struct blk_plug plug;
struct blkdev_dio *dio; struct blkdev_dio *dio;
struct bio *bio; struct bio *bio;
...@@ -310,7 +310,7 @@ static ssize_t __blkdev_direct_IO_async(struct kiocb *iocb, ...@@ -310,7 +310,7 @@ static ssize_t __blkdev_direct_IO_async(struct kiocb *iocb,
struct iov_iter *iter, struct iov_iter *iter,
unsigned int nr_pages) unsigned int nr_pages)
{ {
struct block_device *bdev = iocb->ki_filp->private_data; struct block_device *bdev = I_BDEV(iocb->ki_filp->f_mapping->host);
bool is_read = iov_iter_rw(iter) == READ; bool is_read = iov_iter_rw(iter) == READ;
blk_opf_t opf = is_read ? REQ_OP_READ : dio_bio_write_op(iocb); blk_opf_t opf = is_read ? REQ_OP_READ : dio_bio_write_op(iocb);
struct blkdev_dio *dio; struct blkdev_dio *dio;
...@@ -451,7 +451,7 @@ static loff_t blkdev_llseek(struct file *file, loff_t offset, int whence) ...@@ -451,7 +451,7 @@ static loff_t blkdev_llseek(struct file *file, loff_t offset, int whence)
static int blkdev_fsync(struct file *filp, loff_t start, loff_t end, static int blkdev_fsync(struct file *filp, loff_t start, loff_t end,
int datasync) int datasync)
{ {
struct block_device *bdev = filp->private_data; struct block_device *bdev = I_BDEV(filp->f_mapping->host);
int error; int error;
error = file_write_and_wait_range(filp, start, end); error = file_write_and_wait_range(filp, start, end);
...@@ -516,7 +516,6 @@ static int blkdev_open(struct inode *inode, struct file *filp) ...@@ -516,7 +516,6 @@ static int blkdev_open(struct inode *inode, struct file *filp)
if (IS_ERR(bdev)) if (IS_ERR(bdev))
return PTR_ERR(bdev); return PTR_ERR(bdev);
filp->private_data = bdev;
filp->f_mapping = bdev->bd_inode->i_mapping; filp->f_mapping = bdev->bd_inode->i_mapping;
filp->f_wb_err = filemap_sample_wb_err(filp->f_mapping); filp->f_wb_err = filemap_sample_wb_err(filp->f_mapping);
return 0; return 0;
...@@ -524,9 +523,8 @@ static int blkdev_open(struct inode *inode, struct file *filp) ...@@ -524,9 +523,8 @@ static int blkdev_open(struct inode *inode, struct file *filp)
static int blkdev_release(struct inode *inode, struct file *filp) static int blkdev_release(struct inode *inode, struct file *filp)
{ {
struct block_device *bdev = filp->private_data; blkdev_put(I_BDEV(filp->f_mapping->host),
(filp->f_mode & FMODE_EXCL) ? filp : NULL);
blkdev_put(bdev, (filp->f_mode & FMODE_EXCL) ? filp : NULL);
return 0; return 0;
} }
...@@ -539,7 +537,7 @@ static int blkdev_release(struct inode *inode, struct file *filp) ...@@ -539,7 +537,7 @@ static int blkdev_release(struct inode *inode, struct file *filp)
*/ */
static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from) static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from)
{ {
struct block_device *bdev = iocb->ki_filp->private_data; struct block_device *bdev = I_BDEV(iocb->ki_filp->f_mapping->host);
struct inode *bd_inode = bdev->bd_inode; struct inode *bd_inode = bdev->bd_inode;
loff_t size = bdev_nr_bytes(bdev); loff_t size = bdev_nr_bytes(bdev);
size_t shorted = 0; size_t shorted = 0;
...@@ -575,7 +573,7 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from) ...@@ -575,7 +573,7 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from)
static ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to) static ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to)
{ {
struct block_device *bdev = iocb->ki_filp->private_data; struct block_device *bdev = I_BDEV(iocb->ki_filp->f_mapping->host);
loff_t size = bdev_nr_bytes(bdev); loff_t size = bdev_nr_bytes(bdev);
loff_t pos = iocb->ki_pos; loff_t pos = iocb->ki_pos;
size_t shorted = 0; size_t shorted = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment