summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Brauner <brauner@kernel.org>2024-01-23 14:26:47 +0100
committerChristian Brauner <brauner@kernel.org>2024-02-25 12:05:27 +0100
commit7c09a4ed6156c6cab6b951e027ca6ea24af454ba (patch)
treeff4b70d63f03ac3be031970cc249d56dba9bbb14
parenta56aefca8d386181415a1fb7cfec2f72b0404797 (diff)
bdev: remove bdev pointer from struct bdev_handle
We can always go directly via: * I_BDEV(bdev_file->f_inode) * I_BDEV(bdev_file->f_mapping->host) So keeping struct bdev in struct bdev_handle is redundant. Link: https://lore.kernel.org/r/20240123-vfs-bdev-file-v2-30-adbd023e19cc@kernel.org Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Christian Brauner <brauner@kernel.org>
-rw-r--r--block/bdev.c26
-rw-r--r--block/blk.h3
-rw-r--r--block/fops.c2
3 files changed, 14 insertions, 17 deletions
diff --git a/block/bdev.c b/block/bdev.c
index 8f33f160e923..4e4527c5df00 100644
--- a/block/bdev.c
+++ b/block/bdev.c
@@ -51,8 +51,7 @@ EXPORT_SYMBOL(I_BDEV);
struct block_device *file_bdev(struct file *bdev_file)
{
- struct bdev_handle *handle = bdev_file->private_data;
- return handle->bdev;
+ return I_BDEV(bdev_file->f_mapping->host);
}
EXPORT_SYMBOL(file_bdev);
@@ -891,7 +890,6 @@ int bdev_open(struct block_device *bdev, blk_mode_t mode, void *holder,
if (unblock_events)
disk_unblock_events(disk);
- handle->bdev = bdev;
handle->holder = holder;
handle->mode = mode;
@@ -899,7 +897,7 @@ int bdev_open(struct block_device *bdev, blk_mode_t mode, void *holder,
bdev_file->f_mode |= FMODE_BUF_RASYNC | FMODE_CAN_ODIRECT;
if (bdev_nowait(bdev))
bdev_file->f_mode |= FMODE_NOWAIT;
- bdev_file->f_mapping = handle->bdev->bd_inode->i_mapping;
+ bdev_file->f_mapping = bdev->bd_inode->i_mapping;
bdev_file->f_wb_err = filemap_sample_wb_err(bdev_file->f_mapping);
bdev_file->private_data = handle;
@@ -985,7 +983,7 @@ struct file *bdev_file_open_by_path(const char *path, blk_mode_t mode,
void *holder,
const struct blk_holder_ops *hops)
{
- struct file *bdev_file;
+ struct file *file;
dev_t dev;
int error;
@@ -993,22 +991,22 @@ struct file *bdev_file_open_by_path(const char *path, blk_mode_t mode,
if (error)
return ERR_PTR(error);
- bdev_file = bdev_file_open_by_dev(dev, mode, holder, hops);
- if (!IS_ERR(bdev_file) && (mode & BLK_OPEN_WRITE)) {
- struct bdev_handle *handle = bdev_file->private_data;
- if (bdev_read_only(handle->bdev)) {
- fput(bdev_file);
- bdev_file = ERR_PTR(-EACCES);
+ file = bdev_file_open_by_dev(dev, mode, holder, hops);
+ if (!IS_ERR(file) && (mode & BLK_OPEN_WRITE)) {
+ if (bdev_read_only(file_bdev(file))) {
+ fput(file);
+ file = ERR_PTR(-EACCES);
}
}
- return bdev_file;
+ return file;
}
EXPORT_SYMBOL(bdev_file_open_by_path);
-void bdev_release(struct bdev_handle *handle)
+void bdev_release(struct file *bdev_file)
{
- struct block_device *bdev = handle->bdev;
+ struct block_device *bdev = file_bdev(bdev_file);
+ struct bdev_handle *handle = bdev_file->private_data;
struct gendisk *disk = bdev->bd_disk;
/*
diff --git a/block/blk.h b/block/blk.h
index 19b15870284f..7ca24814f3a0 100644
--- a/block/blk.h
+++ b/block/blk.h
@@ -26,7 +26,6 @@ struct blk_flush_queue {
};
struct bdev_handle {
- struct block_device *bdev;
void *holder;
blk_mode_t mode;
};
@@ -522,7 +521,7 @@ static inline int req_ref_read(struct request *req)
return atomic_read(&req->ref);
}
-void bdev_release(struct bdev_handle *handle);
+void bdev_release(struct file *bdev_file);
int bdev_open(struct block_device *bdev, blk_mode_t mode, void *holder,
const struct blk_holder_ops *hops, struct file *bdev_file);
int bdev_permission(dev_t dev, blk_mode_t mode, void *holder);
diff --git a/block/fops.c b/block/fops.c
index a1ba1a50ae77..aab9b89e4c77 100644
--- a/block/fops.c
+++ b/block/fops.c
@@ -623,7 +623,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->private_data);
+ bdev_release(filp);
return 0;
}