Use file->f_flags instead of file->private_data for determining whether we should set BLK_OPEN_EXCL flag. This allows us to remove somewhat awkward setting of file->private_data before calling file_to_blk_mode() and it also makes following conversion to blkdev_get_handle_by_dev() simpler. Signed-off-by: Jan Kara <jack@xxxxxxx> --- block/fops.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/block/fops.c b/block/fops.c index a286bf3325c5..b6aa470c09ae 100644 --- a/block/fops.c +++ b/block/fops.c @@ -478,7 +478,7 @@ blk_mode_t file_to_blk_mode(struct file *file) mode |= BLK_OPEN_READ; if (file->f_mode & FMODE_WRITE) mode |= BLK_OPEN_WRITE; - if (file->private_data) + if (file->f_flags & O_EXCL) mode |= BLK_OPEN_EXCL; if (file->f_flags & O_NDELAY) mode |= BLK_OPEN_NDELAY; @@ -497,6 +497,7 @@ blk_mode_t file_to_blk_mode(struct file *file) static int blkdev_open(struct inode *inode, struct file *filp) { struct block_device *bdev; + blk_mode_t mode; /* * Preserve backwards compatibility and allow large file access @@ -507,18 +508,14 @@ static int blkdev_open(struct inode *inode, struct file *filp) filp->f_flags |= O_LARGEFILE; filp->f_mode |= FMODE_BUF_RASYNC; - /* - * Use the file private data to store the holder for exclusive openes. - * file_to_blk_mode relies on it being present to set BLK_OPEN_EXCL. - */ - if (filp->f_flags & O_EXCL) - filp->private_data = filp; - - bdev = blkdev_get_by_dev(inode->i_rdev, file_to_blk_mode(filp), - filp->private_data, NULL); + mode = file_to_blk_mode(filp); + bdev = blkdev_get_by_dev(inode->i_rdev, mode, + mode & BLK_OPEN_EXCL ? filp : NULL, NULL); if (IS_ERR(bdev)) return PTR_ERR(bdev); + if (mode & BLK_OPEN_EXCL) + filp->private_data = filp; if (bdev_nowait(bdev)) filp->f_mode |= FMODE_NOWAIT; -- 2.35.3