Skip to content

Commit

Permalink
block: store the holder in file->private_data
Browse files Browse the repository at this point in the history
Store the file struct used as the holder in file->private_data as an
indicator that this file descriptor was opened exclusively to  remove
the last use of FMODE_EXCL.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Link: https://lore.kernel.org/r/20230608110258.189493-30-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Christoph Hellwig authored and axboe committed Jun 12, 2023
1 parent 4e762d8 commit ee3249a
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions block/fops.c
Original file line number Diff line number Diff line change
Expand Up @@ -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->f_mode & FMODE_EXCL)
if (file->private_data)
mode |= BLK_OPEN_EXCL;
if (file->f_flags & O_NDELAY)
mode |= BLK_OPEN_NDELAY;
Expand Down Expand Up @@ -507,12 +507,15 @@ static int blkdev_open(struct inode *inode, struct file *filp)
filp->f_flags |= O_LARGEFILE;
filp->f_mode |= FMODE_NOWAIT | 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->f_mode |= FMODE_EXCL;
filp->private_data = filp;

bdev = blkdev_get_by_dev(inode->i_rdev, file_to_blk_mode(filp),
(filp->f_mode & FMODE_EXCL) ? filp : NULL,
NULL);
filp->private_data, NULL);
if (IS_ERR(bdev))
return PTR_ERR(bdev);

Expand All @@ -523,8 +526,7 @@ static int blkdev_open(struct inode *inode, struct file *filp)

static int blkdev_release(struct inode *inode, struct file *filp)
{
blkdev_put(I_BDEV(filp->f_mapping->host),
(filp->f_mode & FMODE_EXCL) ? filp : NULL);
blkdev_put(I_BDEV(filp->f_mapping->host), filp->private_data);
return 0;
}

Expand Down

0 comments on commit ee3249a

Please sign in to comment.