diff mbox series

[vfs.all,20/26] block: factor out a helper init_bdev_file()

Message ID 20240406090930.2252838-21-yukuai1@huaweicloud.com (mailing list archive)
State New, archived
Headers show
Series fs & block: remove bdev->bd_inode | expand

Commit Message

Yu Kuai April 6, 2024, 9:09 a.m. UTC
From: Yu Kuai <yukuai3@huawei.com>

There are no functional changes, the helper will be used in later
patches to initialize stashed bdev_file as well.

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 block/bdev.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/block/bdev.c b/block/bdev.c
index 4335df6d1266..82fb1688f4c9 100644
--- a/block/bdev.c
+++ b/block/bdev.c
@@ -832,6 +832,20 @@  static void bdev_yield_write_access(struct file *bdev_file)
 		bdev->bd_writers--;
 }
 
+static void init_bdev_file(struct file *bdev_file, struct block_device *bdev,
+			   blk_mode_t mode, void *holder)
+{
+	bdev_file->f_flags |= O_LARGEFILE;
+	bdev_file->f_mode |= FMODE_CAN_ODIRECT;
+	if (bdev_nowait(bdev))
+		bdev_file->f_mode |= FMODE_NOWAIT;
+	if (mode & BLK_OPEN_RESTRICT_WRITES)
+		bdev_file->f_mode |= FMODE_WRITE_RESTRICTED;
+	bdev_file->f_mapping = bdev_mapping(bdev);
+	bdev_file->f_wb_err = filemap_sample_wb_err(bdev_file->f_mapping);
+	bdev_file->private_data = holder;
+}
+
 /**
  * bdev_open - open a block device
  * @bdev: block device to open
@@ -905,15 +919,7 @@  int bdev_open(struct block_device *bdev, blk_mode_t mode, void *holder,
 	if (unblock_events)
 		disk_unblock_events(disk);
 
-	bdev_file->f_flags |= O_LARGEFILE;
-	bdev_file->f_mode |= FMODE_CAN_ODIRECT;
-	if (bdev_nowait(bdev))
-		bdev_file->f_mode |= FMODE_NOWAIT;
-	if (mode & BLK_OPEN_RESTRICT_WRITES)
-		bdev_file->f_mode |= FMODE_WRITE_RESTRICTED;
-	bdev_file->f_mapping = bdev_mapping(bdev);
-	bdev_file->f_wb_err = filemap_sample_wb_err(bdev_file->f_mapping);
-	bdev_file->private_data = holder;
+	init_bdev_file(bdev_file, bdev, mode, holder);
 
 	return 0;
 put_module: