block: remove bdev_handle completely

We just need to use the holder to indicate whether a block device open
was exclusive or not. We did use to do that before but had to give that
up once we switched to struct bdev_handle. Before struct bdev_handle we
only stashed stuff in file->private_data if this was an exclusive open
but after struct bdev_handle we always set file->private_data to a
struct bdev_handle and so we had to use bdev_handle->mode or
bdev_handle->holder. Now that we don't use struct bdev_handle anymore we
can revert back to the old behavior.

Link: https://lore.kernel.org/r/20240123-vfs-bdev-file-v2-32-adbd023e19cc@kernel.org
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
Christian Brauner
2024-01-23 14:26:49 +01:00
parent 321de651fa
commit ab838b3fd9
3 changed files with 34 additions and 39 deletions
+10 -11
View File
@@ -569,18 +569,17 @@ static int blkdev_fsync(struct file *filp, loff_t start, loff_t end,
blk_mode_t file_to_blk_mode(struct file *file)
{
blk_mode_t mode = 0;
struct bdev_handle *handle = file->private_data;
if (file->f_mode & FMODE_READ)
mode |= BLK_OPEN_READ;
if (file->f_mode & FMODE_WRITE)
mode |= BLK_OPEN_WRITE;
/*
* do_dentry_open() clears O_EXCL from f_flags, use handle->mode to
* determine whether the open was exclusive for already open files.
* do_dentry_open() clears O_EXCL from f_flags, use file->private_data
* to determine whether the open was exclusive for already open files.
*/
if (handle)
mode |= handle->mode & BLK_OPEN_EXCL;
if (file->private_data)
mode |= BLK_OPEN_EXCL;
else if (file->f_flags & O_EXCL)
mode |= BLK_OPEN_EXCL;
if (file->f_flags & O_NDELAY)
@@ -601,12 +600,13 @@ static int blkdev_open(struct inode *inode, struct file *filp)
{
struct block_device *bdev;
blk_mode_t mode;
void *holder;
int ret;
mode = file_to_blk_mode(filp);
holder = mode & BLK_OPEN_EXCL ? filp : NULL;
ret = bdev_permission(inode->i_rdev, mode, holder);
/* Use the file as the holder. */
if (mode & BLK_OPEN_EXCL)
filp->private_data = filp;
ret = bdev_permission(inode->i_rdev, mode, filp->private_data);
if (ret)
return ret;
@@ -614,7 +614,7 @@ static int blkdev_open(struct inode *inode, struct file *filp)
if (!bdev)
return -ENXIO;
ret = bdev_open(bdev, mode, holder, NULL, filp);
ret = bdev_open(bdev, mode, filp->private_data, NULL, filp);
if (ret)
blkdev_put_no_open(bdev);
return ret;
@@ -622,8 +622,7 @@ static int blkdev_open(struct inode *inode, struct file *filp)
static int blkdev_release(struct inode *inode, struct file *filp)
{
if (filp->private_data)
bdev_release(filp);
bdev_release(filp);
return 0;
}