Skip to content

Commit ee3249a

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: store the holder in file->private_data
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 <[email protected]> Reviewed-by: Hannes Reinecke <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 4e762d8 commit ee3249a

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

block/fops.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ blk_mode_t file_to_blk_mode(struct file *file)
478478
mode |= BLK_OPEN_READ;
479479
if (file->f_mode & FMODE_WRITE)
480480
mode |= BLK_OPEN_WRITE;
481-
if (file->f_mode & FMODE_EXCL)
481+
if (file->private_data)
482482
mode |= BLK_OPEN_EXCL;
483483
if (file->f_flags & O_NDELAY)
484484
mode |= BLK_OPEN_NDELAY;
@@ -507,12 +507,15 @@ static int blkdev_open(struct inode *inode, struct file *filp)
507507
filp->f_flags |= O_LARGEFILE;
508508
filp->f_mode |= FMODE_NOWAIT | FMODE_BUF_RASYNC;
509509

510+
/*
511+
* Use the file private data to store the holder for exclusive openes.
512+
* file_to_blk_mode relies on it being present to set BLK_OPEN_EXCL.
513+
*/
510514
if (filp->f_flags & O_EXCL)
511-
filp->f_mode |= FMODE_EXCL;
515+
filp->private_data = filp;
512516

513517
bdev = blkdev_get_by_dev(inode->i_rdev, file_to_blk_mode(filp),
514-
(filp->f_mode & FMODE_EXCL) ? filp : NULL,
515-
NULL);
518+
filp->private_data, NULL);
516519
if (IS_ERR(bdev))
517520
return PTR_ERR(bdev);
518521

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

524527
static int blkdev_release(struct inode *inode, struct file *filp)
525528
{
526-
blkdev_put(I_BDEV(filp->f_mapping->host),
527-
(filp->f_mode & FMODE_EXCL) ? filp : NULL);
529+
blkdev_put(I_BDEV(filp->f_mapping->host), filp->private_data);
528530
return 0;
529531
}
530532

0 commit comments

Comments
 (0)