Skip to contentSkip to conversation

Open block devices as files & a bd_inode proposal

RFC PATCH Superseded Christian Brauner 4 participants 52 messages Jan 3, 2024 – Jan 18, 2024

Subsystems (39)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Christian Brauner

author maintainer
#0 lore raw

cover Open block devices as files & a bd_inode proposal

Hey Christoph,
Hey Jan,
Hey Jens,

I've been toying with this idea in between changing diapers essentially and I've taken it far enough that I'd like some general input before going further and massaging out any corner cases I might've missed.

I wanted to see whether we can make struct bdev_handle completely private to the block layer in the next cycle and unexport low-level helpers such as bdev_release() - formerly blkdev_put() - completely.

And afaict, we can actually get that to work. Simply put instead of doing this bdev_open_by_*() dance where we return a struct block_device we can just make bdev_file_open_by_*() return a struct file. Opening and closing a block device from setup_bdev_super() and in all other places just becomes equivalent to opening and closing a file.

This has held up in xfstests and in blktests so far and it seems stable and clean. The equivalence of opening and closing block devices to regular files is a win in and of itself imho. Added to that is the ability to hide away all of the the details of struct bdev_handle and various other low-level helpers.

So for that reason alone I think we should do it. All places were we currently stash a bdev_handle we just stash a file and use accessors such as F_BDEV() akin to I_BDEV() to get to the block device.

While I was doing that I realized that this is also a way for us to get rid of bd_inode in fs/buffer.c though I don't think that's a requirement for this change to be worth it.

Basically we simply record a struct file for the block device in struct buffer_head and in struct iomap. That works without a problem afaict. All filesystems will have a struct file handle to the block device so we can trivially get access to it in nearly all places. The only exception is for the block/fops.c layer itself where we obviously don't have a struct file for the inode. So if we can solve that problem we can kill bd_inode access and simply rely on file->f_mapping->host there as well. IOW, just export and use bdev_file_inode() everywhere in fs/buffer.c

I only roughly drafted that bd_inode removal in fs/buffer.c. I think this would work but I'd like to hear your thoughts on this. But again, I don't think that's a requirement for that change to be worth it.

The patch series is barebones with really tiny commit messages because I'd like to get early input. The core patches are:

bdev: open block device as files

In that patch the order between allocating a file and opening a bdev handle are still reversed that's all fully cleaned up after all users of bdev_handle are ported to rely on files. So the final form is:

bdev: rework bdev_open_by_dev()

and I think that looks fairly nice.

I've added a few additional illustrational patches for future work on top:

* port ext4 to only rely on sb->s_f_bdev instead of sb->s_bdev
* port ext4 to never touch bdev->bd_inode and just rely on bdev_file_inode()
* remove bdev->bd_inode access from fs/buffer.c and just rely on bdev_file_inode()

I haven't though about potential corner cases yet too much but the file stuff should actually be doable.

Thanks!
Christian

---
Christian Brauner (34):
bdev: open block device as files
block/ioctl: port blkdev_bszset() to file
block/genhd: port disk_scan_partitions() to file
md: port block device access to file
swap: port block device usage to file
power: port block device access to file
xfs: port block device access to files
drbd: port block device access to file
pktcdvd: port block device access to file
rnbd: port block device access to file
xen: port block device access to file
zram: port block device access to file
bcache: port block device access to files
block2mtd: port device access to files
nvme: port block device access to file
s390: port block device access to file
target: port block device access to file
bcachefs: port block device access to file
btrfs: port device access to file
erofs: port device access to file
ext4: port block device access to file
f2fs: port block device access to files
jfs: port block device access to file
nfs: port block device access to files
ocfs2: port block device access to file
reiserfs: port block device access to file
bdev: remove bdev_open_by_path()
bdev: make bdev_release() private to block layer
bdev: make struct bdev_handle private to the block layer
bdev: rework bdev_open_by_dev()
ext4: rely on sb->f_bdev only
block: expose bdev_file_inode()
ext4: use bdev_file_inode()
[DRAFT] buffer: port block device access to files and get rid of bd_inode access

 block/bdev.c                        | 220 +++++++++++++++++++++++-------------
 block/blk.h                         |  10 ++
 block/fops.c                        |  40 +++----
 block/genhd.c                       |  12 +-
 block/ioctl.c                       |   9 +-
 drivers/block/drbd/drbd_int.h       |   4 +-
 drivers/block/drbd/drbd_nl.c        |  58 +++++-----
 drivers/block/pktcdvd.c             |  68 +++++------
 drivers/block/rnbd/rnbd-srv.c       |  26 ++---
 drivers/block/rnbd/rnbd-srv.h       |   2 +-
 drivers/block/xen-blkback/blkback.c |   4 +-
 drivers/block/xen-blkback/common.h  |   4 +-
 drivers/block/xen-blkback/xenbus.c  |  36 +++---
 drivers/block/zram/zram_drv.c       |  26 ++---
 drivers/block/zram/zram_drv.h       |   2 +-
 drivers/md/bcache/bcache.h          |   4 +-
 drivers/md/bcache/super.c           |  74 ++++++------
 drivers/md/dm.c                     |  23 ++--
 drivers/md/md-bitmap.c              |   1 +
 drivers/md/md.c                     |  12 +-
 drivers/md/md.h                     |   2 +-
 drivers/mtd/devices/block2mtd.c     |  42 +++----
 drivers/nvme/target/io-cmd-bdev.c   |  16 +--
 drivers/nvme/target/nvmet.h         |   2 +-
 drivers/s390/block/dasd.c           |  10 +-
 drivers/s390/block/dasd_genhd.c     |  36 +++---
 drivers/s390/block/dasd_int.h       |   2 +-
 drivers/s390/block/dasd_ioctl.c     |   2 +-
 drivers/target/target_core_iblock.c |  18 +--
 drivers/target/target_core_iblock.h |   2 +-
 drivers/target/target_core_pscsi.c  |  22 ++--
 drivers/target/target_core_pscsi.h  |   2 +-
 fs/affs/file.c                      |   1 +
 fs/bcachefs/super-io.c              |  20 ++--
 fs/bcachefs/super_types.h           |   2 +-
 fs/btrfs/dev-replace.c              |  14 +--
 fs/btrfs/inode.c                    |   1 +
 fs/btrfs/ioctl.c                    |  16 +--
 fs/btrfs/volumes.c                  |  92 +++++++--------
 fs/btrfs/volumes.h                  |   4 +-
 fs/buffer.c                         |  69 +++++------
 fs/cramfs/inode.c                   |   2 +-
 fs/direct-io.c                      |   2 +-
 fs/erofs/data.c                     |  13 ++-
 fs/erofs/internal.h                 |   3 +-
 fs/erofs/super.c                    |  16 +--
 fs/erofs/zmap.c                     |   1 +
 fs/ext2/inode.c                     |   8 +-
 fs/ext4/dir.c                       |   2 +-
 fs/ext4/ext4.h                      |   2 +-
 fs/ext4/ext4_jbd2.c                 |   2 +-
 fs/ext4/fast_commit.c               |   2 +-
 fs/ext4/fsmap.c                     |   8 +-
 fs/ext4/inode.c                     |   6 +-
 fs/ext4/super.c                     |  88 +++++++--------
 fs/f2fs/data.c                      |   6 +-
 fs/f2fs/f2fs.h                      |   3 +-
 fs/f2fs/super.c                     |  12 +-
 fs/fuse/dax.c                       |   1 +
 fs/gfs2/aops.c                      |   1 +
 fs/gfs2/bmap.c                      |   1 +
 fs/hpfs/file.c                      |   1 +
 fs/jbd2/commit.c                    |   1 +
 fs/jbd2/journal.c                   |  26 +++--
 fs/jbd2/recovery.c                  |   6 +-
 fs/jbd2/revoke.c                    |  10 +-
 fs/jbd2/transaction.c               |   1 +
 fs/jfs/jfs_logmgr.c                 |  26 ++---
 fs/jfs/jfs_logmgr.h                 |   2 +-
 fs/jfs/jfs_mount.c                  |   2 +-
 fs/mpage.c                          |   5 +-
 fs/nfs/blocklayout/blocklayout.h    |   2 +-
 fs/nfs/blocklayout/dev.c            |  68 +++++------
 fs/nilfs2/btnode.c                  |   2 +
 fs/nilfs2/gcinode.c                 |   1 +
 fs/nilfs2/mdt.c                     |   1 +
 fs/nilfs2/page.c                    |   2 +
 fs/nilfs2/recovery.c                |  20 ++--
 fs/nilfs2/the_nilfs.c               |   1 +
 fs/ntfs/aops.c                      |   3 +
 fs/ntfs/file.c                      |   1 +
 fs/ntfs/mft.c                       |   2 +
 fs/ntfs3/fsntfs.c                   |   8 +-
 fs/ntfs3/inode.c                    |   1 +
 fs/ntfs3/super.c                    |   2 +-
 fs/ocfs2/cluster/heartbeat.c        |  32 +++---
 fs/ocfs2/journal.c                  |   2 +-
 fs/reiserfs/journal.c               |  44 ++++----
 fs/reiserfs/procfs.c                |   2 +-
 fs/reiserfs/reiserfs.h              |   8 +-
 fs/reiserfs/tail_conversion.c       |   1 +
 fs/romfs/super.c                    |   2 +-
 fs/super.c                          |  18 +--
 fs/xfs/xfs_buf.c                    |  10 +-
 fs/xfs/xfs_buf.h                    |   4 +-
 fs/xfs/xfs_iomap.c                  |   7 +-
 fs/xfs/xfs_super.c                  |  43 ++++---
 fs/zonefs/file.c                    |   2 +
 include/linux/blkdev.h              |  18 +--
 include/linux/buffer_head.h         |  45 ++++----
 include/linux/device-mapper.h       |   2 +-
 include/linux/fs.h                  |   4 +-
 include/linux/iomap.h               |   1 +
 include/linux/jbd2.h                |   6 +-
 include/linux/pktcdvd.h             |   4 +-
 include/linux/swap.h                |   2 +-
 kernel/power/swap.c                 |  28 ++---
 mm/swapfile.c                       |  22 ++--
 108 files changed, 908 insertions(+), 782 deletions(-)

---
base-commit: aee755dd02191d5669860f38e28ec93d8f0a4e70
change-id: 20240103-vfs-bdev-file-1208da73d7ea

author maintainer
#1 lore raw

RFC PATCH 1/34 bdev: open block device as files

---
 block/bdev.c           | 104 +++++++++++++++++++++++++++++++++++++++++++++++--
 fs/cramfs/inode.c      |   2 +-
 fs/f2fs/super.c        |   2 +-
 fs/jfs/jfs_logmgr.c    |   2 +-
 fs/romfs/super.c       |   2 +-
 fs/super.c             |  18 ++++-----
 fs/xfs/xfs_super.c     |   2 +-
 include/linux/blkdev.h |   6 +++
 include/linux/fs.h     |  10 ++++-
 9 files changed, 128 insertions(+), 20 deletions(-)
block/bdev.c +100 -4
index e9f1b12bd75c..853731fb41ed 100644
@@ -49,6 +49,15 @@ struct block_device *I_BDEV(struct inode *inode)
 }
 EXPORT_SYMBOL(I_BDEV);
 
+/* @bdev_handle will become private to block/blk.h soon. */
+struct block_device *F_BDEV(struct file *f_bdev)
+{
+	struct bdev_handle *handle = f_bdev->private_data;
+	WARN_ON(f_bdev->f_op != &def_blk_fops);
+	return handle->bdev;
+}
+EXPORT_SYMBOL(F_BDEV);
+
 static void bdev_write_inode(struct block_device *bdev)
 {
 	struct inode *inode = bdev->bd_inode;
@@ -368,12 +377,12 @@ static struct file_system_type bd_type = {
 };
 
 struct super_block *blockdev_superblock __ro_after_init;
+struct vfsmount *blockdev_mnt __ro_after_init;
 EXPORT_SYMBOL_GPL(blockdev_superblock);
 
 void __init bdev_cache_init(void)
 {
 	int err;
-	static struct vfsmount *bd_mnt __ro_after_init;
 
 	bdev_cachep = kmem_cache_create("bdev_cache", sizeof(struct bdev_inode),
 			0, (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
@@ -382,10 +391,10 @@ void __init bdev_cache_init(void)
 	err = register_filesystem(&bd_type);
 	if (err)
 		panic("Cannot register bdev pseudo-fs");
-	bd_mnt = kern_mount(&bd_type);
-	if (IS_ERR(bd_mnt))
+	blockdev_mnt = kern_mount(&bd_type);
+	if (IS_ERR(blockdev_mnt))
 		panic("Cannot create bdev pseudo-fs");
-	blockdev_superblock = bd_mnt->mnt_sb;   /* For writeback */
+	blockdev_superblock = blockdev_mnt->mnt_sb;   /* For writeback */
 }
 
 struct block_device *bdev_alloc(struct gendisk *disk, u8 partno)
@@ -911,6 +920,93 @@ struct bdev_handle *bdev_open_by_dev(dev_t dev, blk_mode_t mode, void *holder,
 }
 EXPORT_SYMBOL(bdev_open_by_dev);
 
+static unsigned blk_to_file_flags(blk_mode_t mode)
+{
+	unsigned int flags = 0;
+
+	if ((mode & (BLK_OPEN_READ | BLK_OPEN_WRITE)) ==
+	    (BLK_OPEN_READ | BLK_OPEN_WRITE))
+		flags |= O_RDWR;
+	else if (mode & BLK_OPEN_WRITE)
+		flags |= O_WRONLY;
+	else
+		flags |= O_RDONLY;
+
+	/*
+	 * O_EXCL is one of those flags that the VFS clears once it's done with
+	 * the operation. So don't raise it here either.
+	 */
+	if (mode & BLK_OPEN_NDELAY)
+		flags |= O_NDELAY;
+
+	/*
+	 * If BLK_OPEN_WRITE_IOCTL is set then this is a historical quirk
+	 * associated with the floppy driver where it has allowed ioctls if the
+	 * file was opened for writing, but does not allow reads or writes.
+	 * Make sure that this quirk is reflected in @f_flags.
+	 */
+	if (mode & BLK_OPEN_WRITE_IOCTL)
+		flags |= O_RDWR | O_WRONLY;
+
+	return flags;
+}
+
+struct file *bdev_file_open_by_dev(dev_t dev, blk_mode_t mode, void *holder,
+				   const struct blk_holder_ops *hops)
+{
+	struct file *file;
+	struct bdev_handle *handle;
+	unsigned int flags;
+
+	handle = bdev_open_by_dev(dev, mode, holder, hops);
+	if (IS_ERR(handle))
+		return ERR_CAST(handle);
+
+	flags = blk_to_file_flags(mode);
+	file = alloc_file_pseudo(handle->bdev->bd_inode, blockdev_mnt, "",
+				 flags | O_LARGEFILE, &def_blk_fops);
+	if (IS_ERR(file)) {
+		bdev_release(handle);
+		return file;
+	}
+	ihold(handle->bdev->bd_inode);
+
+	file->f_mode |= FMODE_BUF_RASYNC | FMODE_CAN_ODIRECT | FMODE_NOACCOUNT;
+	if (bdev_nowait(handle->bdev))
+		file->f_mode |= FMODE_NOWAIT;
+
+	file->f_mapping = handle->bdev->bd_inode->i_mapping;
+	file->f_wb_err = filemap_sample_wb_err(file->f_mapping);
+	file->private_data = handle;
+	return file;
+}
+EXPORT_SYMBOL(bdev_file_open_by_dev);
+
+struct file *bdev_file_open_by_path(const char *path, blk_mode_t mode,
+				    void *holder,
+				    const struct blk_holder_ops *hops)
+{
+	struct file *file;
+	dev_t dev;
+	int error;
+
+	error = lookup_bdev(path, &dev);
+	if (error)
+		return ERR_PTR(error);
+
+	file = bdev_file_open_by_dev(dev, mode, holder, hops);
+	if (!IS_ERR(file) && (mode & BLK_OPEN_WRITE)) {
+		struct bdev_handle *handle = file->private_data;
+		if (bdev_read_only(handle->bdev)) {
+			fput(file);
+			file = ERR_PTR(-EACCES);
+		}
+	}
+
+	return file;
+}
+EXPORT_SYMBOL(bdev_file_open_by_path);
+
 /**
  * bdev_open_by_path - open a block device by name
  * @path: path to the block device to open
fs/cramfs/inode.c +1 -1
index 60dbfa0f8805..14d1758daa52 100644
@@ -495,7 +495,7 @@ static void cramfs_kill_sb(struct super_block *sb)
 		sb->s_mtd = NULL;
 	} else if (IS_ENABLED(CONFIG_CRAMFS_BLOCKDEV) && sb->s_bdev) {
 		sync_blockdev(sb->s_bdev);
-		bdev_release(sb->s_bdev_handle);
+		fput(sb->s_f_bdev);
 	}
 	kfree(sbi);
 }
fs/f2fs/super.c +1 -1
index 033af907c3b1..93b8a844b207 100644
@@ -4247,7 +4247,7 @@ static int f2fs_scan_devices(struct f2fs_sb_info *sbi)
 
 	for (i = 0; i < max_devices; i++) {
 		if (i == 0)
-			FDEV(0).bdev_handle = sbi->sb->s_bdev_handle;
+			FDEV(0).bdev_handle = sb_bdev_handle(sbi->sb);
 		else if (!RDEV(i).path[0])
 			break;
 
fs/jfs/jfs_logmgr.c +1 -1
index cb6d1fda66a7..8691463956d1 100644
@@ -1162,7 +1162,7 @@ static int open_inline_log(struct super_block *sb)
 	init_waitqueue_head(&log->syncwait);
 
 	set_bit(log_INLINELOG, &log->flag);
-	log->bdev_handle = sb->s_bdev_handle;
+	log->bdev_handle = sb_bdev_handle(sb);
 	log->base = addressPXD(&JFS_SBI(sb)->logpxd);
 	log->size = lengthPXD(&JFS_SBI(sb)->logpxd) >>
 	    (L2LOGPSIZE - sb->s_blocksize_bits);
fs/romfs/super.c +1 -1
index 545ad44f96b8..b392ae877ac7 100644
@@ -594,7 +594,7 @@ static void romfs_kill_sb(struct super_block *sb)
 #ifdef CONFIG_ROMFS_ON_BLOCK
 	if (sb->s_bdev) {
 		sync_blockdev(sb->s_bdev);
-		bdev_release(sb->s_bdev_handle);
+		fput(sb->s_f_bdev);
 	}
 #endif
 }
fs/super.c +9 -9
index e35936000408..77cc67b8bf44 100644
@@ -1532,16 +1532,16 @@ int setup_bdev_super(struct super_block *sb, int sb_flags,
 		struct fs_context *fc)
 {
 	blk_mode_t mode = sb_open_mode(sb_flags);
-	struct bdev_handle *bdev_handle;
+	struct file *file;
 	struct block_device *bdev;
 
-	bdev_handle = bdev_open_by_dev(sb->s_dev, mode, sb, &fs_holder_ops);
-	if (IS_ERR(bdev_handle)) {
+	file = bdev_file_open_by_dev(sb->s_dev, mode, sb, &fs_holder_ops);
+	if (IS_ERR(file)) {
 		if (fc)
 			errorf(fc, "%s: Can't open blockdev", fc->source);
-		return PTR_ERR(bdev_handle);
+		return PTR_ERR(file);
 	}
-	bdev = bdev_handle->bdev;
+	bdev = F_BDEV(file);
 
 	/*
 	 * This really should be in blkdev_get_by_dev, but right now can't due
@@ -1549,7 +1549,7 @@ int setup_bdev_super(struct super_block *sb, int sb_flags,
 	 * writable from userspace even for a read-only block device.
 	 */
 	if ((mode & BLK_OPEN_WRITE) && bdev_read_only(bdev)) {
-		bdev_release(bdev_handle);
+		fput(file);
 		return -EACCES;
 	}
 
@@ -1560,11 +1560,11 @@ int setup_bdev_super(struct super_block *sb, int sb_flags,
 	if (atomic_read(&bdev->bd_fsfreeze_count) > 0) {
 		if (fc)
 			warnf(fc, "%pg: Can't mount, blockdev is frozen", bdev);
-		bdev_release(bdev_handle);
+		fput(file);
 		return -EBUSY;
 	}
 	spin_lock(&sb_lock);
-	sb->s_bdev_handle = bdev_handle;
+	sb->s_f_bdev = file;
 	sb->s_bdev = bdev;
 	sb->s_bdi = bdi_get(bdev->bd_disk->bdi);
 	if (bdev_stable_writes(bdev))
@@ -1680,7 +1680,7 @@ void kill_block_super(struct super_block *sb)
 	generic_shutdown_super(sb);
 	if (bdev) {
 		sync_blockdev(bdev);
-		bdev_release(sb->s_bdev_handle);
+		fput(sb->s_f_bdev);
 	}
 }
 
fs/xfs/xfs_super.c +1 -1
index 07857d967ee8..0e64220bffdc 100644
@@ -467,7 +467,7 @@ xfs_open_devices(
 	 * Setup xfs_mount buffer target pointers
 	 */
 	error = -ENOMEM;
-	mp->m_ddev_targp = xfs_alloc_buftarg(mp, sb->s_bdev_handle);
+	mp->m_ddev_targp = xfs_alloc_buftarg(mp, sb_bdev_handle(sb));
 	if (!mp->m_ddev_targp)
 		goto out_close_rtdev;
 
include/linux/blkdev.h +6 -0
index 9f6c3373f9fc..e8d11083acbc 100644
@@ -24,6 +24,7 @@
 #include <linux/sbitmap.h>
 #include <linux/uuid.h>
 #include <linux/xarray.h>
+#include <linux/file.h>
 
 struct module;
 struct request_queue;
@@ -1507,6 +1508,10 @@ struct bdev_handle *bdev_open_by_dev(dev_t dev, blk_mode_t mode, void *holder,
 		const struct blk_holder_ops *hops);
 struct bdev_handle *bdev_open_by_path(const char *path, blk_mode_t mode,
 		void *holder, const struct blk_holder_ops *hops);
+struct file *bdev_file_open_by_dev(dev_t dev, blk_mode_t mode, void *holder,
+		const struct blk_holder_ops *hops);
+struct file *bdev_file_open_by_path(const char *path, blk_mode_t mode,
+		void *holder, const struct blk_holder_ops *hops);
 int bd_prepare_to_claim(struct block_device *bdev, void *holder,
 		const struct blk_holder_ops *hops);
 void bd_abort_claiming(struct block_device *bdev, void *holder);
@@ -1517,6 +1522,7 @@ struct block_device *blkdev_get_no_open(dev_t dev);
 void blkdev_put_no_open(struct block_device *bdev);
 
 struct block_device *I_BDEV(struct inode *inode);
+struct block_device *F_BDEV(struct file *file);
 
 #ifdef CONFIG_BLOCK
 void invalidate_bdev(struct block_device *bdev);
include/linux/fs.h +8 -2
index 8e0d77f9464e..b0a5e94e8c3a 100644
@@ -1227,8 +1227,8 @@ struct super_block {
 #endif
 	struct hlist_bl_head	s_roots;	/* alternate root dentries for NFS */
 	struct list_head	s_mounts;	/* list of mounts; _not_ for fs use */
-	struct block_device	*s_bdev;
-	struct bdev_handle	*s_bdev_handle;
+	struct block_device	*s_bdev;	/* can go away once we use an accessor for @s_f_bdev */
+	struct file		*s_f_bdev;
 	struct backing_dev_info *s_bdi;
 	struct mtd_info		*s_mtd;
 	struct hlist_node	s_instances;
@@ -1326,6 +1326,12 @@ struct super_block {
 	struct list_head	s_inodes_wb;	/* writeback inodes */
 } __randomize_layout;
 
+/* Temporary helper that will go away. */
+static inline struct bdev_handle *sb_bdev_handle(struct super_block *sb)
+{
+	return sb->s_f_bdev->private_data;
+}
+
 static inline struct user_namespace *i_user_ns(const struct inode *inode)
 {
 	return inode->i_sb->s_user_ns;
Signature · 1 line
2.42.0
author maintainer
#6 lore raw

RFC PATCH 2/34 block/ioctl: port blkdev_bszset() to file

In reply to Christian Brauner
---
 block/ioctl.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
block/ioctl.c +4 -5
index 4160f4e6bd5b..d04641fe541c 100644
@@ -468,7 +468,7 @@ static int blkdev_bszset(struct block_device *bdev, blk_mode_t mode,
 		int __user *argp)
 {
 	int ret, n;
-	struct bdev_handle *handle;
+	struct file *file;
 
 	if (!capable(CAP_SYS_ADMIN))
 		return -EACCES;
@@ -480,12 +480,11 @@ static int blkdev_bszset(struct block_device *bdev, blk_mode_t mode,
 	if (mode & BLK_OPEN_EXCL)
 		return set_blocksize(bdev, n);
 
-	handle = bdev_open_by_dev(bdev->bd_dev, mode, &bdev, NULL);
-	if (IS_ERR(handle))
+	file = bdev_file_open_by_dev(bdev->bd_dev, mode, &bdev, NULL);
+	if (IS_ERR(file))
 		return -EBUSY;
 	ret = set_blocksize(bdev, n);
-	bdev_release(handle);
-
+	fput(file);
 	return ret;
 }
 
Signature · 1 line
2.42.0
author maintainer
#7 lore raw

RFC PATCH 3/34 block/genhd: port disk_scan_partitions() to file

In reply to Christian Brauner
---
 block/genhd.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
block/genhd.c +6 -6
index c9d06f72c587..bae0503fe6a2 100644
@@ -342,7 +342,7 @@ EXPORT_SYMBOL_GPL(disk_uevent);
 
 int disk_scan_partitions(struct gendisk *disk, blk_mode_t mode)
 {
-	struct bdev_handle *handle;
+	struct file *file;
 	int ret = 0;
 
 	if (disk->flags & (GENHD_FL_NO_PART | GENHD_FL_HIDDEN))
@@ -366,12 +366,12 @@ int disk_scan_partitions(struct gendisk *disk, blk_mode_t mode)
 	}
 
 	set_bit(GD_NEED_PART_SCAN, &disk->state);
-	handle = bdev_open_by_dev(disk_devt(disk), mode & ~BLK_OPEN_EXCL, NULL,
-				  NULL);
-	if (IS_ERR(handle))
-		ret = PTR_ERR(handle);
+	file = bdev_file_open_by_dev(disk_devt(disk), mode & ~BLK_OPEN_EXCL,
+				     NULL, NULL);
+	if (IS_ERR(file))
+		ret = PTR_ERR(file);
 	else
-		bdev_release(handle);
+		fput(file);
 
 	/*
 	 * If blkdev_get_by_dev() failed early, GD_NEED_PART_SCAN is still set,
Signature · 1 line
2.42.0
author maintainer
#8 lore raw

RFC PATCH 4/34 md: port block device access to file

In reply to Christian Brauner
---
 drivers/md/dm.c               | 23 +++++++++++++----------
 drivers/md/md.c               | 12 ++++++------
 drivers/md/md.h               |  2 +-
 include/linux/device-mapper.h |  2 +-
 4 files changed, 21 insertions(+), 18 deletions(-)
drivers/md/dm.c +13 -10
index 8dcabf84d866..5f45dda430d7 100644
@@ -726,7 +726,8 @@ static struct table_device *open_table_device(struct mapped_device *md,
 		dev_t dev, blk_mode_t mode)
 {
 	struct table_device *td;
-	struct bdev_handle *bdev_handle;
+	struct file *f_bdev;
+	struct block_device *bdev;
 	u64 part_off;
 	int r;
 
@@ -735,34 +736,36 @@ static struct table_device *open_table_device(struct mapped_device *md,
 		return ERR_PTR(-ENOMEM);
 	refcount_set(&td->count, 1);
 
-	bdev_handle = bdev_open_by_dev(dev, mode, _dm_claim_ptr, NULL);
-	if (IS_ERR(bdev_handle)) {
-		r = PTR_ERR(bdev_handle);
+	f_bdev = bdev_file_open_by_dev(dev, mode, _dm_claim_ptr, NULL);
+	if (IS_ERR(f_bdev)) {
+		r = PTR_ERR(f_bdev);
 		goto out_free_td;
 	}
 
+	bdev = F_BDEV(f_bdev);
+
 	/*
 	 * We can be called before the dm disk is added.  In that case we can't
 	 * register the holder relation here.  It will be done once add_disk was
 	 * called.
 	 */
 	if (md->disk->slave_dir) {
-		r = bd_link_disk_holder(bdev_handle->bdev, md->disk);
+		r = bd_link_disk_holder(bdev, md->disk);
 		if (r)
 			goto out_blkdev_put;
 	}
 
 	td->dm_dev.mode = mode;
-	td->dm_dev.bdev = bdev_handle->bdev;
-	td->dm_dev.bdev_handle = bdev_handle;
-	td->dm_dev.dax_dev = fs_dax_get_by_bdev(bdev_handle->bdev, &part_off,
+	td->dm_dev.bdev = bdev;
+	td->dm_dev.f_bdev = f_bdev;
+	td->dm_dev.dax_dev = fs_dax_get_by_bdev(bdev, &part_off,
 						NULL, NULL);
 	format_dev_t(td->dm_dev.name, dev);
 	list_add(&td->list, &md->table_devices);
 	return td;
 
 out_blkdev_put:
-	bdev_release(bdev_handle);
+	fput(f_bdev);
 out_free_td:
 	kfree(td);
 	return ERR_PTR(r);
@@ -775,7 +778,7 @@ static void close_table_device(struct table_device *td, struct mapped_device *md
 {
 	if (md->disk->slave_dir)
 		bd_unlink_disk_holder(td->dm_dev.bdev, md->disk);
-	bdev_release(td->dm_dev.bdev_handle);
+	fput(td->dm_dev.f_bdev);
 	put_dax(td->dm_dev.dax_dev);
 	list_del(&td->list);
 	kfree(td);
drivers/md/md.c +6 -6
index 9bdd57324c37..2235285ac58a 100644
@@ -2549,7 +2549,7 @@ static void export_rdev(struct md_rdev *rdev, struct mddev *mddev)
 	if (test_bit(AutoDetected, &rdev->flags))
 		md_autodetect_dev(rdev->bdev->bd_dev);
 #endif
-	bdev_release(rdev->bdev_handle);
+	fput(rdev->f_bdev);
 	rdev->bdev = NULL;
 	kobject_put(&rdev->kobj);
 }
@@ -3748,16 +3748,16 @@ static struct md_rdev *md_import_device(dev_t newdev, int super_format, int supe
 	if (err)
 		goto out_clear_rdev;
 
-	rdev->bdev_handle = bdev_open_by_dev(newdev,
+	rdev->f_bdev = bdev_file_open_by_dev(newdev,
 			BLK_OPEN_READ | BLK_OPEN_WRITE,
 			super_format == -2 ? &claim_rdev : rdev, NULL);
-	if (IS_ERR(rdev->bdev_handle)) {
+	if (IS_ERR(rdev->f_bdev)) {
 		pr_warn("md: could not open device unknown-block(%u,%u).\n",
 			MAJOR(newdev), MINOR(newdev));
-		err = PTR_ERR(rdev->bdev_handle);
+		err = PTR_ERR(rdev->f_bdev);
 		goto out_clear_rdev;
 	}
-	rdev->bdev = rdev->bdev_handle->bdev;
+	rdev->bdev = F_BDEV(rdev->f_bdev);
 
 	kobject_init(&rdev->kobj, &rdev_ktype);
 
@@ -3788,7 +3788,7 @@ static struct md_rdev *md_import_device(dev_t newdev, int super_format, int supe
 	return rdev;
 
 out_blkdev_put:
-	bdev_release(rdev->bdev_handle);
+	fput(rdev->f_bdev);
 out_clear_rdev:
 	md_rdev_clear(rdev);
 out_free_rdev:
drivers/md/md.h +1 -1
index ade83af123a2..67d3a62a11f9 100644
@@ -59,7 +59,7 @@ struct md_rdev {
 	 */
 	struct block_device *meta_bdev;
 	struct block_device *bdev;	/* block device handle */
-	struct bdev_handle *bdev_handle;	/* Handle from open for bdev */
+	struct file *f_bdev;		/* Handle from open for bdev */
 
 	struct page	*sb_page, *bb_page;
 	int		sb_loaded;
include/linux/device-mapper.h +1 -1
index 772ab4d74d94..c6eaa66d753b 100644
@@ -165,7 +165,7 @@ void dm_error(const char *message);
 
 struct dm_dev {
 	struct block_device *bdev;
-	struct bdev_handle *bdev_handle;
+	struct file *f_bdev;
 	struct dax_device *dax_dev;
 	blk_mode_t mode;
 	char name[16];
Signature · 1 line
2.42.0
author maintainer
#9 lore raw

RFC PATCH 5/34 swap: port block device usage to file

In reply to Christian Brauner
---
 include/linux/swap.h |  2 +-
 mm/swapfile.c        | 22 +++++++++++-----------
 2 files changed, 12 insertions(+), 12 deletions(-)
include/linux/swap.h +1 -1
index f6dd6575b905..1c1114867637 100644
@@ -298,7 +298,7 @@ struct swap_info_struct {
 	unsigned int __percpu *cluster_next_cpu; /*percpu index for next allocation */
 	struct percpu_cluster __percpu *percpu_cluster; /* per cpu's swap location */
 	struct rb_root swap_extent_root;/* root of the swap extent rbtree */
-	struct bdev_handle *bdev_handle;/* open handle of the bdev */
+	struct file *f_bdev;		/* open handle of the bdev */
 	struct block_device *bdev;	/* swap device or bdev of swap file */
 	struct file *swap_file;		/* seldom referenced */
 	unsigned int old_block_size;	/* seldom referenced */
mm/swapfile.c +11 -11
index 4bc70f459164..3b2ac701815b 100644
@@ -2530,10 +2530,10 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
 	exit_swap_address_space(p->type);
 
 	inode = mapping->host;
-	if (p->bdev_handle) {
+	if (p->f_bdev) {
 		set_blocksize(p->bdev, old_block_size);
-		bdev_release(p->bdev_handle);
-		p->bdev_handle = NULL;
+		fput(p->f_bdev);
+		p->f_bdev = NULL;
 	}
 
 	inode_lock(inode);
@@ -2763,14 +2763,14 @@ static int claim_swapfile(struct swap_info_struct *p, struct inode *inode)
 	int error;
 
 	if (S_ISBLK(inode->i_mode)) {
-		p->bdev_handle = bdev_open_by_dev(inode->i_rdev,
+		p->f_bdev = bdev_file_open_by_dev(inode->i_rdev,
 				BLK_OPEN_READ | BLK_OPEN_WRITE, p, NULL);
-		if (IS_ERR(p->bdev_handle)) {
-			error = PTR_ERR(p->bdev_handle);
-			p->bdev_handle = NULL;
+		if (IS_ERR(p->f_bdev)) {
+			error = PTR_ERR(p->f_bdev);
+			p->f_bdev = NULL;
 			return error;
 		}
-		p->bdev = p->bdev_handle->bdev;
+		p->bdev = F_BDEV(p->f_bdev);
 		p->old_block_size = block_size(p->bdev);
 		error = set_blocksize(p->bdev, PAGE_SIZE);
 		if (error < 0)
@@ -3206,10 +3206,10 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
 	p->percpu_cluster = NULL;
 	free_percpu(p->cluster_next_cpu);
 	p->cluster_next_cpu = NULL;
-	if (p->bdev_handle) {
+	if (p->f_bdev) {
 		set_blocksize(p->bdev, p->old_block_size);
-		bdev_release(p->bdev_handle);
-		p->bdev_handle = NULL;
+		fput(p->f_bdev);
+		p->f_bdev = NULL;
 	}
 	inode = NULL;
 	destroy_swap_extents(p);
Signature · 1 line
2.42.0
author maintainer
#10 lore raw

RFC PATCH 6/34 power: port block device access to file

In reply to Christian Brauner
---
 kernel/power/swap.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
kernel/power/swap.c +14 -14
index a2cb0babb5ec..e363c80d6259 100644
@@ -222,7 +222,7 @@ int swsusp_swap_in_use(void)
  */
 
 static unsigned short root_swap = 0xffff;
-static struct bdev_handle *hib_resume_bdev_handle;
+static struct file *hib_resume_f_bdev;
 
 struct hib_bio_batch {
 	atomic_t		count;
@@ -276,7 +276,7 @@ static int hib_submit_io(blk_opf_t opf, pgoff_t page_off, void *addr,
 	struct bio *bio;
 	int error = 0;
 
-	bio = bio_alloc(hib_resume_bdev_handle->bdev, 1, opf,
+	bio = bio_alloc(F_BDEV(hib_resume_f_bdev), 1, opf,
 			GFP_NOIO | __GFP_HIGH);
 	bio->bi_iter.bi_sector = page_off * (PAGE_SIZE >> 9);
 
@@ -357,14 +357,14 @@ static int swsusp_swap_check(void)
 		return res;
 	root_swap = res;
 
-	hib_resume_bdev_handle = bdev_open_by_dev(swsusp_resume_device,
+	hib_resume_f_bdev = bdev_file_open_by_dev(swsusp_resume_device,
 			BLK_OPEN_WRITE, NULL, NULL);
-	if (IS_ERR(hib_resume_bdev_handle))
-		return PTR_ERR(hib_resume_bdev_handle);
+	if (IS_ERR(hib_resume_f_bdev))
+		return PTR_ERR(hib_resume_f_bdev);
 
-	res = set_blocksize(hib_resume_bdev_handle->bdev, PAGE_SIZE);
+	res = set_blocksize(F_BDEV(hib_resume_f_bdev), PAGE_SIZE);
 	if (res < 0)
-		bdev_release(hib_resume_bdev_handle);
+		fput(hib_resume_f_bdev);
 
 	return res;
 }
@@ -1523,10 +1523,10 @@ int swsusp_check(bool exclusive)
 	void *holder = exclusive ? &swsusp_holder : NULL;
 	int error;
 
-	hib_resume_bdev_handle = bdev_open_by_dev(swsusp_resume_device,
+	hib_resume_f_bdev = bdev_file_open_by_dev(swsusp_resume_device,
 				BLK_OPEN_READ, holder, NULL);
-	if (!IS_ERR(hib_resume_bdev_handle)) {
-		set_blocksize(hib_resume_bdev_handle->bdev, PAGE_SIZE);
+	if (!IS_ERR(hib_resume_f_bdev)) {
+		set_blocksize(F_BDEV(hib_resume_f_bdev), PAGE_SIZE);
 		clear_page(swsusp_header);
 		error = hib_submit_io(REQ_OP_READ, swsusp_resume_block,
 					swsusp_header, NULL);
@@ -1551,11 +1551,11 @@ int swsusp_check(bool exclusive)
 
 put:
 		if (error)
-			bdev_release(hib_resume_bdev_handle);
+			fput(hib_resume_f_bdev);
 		else
 			pr_debug("Image signature found, resuming\n");
 	} else {
-		error = PTR_ERR(hib_resume_bdev_handle);
+		error = PTR_ERR(hib_resume_f_bdev);
 	}
 
 	if (error)
@@ -1571,12 +1571,12 @@ int swsusp_check(bool exclusive)
 
 void swsusp_close(void)
 {
-	if (IS_ERR(hib_resume_bdev_handle)) {
+	if (IS_ERR(hib_resume_f_bdev)) {
 		pr_debug("Image device not initialised\n");
 		return;
 	}
 
-	bdev_release(hib_resume_bdev_handle);
+	fput(hib_resume_f_bdev);
 }
 
 /**
Signature · 1 line
2.42.0
author maintainer
#11 lore raw

RFC PATCH 7/34 xfs: port block device access to files

In reply to Christian Brauner
---
 fs/xfs/xfs_buf.c   | 10 +++++-----
 fs/xfs/xfs_buf.h   |  4 ++--
 fs/xfs/xfs_super.c | 43 +++++++++++++++++++++----------------------
 3 files changed, 28 insertions(+), 29 deletions(-)
fs/xfs/xfs_buf.c +5 -5
index 545c7991b9b5..685eb2a9f9d2 100644
@@ -1951,7 +1951,7 @@ xfs_free_buftarg(
 	fs_put_dax(btp->bt_daxdev, btp->bt_mount);
 	/* the main block device is closed by kill_block_super */
 	if (btp->bt_bdev != btp->bt_mount->m_super->s_bdev)
-		bdev_release(btp->bt_bdev_handle);
+		fput(btp->bt_f_bdev);
 
 	kmem_free(btp);
 }
@@ -1994,7 +1994,7 @@ xfs_setsize_buftarg_early(
 struct xfs_buftarg *
 xfs_alloc_buftarg(
 	struct xfs_mount	*mp,
-	struct bdev_handle	*bdev_handle)
+	struct file		*f_bdev)
 {
 	xfs_buftarg_t		*btp;
 	const struct dax_holder_operations *ops = NULL;
@@ -2005,9 +2005,9 @@ xfs_alloc_buftarg(
 	btp = kmem_zalloc(sizeof(*btp), KM_NOFS);
 
 	btp->bt_mount = mp;
-	btp->bt_bdev_handle = bdev_handle;
-	btp->bt_dev = bdev_handle->bdev->bd_dev;
-	btp->bt_bdev = bdev_handle->bdev;
+	btp->bt_f_bdev = f_bdev;
+	btp->bt_bdev = F_BDEV(f_bdev);
+	btp->bt_dev = btp->bt_bdev->bd_dev;
 	btp->bt_daxdev = fs_dax_get_by_bdev(btp->bt_bdev, &btp->bt_dax_part_off,
 					    mp, ops);
 
fs/xfs/xfs_buf.h +2 -2
index c86e16419656..4005dcffb792 100644
@@ -98,7 +98,7 @@ typedef unsigned int xfs_buf_flags_t;
  */
 typedef struct xfs_buftarg {
 	dev_t			bt_dev;
-	struct bdev_handle	*bt_bdev_handle;
+	struct file		*bt_f_bdev;
 	struct block_device	*bt_bdev;
 	struct dax_device	*bt_daxdev;
 	u64			bt_dax_part_off;
@@ -365,7 +365,7 @@ xfs_buf_update_cksum(struct xfs_buf *bp, unsigned long cksum_offset)
  *	Handling of buftargs.
  */
 struct xfs_buftarg *xfs_alloc_buftarg(struct xfs_mount *mp,
-		struct bdev_handle *bdev_handle);
+		struct file *f_bdev);
 extern void xfs_free_buftarg(struct xfs_buftarg *);
 extern void xfs_buftarg_wait(struct xfs_buftarg *);
 extern void xfs_buftarg_drain(struct xfs_buftarg *);
fs/xfs/xfs_super.c +21 -22

99 lines not on this page · raw message

Signature · 1 line
2.42.0
author maintainer
#14 lore raw

RFC PATCH 8/34 drbd: port block device access to file

In reply to Christian Brauner
---
 drivers/block/drbd/drbd_int.h |  4 +--
 drivers/block/drbd/drbd_nl.c  | 58 +++++++++++++++++++++----------------------
 2 files changed, 31 insertions(+), 31 deletions(-)
drivers/block/drbd/drbd_int.h +2 -2
index c21e3732759e..3f57b3a04f39 100644
@@ -524,9 +524,9 @@ struct drbd_md {
 
 struct drbd_backing_dev {
 	struct block_device *backing_bdev;
-	struct bdev_handle *backing_bdev_handle;
+	struct file *f_backing_bdev;
 	struct block_device *md_bdev;
-	struct bdev_handle *md_bdev_handle;
+	struct file *f_md_bdev;
 	struct drbd_md md;
 	struct disk_conf *disk_conf; /* RCU, for updates: resource->conf_update */
 	sector_t known_size; /* last known size of that backing device */
drivers/block/drbd/drbd_nl.c +29 -29

120 lines not on this page · raw message

Signature · 1 line
2.42.0
author maintainer
#15 lore raw

RFC PATCH 9/34 pktcdvd: port block device access to file

In reply to Christian Brauner
---
 drivers/block/pktcdvd.c | 68 ++++++++++++++++++++++++-------------------------
 include/linux/pktcdvd.h |  4 +--
 2 files changed, 36 insertions(+), 36 deletions(-)
drivers/block/pktcdvd.c +34 -34
index d56d972aadb3..02ab52e55229 100644
@@ -340,8 +340,8 @@ static ssize_t device_map_show(const struct class *c, const struct class_attribu
 		n += sysfs_emit_at(data, n, "%s %u:%u %u:%u\n",
 			pd->disk->disk_name,
 			MAJOR(pd->pkt_dev), MINOR(pd->pkt_dev),
-			MAJOR(pd->bdev_handle->bdev->bd_dev),
-			MINOR(pd->bdev_handle->bdev->bd_dev));
+			MAJOR(F_BDEV(pd->f_bdev)->bd_dev),
+			MINOR(F_BDEV(pd->f_bdev)->bd_dev));
 	}
 	mutex_unlock(&ctl_mutex);
 	return n;
@@ -438,7 +438,7 @@ static int pkt_seq_show(struct seq_file *m, void *p)
 	int states[PACKET_NUM_STATES];
 
 	seq_printf(m, "Writer %s mapped to %pg:\n", pd->disk->disk_name,
-		   pd->bdev_handle->bdev);
+		   F_BDEV(pd->f_bdev));
 
 	seq_printf(m, "\nSettings:\n");
 	seq_printf(m, "\tpacket size:\t\t%dkB\n", pd->settings.size / 2);
@@ -715,7 +715,7 @@ static void pkt_rbtree_insert(struct pktcdvd_device *pd, struct pkt_rb_node *nod
  */
 static int pkt_generic_packet(struct pktcdvd_device *pd, struct packet_command *cgc)
 {
-	struct request_queue *q = bdev_get_queue(pd->bdev_handle->bdev);
+	struct request_queue *q = bdev_get_queue(F_BDEV(pd->f_bdev));
 	struct scsi_cmnd *scmd;
 	struct request *rq;
 	int ret = 0;
@@ -1048,7 +1048,7 @@ static void pkt_gather_data(struct pktcdvd_device *pd, struct packet_data *pkt)
 			continue;
 
 		bio = pkt->r_bios[f];
-		bio_init(bio, pd->bdev_handle->bdev, bio->bi_inline_vecs, 1,
+		bio_init(bio, F_BDEV(pd->f_bdev), bio->bi_inline_vecs, 1,
 			 REQ_OP_READ);
 		bio->bi_iter.bi_sector = pkt->sector + f * (CD_FRAMESIZE >> 9);
 		bio->bi_end_io = pkt_end_io_read;
@@ -1264,7 +1264,7 @@ static void pkt_start_write(struct pktcdvd_device *pd, struct packet_data *pkt)
 	struct device *ddev = disk_to_dev(pd->disk);
 	int f;
 
-	bio_init(pkt->w_bio, pd->bdev_handle->bdev, pkt->w_bio->bi_inline_vecs,
+	bio_init(pkt->w_bio, F_BDEV(pd->f_bdev), pkt->w_bio->bi_inline_vecs,
 		 pkt->frames, REQ_OP_WRITE);
 	pkt->w_bio->bi_iter.bi_sector = pkt->sector;
 	pkt->w_bio->bi_end_io = pkt_end_io_packet_write;
@@ -2162,20 +2162,20 @@ static int pkt_open_dev(struct pktcdvd_device *pd, bool write)
 	int ret;
 	long lba;
 	struct request_queue *q;
-	struct bdev_handle *bdev_handle;
+	struct file *f_bdev;
 
 	/*
 	 * We need to re-open the cdrom device without O_NONBLOCK to be able
 	 * to read/write from/to it. It is already opened in O_NONBLOCK mode
 	 * so open should not fail.
 	 */
-	bdev_handle = bdev_open_by_dev(pd->bdev_handle->bdev->bd_dev,
+	f_bdev = bdev_file_open_by_dev(F_BDEV(pd->f_bdev)->bd_dev,
 				       BLK_OPEN_READ, pd, NULL);
-	if (IS_ERR(bdev_handle)) {
-		ret = PTR_ERR(bdev_handle);
+	if (IS_ERR(f_bdev)) {
+		ret = PTR_ERR(f_bdev);
 		goto out;
 	}
-	pd->open_bdev_handle = bdev_handle;
+	pd->f_open_bdev = f_bdev;
 
 	ret = pkt_get_last_written(pd, &lba);
 	if (ret) {
@@ -2184,9 +2184,9 @@ static int pkt_open_dev(struct pktcdvd_device *pd, bool write)
 	}
 
 	set_capacity(pd->disk, lba << 2);
-	set_capacity_and_notify(pd->bdev_handle->bdev->bd_disk, lba << 2);
+	set_capacity_and_notify(F_BDEV(pd->f_bdev)->bd_disk, lba << 2);
 
-	q = bdev_get_queue(pd->bdev_handle->bdev);
+	q = bdev_get_queue(F_BDEV(pd->f_bdev));
 	if (write) {
 		ret = pkt_open_write(pd);
 		if (ret)
@@ -2218,7 +2218,7 @@ static int pkt_open_dev(struct pktcdvd_device *pd, bool write)
 	return 0;
 
 out_putdev:
-	bdev_release(bdev_handle);
+	fput(f_bdev);
 out:
 	return ret;
 }
@@ -2237,8 +2237,8 @@ static void pkt_release_dev(struct pktcdvd_device *pd, int flush)
 	pkt_lock_door(pd, 0);
 
 	pkt_set_speed(pd, MAX_SPEED, MAX_SPEED);
-	bdev_release(pd->open_bdev_handle);
-	pd->open_bdev_handle = NULL;
+	fput(pd->f_open_bdev);
+	pd->f_open_bdev = NULL;
 
 	pkt_shrink_pktlist(pd);
 }
@@ -2326,7 +2326,7 @@ static void pkt_end_io_read_cloned(struct bio *bio)
 
 static void pkt_make_request_read(struct pktcdvd_device *pd, struct bio *bio)
 {
-	struct bio *cloned_bio = bio_alloc_clone(pd->bdev_handle->bdev, bio,
+	struct bio *cloned_bio = bio_alloc_clone(F_BDEV(pd->f_bdev), bio,
 		GFP_NOIO, &pkt_bio_set);
 	struct packet_stacked_data *psd = mempool_alloc(&psd_pool, GFP_NOIO);
 
@@ -2497,7 +2497,7 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev)
 {
 	struct device *ddev = disk_to_dev(pd->disk);
 	int i;
-	struct bdev_handle *bdev_handle;
+	struct file *f_bdev;
 	struct scsi_device *sdev;
 
 	if (pd->pkt_dev == dev) {
@@ -2508,9 +2508,9 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev)
 		struct pktcdvd_device *pd2 = pkt_devs[i];
 		if (!pd2)
 			continue;
-		if (pd2->bdev_handle->bdev->bd_dev == dev) {
+		if (F_BDEV(pd2->f_bdev)->bd_dev == dev) {
 			dev_err(ddev, "%pg already setup\n",
-				pd2->bdev_handle->bdev);
+				F_BDEV(pd2->f_bdev));
 			return -EBUSY;
 		}
 		if (pd2->pkt_dev == dev) {
@@ -2519,13 +2519,13 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev)
 		}
 	}
 
-	bdev_handle = bdev_open_by_dev(dev, BLK_OPEN_READ | BLK_OPEN_NDELAY,
+	f_bdev = bdev_file_open_by_dev(dev, BLK_OPEN_READ | BLK_OPEN_NDELAY,
 				       NULL, NULL);
-	if (IS_ERR(bdev_handle))
-		return PTR_ERR(bdev_handle);
-	sdev = scsi_device_from_queue(bdev_handle->bdev->bd_disk->queue);
+	if (IS_ERR(f_bdev))
+		return PTR_ERR(f_bdev);
+	sdev = scsi_device_from_queue(F_BDEV(f_bdev)->bd_disk->queue);
 	if (!sdev) {
-		bdev_release(bdev_handle);
+		fput(f_bdev);
 		return -EINVAL;
 	}
 	put_device(&sdev->sdev_gendev);
@@ -2533,8 +2533,8 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev)
 	/* This is safe, since we have a reference from open(). */
 	__module_get(THIS_MODULE);
 
-	pd->bdev_handle = bdev_handle;
-	set_blocksize(bdev_handle->bdev, CD_FRAMESIZE);
+	pd->f_bdev = f_bdev;
+	set_blocksize(F_BDEV(f_bdev), CD_FRAMESIZE);
 
 	pkt_init_queue(pd);
 
@@ -2546,11 +2546,11 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev)
 	}
 
 	proc_create_single_data(pd->disk->disk_name, 0, pkt_proc, pkt_seq_show, pd);
-	dev_notice(ddev, "writer mapped to %pg\n", bdev_handle->bdev);
+	dev_notice(ddev, "writer mapped to %pg\n", F_BDEV(f_bdev));
 	return 0;
 
 out_mem:
-	bdev_release(bdev_handle);
+	fput(f_bdev);
 	/* This is safe: open() is still holding a reference. */
 	module_put(THIS_MODULE);
 	return -ENOMEM;
@@ -2605,9 +2605,9 @@ static unsigned int pkt_check_events(struct gendisk *disk,
 
 	if (!pd)
 		return 0;
-	if (!pd->bdev_handle)
+	if (!pd->f_bdev)
 		return 0;
-	attached_disk = pd->bdev_handle->bdev->bd_disk;
+	attached_disk = F_BDEV(pd->f_bdev)->bd_disk;
 	if (!attached_disk || !attached_disk->fops->check_events)
 		return 0;
 	return attached_disk->fops->check_events(attached_disk, clearing);
@@ -2692,7 +2692,7 @@ static int pkt_setup_dev(dev_t dev, dev_t* pkt_dev)
 		goto out_mem2;
 
 	/* inherit events of the host device */
-	disk->events = pd->bdev_handle->bdev->bd_disk->events;
+	disk->events = F_BDEV(pd->f_bdev)->bd_disk->events;
 
 	ret = add_disk(disk);
 	if (ret)
@@ -2757,7 +2757,7 @@ static int pkt_remove_dev(dev_t pkt_dev)
 	pkt_debugfs_dev_remove(pd);
 	pkt_sysfs_dev_remove(pd);
 
-	bdev_release(pd->bdev_handle);
+	fput(pd->f_bdev);
 
 	remove_proc_entry(pd->disk->disk_name, pkt_proc);
 	dev_notice(ddev, "writer unmapped\n");
@@ -2784,7 +2784,7 @@ static void pkt_get_status(struct pkt_ctrl_command *ctrl_cmd)
 
 	pd = pkt_find_dev_from_minor(ctrl_cmd->dev_index);
 	if (pd) {
-		ctrl_cmd->dev = new_encode_dev(pd->bdev_handle->bdev->bd_dev);
+		ctrl_cmd->dev = new_encode_dev(F_BDEV(pd->f_bdev)->bd_dev);
 		ctrl_cmd->pkt_dev = new_encode_dev(pd->pkt_dev);
 	} else {
 		ctrl_cmd->dev = 0;
include/linux/pktcdvd.h +2 -2
index 79594aeb160d..e202ec04b7e0 100644
@@ -154,9 +154,9 @@ struct packet_stacked_data
 
 struct pktcdvd_device
 {
-	struct bdev_handle	*bdev_handle;	/* dev attached */
+	struct file		*f_bdev;	/* dev attached */
 	/* handle acquired for bdev during pkt_open_dev() */
-	struct bdev_handle	*open_bdev_handle;
+	struct file		*f_open_bdev;
 	dev_t			pkt_dev;	/* our dev */
 	struct packet_settings	settings;
 	struct packet_stats	stats;
Signature · 1 line
2.42.0
author maintainer
#16 lore raw

RFC PATCH 10/34 rnbd: port block device access to file

In reply to Christian Brauner
---
 drivers/block/rnbd/rnbd-srv.c | 26 +++++++++++++-------------
 drivers/block/rnbd/rnbd-srv.h |  2 +-
 2 files changed, 14 insertions(+), 14 deletions(-)
drivers/block/rnbd/rnbd-srv.c +13 -13
index 65de51f3dfd9..2aeedca4ba21 100644
@@ -145,7 +145,7 @@ static int process_rdma(struct rnbd_srv_session *srv_sess,
 	priv->sess_dev = sess_dev;
 	priv->id = id;
 
-	bio = bio_alloc(sess_dev->bdev_handle->bdev, 1,
+	bio = bio_alloc(F_BDEV(sess_dev->f_bdev), 1,
 			rnbd_to_bio_flags(le32_to_cpu(msg->rw)), GFP_KERNEL);
 	if (bio_add_page(bio, virt_to_page(data), datalen,
 			offset_in_page(data)) != datalen) {
@@ -219,7 +219,7 @@ void rnbd_destroy_sess_dev(struct rnbd_srv_sess_dev *sess_dev, bool keep_id)
 	rnbd_put_sess_dev(sess_dev);
 	wait_for_completion(&dc); /* wait for inflights to drop to zero */
 
-	bdev_release(sess_dev->bdev_handle);
+	fput(sess_dev->f_bdev);
 	mutex_lock(&sess_dev->dev->lock);
 	list_del(&sess_dev->dev_list);
 	if (!sess_dev->readonly)
@@ -534,7 +534,7 @@ rnbd_srv_get_or_create_srv_dev(struct block_device *bdev,
 static void rnbd_srv_fill_msg_open_rsp(struct rnbd_msg_open_rsp *rsp,
 					struct rnbd_srv_sess_dev *sess_dev)
 {
-	struct block_device *bdev = sess_dev->bdev_handle->bdev;
+	struct block_device *bdev = F_BDEV(sess_dev->f_bdev);
 
 	rsp->hdr.type = cpu_to_le16(RNBD_MSG_OPEN_RSP);
 	rsp->device_id = cpu_to_le32(sess_dev->device_id);
@@ -559,7 +559,7 @@ static void rnbd_srv_fill_msg_open_rsp(struct rnbd_msg_open_rsp *rsp,
 static struct rnbd_srv_sess_dev *
 rnbd_srv_create_set_sess_dev(struct rnbd_srv_session *srv_sess,
 			      const struct rnbd_msg_open *open_msg,
-			      struct bdev_handle *handle, bool readonly,
+			      struct file *f_bdev, bool readonly,
 			      struct rnbd_srv_dev *srv_dev)
 {
 	struct rnbd_srv_sess_dev *sdev = rnbd_sess_dev_alloc(srv_sess);
@@ -571,7 +571,7 @@ rnbd_srv_create_set_sess_dev(struct rnbd_srv_session *srv_sess,
 
 	strscpy(sdev->pathname, open_msg->dev_name, sizeof(sdev->pathname));
 
-	sdev->bdev_handle	= handle;
+	sdev->f_bdev		= f_bdev;
 	sdev->sess		= srv_sess;
 	sdev->dev		= srv_dev;
 	sdev->readonly		= readonly;
@@ -676,7 +676,7 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess,
 	struct rnbd_srv_dev *srv_dev;
 	struct rnbd_srv_sess_dev *srv_sess_dev;
 	const struct rnbd_msg_open *open_msg = msg;
-	struct bdev_handle *bdev_handle;
+	struct file *f_bdev;
 	blk_mode_t open_flags = BLK_OPEN_READ;
 	char *full_path;
 	struct rnbd_msg_open_rsp *rsp = data;
@@ -714,15 +714,15 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess,
 		goto reject;
 	}
 
-	bdev_handle = bdev_open_by_path(full_path, open_flags, NULL, NULL);
-	if (IS_ERR(bdev_handle)) {
-		ret = PTR_ERR(bdev_handle);
+	f_bdev = bdev_file_open_by_path(full_path, open_flags, NULL, NULL);
+	if (IS_ERR(f_bdev)) {
+		ret = PTR_ERR(f_bdev);
 		pr_err("Opening device '%s' on session %s failed, failed to open the block device, err: %d\n",
 		       full_path, srv_sess->sessname, ret);
 		goto free_path;
 	}
 
-	srv_dev = rnbd_srv_get_or_create_srv_dev(bdev_handle->bdev, srv_sess,
+	srv_dev = rnbd_srv_get_or_create_srv_dev(F_BDEV(f_bdev), srv_sess,
 						  open_msg->access_mode);
 	if (IS_ERR(srv_dev)) {
 		pr_err("Opening device '%s' on session %s failed, creating srv_dev failed, err: %ld\n",
@@ -732,7 +732,7 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess,
 	}
 
 	srv_sess_dev = rnbd_srv_create_set_sess_dev(srv_sess, open_msg,
-				bdev_handle,
+				f_bdev,
 				open_msg->access_mode == RNBD_ACCESS_RO,
 				srv_dev);
 	if (IS_ERR(srv_sess_dev)) {
@@ -748,7 +748,7 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess,
 	 */
 	mutex_lock(&srv_dev->lock);
 	if (!srv_dev->dev_kobj.state_in_sysfs) {
-		ret = rnbd_srv_create_dev_sysfs(srv_dev, bdev_handle->bdev);
+		ret = rnbd_srv_create_dev_sysfs(srv_dev, F_BDEV(f_bdev));
 		if (ret) {
 			mutex_unlock(&srv_dev->lock);
 			rnbd_srv_err(srv_sess_dev,
@@ -791,7 +791,7 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess,
 	}
 	rnbd_put_srv_dev(srv_dev);
 blkdev_put:
-	bdev_release(bdev_handle);
+	fput(f_bdev);
 free_path:
 	kfree(full_path);
 reject:
drivers/block/rnbd/rnbd-srv.h +1 -1
index 343cc682b617..c91973f4326e 100644
@@ -46,7 +46,7 @@ struct rnbd_srv_dev {
 struct rnbd_srv_sess_dev {
 	/* Entry inside rnbd_srv_dev struct */
 	struct list_head		dev_list;
-	struct bdev_handle		*bdev_handle;
+	struct file			*f_bdev;
 	struct rnbd_srv_session		*sess;
 	struct rnbd_srv_dev		*dev;
 	struct kobject                  kobj;
Signature · 1 line
2.42.0
author maintainer
#17 lore raw

RFC PATCH 11/34 xen: port block device access to file

In reply to Christian Brauner
---
 drivers/block/xen-blkback/blkback.c |  4 ++--
 drivers/block/xen-blkback/common.h  |  4 ++--
 drivers/block/xen-blkback/xenbus.c  | 36 ++++++++++++++++++------------------
 3 files changed, 22 insertions(+), 22 deletions(-)
drivers/block/xen-blkback/blkback.c +2 -2
index 4defd7f387c7..752fd41c5ed9 100644
@@ -465,7 +465,7 @@ static int xen_vbd_translate(struct phys_req *req, struct xen_blkif *blkif,
 	}
 
 	req->dev  = vbd->pdevice;
-	req->bdev = vbd->bdev_handle->bdev;
+	req->bdev = F_BDEV(vbd->f_bdev);
 	rc = 0;
 
  out:
@@ -969,7 +969,7 @@ static int dispatch_discard_io(struct xen_blkif_ring *ring,
 	int err = 0;
 	int status = BLKIF_RSP_OKAY;
 	struct xen_blkif *blkif = ring->blkif;
-	struct block_device *bdev = blkif->vbd.bdev_handle->bdev;
+	struct block_device *bdev = F_BDEV(blkif->vbd.f_bdev);
 	struct phys_req preq;
 
 	xen_blkif_get(blkif);
drivers/block/xen-blkback/common.h +2 -2
index 5ff50e76cee5..44070e38e5c2 100644
@@ -221,7 +221,7 @@ struct xen_vbd {
 	unsigned char		type;
 	/* phys device that this vbd maps to. */
 	u32			pdevice;
-	struct bdev_handle	*bdev_handle;
+	struct file		*f_bdev;
 	/* Cached size parameter. */
 	sector_t		size;
 	unsigned int		flush_support:1;
@@ -360,7 +360,7 @@ struct pending_req {
 };
 
 
-#define vbd_sz(_v)	bdev_nr_sectors((_v)->bdev_handle->bdev)
+#define vbd_sz(_v)	bdev_nr_sectors(F_BDEV((_v)->f_bdev))
 
 #define xen_blkif_get(_b) (atomic_inc(&(_b)->refcnt))
 #define xen_blkif_put(_b)				\
drivers/block/xen-blkback/xenbus.c +18 -18
index e34219ea2b05..5386e123fada 100644
@@ -81,7 +81,7 @@ static void xen_update_blkif_status(struct xen_blkif *blkif)
 	int i;
 
 	/* Not ready to connect? */
-	if (!blkif->rings || !blkif->rings[0].irq || !blkif->vbd.bdev_handle)
+	if (!blkif->rings || !blkif->rings[0].irq || !blkif->vbd.f_bdev)
 		return;
 
 	/* Already connected? */
@@ -99,13 +99,13 @@ static void xen_update_blkif_status(struct xen_blkif *blkif)
 		return;
 	}
 
-	err = sync_blockdev(blkif->vbd.bdev_handle->bdev);
+	err = sync_blockdev(F_BDEV(blkif->vbd.f_bdev));
 	if (err) {
 		xenbus_dev_error(blkif->be->dev, err, "block flush");
 		return;
 	}
 	invalidate_inode_pages2(
-			blkif->vbd.bdev_handle->bdev->bd_inode->i_mapping);
+			file_inode(blkif->vbd.f_bdev)->i_mapping);
 
 	for (i = 0; i < blkif->nr_rings; i++) {
 		ring = &blkif->rings[i];
@@ -473,9 +473,9 @@ static void xenvbd_sysfs_delif(struct xenbus_device *dev)
 
 static void xen_vbd_free(struct xen_vbd *vbd)
 {
-	if (vbd->bdev_handle)
-		bdev_release(vbd->bdev_handle);
-	vbd->bdev_handle = NULL;
+	if (vbd->f_bdev)
+		fput(vbd->f_bdev);
+	vbd->f_bdev = NULL;
 }
 
 static int xen_vbd_create(struct xen_blkif *blkif, blkif_vdev_t handle,
@@ -483,7 +483,7 @@ static int xen_vbd_create(struct xen_blkif *blkif, blkif_vdev_t handle,
 			  int cdrom)
 {
 	struct xen_vbd *vbd;
-	struct bdev_handle *bdev_handle;
+	struct file *f_bdev;
 
 	vbd = &blkif->vbd;
 	vbd->handle   = handle;
@@ -492,17 +492,17 @@ static int xen_vbd_create(struct xen_blkif *blkif, blkif_vdev_t handle,
 
 	vbd->pdevice  = MKDEV(major, minor);
 
-	bdev_handle = bdev_open_by_dev(vbd->pdevice, vbd->readonly ?
+	f_bdev = bdev_file_open_by_dev(vbd->pdevice, vbd->readonly ?
 				 BLK_OPEN_READ : BLK_OPEN_WRITE, NULL, NULL);
 
-	if (IS_ERR(bdev_handle)) {
+	if (IS_ERR(f_bdev)) {
 		pr_warn("xen_vbd_create: device %08x could not be opened\n",
 			vbd->pdevice);
 		return -ENOENT;
 	}
 
-	vbd->bdev_handle = bdev_handle;
-	if (vbd->bdev_handle->bdev->bd_disk == NULL) {
+	vbd->f_bdev = f_bdev;
+	if (F_BDEV(vbd->f_bdev)->bd_disk == NULL) {
 		pr_warn("xen_vbd_create: device %08x doesn't exist\n",
 			vbd->pdevice);
 		xen_vbd_free(vbd);
@@ -510,14 +510,14 @@ static int xen_vbd_create(struct xen_blkif *blkif, blkif_vdev_t handle,
 	}
 	vbd->size = vbd_sz(vbd);
 
-	if (cdrom || disk_to_cdi(vbd->bdev_handle->bdev->bd_disk))
+	if (cdrom || disk_to_cdi(F_BDEV(vbd->f_bdev)->bd_disk))
 		vbd->type |= VDISK_CDROM;
-	if (vbd->bdev_handle->bdev->bd_disk->flags & GENHD_FL_REMOVABLE)
+	if (F_BDEV(vbd->f_bdev)->bd_disk->flags & GENHD_FL_REMOVABLE)
 		vbd->type |= VDISK_REMOVABLE;
 
-	if (bdev_write_cache(bdev_handle->bdev))
+	if (bdev_write_cache(F_BDEV(f_bdev)))
 		vbd->flush_support = true;
-	if (bdev_max_secure_erase_sectors(bdev_handle->bdev))
+	if (bdev_max_secure_erase_sectors(F_BDEV(f_bdev)))
 		vbd->discard_secure = true;
 
 	pr_debug("Successful creation of handle=%04x (dom=%u)\n",
@@ -570,7 +570,7 @@ static void xen_blkbk_discard(struct xenbus_transaction xbt, struct backend_info
 	struct xen_blkif *blkif = be->blkif;
 	int err;
 	int state = 0;
-	struct block_device *bdev = be->blkif->vbd.bdev_handle->bdev;
+	struct block_device *bdev = F_BDEV(be->blkif->vbd.f_bdev);
 
 	if (!xenbus_read_unsigned(dev->nodename, "discard-enable", 1))
 		return;
@@ -932,7 +932,7 @@ static void connect(struct backend_info *be)
 	}
 	err = xenbus_printf(xbt, dev->nodename, "sector-size", "%lu",
 			    (unsigned long)bdev_logical_block_size(
-					be->blkif->vbd.bdev_handle->bdev));
+					F_BDEV(be->blkif->vbd.f_bdev)));
 	if (err) {
 		xenbus_dev_fatal(dev, err, "writing %s/sector-size",
 				 dev->nodename);
@@ -940,7 +940,7 @@ static void connect(struct backend_info *be)
 	}
 	err = xenbus_printf(xbt, dev->nodename, "physical-sector-size", "%u",
 			    bdev_physical_block_size(
-					be->blkif->vbd.bdev_handle->bdev));
+					F_BDEV(be->blkif->vbd.f_bdev)));
 	if (err)
 		xenbus_dev_error(dev, err, "writing %s/physical-sector-size",
 				 dev->nodename);
Signature · 1 line
2.42.0
author maintainer
#18 lore raw

RFC PATCH 12/34 zram: port block device access to file

In reply to Christian Brauner
---
 drivers/block/zram/zram_drv.c | 26 +++++++++++++-------------
 drivers/block/zram/zram_drv.h |  2 +-
 2 files changed, 14 insertions(+), 14 deletions(-)
drivers/block/zram/zram_drv.c +13 -13
index d77d3664ca08..7bf8360831b7 100644
@@ -417,11 +417,11 @@ static void reset_bdev(struct zram *zram)
 	if (!zram->backing_dev)
 		return;
 
-	bdev_release(zram->bdev_handle);
+	fput(zram->f_bdev);
 	/* hope filp_close flush all of IO */
 	filp_close(zram->backing_dev, NULL);
 	zram->backing_dev = NULL;
-	zram->bdev_handle = NULL;
+	zram->f_bdev = NULL;
 	zram->disk->fops = &zram_devops;
 	kvfree(zram->bitmap);
 	zram->bitmap = NULL;
@@ -467,7 +467,7 @@ static ssize_t backing_dev_store(struct device *dev,
 	struct address_space *mapping;
 	unsigned int bitmap_sz;
 	unsigned long nr_pages, *bitmap = NULL;
-	struct bdev_handle *bdev_handle = NULL;
+	struct file *f_bdev = NULL;
 	int err;
 	struct zram *zram = dev_to_zram(dev);
 
@@ -504,11 +504,11 @@ static ssize_t backing_dev_store(struct device *dev,
 		goto out;
 	}
 
-	bdev_handle = bdev_open_by_dev(inode->i_rdev,
+	f_bdev = bdev_file_open_by_dev(inode->i_rdev,
 				BLK_OPEN_READ | BLK_OPEN_WRITE, zram, NULL);
-	if (IS_ERR(bdev_handle)) {
-		err = PTR_ERR(bdev_handle);
-		bdev_handle = NULL;
+	if (IS_ERR(f_bdev)) {
+		err = PTR_ERR(f_bdev);
+		f_bdev = NULL;
 		goto out;
 	}
 
@@ -522,7 +522,7 @@ static ssize_t backing_dev_store(struct device *dev,
 
 	reset_bdev(zram);
 
-	zram->bdev_handle = bdev_handle;
+	zram->f_bdev = f_bdev;
 	zram->backing_dev = backing_dev;
 	zram->bitmap = bitmap;
 	zram->nr_pages = nr_pages;
@@ -535,8 +535,8 @@ static ssize_t backing_dev_store(struct device *dev,
 out:
 	kvfree(bitmap);
 
-	if (bdev_handle)
-		bdev_release(bdev_handle);
+	if (f_bdev)
+		fput(f_bdev);
 
 	if (backing_dev)
 		filp_close(backing_dev, NULL);
@@ -578,7 +578,7 @@ static void read_from_bdev_async(struct zram *zram, struct page *page,
 {
 	struct bio *bio;
 
-	bio = bio_alloc(zram->bdev_handle->bdev, 1, parent->bi_opf, GFP_NOIO);
+	bio = bio_alloc(F_BDEV(zram->f_bdev), 1, parent->bi_opf, GFP_NOIO);
 	bio->bi_iter.bi_sector = entry * (PAGE_SIZE >> 9);
 	__bio_add_page(bio, page, PAGE_SIZE, 0);
 	bio_chain(bio, parent);
@@ -694,7 +694,7 @@ static ssize_t writeback_store(struct device *dev,
 			continue;
 		}
 
-		bio_init(&bio, zram->bdev_handle->bdev, &bio_vec, 1,
+		bio_init(&bio, F_BDEV(zram->f_bdev), &bio_vec, 1,
 			 REQ_OP_WRITE | REQ_SYNC);
 		bio.bi_iter.bi_sector = blk_idx * (PAGE_SIZE >> 9);
 		__bio_add_page(&bio, page, PAGE_SIZE, 0);
@@ -776,7 +776,7 @@ static void zram_sync_read(struct work_struct *work)
 	struct bio_vec bv;
 	struct bio bio;
 
-	bio_init(&bio, zw->zram->bdev_handle->bdev, &bv, 1, REQ_OP_READ);
+	bio_init(&bio, F_BDEV(zw->zram->f_bdev), &bv, 1, REQ_OP_READ);
 	bio.bi_iter.bi_sector = zw->entry * (PAGE_SIZE >> 9);
 	__bio_add_page(&bio, zw->page, PAGE_SIZE, 0);
 	zw->error = submit_bio_wait(&bio);
drivers/block/zram/zram_drv.h +1 -1
index d090753f97be..6d02e678483e 100644
@@ -132,7 +132,7 @@ struct zram {
 	spinlock_t wb_limit_lock;
 	bool wb_limit_enable;
 	u64 bd_wb_limit;
-	struct bdev_handle *bdev_handle;
+	struct file *f_bdev;
 	unsigned long *bitmap;
 	unsigned long nr_pages;
 #endif
Signature · 1 line
2.42.0
author maintainer
#19 lore raw

RFC PATCH 13/34 bcache: port block device access to files

In reply to Christian Brauner
---
 drivers/md/bcache/bcache.h |  4 +--
 drivers/md/bcache/super.c  | 74 +++++++++++++++++++++++-----------------------
 2 files changed, 39 insertions(+), 39 deletions(-)
drivers/md/bcache/bcache.h +2 -2
index 6ae2329052c9..f1579b0acd8d 100644
@@ -300,7 +300,7 @@ struct cached_dev {
 	struct list_head	list;
 	struct bcache_device	disk;
 	struct block_device	*bdev;
-	struct bdev_handle	*bdev_handle;
+	struct file		*f_bdev;
 
 	struct cache_sb		sb;
 	struct cache_sb_disk	*sb_disk;
@@ -423,7 +423,7 @@ struct cache {
 
 	struct kobject		kobj;
 	struct block_device	*bdev;
-	struct bdev_handle	*bdev_handle;
+	struct file		*f_bdev;
 
 	struct task_struct	*alloc_thread;
 
drivers/md/bcache/super.c +37 -37

198 lines not on this page · raw message

Signature · 1 line
2.42.0
author maintainer
#20 lore raw

RFC PATCH 14/34 block2mtd: port device access to files

In reply to Christian Brauner
---
 drivers/mtd/devices/block2mtd.c | 42 ++++++++++++++++++++---------------------
 1 file changed, 21 insertions(+), 21 deletions(-)
drivers/mtd/devices/block2mtd.c +21 -21
index aa44a23ec045..290e08afb8d0 100644
@@ -37,7 +37,7 @@
 /* Info for the block device */
 struct block2mtd_dev {
 	struct list_head list;
-	struct bdev_handle *bdev_handle;
+	struct file *f_bdev;
 	struct mtd_info mtd;
 	struct mutex write_mutex;
 };
@@ -56,7 +56,7 @@ static struct page *page_read(struct address_space *mapping, pgoff_t index)
 static int _block2mtd_erase(struct block2mtd_dev *dev, loff_t to, size_t len)
 {
 	struct address_space *mapping =
-				dev->bdev_handle->bdev->bd_inode->i_mapping;
+				file_inode(dev->f_bdev)->i_mapping;
 	struct page *page;
 	pgoff_t index = to >> PAGE_SHIFT;	// page index
 	int pages = len >> PAGE_SHIFT;
@@ -107,7 +107,7 @@ static int block2mtd_read(struct mtd_info *mtd, loff_t from, size_t len,
 {
 	struct block2mtd_dev *dev = mtd->priv;
 	struct address_space *mapping =
-				dev->bdev_handle->bdev->bd_inode->i_mapping;
+				file_inode(dev->f_bdev)->i_mapping;
 	struct page *page;
 	pgoff_t index = from >> PAGE_SHIFT;
 	int offset = from & (PAGE_SIZE-1);
@@ -143,7 +143,7 @@ static int _block2mtd_write(struct block2mtd_dev *dev, const u_char *buf,
 {
 	struct page *page;
 	struct address_space *mapping =
-				dev->bdev_handle->bdev->bd_inode->i_mapping;
+				file_inode(dev->f_bdev)->i_mapping;
 	pgoff_t index = to >> PAGE_SHIFT;	// page index
 	int offset = to & ~PAGE_MASK;	// page offset
 	int cpylen;
@@ -198,7 +198,7 @@ static int block2mtd_write(struct mtd_info *mtd, loff_t to, size_t len,
 static void block2mtd_sync(struct mtd_info *mtd)
 {
 	struct block2mtd_dev *dev = mtd->priv;
-	sync_blockdev(dev->bdev_handle->bdev);
+	sync_blockdev(F_BDEV(dev->f_bdev));
 	return;
 }
 
@@ -210,10 +210,10 @@ static void block2mtd_free_device(struct block2mtd_dev *dev)
 
 	kfree(dev->mtd.name);
 
-	if (dev->bdev_handle) {
+	if (dev->f_bdev) {
 		invalidate_mapping_pages(
-			dev->bdev_handle->bdev->bd_inode->i_mapping, 0, -1);
-		bdev_release(dev->bdev_handle);
+			file_inode(dev->f_bdev)->i_mapping, 0, -1);
+		fput(dev->f_bdev);
 	}
 
 	kfree(dev);
@@ -223,10 +223,10 @@ static void block2mtd_free_device(struct block2mtd_dev *dev)
  * This function is marked __ref because it calls the __init marked
  * early_lookup_bdev when called from the early boot code.
  */
-static struct bdev_handle __ref *mdtblock_early_get_bdev(const char *devname,
+static struct file __ref *mdtblock_early_get_bdev(const char *devname,
 		blk_mode_t mode, int timeout, struct block2mtd_dev *dev)
 {
-	struct bdev_handle *bdev_handle = ERR_PTR(-ENODEV);
+	struct file *f_bdev = ERR_PTR(-ENODEV);
 #ifndef MODULE
 	int i;
 
@@ -234,7 +234,7 @@ static struct bdev_handle __ref *mdtblock_early_get_bdev(const char *devname,
 	 * We can't use early_lookup_bdev from a running system.
 	 */
 	if (system_state >= SYSTEM_RUNNING)
-		return bdev_handle;
+		return f_bdev;
 
 	/*
 	 * We might not have the root device mounted at this point.
@@ -253,20 +253,20 @@ static struct bdev_handle __ref *mdtblock_early_get_bdev(const char *devname,
 		wait_for_device_probe();
 
 		if (!early_lookup_bdev(devname, &devt)) {
-			bdev_handle = bdev_open_by_dev(devt, mode, dev, NULL);
-			if (!IS_ERR(bdev_handle))
+			f_bdev = bdev_file_open_by_dev(devt, mode, dev, NULL);
+			if (!IS_ERR(f_bdev))
 				break;
 		}
 	}
 #endif
-	return bdev_handle;
+	return f_bdev;
 }
 
 static struct block2mtd_dev *add_device(char *devname, int erase_size,
 		char *label, int timeout)
 {
 	const blk_mode_t mode = BLK_OPEN_READ | BLK_OPEN_WRITE;
-	struct bdev_handle *bdev_handle;
+	struct file *f_bdev;
 	struct block_device *bdev;
 	struct block2mtd_dev *dev;
 	char *name;
@@ -279,16 +279,16 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size,
 		return NULL;
 
 	/* Get a handle on the device */
-	bdev_handle = bdev_open_by_path(devname, mode, dev, NULL);
-	if (IS_ERR(bdev_handle))
-		bdev_handle = mdtblock_early_get_bdev(devname, mode, timeout,
+	f_bdev = bdev_file_open_by_path(devname, mode, dev, NULL);
+	if (IS_ERR(f_bdev))
+		f_bdev = mdtblock_early_get_bdev(devname, mode, timeout,
 						      dev);
-	if (IS_ERR(bdev_handle)) {
+	if (IS_ERR(f_bdev)) {
 		pr_err("error: cannot open device %s\n", devname);
 		goto err_free_block2mtd;
 	}
-	dev->bdev_handle = bdev_handle;
-	bdev = bdev_handle->bdev;
+	dev->f_bdev = f_bdev;
+	bdev = F_BDEV(f_bdev);
 
 	if (MAJOR(bdev->bd_dev) == MTD_BLOCK_MAJOR) {
 		pr_err("attempting to use an MTD device as a block device\n");
Signature · 1 line
2.42.0
author maintainer
#21 lore raw

RFC PATCH 15/34 nvme: port block device access to file

In reply to Christian Brauner
---
 drivers/nvme/target/io-cmd-bdev.c | 16 ++++++++--------
 drivers/nvme/target/nvmet.h       |  2 +-
 2 files changed, 9 insertions(+), 9 deletions(-)
drivers/nvme/target/io-cmd-bdev.c +8 -8
index f11400a908f2..60dff841aa97 100644
@@ -50,10 +50,10 @@ void nvmet_bdev_set_limits(struct block_device *bdev, struct nvme_id_ns *id)
 
 void nvmet_bdev_ns_disable(struct nvmet_ns *ns)
 {
-	if (ns->bdev_handle) {
-		bdev_release(ns->bdev_handle);
+	if (ns->f_bdev) {
+		fput(ns->f_bdev);
 		ns->bdev = NULL;
-		ns->bdev_handle = NULL;
+		ns->f_bdev = NULL;
 	}
 }
 
@@ -85,18 +85,18 @@ int nvmet_bdev_ns_enable(struct nvmet_ns *ns)
 	if (ns->buffered_io)
 		return -ENOTBLK;
 
-	ns->bdev_handle = bdev_open_by_path(ns->device_path,
+	ns->f_bdev = bdev_file_open_by_path(ns->device_path,
 				BLK_OPEN_READ | BLK_OPEN_WRITE, NULL, NULL);
-	if (IS_ERR(ns->bdev_handle)) {
-		ret = PTR_ERR(ns->bdev_handle);
+	if (IS_ERR(ns->f_bdev)) {
+		ret = PTR_ERR(ns->f_bdev);
 		if (ret != -ENOTBLK) {
 			pr_err("failed to open block device %s: (%d)\n",
 					ns->device_path, ret);
 		}
-		ns->bdev_handle = NULL;
+		ns->f_bdev = NULL;
 		return ret;
 	}
-	ns->bdev = ns->bdev_handle->bdev;
+	ns->bdev = F_BDEV(ns->f_bdev);
 	ns->size = bdev_nr_bytes(ns->bdev);
 	ns->blksize_shift = blksize_bits(bdev_logical_block_size(ns->bdev));
 
drivers/nvme/target/nvmet.h +1 -1
index 6c8acebe1a1a..1d8a007e572d 100644
@@ -58,7 +58,7 @@
 
 struct nvmet_ns {
 	struct percpu_ref	ref;
-	struct bdev_handle	*bdev_handle;
+	struct file		*f_bdev;
 	struct block_device	*bdev;
 	struct file		*file;
 	bool			readonly;
Signature · 1 line
2.42.0
author maintainer
#22 lore raw

RFC PATCH 16/34 s390: port block device access to file

In reply to Christian Brauner
---
 drivers/s390/block/dasd.c       | 10 +++++-----
 drivers/s390/block/dasd_genhd.c | 36 ++++++++++++++++++------------------
 drivers/s390/block/dasd_int.h   |  2 +-
 drivers/s390/block/dasd_ioctl.c |  2 +-
 4 files changed, 25 insertions(+), 25 deletions(-)
drivers/s390/block/dasd.c +5 -5
index 833cfab7d877..e462dcad84b1 100644
@@ -412,7 +412,7 @@ dasd_state_ready_to_online(struct dasd_device * device)
 					KOBJ_CHANGE);
 			return 0;
 		}
-		disk_uevent(device->block->bdev_handle->bdev->bd_disk,
+		disk_uevent(F_BDEV(device->block->f_bdev)->bd_disk,
 			    KOBJ_CHANGE);
 	}
 	return 0;
@@ -433,7 +433,7 @@ static int dasd_state_online_to_ready(struct dasd_device *device)
 
 	device->state = DASD_STATE_READY;
 	if (device->block && !(device->features & DASD_FEATURE_USERAW))
-		disk_uevent(device->block->bdev_handle->bdev->bd_disk,
+		disk_uevent(F_BDEV(device->block->f_bdev)->bd_disk,
 			    KOBJ_CHANGE);
 	return 0;
 }
@@ -3594,7 +3594,7 @@ int dasd_generic_set_offline(struct ccw_device *cdev)
 	 * in the other openers.
 	 */
 	if (device->block) {
-		max_count = device->block->bdev_handle ? 0 : -1;
+		max_count = device->block->f_bdev ? 0 : -1;
 		open_count = atomic_read(&device->block->open_count);
 		if (open_count > max_count) {
 			if (open_count > 0)
@@ -3640,8 +3640,8 @@ int dasd_generic_set_offline(struct ccw_device *cdev)
 		 * so sync bdev first and then wait for our queues to become
 		 * empty
 		 */
-		if (device->block && device->block->bdev_handle)
-			bdev_mark_dead(device->block->bdev_handle->bdev, false);
+		if (device->block && device->block->f_bdev)
+			bdev_mark_dead(F_BDEV(device->block->f_bdev), false);
 		dasd_schedule_device_bh(device);
 		rc = wait_event_interruptible(shutdown_waitq,
 					      _wait_for_empty_queues(device));
drivers/s390/block/dasd_genhd.c +18 -18
index 55e3abe94cde..4c389b7416f8 100644
@@ -127,15 +127,15 @@ void dasd_gendisk_free(struct dasd_block *block)
  */
 int dasd_scan_partitions(struct dasd_block *block)
 {
-	struct bdev_handle *bdev_handle;
+	struct file *f_bdev;
 	int rc;
 
-	bdev_handle = bdev_open_by_dev(disk_devt(block->gdp), BLK_OPEN_READ,
+	f_bdev = bdev_file_open_by_dev(disk_devt(block->gdp), BLK_OPEN_READ,
 				       NULL, NULL);
-	if (IS_ERR(bdev_handle)) {
+	if (IS_ERR(f_bdev)) {
 		DBF_DEV_EVENT(DBF_ERR, block->base,
 			      "scan partitions error, blkdev_get returned %ld",
-			      PTR_ERR(bdev_handle));
+			      PTR_ERR(f_bdev));
 		return -ENODEV;
 	}
 
@@ -147,15 +147,15 @@ int dasd_scan_partitions(struct dasd_block *block)
 				"scan partitions error, rc %d", rc);
 
 	/*
-	 * Since the matching bdev_release() call to the
-	 * bdev_open_by_path() in this function is not called before
+	 * Since the matching fput() call to the
+	 * bdev_file_open_by_path() in this function is not called before
 	 * dasd_destroy_partitions the offline open_count limit needs to be
-	 * increased from 0 to 1. This is done by setting device->bdev_handle
+	 * increased from 0 to 1. This is done by setting device->f_bdev
 	 * (see dasd_generic_set_offline). As long as the partition detection
 	 * is running no offline should be allowed. That is why the assignment
-	 * to block->bdev_handle is done AFTER the BLKRRPART ioctl.
+	 * to block->f_bdev is done AFTER the BLKRRPART ioctl.
 	 */
-	block->bdev_handle = bdev_handle;
+	block->f_bdev = f_bdev;
 	return 0;
 }
 
@@ -165,21 +165,21 @@ int dasd_scan_partitions(struct dasd_block *block)
  */
 void dasd_destroy_partitions(struct dasd_block *block)
 {
-	struct bdev_handle *bdev_handle;
+	struct file *f_bdev;
 
 	/*
-	 * Get the bdev_handle pointer from the device structure and clear
-	 * device->bdev_handle to lower the offline open_count limit again.
+	 * Get the f_bdev pointer from the device structure and clear
+	 * device->f_bdev to lower the offline open_count limit again.
 	 */
-	bdev_handle = block->bdev_handle;
-	block->bdev_handle = NULL;
+	f_bdev = block->f_bdev;
+	block->f_bdev = NULL;
 
-	mutex_lock(&bdev_handle->bdev->bd_disk->open_mutex);
-	bdev_disk_changed(bdev_handle->bdev->bd_disk, true);
-	mutex_unlock(&bdev_handle->bdev->bd_disk->open_mutex);
+	mutex_lock(&F_BDEV(f_bdev)->bd_disk->open_mutex);
+	bdev_disk_changed(F_BDEV(f_bdev)->bd_disk, true);
+	mutex_unlock(&F_BDEV(f_bdev)->bd_disk->open_mutex);
 
 	/* Matching blkdev_put to the blkdev_get in dasd_scan_partitions. */
-	bdev_release(bdev_handle);
+	fput(f_bdev);
 }
 
 int dasd_gendisk_init(void)
drivers/s390/block/dasd_int.h +1 -1
index 1b1b8a41c4d4..a2c16434d89f 100644
@@ -650,7 +650,7 @@ struct dasd_block {
 	struct gendisk *gdp;
 	spinlock_t request_queue_lock;
 	struct blk_mq_tag_set tag_set;
-	struct bdev_handle *bdev_handle;
+	struct file *f_bdev;
 	atomic_t open_count;
 
 	unsigned long blocks;	   /* size of volume in blocks */
drivers/s390/block/dasd_ioctl.c +1 -1
index 61b9675e2a67..c73419a09bbd 100644
@@ -537,7 +537,7 @@ static int __dasd_ioctl_information(struct dasd_block *block,
 	 * This must be hidden from user-space.
 	 */
 	dasd_info->open_count = atomic_read(&block->open_count);
-	if (!block->bdev_handle)
+	if (!block->f_bdev)
 		dasd_info->open_count++;
 
 	/*
Signature · 1 line
2.42.0
author maintainer
#23 lore raw

RFC PATCH 17/34 target: port block device access to file

In reply to Christian Brauner
---
 drivers/target/target_core_iblock.c | 18 +++++++++---------
 drivers/target/target_core_iblock.h |  2 +-
 drivers/target/target_core_pscsi.c  | 22 +++++++++++-----------
 drivers/target/target_core_pscsi.h  |  2 +-
 4 files changed, 22 insertions(+), 22 deletions(-)
drivers/target/target_core_iblock.c +9 -9
index 8eb9eb7ce5df..79e79ec06856 100644
@@ -91,7 +91,7 @@ static int iblock_configure_device(struct se_device *dev)
 {
 	struct iblock_dev *ib_dev = IBLOCK_DEV(dev);
 	struct request_queue *q;
-	struct bdev_handle *bdev_handle;
+	struct file *f_bdev;
 	struct block_device *bd;
 	struct blk_integrity *bi;
 	blk_mode_t mode = BLK_OPEN_READ;
@@ -117,14 +117,14 @@ static int iblock_configure_device(struct se_device *dev)
 	else
 		dev->dev_flags |= DF_READ_ONLY;
 
-	bdev_handle = bdev_open_by_path(ib_dev->ibd_udev_path, mode, ib_dev,
+	f_bdev = bdev_file_open_by_path(ib_dev->ibd_udev_path, mode, ib_dev,
 					NULL);
-	if (IS_ERR(bdev_handle)) {
-		ret = PTR_ERR(bdev_handle);
+	if (IS_ERR(f_bdev)) {
+		ret = PTR_ERR(f_bdev);
 		goto out_free_bioset;
 	}
-	ib_dev->ibd_bdev_handle = bdev_handle;
-	ib_dev->ibd_bd = bd = bdev_handle->bdev;
+	ib_dev->ibd_f_bdev = f_bdev;
+	ib_dev->ibd_bd = bd = F_BDEV(f_bdev);
 
 	q = bdev_get_queue(bd);
 
@@ -180,7 +180,7 @@ static int iblock_configure_device(struct se_device *dev)
 	return 0;
 
 out_blkdev_put:
-	bdev_release(ib_dev->ibd_bdev_handle);
+	fput(ib_dev->ibd_f_bdev);
 out_free_bioset:
 	bioset_exit(&ib_dev->ibd_bio_set);
 out:
@@ -205,8 +205,8 @@ static void iblock_destroy_device(struct se_device *dev)
 {
 	struct iblock_dev *ib_dev = IBLOCK_DEV(dev);
 
-	if (ib_dev->ibd_bdev_handle)
-		bdev_release(ib_dev->ibd_bdev_handle);
+	if (ib_dev->ibd_f_bdev)
+		fput(ib_dev->ibd_f_bdev);
 	bioset_exit(&ib_dev->ibd_bio_set);
 }
 
drivers/target/target_core_iblock.h +1 -1
index 683f9a55945b..769b6b7731a9 100644
@@ -32,7 +32,7 @@ struct iblock_dev {
 	u32	ibd_flags;
 	struct bio_set	ibd_bio_set;
 	struct block_device *ibd_bd;
-	struct bdev_handle *ibd_bdev_handle;
+	struct file *ibd_f_bdev;
 	bool ibd_readonly;
 	struct iblock_dev_plug *ibd_plug;
 } ____cacheline_aligned;
drivers/target/target_core_pscsi.c +11 -11
index 41b7489d37ce..9f7e423ed11b 100644
@@ -352,7 +352,7 @@ static int pscsi_create_type_disk(struct se_device *dev, struct scsi_device *sd)
 	struct pscsi_hba_virt *phv = dev->se_hba->hba_ptr;
 	struct pscsi_dev_virt *pdv = PSCSI_DEV(dev);
 	struct Scsi_Host *sh = sd->host;
-	struct bdev_handle *bdev_handle;
+	struct file *f_bdev;
 	int ret;
 
 	if (scsi_device_get(sd)) {
@@ -366,18 +366,18 @@ static int pscsi_create_type_disk(struct se_device *dev, struct scsi_device *sd)
 	 * Claim exclusive struct block_device access to struct scsi_device
 	 * for TYPE_DISK and TYPE_ZBC using supplied udev_path
 	 */
-	bdev_handle = bdev_open_by_path(dev->udev_path,
+	f_bdev = bdev_file_open_by_path(dev->udev_path,
 				BLK_OPEN_WRITE | BLK_OPEN_READ, pdv, NULL);
-	if (IS_ERR(bdev_handle)) {
+	if (IS_ERR(f_bdev)) {
 		pr_err("pSCSI: bdev_open_by_path() failed\n");
 		scsi_device_put(sd);
-		return PTR_ERR(bdev_handle);
+		return PTR_ERR(f_bdev);
 	}
-	pdv->pdv_bdev_handle = bdev_handle;
+	pdv->pdv_f_bdev = f_bdev;
 
 	ret = pscsi_add_device_to_list(dev, sd);
 	if (ret) {
-		bdev_release(bdev_handle);
+		fput(f_bdev);
 		scsi_device_put(sd);
 		return ret;
 	}
@@ -564,9 +564,9 @@ static void pscsi_destroy_device(struct se_device *dev)
 		 * from pscsi_create_type_disk()
 		 */
 		if ((sd->type == TYPE_DISK || sd->type == TYPE_ZBC) &&
-		    pdv->pdv_bdev_handle) {
-			bdev_release(pdv->pdv_bdev_handle);
-			pdv->pdv_bdev_handle = NULL;
+		    pdv->pdv_f_bdev) {
+			fput(pdv->pdv_f_bdev);
+			pdv->pdv_f_bdev = NULL;
 		}
 		/*
 		 * For HBA mode PHV_LLD_SCSI_HOST_NO, release the reference
@@ -994,8 +994,8 @@ static sector_t pscsi_get_blocks(struct se_device *dev)
 {
 	struct pscsi_dev_virt *pdv = PSCSI_DEV(dev);
 
-	if (pdv->pdv_bdev_handle)
-		return bdev_nr_sectors(pdv->pdv_bdev_handle->bdev);
+	if (pdv->pdv_f_bdev)
+		return bdev_nr_sectors(F_BDEV(pdv->pdv_f_bdev));
 	return 0;
 }
 
drivers/target/target_core_pscsi.h +1 -1
index b0a3ef136592..8cdbe3f32262 100644
@@ -37,7 +37,7 @@ struct pscsi_dev_virt {
 	int	pdv_channel_id;
 	int	pdv_target_id;
 	int	pdv_lun_id;
-	struct bdev_handle *pdv_bdev_handle;
+	struct file *pdv_f_bdev;
 	struct scsi_device *pdv_sd;
 	struct Scsi_Host *pdv_lld_host;
 } ____cacheline_aligned;
Signature · 1 line
2.42.0
author maintainer
#24 lore raw

RFC PATCH 18/34 bcachefs: port block device access to file

In reply to Christian Brauner
---
 fs/bcachefs/super-io.c    | 20 ++++++++++----------
 fs/bcachefs/super_types.h |  2 +-
 2 files changed, 11 insertions(+), 11 deletions(-)
fs/bcachefs/super-io.c +10 -10
index 801590bbc68c..927b977dfbda 100644
@@ -163,8 +163,8 @@ void bch2_sb_field_delete(struct bch_sb_handle *sb,
 void bch2_free_super(struct bch_sb_handle *sb)
 {
 	kfree(sb->bio);
-	if (!IS_ERR_OR_NULL(sb->bdev_handle))
-		bdev_release(sb->bdev_handle);
+	if (!IS_ERR_OR_NULL(sb->s_f_bdev))
+		fput(sb->s_f_bdev);
 	kfree(sb->holder);
 	kfree(sb->sb_name);
 
@@ -691,22 +691,22 @@ int bch2_read_super(const char *path, struct bch_opts *opts,
 	if (!opt_get(*opts, nochanges))
 		sb->mode |= BLK_OPEN_WRITE;
 
-	sb->bdev_handle = bdev_open_by_path(path, sb->mode, sb->holder, &bch2_sb_handle_bdev_ops);
-	if (IS_ERR(sb->bdev_handle) &&
-	    PTR_ERR(sb->bdev_handle) == -EACCES &&
+	sb->s_f_bdev = bdev_file_open_by_path(path, sb->mode, sb->holder, &bch2_sb_handle_bdev_ops);
+	if (IS_ERR(sb->s_f_bdev) &&
+	    PTR_ERR(sb->s_f_bdev) == -EACCES &&
 	    opt_get(*opts, read_only)) {
 		sb->mode &= ~BLK_OPEN_WRITE;
 
-		sb->bdev_handle = bdev_open_by_path(path, sb->mode, sb->holder, &bch2_sb_handle_bdev_ops);
-		if (!IS_ERR(sb->bdev_handle))
+		sb->s_f_bdev = bdev_file_open_by_path(path, sb->mode, sb->holder, &bch2_sb_handle_bdev_ops);
+		if (!IS_ERR(sb->s_f_bdev))
 			opt_set(*opts, nochanges, true);
 	}
 
-	if (IS_ERR(sb->bdev_handle)) {
-		ret = PTR_ERR(sb->bdev_handle);
+	if (IS_ERR(sb->s_f_bdev)) {
+		ret = PTR_ERR(sb->s_f_bdev);
 		goto out;
 	}
-	sb->bdev = sb->bdev_handle->bdev;
+	sb->bdev = F_BDEV(sb->s_f_bdev);
 
 	ret = bch2_sb_realloc(sb, 0);
 	if (ret) {
fs/bcachefs/super_types.h +1 -1
index b2119686e2e1..e98df6428d38 100644
@@ -4,7 +4,7 @@
 
 struct bch_sb_handle {
 	struct bch_sb		*sb;
-	struct bdev_handle	*bdev_handle;
+	struct file		*s_f_bdev;
 	struct block_device	*bdev;
 	char			*sb_name;
 	struct bio		*bio;
Signature · 1 line
2.42.0
author maintainer
#25 lore raw

RFC PATCH 19/34 btrfs: port device access to file

In reply to Christian Brauner
---
 fs/btrfs/dev-replace.c | 14 ++++----
 fs/btrfs/ioctl.c       | 16 ++++-----
 fs/btrfs/volumes.c     | 92 +++++++++++++++++++++++++-------------------------
 fs/btrfs/volumes.h     |  4 +--
 4 files changed, 63 insertions(+), 63 deletions(-)
fs/btrfs/dev-replace.c +7 -7
index f9544fda38e9..74d171f91369 100644
@@ -246,7 +246,7 @@ static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,
 {
 	struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
 	struct btrfs_device *device;
-	struct bdev_handle *bdev_handle;
+	struct file *f_bdev;
 	struct block_device *bdev;
 	u64 devid = BTRFS_DEV_REPLACE_DEVID;
 	int ret = 0;
@@ -257,13 +257,13 @@ static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,
 		return -EINVAL;
 	}
 
-	bdev_handle = bdev_open_by_path(device_path, BLK_OPEN_WRITE,
+	f_bdev = bdev_file_open_by_path(device_path, BLK_OPEN_WRITE,
 					fs_info->bdev_holder, NULL);
-	if (IS_ERR(bdev_handle)) {
+	if (IS_ERR(f_bdev)) {
 		btrfs_err(fs_info, "target device %s is invalid!", device_path);
-		return PTR_ERR(bdev_handle);
+		return PTR_ERR(f_bdev);
 	}
-	bdev = bdev_handle->bdev;
+	bdev = F_BDEV(f_bdev);
 
 	if (!btrfs_check_device_zone_type(fs_info, bdev)) {
 		btrfs_err(fs_info,
@@ -314,7 +314,7 @@ static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,
 	device->commit_bytes_used = device->bytes_used;
 	device->fs_info = fs_info;
 	device->bdev = bdev;
-	device->bdev_handle = bdev_handle;
+	device->f_bdev = f_bdev;
 	set_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state);
 	set_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state);
 	device->dev_stats_valid = 1;
@@ -335,7 +335,7 @@ static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,
 	return 0;
 
 error:
-	bdev_release(bdev_handle);
+	fput(f_bdev);
 	return ret;
 }
 
fs/btrfs/ioctl.c +8 -8
index 41b479861b3c..2bd9e137661a 100644
@@ -2691,7 +2691,7 @@ static long btrfs_ioctl_rm_dev_v2(struct file *file, void __user *arg)
 	struct inode *inode = file_inode(file);
 	struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
 	struct btrfs_ioctl_vol_args_v2 *vol_args;
-	struct bdev_handle *bdev_handle = NULL;
+	struct file *f_bdev = NULL;
 	int ret;
 	bool cancel = false;
 
@@ -2728,7 +2728,7 @@ static long btrfs_ioctl_rm_dev_v2(struct file *file, void __user *arg)
 		goto err_drop;
 
 	/* Exclusive operation is now claimed */
-	ret = btrfs_rm_device(fs_info, &args, &bdev_handle);
+	ret = btrfs_rm_device(fs_info, &args, &f_bdev);
 
 	btrfs_exclop_finish(fs_info);
 
@@ -2742,8 +2742,8 @@ static long btrfs_ioctl_rm_dev_v2(struct file *file, void __user *arg)
 	}
 err_drop:
 	mnt_drop_write_file(file);
-	if (bdev_handle)
-		bdev_release(bdev_handle);
+	if (f_bdev)
+		fput(f_bdev);
 out:
 	btrfs_put_dev_args_from_path(&args);
 	kfree(vol_args);
@@ -2756,7 +2756,7 @@ static long btrfs_ioctl_rm_dev(struct file *file, void __user *arg)
 	struct inode *inode = file_inode(file);
 	struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
 	struct btrfs_ioctl_vol_args *vol_args;
-	struct bdev_handle *bdev_handle = NULL;
+	struct file *f_bdev = NULL;
 	int ret;
 	bool cancel = false;
 
@@ -2783,15 +2783,15 @@ static long btrfs_ioctl_rm_dev(struct file *file, void __user *arg)
 	ret = exclop_start_or_cancel_reloc(fs_info, BTRFS_EXCLOP_DEV_REMOVE,
 					   cancel);
 	if (ret == 0) {
-		ret = btrfs_rm_device(fs_info, &args, &bdev_handle);
+		ret = btrfs_rm_device(fs_info, &args, &f_bdev);
 		if (!ret)
 			btrfs_info(fs_info, "disk deleted %s", vol_args->name);
 		btrfs_exclop_finish(fs_info);
 	}
 
 	mnt_drop_write_file(file);
-	if (bdev_handle)
-		bdev_release(bdev_handle);
+	if (f_bdev)
+		fput(f_bdev);
 out:
 	btrfs_put_dev_args_from_path(&args);
 	kfree(vol_args);
fs/btrfs/volumes.c +46 -46

271 lines not on this page · raw message

fs/btrfs/volumes.h +2 -2
index 9cc374864a79..78de9ab6652a 100644
@@ -90,7 +90,7 @@ struct btrfs_device {
 
 	u64 generation;
 
-	struct bdev_handle *bdev_handle;
+	struct file *f_bdev;
 	struct block_device *bdev;
 
 	struct btrfs_zoned_device_info *zone_info;
@@ -646,7 +646,7 @@ struct btrfs_device *btrfs_alloc_device(struct btrfs_fs_info *fs_info,
 void btrfs_put_dev_args_from_path(struct btrfs_dev_lookup_args *args);
 int btrfs_rm_device(struct btrfs_fs_info *fs_info,
 		    struct btrfs_dev_lookup_args *args,
-		    struct bdev_handle **bdev_handle);
+		    struct file **f_bdev);
 void __exit btrfs_cleanup_fs_uuids(void);
 int btrfs_num_copies(struct btrfs_fs_info *fs_info, u64 logical, u64 len);
 int btrfs_grow_device(struct btrfs_trans_handle *trans,
Signature · 1 line
2.42.0
author maintainer
#26 lore raw

RFC PATCH 20/34 erofs: port device access to file

In reply to Christian Brauner
---
 fs/erofs/data.c     |  6 +++---
 fs/erofs/internal.h |  2 +-
 fs/erofs/super.c    | 16 ++++++++--------
 3 files changed, 12 insertions(+), 12 deletions(-)
fs/erofs/data.c +3 -3
index c98aeda8abb2..fed9153f2b83 100644
@@ -220,7 +220,7 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *map)
 			up_read(&devs->rwsem);
 			return 0;
 		}
-		map->m_bdev = dif->bdev_handle ? dif->bdev_handle->bdev : NULL;
+		map->m_bdev = dif->f_bdev ? F_BDEV(dif->f_bdev) : NULL;
 		map->m_daxdev = dif->dax_dev;
 		map->m_dax_part_off = dif->dax_part_off;
 		map->m_fscache = dif->fscache;
@@ -238,8 +238,8 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *map)
 			if (map->m_pa >= startoff &&
 			    map->m_pa < startoff + length) {
 				map->m_pa -= startoff;
-				map->m_bdev = dif->bdev_handle ?
-					      dif->bdev_handle->bdev : NULL;
+				map->m_bdev = dif->f_bdev ?
+					      F_BDEV(dif->f_bdev) : NULL;
 				map->m_daxdev = dif->dax_dev;
 				map->m_dax_part_off = dif->dax_part_off;
 				map->m_fscache = dif->fscache;
fs/erofs/internal.h +1 -1
index b0409badb017..8ad8957de64c 100644
@@ -49,7 +49,7 @@ typedef u32 erofs_blk_t;
 struct erofs_device_info {
 	char *path;
 	struct erofs_fscache *fscache;
-	struct bdev_handle *bdev_handle;
+	struct file *f_bdev;
 	struct dax_device *dax_dev;
 	u64 dax_part_off;
 
fs/erofs/super.c +8 -8
index 3789d6224513..bc0772445ad5 100644
@@ -171,7 +171,7 @@ static int erofs_init_device(struct erofs_buf *buf, struct super_block *sb,
 	struct erofs_sb_info *sbi = EROFS_SB(sb);
 	struct erofs_fscache *fscache;
 	struct erofs_deviceslot *dis;
-	struct bdev_handle *bdev_handle;
+	struct file *f_bdev;
 	void *ptr;
 
 	ptr = erofs_read_metabuf(buf, sb, erofs_blknr(sb, *pos), EROFS_KMAP);
@@ -195,12 +195,12 @@ static int erofs_init_device(struct erofs_buf *buf, struct super_block *sb,
 			return PTR_ERR(fscache);
 		dif->fscache = fscache;
 	} else if (!sbi->devs->flatdev) {
-		bdev_handle = bdev_open_by_path(dif->path, BLK_OPEN_READ,
+		f_bdev = bdev_file_open_by_path(dif->path, BLK_OPEN_READ,
 						sb->s_type, NULL);
-		if (IS_ERR(bdev_handle))
-			return PTR_ERR(bdev_handle);
-		dif->bdev_handle = bdev_handle;
-		dif->dax_dev = fs_dax_get_by_bdev(bdev_handle->bdev,
+		if (IS_ERR(f_bdev))
+			return PTR_ERR(f_bdev);
+		dif->f_bdev = f_bdev;
+		dif->dax_dev = fs_dax_get_by_bdev(F_BDEV(f_bdev),
 				&dif->dax_part_off, NULL, NULL);
 	}
 
@@ -748,8 +748,8 @@ static int erofs_release_device_info(int id, void *ptr, void *data)
 	struct erofs_device_info *dif = ptr;
 
 	fs_put_dax(dif->dax_dev, NULL);
-	if (dif->bdev_handle)
-		bdev_release(dif->bdev_handle);
+	if (dif->f_bdev)
+		fput(dif->f_bdev);
 	erofs_fscache_unregister_cookie(dif->fscache);
 	dif->fscache = NULL;
 	kfree(dif->path);
Signature · 1 line
2.42.0
author maintainer
#27 lore raw

RFC PATCH 21/34 ext4: port block device access to file

In reply to Christian Brauner
---
 fs/ext4/ext4.h  |  2 +-
 fs/ext4/fsmap.c |  8 ++++----
 fs/ext4/super.c | 52 ++++++++++++++++++++++++++--------------------------
 3 files changed, 31 insertions(+), 31 deletions(-)
fs/ext4/ext4.h +1 -1
index a5d784872303..fa0de10ae12b 100644
@@ -1548,7 +1548,7 @@ struct ext4_sb_info {
 	unsigned long s_commit_interval;
 	u32 s_max_batch_time;
 	u32 s_min_batch_time;
-	struct bdev_handle *s_journal_bdev_handle;
+	struct file *s_journal_f_bdev;
 #ifdef CONFIG_QUOTA
 	/* Names of quota files with journalled quota */
 	char __rcu *s_qf_names[EXT4_MAXQUOTAS];
fs/ext4/fsmap.c +4 -4
index 11e6f33677a2..6dac2866c3f1 100644
@@ -576,9 +576,9 @@ static bool ext4_getfsmap_is_valid_device(struct super_block *sb,
 	if (fm->fmr_device == 0 || fm->fmr_device == UINT_MAX ||
 	    fm->fmr_device == new_encode_dev(sb->s_bdev->bd_dev))
 		return true;
-	if (EXT4_SB(sb)->s_journal_bdev_handle &&
+	if (EXT4_SB(sb)->s_journal_f_bdev &&
 	    fm->fmr_device ==
-	    new_encode_dev(EXT4_SB(sb)->s_journal_bdev_handle->bdev->bd_dev))
+	    new_encode_dev(F_BDEV(EXT4_SB(sb)->s_journal_f_bdev)->bd_dev))
 		return true;
 	return false;
 }
@@ -648,9 +648,9 @@ int ext4_getfsmap(struct super_block *sb, struct ext4_fsmap_head *head,
 	memset(handlers, 0, sizeof(handlers));
 	handlers[0].gfd_dev = new_encode_dev(sb->s_bdev->bd_dev);
 	handlers[0].gfd_fn = ext4_getfsmap_datadev;
-	if (EXT4_SB(sb)->s_journal_bdev_handle) {
+	if (EXT4_SB(sb)->s_journal_f_bdev) {
 		handlers[1].gfd_dev = new_encode_dev(
-			EXT4_SB(sb)->s_journal_bdev_handle->bdev->bd_dev);
+			F_BDEV(EXT4_SB(sb)->s_journal_f_bdev)->bd_dev);
 		handlers[1].gfd_fn = ext4_getfsmap_logdev;
 	}
 
fs/ext4/super.c +26 -26

138 lines not on this page · raw message

Signature · 1 line
2.42.0
author maintainer
#28 lore raw

RFC PATCH 22/34 f2fs: port block device access to files

In reply to Christian Brauner
---
 fs/f2fs/f2fs.h  |  2 +-
 fs/f2fs/super.c | 12 ++++++------
 2 files changed, 7 insertions(+), 7 deletions(-)
fs/f2fs/f2fs.h +1 -1
index 9043cedfa12b..9a73eed3b424 100644
@@ -1234,7 +1234,7 @@ struct f2fs_bio_info {
 #define FDEV(i)				(sbi->devs[i])
 #define RDEV(i)				(raw_super->devs[i])
 struct f2fs_dev_info {
-	struct bdev_handle *bdev_handle;
+	struct file *f_bdev;
 	struct block_device *bdev;
 	char path[MAX_PATH_LEN];
 	unsigned int total_segments;
fs/f2fs/super.c +6 -6
index 93b8a844b207..5e0687a85b4d 100644
@@ -1610,7 +1610,7 @@ static void destroy_device_list(struct f2fs_sb_info *sbi)
 
 	for (i = 0; i < sbi->s_ndevs; i++) {
 		if (i > 0)
-			bdev_release(FDEV(i).bdev_handle);
+			fput(FDEV(i).f_bdev);
 #ifdef CONFIG_BLK_DEV_ZONED
 		kvfree(FDEV(i).blkz_seq);
 #endif
@@ -4247,7 +4247,7 @@ static int f2fs_scan_devices(struct f2fs_sb_info *sbi)
 
 	for (i = 0; i < max_devices; i++) {
 		if (i == 0)
-			FDEV(0).bdev_handle = sb_bdev_handle(sbi->sb);
+			FDEV(0).f_bdev = sbi->sb->s_f_bdev;
 		else if (!RDEV(i).path[0])
 			break;
 
@@ -4267,14 +4267,14 @@ static int f2fs_scan_devices(struct f2fs_sb_info *sbi)
 				FDEV(i).end_blk = FDEV(i).start_blk +
 					(FDEV(i).total_segments <<
 					sbi->log_blocks_per_seg) - 1;
-				FDEV(i).bdev_handle = bdev_open_by_path(
+				FDEV(i).f_bdev = bdev_file_open_by_path(
 					FDEV(i).path, mode, sbi->sb, NULL);
 			}
 		}
-		if (IS_ERR(FDEV(i).bdev_handle))
-			return PTR_ERR(FDEV(i).bdev_handle);
+		if (IS_ERR(FDEV(i).f_bdev))
+			return PTR_ERR(FDEV(i).f_bdev);
 
-		FDEV(i).bdev = FDEV(i).bdev_handle->bdev;
+		FDEV(i).bdev = F_BDEV(FDEV(i).f_bdev);
 		/* to release errored devices */
 		sbi->s_ndevs = i + 1;
 
Signature · 1 line
2.42.0
author maintainer
#29 lore raw

RFC PATCH 23/34 jfs: port block device access to file

In reply to Christian Brauner
---
 fs/jfs/jfs_logmgr.c | 26 +++++++++++++-------------
 fs/jfs/jfs_logmgr.h |  2 +-
 fs/jfs/jfs_mount.c  |  2 +-
 3 files changed, 15 insertions(+), 15 deletions(-)
fs/jfs/jfs_logmgr.c +13 -13
index 8691463956d1..7dd6b3b6fde0 100644
@@ -1058,7 +1058,7 @@ void jfs_syncpt(struct jfs_log *log, int hard_sync)
 int lmLogOpen(struct super_block *sb)
 {
 	int rc;
-	struct bdev_handle *bdev_handle;
+	struct file *f_bdev;
 	struct jfs_log *log;
 	struct jfs_sb_info *sbi = JFS_SBI(sb);
 
@@ -1070,7 +1070,7 @@ int lmLogOpen(struct super_block *sb)
 
 	mutex_lock(&jfs_log_mutex);
 	list_for_each_entry(log, &jfs_external_logs, journal_list) {
-		if (log->bdev_handle->bdev->bd_dev == sbi->logdev) {
+		if (F_BDEV(log->f_bdev)->bd_dev == sbi->logdev) {
 			if (!uuid_equal(&log->uuid, &sbi->loguuid)) {
 				jfs_warn("wrong uuid on JFS journal");
 				mutex_unlock(&jfs_log_mutex);
@@ -1100,14 +1100,14 @@ int lmLogOpen(struct super_block *sb)
 	 * file systems to log may have n-to-1 relationship;
 	 */
 
-	bdev_handle = bdev_open_by_dev(sbi->logdev,
+	f_bdev = bdev_file_open_by_dev(sbi->logdev,
 			BLK_OPEN_READ | BLK_OPEN_WRITE, log, NULL);
-	if (IS_ERR(bdev_handle)) {
-		rc = PTR_ERR(bdev_handle);
+	if (IS_ERR(f_bdev)) {
+		rc = PTR_ERR(f_bdev);
 		goto free;
 	}
 
-	log->bdev_handle = bdev_handle;
+	log->f_bdev = f_bdev;
 	uuid_copy(&log->uuid, &sbi->loguuid);
 
 	/*
@@ -1141,7 +1141,7 @@ int lmLogOpen(struct super_block *sb)
 	lbmLogShutdown(log);
 
       close:		/* close external log device */
-	bdev_release(bdev_handle);
+	fput(f_bdev);
 
       free:		/* free log descriptor */
 	mutex_unlock(&jfs_log_mutex);
@@ -1162,7 +1162,7 @@ static int open_inline_log(struct super_block *sb)
 	init_waitqueue_head(&log->syncwait);
 
 	set_bit(log_INLINELOG, &log->flag);
-	log->bdev_handle = sb_bdev_handle(sb);
+	log->f_bdev = sb->s_f_bdev;
 	log->base = addressPXD(&JFS_SBI(sb)->logpxd);
 	log->size = lengthPXD(&JFS_SBI(sb)->logpxd) >>
 	    (L2LOGPSIZE - sb->s_blocksize_bits);
@@ -1436,7 +1436,7 @@ int lmLogClose(struct super_block *sb)
 {
 	struct jfs_sb_info *sbi = JFS_SBI(sb);
 	struct jfs_log *log = sbi->log;
-	struct bdev_handle *bdev_handle;
+	struct file *f_bdev;
 	int rc = 0;
 
 	jfs_info("lmLogClose: log:0x%p", log);
@@ -1482,10 +1482,10 @@ int lmLogClose(struct super_block *sb)
 	 *	external log as separate logical volume
 	 */
 	list_del(&log->journal_list);
-	bdev_handle = log->bdev_handle;
+	f_bdev = log->f_bdev;
 	rc = lmLogShutdown(log);
 
-	bdev_release(bdev_handle);
+	fput(f_bdev);
 
 	kfree(log);
 
@@ -1972,7 +1972,7 @@ static int lbmRead(struct jfs_log * log, int pn, struct lbuf ** bpp)
 
 	bp->l_flag |= lbmREAD;
 
-	bio = bio_alloc(log->bdev_handle->bdev, 1, REQ_OP_READ, GFP_NOFS);
+	bio = bio_alloc(F_BDEV(log->f_bdev), 1, REQ_OP_READ, GFP_NOFS);
 	bio->bi_iter.bi_sector = bp->l_blkno << (log->l2bsize - 9);
 	__bio_add_page(bio, bp->l_page, LOGPSIZE, bp->l_offset);
 	BUG_ON(bio->bi_iter.bi_size != LOGPSIZE);
@@ -2115,7 +2115,7 @@ static void lbmStartIO(struct lbuf * bp)
 	jfs_info("lbmStartIO");
 
 	if (!log->no_integrity)
-		bdev = log->bdev_handle->bdev;
+		bdev = F_BDEV(log->f_bdev);
 
 	bio = bio_alloc(bdev, 1, REQ_OP_WRITE | REQ_SYNC,
 			GFP_NOFS);
fs/jfs/jfs_logmgr.h +1 -1
index 84aa2d253907..c7d2d8fb0204 100644
@@ -356,7 +356,7 @@ struct jfs_log {
 				 *    before writing syncpt.
 				 */
 	struct list_head journal_list; /* Global list */
-	struct bdev_handle *bdev_handle; /* 4: log lv pointer */
+	struct file *f_bdev;	/* 4: log lv pointer */
 	int serial;		/* 4: log mount serial number */
 
 	s64 base;		/* @8: log extent address (inline log ) */
fs/jfs/jfs_mount.c +1 -1
index 415eb65a36ff..035ab9de4b4f 100644
@@ -431,7 +431,7 @@ int updateSuper(struct super_block *sb, uint state)
 	if (state == FM_MOUNT) {
 		/* record log's dev_t and mount serial number */
 		j_sb->s_logdev = cpu_to_le32(
-			new_encode_dev(sbi->log->bdev_handle->bdev->bd_dev));
+			new_encode_dev(F_BDEV(sbi->log->f_bdev)->bd_dev));
 		j_sb->s_logserial = cpu_to_le32(sbi->log->serial);
 	} else if (state == FM_CLEAN) {
 		/*
Signature · 1 line
2.42.0
author maintainer
#30 lore raw

RFC PATCH 24/34 nfs: port block device access to files

In reply to Christian Brauner
---
 fs/nfs/blocklayout/blocklayout.h |  2 +-
 fs/nfs/blocklayout/dev.c         | 68 ++++++++++++++++++++--------------------
 2 files changed, 35 insertions(+), 35 deletions(-)
fs/nfs/blocklayout/blocklayout.h +1 -1
index b4294a8aa2d4..5f9d9a823c9b 100644
@@ -108,7 +108,7 @@ struct pnfs_block_dev {
 	struct pnfs_block_dev		*children;
 	u64				chunk_size;
 
-	struct bdev_handle		*bdev_handle;
+	struct file			*f_bdev;
 	u64				disk_offset;
 
 	u64				pr_key;
fs/nfs/blocklayout/dev.c +34 -34

155 lines not on this page · raw message

Signature · 1 line
2.42.0
author maintainer
#31 lore raw

RFC PATCH 25/34 ocfs2: port block device access to file

In reply to Christian Brauner
---
 fs/ocfs2/cluster/heartbeat.c | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)
fs/ocfs2/cluster/heartbeat.c +16 -16
index 4d7efefa98c5..e212961493d4 100644
@@ -213,7 +213,7 @@ struct o2hb_region {
 	unsigned int		hr_num_pages;
 
 	struct page             **hr_slot_data;
-	struct bdev_handle	*hr_bdev_handle;
+	struct file		*hr_f_bdev;
 	struct o2hb_disk_slot	*hr_slots;
 
 	/* live node map of this region */
@@ -263,7 +263,7 @@ struct o2hb_region {
 
 static inline struct block_device *reg_bdev(struct o2hb_region *reg)
 {
-	return reg->hr_bdev_handle ? reg->hr_bdev_handle->bdev : NULL;
+	return reg->hr_f_bdev ? F_BDEV(reg->hr_f_bdev) : NULL;
 }
 
 struct o2hb_bio_wait_ctxt {
@@ -1509,8 +1509,8 @@ static void o2hb_region_release(struct config_item *item)
 		kfree(reg->hr_slot_data);
 	}
 
-	if (reg->hr_bdev_handle)
-		bdev_release(reg->hr_bdev_handle);
+	if (reg->hr_f_bdev)
+		fput(reg->hr_f_bdev);
 
 	kfree(reg->hr_slots);
 
@@ -1569,7 +1569,7 @@ static ssize_t o2hb_region_block_bytes_store(struct config_item *item,
 	unsigned long block_bytes;
 	unsigned int block_bits;
 
-	if (reg->hr_bdev_handle)
+	if (reg->hr_f_bdev)
 		return -EINVAL;
 
 	status = o2hb_read_block_input(reg, page, &block_bytes,
@@ -1598,7 +1598,7 @@ static ssize_t o2hb_region_start_block_store(struct config_item *item,
 	char *p = (char *)page;
 	ssize_t ret;
 
-	if (reg->hr_bdev_handle)
+	if (reg->hr_f_bdev)
 		return -EINVAL;
 
 	ret = kstrtoull(p, 0, &tmp);
@@ -1623,7 +1623,7 @@ static ssize_t o2hb_region_blocks_store(struct config_item *item,
 	unsigned long tmp;
 	char *p = (char *)page;
 
-	if (reg->hr_bdev_handle)
+	if (reg->hr_f_bdev)
 		return -EINVAL;
 
 	tmp = simple_strtoul(p, &p, 0);
@@ -1642,7 +1642,7 @@ static ssize_t o2hb_region_dev_show(struct config_item *item, char *page)
 {
 	unsigned int ret = 0;
 
-	if (to_o2hb_region(item)->hr_bdev_handle)
+	if (to_o2hb_region(item)->hr_f_bdev)
 		ret = sprintf(page, "%pg\n", reg_bdev(to_o2hb_region(item)));
 
 	return ret;
@@ -1753,7 +1753,7 @@ static int o2hb_populate_slot_data(struct o2hb_region *reg)
 }
 
 /*
- * this is acting as commit; we set up all of hr_bdev_handle and hr_task or
+ * this is acting as commit; we set up all of hr_f_bdev and hr_task or
  * nothing
  */
 static ssize_t o2hb_region_dev_store(struct config_item *item,
@@ -1769,7 +1769,7 @@ static ssize_t o2hb_region_dev_store(struct config_item *item,
 	ssize_t ret = -EINVAL;
 	int live_threshold;
 
-	if (reg->hr_bdev_handle)
+	if (reg->hr_f_bdev)
 		goto out;
 
 	/* We can't heartbeat without having had our node number
@@ -1795,11 +1795,11 @@ static ssize_t o2hb_region_dev_store(struct config_item *item,
 	if (!S_ISBLK(f.file->f_mapping->host->i_mode))
 		goto out2;
 
-	reg->hr_bdev_handle = bdev_open_by_dev(f.file->f_mapping->host->i_rdev,
+	reg->hr_f_bdev = bdev_file_open_by_dev(f.file->f_mapping->host->i_rdev,
 			BLK_OPEN_WRITE | BLK_OPEN_READ, NULL, NULL);
-	if (IS_ERR(reg->hr_bdev_handle)) {
-		ret = PTR_ERR(reg->hr_bdev_handle);
-		reg->hr_bdev_handle = NULL;
+	if (IS_ERR(reg->hr_f_bdev)) {
+		ret = PTR_ERR(reg->hr_f_bdev);
+		reg->hr_f_bdev = NULL;
 		goto out2;
 	}
 
@@ -1903,8 +1903,8 @@ static ssize_t o2hb_region_dev_store(struct config_item *item,
 
 out3:
 	if (ret < 0) {
-		bdev_release(reg->hr_bdev_handle);
-		reg->hr_bdev_handle = NULL;
+		fput(reg->hr_f_bdev);
+		reg->hr_f_bdev = NULL;
 	}
 out2:
 	fdput(f);
Signature · 1 line
2.42.0
author maintainer
#32 lore raw

RFC PATCH 26/34 reiserfs: port block device access to file

In reply to Christian Brauner
---
 fs/reiserfs/journal.c  | 38 +++++++++++++++++++-------------------
 fs/reiserfs/procfs.c   |  2 +-
 fs/reiserfs/reiserfs.h |  8 ++++----
 3 files changed, 24 insertions(+), 24 deletions(-)
fs/reiserfs/journal.c +19 -19
index 171c912af50f..177ccb4d9bc3 100644
@@ -2386,7 +2386,7 @@ static int journal_read(struct super_block *sb)
 
 	cur_dblock = SB_ONDISK_JOURNAL_1st_BLOCK(sb);
 	reiserfs_info(sb, "checking transaction log (%pg)\n",
-		      journal->j_bdev_handle->bdev);
+		      F_BDEV(journal->j_f_bdev));
 	start = ktime_get_seconds();
 
 	/*
@@ -2447,7 +2447,7 @@ static int journal_read(struct super_block *sb)
 		 * device and journal device to be the same
 		 */
 		d_bh =
-		    reiserfs_breada(journal->j_bdev_handle->bdev, cur_dblock,
+		    reiserfs_breada(F_BDEV(journal->j_f_bdev), cur_dblock,
 				    sb->s_blocksize,
 				    SB_ONDISK_JOURNAL_1st_BLOCK(sb) +
 				    SB_ONDISK_JOURNAL_SIZE(sb));
@@ -2588,9 +2588,9 @@ static void journal_list_init(struct super_block *sb)
 
 static void release_journal_dev(struct reiserfs_journal *journal)
 {
-	if (journal->j_bdev_handle) {
-		bdev_release(journal->j_bdev_handle);
-		journal->j_bdev_handle = NULL;
+	if (journal->j_f_bdev) {
+		fput(journal->j_f_bdev);
+		journal->j_f_bdev = NULL;
 	}
 }
 
@@ -2605,7 +2605,7 @@ static int journal_init_dev(struct super_block *super,
 
 	result = 0;
 
-	journal->j_bdev_handle = NULL;
+	journal->j_f_bdev = NULL;
 	jdev = SB_ONDISK_JOURNAL_DEVICE(super) ?
 	    new_decode_dev(SB_ONDISK_JOURNAL_DEVICE(super)) : super->s_dev;
 
@@ -2616,37 +2616,37 @@ static int journal_init_dev(struct super_block *super,
 	if ((!jdev_name || !jdev_name[0])) {
 		if (jdev == super->s_dev)
 			holder = NULL;
-		journal->j_bdev_handle = bdev_open_by_dev(jdev, blkdev_mode,
+		journal->j_f_bdev = bdev_file_open_by_dev(jdev, blkdev_mode,
 							  holder, NULL);
-		if (IS_ERR(journal->j_bdev_handle)) {
-			result = PTR_ERR(journal->j_bdev_handle);
-			journal->j_bdev_handle = NULL;
+		if (IS_ERR(journal->j_f_bdev)) {
+			result = PTR_ERR(journal->j_f_bdev);
+			journal->j_f_bdev = NULL;
 			reiserfs_warning(super, "sh-458",
 					 "cannot init journal device unknown-block(%u,%u): %i",
 					 MAJOR(jdev), MINOR(jdev), result);
 			return result;
 		} else if (jdev != super->s_dev)
-			set_blocksize(journal->j_bdev_handle->bdev,
+			set_blocksize(F_BDEV(journal->j_f_bdev),
 				      super->s_blocksize);
 
 		return 0;
 	}
 
-	journal->j_bdev_handle = bdev_open_by_path(jdev_name, blkdev_mode,
+	journal->j_f_bdev = bdev_file_open_by_path(jdev_name, blkdev_mode,
 						   holder, NULL);
-	if (IS_ERR(journal->j_bdev_handle)) {
-		result = PTR_ERR(journal->j_bdev_handle);
-		journal->j_bdev_handle = NULL;
+	if (IS_ERR(journal->j_f_bdev)) {
+		result = PTR_ERR(journal->j_f_bdev);
+		journal->j_f_bdev = NULL;
 		reiserfs_warning(super, "sh-457",
 				 "journal_init_dev: Cannot open '%s': %i",
 				 jdev_name, result);
 		return result;
 	}
 
-	set_blocksize(journal->j_bdev_handle->bdev, super->s_blocksize);
+	set_blocksize(F_BDEV(journal->j_f_bdev), super->s_blocksize);
 	reiserfs_info(super,
 		      "journal_init_dev: journal device: %pg\n",
-		      journal->j_bdev_handle->bdev);
+		      F_BDEV(journal->j_f_bdev));
 	return 0;
 }
 
@@ -2804,7 +2804,7 @@ int journal_init(struct super_block *sb, const char *j_dev_name,
 				 "journal header magic %x (device %pg) does "
 				 "not match to magic found in super block %x",
 				 jh->jh_journal.jp_journal_magic,
-				 journal->j_bdev_handle->bdev,
+				 F_BDEV(journal->j_f_bdev),
 				 sb_jp_journal_magic(rs));
 		brelse(bhjh);
 		goto free_and_return;
@@ -2828,7 +2828,7 @@ int journal_init(struct super_block *sb, const char *j_dev_name,
 	reiserfs_info(sb, "journal params: device %pg, size %u, "
 		      "journal first block %u, max trans len %u, max batch %u, "
 		      "max commit age %u, max trans age %u\n",
-		      journal->j_bdev_handle->bdev,
+		      F_BDEV(journal->j_f_bdev),
 		      SB_ONDISK_JOURNAL_SIZE(sb),
 		      SB_ONDISK_JOURNAL_1st_BLOCK(sb),
 		      journal->j_trans_max,
fs/reiserfs/procfs.c +1 -1
index 83cb9402e0f9..ff90a822e8eb 100644
@@ -354,7 +354,7 @@ static int show_journal(struct seq_file *m, void *unused)
 		   "prepare: \t%12lu\n"
 		   "prepare_retry: \t%12lu\n",
 		   DJP(jp_journal_1st_block),
-		   SB_JOURNAL(sb)->j_bdev_handle->bdev,
+		   F_BDEV(SB_JOURNAL(sb)->j_f_bdev),
 		   DJP(jp_journal_dev),
 		   DJP(jp_journal_size),
 		   DJP(jp_journal_trans_max),
fs/reiserfs/reiserfs.h +4 -4
index 725667880e62..ea2f5950e5c6 100644
@@ -299,7 +299,7 @@ struct reiserfs_journal {
 	/* oldest journal block.  start here for traverse */
 	struct reiserfs_journal_cnode *j_first;
 
-	struct bdev_handle *j_bdev_handle;
+	struct file *j_f_bdev;
 
 	/* first block on s_dev of reserved area journal */
 	int j_1st_reserved_block;
@@ -2810,10 +2810,10 @@ struct reiserfs_journal_header {
 
 /* We need these to make journal.c code more readable */
 #define journal_find_get_block(s, block) __find_get_block(\
-		SB_JOURNAL(s)->j_bdev_handle->bdev, block, s->s_blocksize)
-#define journal_getblk(s, block) __getblk(SB_JOURNAL(s)->j_bdev_handle->bdev,\
+		F_BDEV(SB_JOURNAL(s)->j_f_bdev), block, s->s_blocksize)
+#define journal_getblk(s, block) __getblk(F_BDEV(SB_JOURNAL(s)->j_f_bdev),\
 		block, s->s_blocksize)
-#define journal_bread(s, block) __bread(SB_JOURNAL(s)->j_bdev_handle->bdev,\
+#define journal_bread(s, block) __bread(F_BDEV(SB_JOURNAL(s)->j_f_bdev),\
 		block, s->s_blocksize)
 
 enum reiserfs_bh_state_bits {
Signature · 1 line
2.42.0
author maintainer
#33 lore raw

RFC PATCH 27/34 bdev: remove bdev_open_by_path()

In reply to Christian Brauner
---
 block/bdev.c           | 40 ----------------------------------------
 include/linux/blkdev.h |  2 --
 2 files changed, 42 deletions(-)
block/bdev.c +0 -40
index 853731fb41ed..a5a1b6cd51ee 100644
@@ -1007,46 +1007,6 @@ struct file *bdev_file_open_by_path(const char *path, blk_mode_t mode,
 }
 EXPORT_SYMBOL(bdev_file_open_by_path);
 
-/**
- * bdev_open_by_path - open a block device by name
- * @path: path to the block device to open
- * @mode: open mode (BLK_OPEN_*)
- * @holder: exclusive holder identifier
- * @hops: holder operations
- *
- * Open the block device described by the device file at @path.  If @holder is
- * not %NULL, the block device is opened with exclusive access.  Exclusive opens
- * may nest for the same @holder.
- *
- * CONTEXT:
- * Might sleep.
- *
- * RETURNS:
- * Handle with a reference to the block_device on success, ERR_PTR(-errno) on
- * failure.
- */
-struct bdev_handle *bdev_open_by_path(const char *path, blk_mode_t mode,
-		void *holder, const struct blk_holder_ops *hops)
-{
-	struct bdev_handle *handle;
-	dev_t dev;
-	int error;
-
-	error = lookup_bdev(path, &dev);
-	if (error)
-		return ERR_PTR(error);
-
-	handle = bdev_open_by_dev(dev, mode, holder, hops);
-	if (!IS_ERR(handle) && (mode & BLK_OPEN_WRITE) &&
-	    bdev_read_only(handle->bdev)) {
-		bdev_release(handle);
-		return ERR_PTR(-EACCES);
-	}
-
-	return handle;
-}
-EXPORT_SYMBOL(bdev_open_by_path);
-
 void bdev_release(struct bdev_handle *handle)
 {
 	struct block_device *bdev = handle->bdev;
include/linux/blkdev.h +0 -2
index e8d11083acbc..8864b978fdb0 100644
@@ -1506,8 +1506,6 @@ struct bdev_handle {
 
 struct bdev_handle *bdev_open_by_dev(dev_t dev, blk_mode_t mode, void *holder,
 		const struct blk_holder_ops *hops);
-struct bdev_handle *bdev_open_by_path(const char *path, blk_mode_t mode,
-		void *holder, const struct blk_holder_ops *hops);
 struct file *bdev_file_open_by_dev(dev_t dev, blk_mode_t mode, void *holder,
 		const struct blk_holder_ops *hops);
 struct file *bdev_file_open_by_path(const char *path, blk_mode_t mode,
Signature · 1 line
2.42.0
author maintainer
#34 lore raw

RFC PATCH 28/34 bdev: make bdev_release() private to block layer

In reply to Christian Brauner

and move both of them to the private block header. There's no caller in the tree anymore that uses them directly.

---
 block/bdev.c           | 2 --
 block/blk.h            | 4 ++++
 include/linux/blkdev.h | 3 ---
 3 files changed, 4 insertions(+), 5 deletions(-)
block/bdev.c +0 -2
index a5a1b6cd51ee..80caa71a65db 100644
@@ -918,7 +918,6 @@ struct bdev_handle *bdev_open_by_dev(dev_t dev, blk_mode_t mode, void *holder,
 	kfree(handle);
 	return ERR_PTR(ret);
 }
-EXPORT_SYMBOL(bdev_open_by_dev);
 
 static unsigned blk_to_file_flags(blk_mode_t mode)
 {
@@ -1045,7 +1044,6 @@ void bdev_release(struct bdev_handle *handle)
 	blkdev_put_no_open(bdev);
 	kfree(handle);
 }
-EXPORT_SYMBOL(bdev_release);
 
 /**
  * lookup_bdev() - Look up a struct block_device by name.
block/blk.h +4 -0
index 08a358bc0919..3ec5e9b5c26c 100644
@@ -518,4 +518,8 @@ static inline int req_ref_read(struct request *req)
 	return atomic_read(&req->ref);
 }
 
+void bdev_release(struct bdev_handle *handle);
+struct bdev_handle *bdev_open_by_dev(dev_t dev, blk_mode_t mode, void *holder,
+		const struct blk_holder_ops *hops);
+
 #endif /* BLK_INTERNAL_H */
include/linux/blkdev.h +0 -3
index 8864b978fdb0..2d06f02f6d5e 100644
@@ -1504,8 +1504,6 @@ struct bdev_handle {
 	blk_mode_t mode;
 };
 
-struct bdev_handle *bdev_open_by_dev(dev_t dev, blk_mode_t mode, void *holder,
-		const struct blk_holder_ops *hops);
 struct file *bdev_file_open_by_dev(dev_t dev, blk_mode_t mode, void *holder,
 		const struct blk_holder_ops *hops);
 struct file *bdev_file_open_by_path(const char *path, blk_mode_t mode,
@@ -1513,7 +1511,6 @@ struct file *bdev_file_open_by_path(const char *path, blk_mode_t mode,
 int bd_prepare_to_claim(struct block_device *bdev, void *holder,
 		const struct blk_holder_ops *hops);
 void bd_abort_claiming(struct block_device *bdev, void *holder);
-void bdev_release(struct bdev_handle *handle);
 
 /* just for blk-cgroup, don't use elsewhere */
 struct block_device *blkdev_get_no_open(dev_t dev);
Signature · 1 line
2.42.0
author maintainer
#35 lore raw

RFC PATCH 29/34 bdev: make struct bdev_handle private to the block layer

In reply to Christian Brauner
---
 block/bdev.c           | 1 -
 block/blk.h            | 6 ++++++
 include/linux/blkdev.h | 6 ------
 include/linux/fs.h     | 6 ------
 4 files changed, 6 insertions(+), 13 deletions(-)
block/bdev.c +0 -1
index 80caa71a65db..b276ef994858 100644
@@ -49,7 +49,6 @@ struct block_device *I_BDEV(struct inode *inode)
 }
 EXPORT_SYMBOL(I_BDEV);
 
-/* @bdev_handle will become private to block/blk.h soon. */
 struct block_device *F_BDEV(struct file *f_bdev)
 {
 	struct bdev_handle *handle = f_bdev->private_data;
block/blk.h +6 -0
index 3ec5e9b5c26c..d1a2030fa5c3 100644
@@ -25,6 +25,12 @@ struct blk_flush_queue {
 	struct request		*flush_rq;
 };
 
+struct bdev_handle {
+	struct block_device *bdev;
+	void *holder;
+	blk_mode_t mode;
+};
+
 bool is_flush_rq(struct request *req);
 
 struct blk_flush_queue *blk_alloc_flush_queue(int node, int cmd_size,
include/linux/blkdev.h +0 -6
index 2d06f02f6d5e..5599a33e78a6 100644
@@ -1498,12 +1498,6 @@ extern const struct blk_holder_ops fs_holder_ops;
 	(BLK_OPEN_READ | BLK_OPEN_RESTRICT_WRITES | \
 	 (((flags) & SB_RDONLY) ? 0 : BLK_OPEN_WRITE))
 
-struct bdev_handle {
-	struct block_device *bdev;
-	void *holder;
-	blk_mode_t mode;
-};
-
 struct file *bdev_file_open_by_dev(dev_t dev, blk_mode_t mode, void *holder,
 		const struct blk_holder_ops *hops);
 struct file *bdev_file_open_by_path(const char *path, blk_mode_t mode,
include/linux/fs.h +0 -6
index b0a5e94e8c3a..b23d49f7adfe 100644
@@ -1326,12 +1326,6 @@ struct super_block {
 	struct list_head	s_inodes_wb;	/* writeback inodes */
 } __randomize_layout;
 
-/* Temporary helper that will go away. */
-static inline struct bdev_handle *sb_bdev_handle(struct super_block *sb)
-{
-	return sb->s_f_bdev->private_data;
-}
-
 static inline struct user_namespace *i_user_ns(const struct inode *inode)
 {
 	return inode->i_sb->s_user_ns;
Signature · 1 line
2.42.0
author maintainer
#36 lore raw

RFC PATCH 30/34 bdev: rework bdev_open_by_dev()

In reply to Christian Brauner

Now that we always use files when opening block devices rework bdev_open_by_dev() to work well with both bdev_file_open_by_*() and blkdev_open().

---
 block/bdev.c | 139 +++++++++++++++++++++++++++++++++--------------------------
 block/blk.h  |   6 +--
 block/fops.c |  34 ++++++---------
 3 files changed, 94 insertions(+), 85 deletions(-)
block/bdev.c +77 -62
index b276ef994858..2867edba0169 100644
@@ -704,6 +704,24 @@ static int blkdev_get_part(struct block_device *part, blk_mode_t mode)
 	return ret;
 }
 
+int bdev_permission(dev_t dev, blk_mode_t mode, void *holder)
+{
+	int ret;
+
+	ret = devcgroup_check_permission(
+		DEVCG_DEV_BLOCK, MAJOR(dev), MINOR(dev),
+		((mode & BLK_OPEN_READ) ? DEVCG_ACC_READ : 0) |
+			((mode & BLK_OPEN_WRITE) ? DEVCG_ACC_WRITE : 0));
+	if (ret)
+		return ret;
+
+	/* Blocking writes requires exclusive opener */
+	if (mode & BLK_OPEN_RESTRICT_WRITES && !holder)
+		return -EINVAL;
+
+	return 0;
+}
+
 static void blkdev_put_part(struct block_device *part)
 {
 	struct block_device *whole = bdev_whole(part);
@@ -796,15 +814,15 @@ static void bdev_yield_write_access(struct block_device *bdev, blk_mode_t mode)
 }
 
 /**
- * bdev_open_by_dev - open a block device by device number
- * @dev: device number of block device to open
+ * bdev_open - open a block device
+ * @bdev: block device to open
  * @mode: open mode (BLK_OPEN_*)
  * @holder: exclusive holder identifier
  * @hops: holder operations
+ * @f_bdev: file for the block device
  *
- * Open the block device described by device number @dev. If @holder is not
- * %NULL, the block device is opened with exclusive access.  Exclusive opens may
- * nest for the same @holder.
+ * Open the block device. If @holder is not %NULL, the block device is opened
+ * with exclusive access.  Exclusive opens may nest for the same @holder.
  *
  * Use this interface ONLY if you really do not have anything better - i.e. when
  * you are behind a truly sucky interface and all you are given is a device
@@ -814,52 +832,29 @@ static void bdev_yield_write_access(struct block_device *bdev, blk_mode_t mode)
  * Might sleep.
  *
  * RETURNS:
- * Handle with a reference to the block_device on success, ERR_PTR(-errno) on
- * failure.
+ * zero on success, -errno on failure.
  */
-struct bdev_handle *bdev_open_by_dev(dev_t dev, blk_mode_t mode, void *holder,
-				     const struct blk_holder_ops *hops)
+int bdev_open(struct block_device *bdev, blk_mode_t mode, void *holder,
+	      const struct blk_holder_ops *hops, struct file *f_bdev)
 {
 	struct bdev_handle *handle = kmalloc(sizeof(struct bdev_handle),
 					     GFP_KERNEL);
-	struct block_device *bdev;
 	bool unblock_events = true;
-	struct gendisk *disk;
+	struct gendisk *disk = bdev->bd_disk;
 	int ret;
 
+	handle = kmalloc(sizeof(struct bdev_handle), GFP_KERNEL);
 	if (!handle)
-		return ERR_PTR(-ENOMEM);
-
-	ret = devcgroup_check_permission(DEVCG_DEV_BLOCK,
-			MAJOR(dev), MINOR(dev),
-			((mode & BLK_OPEN_READ) ? DEVCG_ACC_READ : 0) |
-			((mode & BLK_OPEN_WRITE) ? DEVCG_ACC_WRITE : 0));
-	if (ret)
-		goto free_handle;
-
-	/* Blocking writes requires exclusive opener */
-	if (mode & BLK_OPEN_RESTRICT_WRITES && !holder) {
-		ret = -EINVAL;
-		goto free_handle;
-	}
-
-	bdev = blkdev_get_no_open(dev);
-	if (!bdev) {
-		ret = -ENXIO;
-		goto free_handle;
-	}
-	disk = bdev->bd_disk;
+		return -ENOMEM;
 
 	if (holder) {
 		mode |= BLK_OPEN_EXCL;
 		ret = bd_prepare_to_claim(bdev, holder, hops);
 		if (ret)
-			goto put_blkdev;
+			return ret;
 	} else {
-		if (WARN_ON_ONCE(mode & BLK_OPEN_EXCL)) {
-			ret = -EIO;
-			goto put_blkdev;
-		}
+		if (WARN_ON_ONCE(mode & BLK_OPEN_EXCL))
+			return -EIO;
 	}
 
 	disk_block_events(disk);
@@ -903,7 +898,22 @@ struct bdev_handle *bdev_open_by_dev(dev_t dev, blk_mode_t mode, void *holder,
 	handle->bdev = bdev;
 	handle->holder = holder;
 	handle->mode = mode;
-	return handle;
+
+	/*
+	 * Preserve backwards compatibility and allow large file access
+	 * even if userspace doesn't ask for it explicitly. Some mkfs
+	 * binary needs it. We might want to drop this workaround
+	 * during an unstable branch.
+	 */
+	f_bdev->f_flags |= O_LARGEFILE;
+	f_bdev->f_mode |= FMODE_BUF_RASYNC | FMODE_CAN_ODIRECT;
+	if (bdev_nowait(bdev))
+		f_bdev->f_mode |= FMODE_NOWAIT;
+	f_bdev->f_mapping = handle->bdev->bd_inode->i_mapping;
+	f_bdev->f_wb_err = filemap_sample_wb_err(f_bdev->f_mapping);
+	f_bdev->private_data = handle;
+
+	return 0;
 put_module:
 	module_put(disk->fops->owner);
 abort_claiming:
@@ -911,11 +921,8 @@ struct bdev_handle *bdev_open_by_dev(dev_t dev, blk_mode_t mode, void *holder,
 		bd_abort_claiming(bdev, holder);
 	mutex_unlock(&disk->open_mutex);
 	disk_unblock_events(disk);
-put_blkdev:
-	blkdev_put_no_open(bdev);
-free_handle:
 	kfree(handle);
-	return ERR_PTR(ret);
+	return ret;
 }
 
 static unsigned blk_to_file_flags(blk_mode_t mode)
@@ -927,8 +934,10 @@ static unsigned blk_to_file_flags(blk_mode_t mode)
 		flags |= O_RDWR;
 	else if (mode & BLK_OPEN_WRITE)
 		flags |= O_WRONLY;
-	else
+	else if (mode & BLK_OPEN_READ)
 		flags |= O_RDONLY;
+	else /* Neither read nor write for a block device requested? */
+		WARN_ON_ONCE(true);
 
 	/*
 	 * O_EXCL is one of those flags that the VFS clears once it's done with
@@ -952,31 +961,37 @@ static unsigned blk_to_file_flags(blk_mode_t mode)
 struct file *bdev_file_open_by_dev(dev_t dev, blk_mode_t mode, void *holder,
 				   const struct blk_holder_ops *hops)
 {
-	struct file *file;
-	struct bdev_handle *handle;
+	struct file *f_bdev;
+	struct block_device *bdev;
 	unsigned int flags;
+	int ret;
 
-	handle = bdev_open_by_dev(dev, mode, holder, hops);
-	if (IS_ERR(handle))
-		return ERR_CAST(handle);
+	ret = bdev_permission(dev, 0, holder);
+	if (ret)
+		return ERR_PTR(ret);
+
+	bdev = blkdev_get_no_open(dev);
+	if (!bdev)
+		return ERR_PTR(-ENXIO);
 
 	flags = blk_to_file_flags(mode);
-	file = alloc_file_pseudo(handle->bdev->bd_inode, blockdev_mnt, "",
-				 flags | O_LARGEFILE, &def_blk_fops);
-	if (IS_ERR(file)) {
-		bdev_release(handle);
-		return file;
+	f_bdev = alloc_file_pseudo(bdev->bd_inode, blockdev_mnt, "",
+				   flags | O_LARGEFILE, &def_blk_fops);
+	if (IS_ERR(f_bdev)) {
+		blkdev_put_no_open(bdev);
+		return f_bdev;
 	}
-	ihold(handle->bdev->bd_inode);
-
-	file->f_mode |= FMODE_BUF_RASYNC | FMODE_CAN_ODIRECT | FMODE_NOACCOUNT;
-	if (bdev_nowait(handle->bdev))
-		file->f_mode |= FMODE_NOWAIT;
+	f_bdev->f_mode &= ~FMODE_OPENED;
 
-	file->f_mapping = handle->bdev->bd_inode->i_mapping;
-	file->f_wb_err = filemap_sample_wb_err(file->f_mapping);
-	file->private_data = handle;
-	return file;
+	ihold(bdev->bd_inode);
+	ret = bdev_open(bdev, mode, holder, hops, f_bdev);
+	if (ret) {
+		fput(f_bdev);
+		return ERR_PTR(ret);
+	}
+	/* Now that thing is opened. */
+	f_bdev->f_mode |= FMODE_OPENED;
+	return f_bdev;
 }
 EXPORT_SYMBOL(bdev_file_open_by_dev);
 
block/blk.h +3 -3
index d1a2030fa5c3..ab1a5ab8cd2e 100644
@@ -525,7 +525,7 @@ static inline int req_ref_read(struct request *req)
 }
 
 void bdev_release(struct bdev_handle *handle);
-struct bdev_handle *bdev_open_by_dev(dev_t dev, blk_mode_t mode, void *holder,
-		const struct blk_holder_ops *hops);
-
+int bdev_open(struct block_device *bdev, blk_mode_t mode, void *holder,
+	      const struct blk_holder_ops *hops, struct file *f_bdev);
+int bdev_permission(dev_t dev, blk_mode_t mode, void *holder);
 #endif /* BLK_INTERNAL_H */
block/fops.c +14 -20
index 0abaac705daf..ed7be8b5810e 100644
@@ -584,31 +584,25 @@ blk_mode_t file_to_blk_mode(struct file *file)
 
 static int blkdev_open(struct inode *inode, struct file *filp)
 {
-	struct bdev_handle *handle;
+	struct block_device *bdev;
 	blk_mode_t mode;
-
-	/*
-	 * Preserve backwards compatibility and allow large file access
-	 * even if userspace doesn't ask for it explicitly. Some mkfs
-	 * binary needs it. We might want to drop this workaround
-	 * during an unstable branch.
-	 */
-	filp->f_flags |= O_LARGEFILE;
-	filp->f_mode |= FMODE_BUF_RASYNC | FMODE_CAN_ODIRECT;
+	void *holder;
+	int ret;
 
 	mode = file_to_blk_mode(filp);
-	handle = bdev_open_by_dev(inode->i_rdev, mode,
-			mode & BLK_OPEN_EXCL ? filp : NULL, NULL);
-	if (IS_ERR(handle))
-		return PTR_ERR(handle);
+	holder = mode & BLK_OPEN_EXCL ? filp : NULL;
+	ret = bdev_permission(inode->i_rdev, mode, holder);
+	if (ret)
+		return ret;
 
-	if (bdev_nowait(handle->bdev))
-		filp->f_mode |= FMODE_NOWAIT;
+	bdev = blkdev_get_no_open(inode->i_rdev);
+	if (!bdev)
+		return -ENXIO;
 
-	filp->f_mapping = handle->bdev->bd_inode->i_mapping;
-	filp->f_wb_err = filemap_sample_wb_err(filp->f_mapping);
-	filp->private_data = handle;
-	return 0;
+	ret = bdev_open(bdev, mode, holder, NULL, filp);
+	if (ret)
+		blkdev_put_no_open(bdev);
+	return ret;
 }
 
 static int blkdev_release(struct inode *inode, struct file *filp)
Signature · 1 line
2.42.0
author maintainer
#37 lore raw

RFC PATCH 31/34 ext4: rely on sb->f_bdev only

In reply to Christian Brauner
---
 fs/ext4/dir.c         |  2 +-
 fs/ext4/ext4_jbd2.c   |  2 +-
 fs/ext4/fast_commit.c |  2 +-
 fs/ext4/super.c       | 36 ++++++++++++++++++------------------
 4 files changed, 21 insertions(+), 21 deletions(-)
fs/ext4/dir.c +1 -1
index 3985f8c33f95..992f09aff438 100644
@@ -192,7 +192,7 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx)
 					(PAGE_SHIFT - inode->i_blkbits);
 			if (!ra_has_index(&file->f_ra, index))
 				page_cache_sync_readahead(
-					sb->s_bdev->bd_inode->i_mapping,
+					F_BDEV(sb->s_f_bdev)->bd_inode->i_mapping,
 					&file->f_ra, file,
 					index, 1);
 			file->f_ra.prev_pos = (loff_t)index << PAGE_SHIFT;
fs/ext4/ext4_jbd2.c +1 -1
index d1a2e6624401..97f9ba412f1e 100644
@@ -206,7 +206,7 @@ static void ext4_journal_abort_handle(const char *caller, unsigned int line,
 
 static void ext4_check_bdev_write_error(struct super_block *sb)
 {
-	struct address_space *mapping = sb->s_bdev->bd_inode->i_mapping;
+	struct address_space *mapping = F_BDEV(sb->s_f_bdev)->bd_inode->i_mapping;
 	struct ext4_sb_info *sbi = EXT4_SB(sb);
 	int err;
 
fs/ext4/fast_commit.c +1 -1
index 87c009e0c59a..60ca93b7df81 100644
@@ -1605,7 +1605,7 @@ static int ext4_fc_replay_inode(struct super_block *sb,
 out:
 	iput(inode);
 	if (!ret)
-		blkdev_issue_flush(sb->s_bdev);
+		blkdev_issue_flush(F_BDEV(sb->s_f_bdev));
 
 	return 0;
 }
fs/ext4/super.c +18 -18
index 3fec1decccbf..6ea654105076 100644
@@ -244,7 +244,7 @@ static struct buffer_head *__ext4_sb_bread_gfp(struct super_block *sb,
 struct buffer_head *ext4_sb_bread(struct super_block *sb, sector_t block,
 				   blk_opf_t op_flags)
 {
-	gfp_t gfp = mapping_gfp_constraint(sb->s_bdev->bd_inode->i_mapping,
+	gfp_t gfp = mapping_gfp_constraint(F_BDEV(sb->s_f_bdev)->bd_inode->i_mapping,
 			~__GFP_FS) | __GFP_MOVABLE;
 
 	return __ext4_sb_bread_gfp(sb, block, op_flags, gfp);
@@ -253,7 +253,7 @@ struct buffer_head *ext4_sb_bread(struct super_block *sb, sector_t block,
 struct buffer_head *ext4_sb_bread_unmovable(struct super_block *sb,
 					    sector_t block)
 {
-	gfp_t gfp = mapping_gfp_constraint(sb->s_bdev->bd_inode->i_mapping,
+	gfp_t gfp = mapping_gfp_constraint(F_BDEV(sb->s_f_bdev)->bd_inode->i_mapping,
 			~__GFP_FS);
 
 	return __ext4_sb_bread_gfp(sb, block, 0, gfp);
@@ -261,7 +261,7 @@ struct buffer_head *ext4_sb_bread_unmovable(struct super_block *sb,
 
 void ext4_sb_breadahead_unmovable(struct super_block *sb, sector_t block)
 {
-	struct buffer_head *bh = bdev_getblk(sb->s_bdev, block,
+	struct buffer_head *bh = bdev_getblk(F_BDEV(sb->s_f_bdev), block,
 			sb->s_blocksize, GFP_NOWAIT | __GFP_NOWARN);
 
 	if (likely(bh)) {
@@ -477,7 +477,7 @@ static void ext4_maybe_update_superblock(struct super_block *sb)
 		return;
 
 	lifetime_write_kbytes = sbi->s_kbytes_written +
-		((part_stat_read(sb->s_bdev, sectors[STAT_WRITE]) -
+		((part_stat_read(F_BDEV(sb->s_f_bdev), sectors[STAT_WRITE]) -
 		  sbi->s_sectors_written_start) >> 1);
 
 	/* Get the number of kilobytes not written to disk to account
@@ -502,7 +502,7 @@ static void ext4_maybe_update_superblock(struct super_block *sb)
  */
 static int block_device_ejected(struct super_block *sb)
 {
-	struct inode *bd_inode = sb->s_bdev->bd_inode;
+	struct inode *bd_inode = F_BDEV(sb->s_f_bdev)->bd_inode;
 	struct backing_dev_info *bdi = inode_to_bdi(bd_inode);
 
 	return bdi->dev == NULL;
@@ -722,7 +722,7 @@ static void ext4_handle_error(struct super_block *sb, bool force_ro, int error,
 			jbd2_journal_abort(journal, -EIO);
 	}
 
-	if (!bdev_read_only(sb->s_bdev)) {
+	if (!bdev_read_only(F_BDEV(sb->s_f_bdev))) {
 		save_error_info(sb, error, ino, block, func, line);
 		/*
 		 * In case the fs should keep running, we need to writeout
@@ -1084,7 +1084,7 @@ __acquires(bitlock)
 		if (test_opt(sb, WARN_ON_ERROR))
 			WARN_ON_ONCE(1);
 		EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
-		if (!bdev_read_only(sb->s_bdev)) {
+		if (!bdev_read_only(F_BDEV(sb->s_f_bdev))) {
 			save_error_info(sb, EFSCORRUPTED, ino, block, function,
 					line);
 			schedule_work(&EXT4_SB(sb)->s_sb_upd_work);
@@ -1357,8 +1357,8 @@ static void ext4_put_super(struct super_block *sb)
 		dump_orphan_list(sb, sbi);
 	ASSERT(list_empty(&sbi->s_orphan));
 
-	sync_blockdev(sb->s_bdev);
-	invalidate_bdev(sb->s_bdev);
+	sync_blockdev(F_BDEV(sb->s_f_bdev));
+	invalidate_bdev(F_BDEV(sb->s_f_bdev));
 	if (sbi->s_journal_f_bdev) {
 		/*
 		 * Invalidate the journal device's buffers.  We don't want them
@@ -4338,7 +4338,7 @@ static struct ext4_sb_info *ext4_alloc_sbi(struct super_block *sb)
 	if (!sbi)
 		return NULL;
 
-	sbi->s_daxdev = fs_dax_get_by_bdev(sb->s_bdev, &sbi->s_dax_part_off,
+	sbi->s_daxdev = fs_dax_get_by_bdev(F_BDEV(sb->s_f_bdev), &sbi->s_dax_part_off,
 					   NULL, NULL);
 
 	sbi->s_blockgroup_lock =
@@ -5231,7 +5231,7 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
 
 	sbi->s_inode_readahead_blks = EXT4_DEF_INODE_READAHEAD_BLKS;
 	sbi->s_sectors_written_start =
-		part_stat_read(sb->s_bdev, sectors[STAT_WRITE]);
+		part_stat_read(F_BDEV(sb->s_f_bdev), sectors[STAT_WRITE]);
 
 	err = ext4_load_super(sb, &logical_sb_block, silent);
 	if (err)
@@ -5585,7 +5585,7 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
 	 * used to detect the metadata async write error.
 	 */
 	spin_lock_init(&sbi->s_bdev_wb_lock);
-	errseq_check_and_advance(&sb->s_bdev->bd_inode->i_mapping->wb_err,
+	errseq_check_and_advance(&F_BDEV(sb->s_f_bdev)->bd_inode->i_mapping->wb_err,
 				 &sbi->s_bdev_wb_err);
 	EXT4_SB(sb)->s_mount_state |= EXT4_ORPHAN_FS;
 	ext4_orphan_cleanup(sb, es);
@@ -5605,7 +5605,7 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
 			goto failed_mount10;
 	}
 
-	if (test_opt(sb, DISCARD) && !bdev_max_discard_sectors(sb->s_bdev))
+	if (test_opt(sb, DISCARD) && !bdev_max_discard_sectors(F_BDEV(sb->s_f_bdev)))
 		ext4_msg(sb, KERN_WARNING,
 			 "mounting with \"discard\" option, but the device does not support discard");
 
@@ -5684,7 +5684,7 @@ failed_mount9: __maybe_unused
 		fput(sbi->s_journal_f_bdev);
 	}
 out_fail:
-	invalidate_bdev(sb->s_bdev);
+	invalidate_bdev(F_BDEV(sb->s_f_bdev));
 	sb->s_fs_info = NULL;
 	return err;
 }
@@ -5943,7 +5943,7 @@ static journal_t *ext4_open_dev_journal(struct super_block *sb,
 	if (IS_ERR(f_bdev))
 		return ERR_CAST(f_bdev);
 
-	journal = jbd2_journal_init_dev(F_BDEV(f_bdev), sb->s_bdev, j_start,
+	journal = jbd2_journal_init_dev(F_BDEV(f_bdev), F_BDEV(sb->s_f_bdev), j_start,
 					j_len, sb->s_blocksize);
 	if (IS_ERR(journal)) {
 		ext4_msg(sb, KERN_ERR, "failed to create device journal");
@@ -6008,7 +6008,7 @@ static int ext4_load_journal(struct super_block *sb,
 	}
 
 	journal_dev_ro = bdev_read_only(journal->j_dev);
-	really_read_only = bdev_read_only(sb->s_bdev) | journal_dev_ro;
+	really_read_only = bdev_read_only(F_BDEV(sb->s_f_bdev)) | journal_dev_ro;
 
 	if (journal_dev_ro && !sb_rdonly(sb)) {
 		ext4_msg(sb, KERN_ERR,
@@ -6125,7 +6125,7 @@ static void ext4_update_super(struct super_block *sb)
 		ext4_update_tstamp(es, s_wtime);
 	es->s_kbytes_written =
 		cpu_to_le64(sbi->s_kbytes_written +
-		    ((part_stat_read(sb->s_bdev, sectors[STAT_WRITE]) -
+		    ((part_stat_read(F_BDEV(sb->s_f_bdev), sectors[STAT_WRITE]) -
 		      sbi->s_sectors_written_start) >> 1));
 	if (percpu_counter_initialized(&sbi->s_freeclusters_counter))
 		ext4_free_blocks_count_set(es,
@@ -6359,7 +6359,7 @@ static int ext4_sync_fs(struct super_block *sb, int wait)
 		needs_barrier = true;
 	if (needs_barrier) {
 		int err;
-		err = blkdev_issue_flush(sb->s_bdev);
+		err = blkdev_issue_flush(F_BDEV(sb->s_f_bdev));
 		if (!ret)
 			ret = err;
 	}
Signature · 1 line
2.42.0
author maintainer
#38 lore raw

RFC PATCH 32/34 block: expose bdev_file_inode()

In reply to Christian Brauner

Now that we open block devices as files we don't need to rely on bd_inode to get to the correct inode. Use the helper.

---
 block/fops.c           | 5 -----
 include/linux/blkdev.h | 5 +++++
 2 files changed, 5 insertions(+), 5 deletions(-)
block/fops.c +0 -5
index ed7be8b5810e..e831196dafac 100644
@@ -19,11 +19,6 @@
 #include <linux/module.h>
 #include "blk.h"
 
-static inline struct inode *bdev_file_inode(struct file *file)
-{
-	return file->f_mapping->host;
-}
-
 static blk_opf_t dio_bio_write_op(struct kiocb *iocb)
 {
 	blk_opf_t opf = REQ_OP_WRITE | REQ_SYNC | REQ_IDLE;
include/linux/blkdev.h +5 -0
index 5599a33e78a6..4bde3e87817d 100644
@@ -1513,6 +1513,11 @@ void blkdev_put_no_open(struct block_device *bdev);
 struct block_device *I_BDEV(struct inode *inode);
 struct block_device *F_BDEV(struct file *file);
 
+static inline struct inode *bdev_file_inode(struct file *file)
+{
+	return file->f_mapping->host;
+}
+
 #ifdef CONFIG_BLOCK
 void invalidate_bdev(struct block_device *bdev);
 int sync_blockdev(struct block_device *bdev);
Signature · 1 line
2.42.0
author maintainer
#39 lore raw

RFC PATCH 33/34 ext4: use bdev_file_inode()

In reply to Christian Brauner

There's no need to access bd_inode directly anymore now that we use a struct file for block device opening.

---
 fs/ext4/dir.c       | 2 +-
 fs/ext4/ext4_jbd2.c | 2 +-
 fs/ext4/super.c     | 8 ++++----
 3 files changed, 6 insertions(+), 6 deletions(-)
fs/ext4/dir.c +1 -1
index 992f09aff438..5037329f35c7 100644
@@ -192,7 +192,7 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx)
 					(PAGE_SHIFT - inode->i_blkbits);
 			if (!ra_has_index(&file->f_ra, index))
 				page_cache_sync_readahead(
-					F_BDEV(sb->s_f_bdev)->bd_inode->i_mapping,
+					bdev_file_inode(sb->s_f_bdev)->i_mapping,
 					&file->f_ra, file,
 					index, 1);
 			file->f_ra.prev_pos = (loff_t)index << PAGE_SHIFT;
fs/ext4/ext4_jbd2.c +1 -1
index 97f9ba412f1e..eaec6d2429cc 100644
@@ -206,7 +206,7 @@ static void ext4_journal_abort_handle(const char *caller, unsigned int line,
 
 static void ext4_check_bdev_write_error(struct super_block *sb)
 {
-	struct address_space *mapping = F_BDEV(sb->s_f_bdev)->bd_inode->i_mapping;
+	struct address_space *mapping = bdev_file_inode(sb->s_f_bdev)->i_mapping;
 	struct ext4_sb_info *sbi = EXT4_SB(sb);
 	int err;
 
fs/ext4/super.c +4 -4
index 6ea654105076..40387ba598f4 100644
@@ -244,7 +244,7 @@ static struct buffer_head *__ext4_sb_bread_gfp(struct super_block *sb,
 struct buffer_head *ext4_sb_bread(struct super_block *sb, sector_t block,
 				   blk_opf_t op_flags)
 {
-	gfp_t gfp = mapping_gfp_constraint(F_BDEV(sb->s_f_bdev)->bd_inode->i_mapping,
+	gfp_t gfp = mapping_gfp_constraint(bdev_file_inode(sb->s_f_bdev)->i_mapping,
 			~__GFP_FS) | __GFP_MOVABLE;
 
 	return __ext4_sb_bread_gfp(sb, block, op_flags, gfp);
@@ -253,7 +253,7 @@ struct buffer_head *ext4_sb_bread(struct super_block *sb, sector_t block,
 struct buffer_head *ext4_sb_bread_unmovable(struct super_block *sb,
 					    sector_t block)
 {
-	gfp_t gfp = mapping_gfp_constraint(F_BDEV(sb->s_f_bdev)->bd_inode->i_mapping,
+	gfp_t gfp = mapping_gfp_constraint(bdev_file_inode(sb->s_f_bdev)->i_mapping,
 			~__GFP_FS);
 
 	return __ext4_sb_bread_gfp(sb, block, 0, gfp);
@@ -502,7 +502,7 @@ static void ext4_maybe_update_superblock(struct super_block *sb)
  */
 static int block_device_ejected(struct super_block *sb)
 {
-	struct inode *bd_inode = F_BDEV(sb->s_f_bdev)->bd_inode;
+	struct inode *bd_inode = bdev_file_inode(sb->s_f_bdev);
 	struct backing_dev_info *bdi = inode_to_bdi(bd_inode);
 
 	return bdi->dev == NULL;
@@ -5585,7 +5585,7 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
 	 * used to detect the metadata async write error.
 	 */
 	spin_lock_init(&sbi->s_bdev_wb_lock);
-	errseq_check_and_advance(&F_BDEV(sb->s_f_bdev)->bd_inode->i_mapping->wb_err,
+	errseq_check_and_advance(&bdev_file_inode(sb->s_f_bdev)->i_mapping->wb_err,
 				 &sbi->s_bdev_wb_err);
 	EXT4_SB(sb)->s_mount_state |= EXT4_ORPHAN_FS;
 	ext4_orphan_cleanup(sb, es);
Signature · 1 line
2.42.0
author maintainer
#40 lore raw

RFC PATCH 34/34 buffer: port block device access to files and get rid of bd_inode access

In reply to Christian Brauner
---
 block/fops.c                  |  1 +
 drivers/md/md-bitmap.c        |  1 +
 fs/affs/file.c                |  1 +
 fs/btrfs/inode.c              |  1 +
 fs/buffer.c                   | 69 ++++++++++++++++++++++---------------------
 fs/direct-io.c                |  2 +-
 fs/erofs/data.c               |  7 +++--
 fs/erofs/internal.h           |  1 +
 fs/erofs/zmap.c               |  1 +
 fs/ext2/inode.c               |  8 +++--
 fs/ext4/inode.c               |  6 ++--
 fs/ext4/super.c               |  6 ++--
 fs/f2fs/data.c                |  6 +++-
 fs/f2fs/f2fs.h                |  1 +
 fs/fuse/dax.c                 |  1 +
 fs/gfs2/aops.c                |  1 +
 fs/gfs2/bmap.c                |  1 +
 fs/hpfs/file.c                |  1 +
 fs/jbd2/commit.c              |  1 +
 fs/jbd2/journal.c             | 26 +++++++++-------
 fs/jbd2/recovery.c            |  6 ++--
 fs/jbd2/revoke.c              | 10 +++----
 fs/jbd2/transaction.c         |  1 +
 fs/mpage.c                    |  5 +++-
 fs/nilfs2/btnode.c            |  2 ++
 fs/nilfs2/gcinode.c           |  1 +
 fs/nilfs2/mdt.c               |  1 +
 fs/nilfs2/page.c              |  2 ++
 fs/nilfs2/recovery.c          | 20 ++++++-------
 fs/nilfs2/the_nilfs.c         |  1 +
 fs/ntfs/aops.c                |  3 ++
 fs/ntfs/file.c                |  1 +
 fs/ntfs/mft.c                 |  2 ++
 fs/ntfs3/fsntfs.c             |  8 ++---
 fs/ntfs3/inode.c              |  1 +
 fs/ntfs3/super.c              |  2 +-
 fs/ocfs2/journal.c            |  2 +-
 fs/reiserfs/journal.c         |  8 ++---
 fs/reiserfs/reiserfs.h        |  6 ++--
 fs/reiserfs/tail_conversion.c |  1 +
 fs/xfs/xfs_iomap.c            |  7 +++--
 fs/zonefs/file.c              |  2 ++
 include/linux/buffer_head.h   | 45 +++++++++++++++-------------
 include/linux/iomap.h         |  1 +
 include/linux/jbd2.h          |  6 ++--
 45 files changed, 172 insertions(+), 114 deletions(-)
block/fops.c +1 -0
index e831196dafac..6557b71c7657 100644
@@ -381,6 +381,7 @@ static int blkdev_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
 	loff_t isize = i_size_read(inode);
 
 	iomap->bdev = bdev;
+	BUG_ON(true /* TODO(brauner): This is the only place where we don't go from inode->i_sb->s_f_bdev for obvious reasons. Thoughts? */);
 	iomap->offset = ALIGN_DOWN(offset, bdev_logical_block_size(bdev));
 	if (iomap->offset >= isize)
 		return -EIO;
drivers/md/md-bitmap.c +1 -0
index 9672f75c3050..489d9c74e1af 100644
@@ -380,6 +380,7 @@ static int read_file_page(struct file *file, unsigned long index,
 			}
 
 			bh->b_blocknr = block;
+			bh->f_b_bdev = inode->i_sb->s_f_bdev;
 			bh->b_bdev = inode->i_sb->s_bdev;
 			if (count < blocksize)
 				count = 0;
fs/affs/file.c +1 -0
index 04c018e19602..7b62430d7052 100644
@@ -366,6 +366,7 @@ affs_get_block(struct inode *inode, sector_t block, struct buffer_head *bh_resul
 	brelse(ext_bh);
 	clear_buffer_mapped(bh_result);
 	bh_result->b_bdev = NULL;
+	bh_result->f_b_bdev = NULL;
 	// unlock cache
 	affs_unlock_ext(inode);
 	return -ENOSPC;
fs/btrfs/inode.c +1 -0
index fb3c3f43c3fa..ee895a8be28d 100644
@@ -7647,6 +7647,7 @@ static int btrfs_dio_iomap_begin(struct inode *inode, loff_t start,
 	}
 	iomap->offset = start;
 	iomap->bdev = fs_info->fs_devices->latest_dev->bdev;
+	iomap->f_bdev = fs_info->fs_devices->latest_dev->f_bdev;
 	iomap->length = len;
 	free_extent_map(em);
 
fs/buffer.c +36 -33

225 lines not on this page · raw message

fs/direct-io.c +1 -1
index 60456263a338..7ee66552bddc 100644
@@ -946,7 +946,7 @@ static int do_direct_IO(struct dio *dio, struct dio_submit *sdio,
 					map_bh->b_blocknr << sdio->blkfactor;
 				if (buffer_new(map_bh)) {
 					clean_bdev_aliases(
-						map_bh->b_bdev,
+						map_bh->f_b_bdev,
 						map_bh->b_blocknr,
 						map_bh->b_size >> i_blkbits);
 				}
fs/erofs/data.c +5 -2
index fed9153f2b83..a7cdec57e226 100644
@@ -204,6 +204,7 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *map)
 	int id;
 
 	map->m_bdev = sb->s_bdev;
+	map->f_m_bdev = sb->s_f_bdev;
 	map->m_daxdev = EROFS_SB(sb)->dax_dev;
 	map->m_dax_part_off = EROFS_SB(sb)->dax_part_off;
 	map->m_fscache = EROFS_SB(sb)->s_fscache;
@@ -275,10 +276,12 @@ static int erofs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
 		return ret;
 
 	iomap->offset = map.m_la;
-	if (flags & IOMAP_DAX)
+	if (flags & IOMAP_DAX) {
 		iomap->dax_dev = mdev.m_daxdev;
-	else
+	} else {
 		iomap->bdev = mdev.m_bdev;
+		iomap->f_bdev = mdev.f_m_bdev;
+	}
 	iomap->length = map.m_llen;
 	iomap->flags = 0;
 	iomap->private = NULL;
fs/erofs/internal.h +1 -0
index 8ad8957de64c..2c55d7a7b79d 100644
@@ -377,6 +377,7 @@ enum {
 
 struct erofs_map_dev {
 	struct erofs_fscache *m_fscache;
+	struct file *f_m_bdev;
 	struct block_device *m_bdev;
 	struct dax_device *m_daxdev;
 	u64 m_dax_part_off;
fs/erofs/zmap.c +1 -0
index 7b55111fd533..90f6fb155400 100644
@@ -741,6 +741,7 @@ static int z_erofs_iomap_begin_report(struct inode *inode, loff_t offset,
 		return ret;
 
 	iomap->bdev = inode->i_sb->s_bdev;
+	iomap->f_bdev = inode->i_sb->s_f_bdev;
 	iomap->offset = map.m_la;
 	iomap->length = map.m_llen;
 	if (map.m_flags & EROFS_MAP_MAPPED) {
fs/ext2/inode.c +5 -3
index 464faf6c217e..f92cd53a1b5c 100644
@@ -744,7 +744,7 @@ static int ext2_get_blocks(struct inode *inode,
 		 * We must unmap blocks before zeroing so that writeback cannot
 		 * overwrite zeros with stale data from block device page cache.
 		 */
-		clean_bdev_aliases(inode->i_sb->s_bdev,
+		clean_bdev_aliases(inode->i_sb->s_f_bdev,
 				   le32_to_cpu(chain[depth-1].key),
 				   count);
 		/*
@@ -839,10 +839,12 @@ static int ext2_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
 
 	iomap->flags = 0;
 	iomap->offset = (u64)first_block << blkbits;
-	if (flags & IOMAP_DAX)
+	if (flags & IOMAP_DAX) {
 		iomap->dax_dev = sbi->s_daxdev;
-	else
+	} else {
 		iomap->bdev = inode->i_sb->s_bdev;
+		iomap->f_bdev = inode->i_sb->s_f_bdev;
+	}
 
 	if (ret == 0) {
 		/*
fs/ext4/inode.c +4 -2
index 0558c8c986d4..6685801dde6f 100644
@@ -3237,10 +3237,12 @@ static void ext4_set_iomap(struct inode *inode, struct iomap *iomap,
 	if (map->m_flags & EXT4_MAP_NEW)
 		iomap->flags |= IOMAP_F_NEW;
 
-	if (flags & IOMAP_DAX)
+	if (flags & IOMAP_DAX) {
 		iomap->dax_dev = EXT4_SB(inode->i_sb)->s_daxdev;
-	else
+	} else {
 		iomap->bdev = inode->i_sb->s_bdev;
+		iomap->f_bdev = inode->i_sb->s_f_bdev;
+	}
 	iomap->offset = (u64) map->m_lblk << blkbits;
 	iomap->length = (u64) map->m_len << blkbits;
 
fs/ext4/super.c +3 -3
index 40387ba598f4..97fa9f36c1dd 100644
@@ -261,7 +261,7 @@ struct buffer_head *ext4_sb_bread_unmovable(struct super_block *sb,
 
 void ext4_sb_breadahead_unmovable(struct super_block *sb, sector_t block)
 {
-	struct buffer_head *bh = bdev_getblk(F_BDEV(sb->s_f_bdev), block,
+	struct buffer_head *bh = bdev_getblk(sb->s_f_bdev, block,
 			sb->s_blocksize, GFP_NOWAIT | __GFP_NOWARN);
 
 	if (likely(bh)) {
@@ -5887,7 +5887,7 @@ static struct file *ext4_get_journal_blkdev(struct super_block *sb,
 	sb_block = EXT4_MIN_BLOCK_SIZE / blocksize;
 	offset = EXT4_MIN_BLOCK_SIZE % blocksize;
 	set_blocksize(bdev, blocksize);
-	bh = __bread(bdev, sb_block, blocksize);
+	bh = __bread(f_bdev, sb_block, blocksize);
 	if (!bh) {
 		ext4_msg(sb, KERN_ERR, "couldn't read superblock of "
 		       "external journal");
@@ -5943,7 +5943,7 @@ static journal_t *ext4_open_dev_journal(struct super_block *sb,
 	if (IS_ERR(f_bdev))
 		return ERR_CAST(f_bdev);
 
-	journal = jbd2_journal_init_dev(F_BDEV(f_bdev), F_BDEV(sb->s_f_bdev), j_start,
+	journal = jbd2_journal_init_dev(f_bdev, sb->s_f_bdev, j_start,
 					j_len, sb->s_blocksize);
 	if (IS_ERR(journal)) {
 		ext4_msg(sb, KERN_ERR, "failed to create device journal");
fs/f2fs/data.c +5 -1
index 4e42b5f24deb..dee05c392f88 100644
@@ -1615,6 +1615,7 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, int flag)
 		goto out;
 
 	map->m_bdev = inode->i_sb->s_bdev;
+	map->f_m_bdev = inode->i_sb->s_f_bdev;
 	map->m_multidev_dio =
 		f2fs_allow_multi_device_dio(F2FS_I_SB(inode), flag);
 
@@ -1733,8 +1734,10 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, int flag)
 		map->m_pblk = blkaddr;
 		map->m_len = 1;
 
-		if (map->m_multidev_dio)
+		if (map->m_multidev_dio) {
 			map->m_bdev = FDEV(bidx).bdev;
+			map->f_m_bdev = FDEV(bidx).f_bdev;
+		}
 	} else if ((map->m_pblk != NEW_ADDR &&
 			blkaddr == (map->m_pblk + ofs)) ||
 			(map->m_pblk == NEW_ADDR && blkaddr == NEW_ADDR) ||
@@ -4263,6 +4266,7 @@ static int f2fs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
 		iomap->type = IOMAP_MAPPED;
 		iomap->flags |= IOMAP_F_MERGED;
 		iomap->bdev = map.m_bdev;
+		iomap->f_bdev = map.f_m_bdev;
 		iomap->addr = blks_to_bytes(inode, map.m_pblk);
 	} else {
 		if (flags & IOMAP_WRITE)
fs/f2fs/f2fs.h +1 -0
index 9a73eed3b424..831d3f43a157 100644
@@ -684,6 +684,7 @@ struct extent_tree_info {
 				F2FS_MAP_DELALLOC)
 
 struct f2fs_map_blocks {
+	struct file *f_m_bdev;	/* for multi-device dio */
 	struct block_device *m_bdev;	/* for multi-device dio */
 	block_t m_pblk;
 	block_t m_lblk;
fs/fuse/dax.c +1 -0
index 12ef91d170bb..44ad0468e1da 100644
@@ -576,6 +576,7 @@ static int fuse_iomap_begin(struct inode *inode, loff_t pos, loff_t length,
 	iomap->offset = pos;
 	iomap->flags = 0;
 	iomap->bdev = NULL;
+	iomap->f_bdev = NULL;
 	iomap->dax_dev = fc->dax->dev;
 
 	/*
fs/gfs2/aops.c +1 -0
index 9611bfceda4b..6b327f6589b5 100644
@@ -626,6 +626,7 @@ static void gfs2_discard(struct gfs2_sbd *sdp, struct buffer_head *bh)
 		}
 	}
 	bh->b_bdev = NULL;
+	bh->f_b_bdev = NULL;
 	clear_buffer_mapped(bh);
 	clear_buffer_req(bh);
 	clear_buffer_new(bh);
fs/gfs2/bmap.c +1 -0
index d9ccfd27e4f1..eaf6346ee602 100644
@@ -927,6 +927,7 @@ static int __gfs2_iomap_get(struct inode *inode, loff_t pos, loff_t length,
 
 out:
 	iomap->bdev = inode->i_sb->s_bdev;
+	iomap->f_bdev = inode->i_sb->s_f_bdev;
 unlock:
 	up_read(&ip->i_rw_mutex);
 	return ret;
fs/hpfs/file.c +1 -0
index 1bb8d97cd9ae..a4d16f72c0de 100644
@@ -129,6 +129,7 @@ static int hpfs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
 		return -EINVAL;
 
 	iomap->bdev = inode->i_sb->s_bdev;
+	iomap->f_bdev = inode->i_sb->s_f_bdev;
 	iomap->offset = offset;
 
 	hpfs_lock(sb);
fs/jbd2/commit.c +1 -0
index 5e122586e06e..2a0d8c8cc94d 100644
@@ -1015,6 +1015,7 @@ void jbd2_journal_commit_transaction(journal_t *journal)
 				clear_buffer_new(bh);
 				clear_buffer_req(bh);
 				bh->b_bdev = NULL;
+				bh->f_b_bdev = NULL;
 			}
 		}
 
fs/jbd2/journal.c +15 -11
index 206cb53ef2b0..4f5165ba7ff1 100644
@@ -435,6 +435,7 @@ int jbd2_journal_write_metadata_buffer(transaction_t *transaction,
 	folio_set_bh(new_bh, new_folio, new_offset);
 	new_bh->b_size = bh_in->b_size;
 	new_bh->b_bdev = journal->j_dev;
+	new_bh->f_b_bdev = journal->f_j_dev;
 	new_bh->b_blocknr = blocknr;
 	new_bh->b_private = bh_in;
 	set_buffer_mapped(new_bh);
@@ -880,7 +881,7 @@ int jbd2_fc_get_buf(journal_t *journal, struct buffer_head **bh_out)
 	if (ret)
 		return ret;
 
-	bh = __getblk(journal->j_dev, pblock, journal->j_blocksize);
+	bh = __getblk(journal->f_j_dev, pblock, journal->j_blocksize);
 	if (!bh)
 		return -ENOMEM;
 
@@ -1007,7 +1008,7 @@ jbd2_journal_get_descriptor_buffer(transaction_t *transaction, int type)
 	if (err)
 		return NULL;
 
-	bh = __getblk(journal->j_dev, blocknr, journal->j_blocksize);
+	bh = __getblk(journal->f_j_dev, blocknr, journal->j_blocksize);
 	if (!bh)
 		return NULL;
 	atomic_dec(&transaction->t_outstanding_credits);
@@ -1461,7 +1462,7 @@ static int journal_load_superblock(journal_t *journal)
 	struct buffer_head *bh;
 	journal_superblock_t *sb;
 
-	bh = getblk_unmovable(journal->j_dev, journal->j_blk_offset,
+	bh = getblk_unmovable(journal->f_j_dev, journal->j_blk_offset,
 			      journal->j_blocksize);
 	if (bh)
 		err = bh_read(bh, 0);
@@ -1516,11 +1517,12 @@ static int journal_load_superblock(journal_t *journal)
  * very few fields yet: that has to wait until we have created the
  * journal structures from from scratch, or loaded them from disk. */
 
-static journal_t *journal_init_common(struct block_device *bdev,
-			struct block_device *fs_dev,
+static journal_t *journal_init_common(struct file *f_bdev,
+			struct file *fs_dev,
 			unsigned long long start, int len, int blocksize)
 {
 	static struct lock_class_key jbd2_trans_commit_key;
+	struct block_device *bdev = F_BDEV(f_bdev);
 	journal_t *journal;
 	int err;
 	int n;
@@ -1530,8 +1532,10 @@ static journal_t *journal_init_common(struct block_device *bdev,
 		return ERR_PTR(-ENOMEM);
 
 	journal->j_blocksize = blocksize;
-	journal->j_dev = bdev;
-	journal->j_fs_dev = fs_dev;
+	journal->f_j_dev = f_bdev;
+	journal->f_j_fs_dev = fs_dev;
+	journal->j_dev = F_BDEV(f_bdev);
+	journal->j_fs_dev = F_BDEV(fs_dev);
 	journal->j_blk_offset = start;
 	journal->j_total_len = len;
 
@@ -1639,13 +1643,13 @@ static journal_t *journal_init_common(struct block_device *bdev,
  *  range of blocks on an arbitrary block device.
  *
  */
-journal_t *jbd2_journal_init_dev(struct block_device *bdev,
-			struct block_device *fs_dev,
+journal_t *jbd2_journal_init_dev(struct file *f_bdev,
+			struct file *fs_dev,
 			unsigned long long start, int len, int blocksize)
 {
 	journal_t *journal;
 
-	journal = journal_init_common(bdev, fs_dev, start, len, blocksize);
+	journal = journal_init_common(f_bdev, fs_dev, start, len, blocksize);
 	if (IS_ERR(journal))
 		return ERR_CAST(journal);
 
@@ -1682,7 +1686,7 @@ journal_t *jbd2_journal_init_inode(struct inode *inode)
 		  inode->i_sb->s_id, inode->i_ino, (long long) inode->i_size,
 		  inode->i_sb->s_blocksize_bits, inode->i_sb->s_blocksize);
 
-	journal = journal_init_common(inode->i_sb->s_bdev, inode->i_sb->s_bdev,
+	journal = journal_init_common(inode->i_sb->s_f_bdev, inode->i_sb->s_f_bdev,
 			blocknr, inode->i_size >> inode->i_sb->s_blocksize_bits,
 			inode->i_sb->s_blocksize);
 	if (IS_ERR(journal))
fs/jbd2/recovery.c +3 -3
index 01f744cb97a4..6a2edc91b378 100644
@@ -92,7 +92,7 @@ static int do_readahead(journal_t *journal, unsigned int start)
 			goto failed;
 		}
 
-		bh = __getblk(journal->j_dev, blocknr, journal->j_blocksize);
+		bh = __getblk(journal->f_j_dev, blocknr, journal->j_blocksize);
 		if (!bh) {
 			err = -ENOMEM;
 			goto failed;
@@ -148,7 +148,7 @@ static int jread(struct buffer_head **bhp, journal_t *journal,
 		return err;
 	}
 
-	bh = __getblk(journal->j_dev, blocknr, journal->j_blocksize);
+	bh = __getblk(journal->f_j_dev, blocknr, journal->j_blocksize);
 	if (!bh)
 		return -ENOMEM;
 
@@ -677,7 +677,7 @@ static int do_one_pass(journal_t *journal,
 
 					/* Find a buffer for the new
 					 * data being restored */
-					nbh = __getblk(journal->j_fs_dev,
+					nbh = __getblk(journal->f_j_fs_dev,
 							blocknr,
 							journal->j_blocksize);
 					if (nbh == NULL) {
fs/jbd2/revoke.c +4 -6
index 4556e4689024..8d21b2995ff8 100644
@@ -328,7 +328,6 @@ int jbd2_journal_revoke(handle_t *handle, unsigned long long blocknr,
 {
 	struct buffer_head *bh = NULL;
 	journal_t *journal;
-	struct block_device *bdev;
 	int err;
 
 	might_sleep();
@@ -341,11 +340,10 @@ int jbd2_journal_revoke(handle_t *handle, unsigned long long blocknr,
 		return -EINVAL;
 	}
 
-	bdev = journal->j_fs_dev;
 	bh = bh_in;
 
 	if (!bh) {
-		bh = __find_get_block(bdev, blocknr, journal->j_blocksize);
+		bh = __find_get_block(journal->f_j_fs_dev, blocknr, journal->j_blocksize);
 		if (bh)
 			BUFFER_TRACE(bh, "found on hash");
 	}
@@ -355,7 +353,7 @@ int jbd2_journal_revoke(handle_t *handle, unsigned long long blocknr,
 
 		/* If there is a different buffer_head lying around in
 		 * memory anywhere... */
-		bh2 = __find_get_block(bdev, blocknr, journal->j_blocksize);
+		bh2 = __find_get_block(journal->f_j_fs_dev, blocknr, journal->j_blocksize);
 		if (bh2) {
 			/* ... and it has RevokeValid status... */
 			if (bh2 != bh && buffer_revokevalid(bh2))
@@ -466,7 +464,7 @@ int jbd2_journal_cancel_revoke(handle_t *handle, struct journal_head *jh)
 	 * state machine will get very upset later on. */
 	if (need_cancel) {
 		struct buffer_head *bh2;
-		bh2 = __find_get_block(bh->b_bdev, bh->b_blocknr, bh->b_size);
+		bh2 = __find_get_block(bh->f_b_bdev, bh->b_blocknr, bh->b_size);
 		if (bh2) {
 			if (bh2 != bh)
 				clear_buffer_revoked(bh2);
@@ -495,7 +493,7 @@ void jbd2_clear_buffer_revoked_flags(journal_t *journal)
 			struct jbd2_revoke_record_s *record;
 			struct buffer_head *bh;
 			record = (struct jbd2_revoke_record_s *)list_entry;
-			bh = __find_get_block(journal->j_fs_dev,
+			bh = __find_get_block(journal->f_j_fs_dev,
 					      record->blocknr,
 					      journal->j_blocksize);
 			if (bh) {
fs/jbd2/transaction.c +1 -0
index 5f08b5fd105a..b7309b894c91 100644
@@ -2415,6 +2415,7 @@ static int journal_unmap_buffer(journal_t *journal, struct buffer_head *bh,
 	clear_buffer_delay(bh);
 	clear_buffer_unwritten(bh);
 	bh->b_bdev = NULL;
+	bh->f_b_bdev = NULL;
 	return may_free;
 }
 
fs/mpage.c +4 -1
index ffb064ed9d04..f526ad5a8386 100644
@@ -483,6 +483,7 @@ static int __mpage_writepage(struct folio *folio, struct writeback_control *wbc,
 	int boundary = 0;
 	sector_t boundary_block = 0;
 	struct block_device *boundary_bdev = NULL;
+	struct file *f_boundary_bdev = NULL;
 	size_t length;
 	struct buffer_head map_bh;
 	loff_t i_size = i_size_read(inode);
@@ -522,6 +523,7 @@ static int __mpage_writepage(struct folio *folio, struct writeback_control *wbc,
 			if (boundary) {
 				boundary_block = bh->b_blocknr;
 				boundary_bdev = bh->b_bdev;
+				f_boundary_bdev = bh->f_b_bdev;
 			}
 			bdev = bh->b_bdev;
 		} while ((bh = bh->b_this_page) != head);
@@ -564,6 +566,7 @@ static int __mpage_writepage(struct folio *folio, struct writeback_control *wbc,
 		if (buffer_boundary(&map_bh)) {
 			boundary_block = map_bh.b_blocknr;
 			boundary_bdev = map_bh.b_bdev;
+			f_boundary_bdev = map_bh.f_b_bdev;
 		}
 		if (page_block) {
 			if (map_bh.b_blocknr != blocks[page_block-1] + 1)
@@ -633,7 +636,7 @@ static int __mpage_writepage(struct folio *folio, struct writeback_control *wbc,
 	if (boundary || (first_unmapped != blocks_per_page)) {
 		bio = mpage_bio_submit_write(bio);
 		if (boundary_block) {
-			write_boundary_block(boundary_bdev,
+			write_boundary_block(f_boundary_bdev,
 					boundary_block, 1 << blkbits);
 		}
 	} else {
fs/nilfs2/btnode.c +2 -0
index 5710833ac1cc..9c6314e5cd7a 100644
@@ -60,6 +60,7 @@ nilfs_btnode_create_block(struct address_space *btnc, __u64 blocknr)
 	}
 	memset(bh->b_data, 0, i_blocksize(inode));
 	bh->b_bdev = inode->i_sb->s_bdev;
+	bh->f_b_bdev = inode->i_sb->f_s_bdev;
 	bh->b_blocknr = blocknr;
 	set_buffer_mapped(bh);
 	set_buffer_uptodate(bh);
@@ -119,6 +120,7 @@ int nilfs_btnode_submit_block(struct address_space *btnc, __u64 blocknr,
 	}
 	set_buffer_mapped(bh);
 	bh->b_bdev = inode->i_sb->s_bdev;
+	bh->f_b_bdev = inode->i_sb->f_s_bdev;
 	bh->b_blocknr = pblocknr; /* set block address for read */
 	bh->b_end_io = end_buffer_read_sync;
 	get_bh(bh);
fs/nilfs2/gcinode.c +1 -0
index 8beb2730929d..f15f3b012d92 100644
@@ -85,6 +85,7 @@ int nilfs_gccache_submit_read_data(struct inode *inode, sector_t blkoff,
 
 	if (!buffer_mapped(bh)) {
 		bh->b_bdev = inode->i_sb->s_bdev;
+		bh->f_b_bdev = inode->i_sb->f_s_bdev;
 		set_buffer_mapped(bh);
 	}
 	bh->b_blocknr = pbn;
fs/nilfs2/mdt.c +1 -0
index c97c77a39668..a7205ca74937 100644
@@ -90,6 +90,7 @@ static int nilfs_mdt_create_block(struct inode *inode, unsigned long block,
 		goto failed_bh;
 
 	bh->b_bdev = sb->s_bdev;
+	bh->f_b_bdev = sb->f_s_bdev;
 	err = nilfs_mdt_insert_new_block(inode, block, bh, init_block);
 	if (likely(!err)) {
 		get_bh(bh);
fs/nilfs2/page.c +2 -0
index 06b04758f289..5809cfc99781 100644
@@ -112,6 +112,7 @@ void nilfs_copy_buffer(struct buffer_head *dbh, struct buffer_head *sbh)
 	dbh->b_state = sbh->b_state & NILFS_BUFFER_INHERENT_BITS;
 	dbh->b_blocknr = sbh->b_blocknr;
 	dbh->b_bdev = sbh->b_bdev;
+	dbh->f_b_bdev = sbh->f_b_bdev;
 
 	bh = dbh;
 	bits = sbh->b_state & (BIT(BH_Uptodate) | BIT(BH_Mapped));
@@ -216,6 +217,7 @@ static void nilfs_copy_folio(struct folio *dst, struct folio *src,
 		dbh->b_state = sbh->b_state & mask;
 		dbh->b_blocknr = sbh->b_blocknr;
 		dbh->b_bdev = sbh->b_bdev;
+		dbh->f_b_bdev = sbh->f_b_bdev;
 		sbh = sbh->b_this_page;
 		dbh = dbh->b_this_page;
 	} while (dbh != dbufs);
fs/nilfs2/recovery.c +10 -10
index 0955b657938f..cbd30496fca2 100644
@@ -107,7 +107,7 @@ static int nilfs_compute_checksum(struct the_nilfs *nilfs,
 		do {
 			struct buffer_head *bh;
 
-			bh = __bread(nilfs->ns_bdev, ++start, blocksize);
+			bh = __bread(nilfs->ns_f_bdev, ++start, blocksize);
 			if (!bh)
 				return -EIO;
 			check_bytes -= size;
@@ -136,7 +136,7 @@ int nilfs_read_super_root_block(struct the_nilfs *nilfs, sector_t sr_block,
 	int ret;
 
 	*pbh = NULL;
-	bh_sr = __bread(nilfs->ns_bdev, sr_block, nilfs->ns_blocksize);
+	bh_sr = __bread(nilfs->ns_f_bdev, sr_block, nilfs->ns_blocksize);
 	if (unlikely(!bh_sr)) {
 		ret = NILFS_SEG_FAIL_IO;
 		goto failed;
@@ -183,7 +183,7 @@ nilfs_read_log_header(struct the_nilfs *nilfs, sector_t start_blocknr,
 {
 	struct buffer_head *bh_sum;
 
-	bh_sum = __bread(nilfs->ns_bdev, start_blocknr, nilfs->ns_blocksize);
+	bh_sum = __bread(nilfs->ns_f_bdev, start_blocknr, nilfs->ns_blocksize);
 	if (bh_sum)
 		*sum = (struct nilfs_segment_summary *)bh_sum->b_data;
 	return bh_sum;
@@ -250,7 +250,7 @@ static void *nilfs_read_summary_info(struct the_nilfs *nilfs,
 	if (bytes > (*pbh)->b_size - *offset) {
 		blocknr = (*pbh)->b_blocknr;
 		brelse(*pbh);
-		*pbh = __bread(nilfs->ns_bdev, blocknr + 1,
+		*pbh = __bread(nilfs->ns_f_bdev, blocknr + 1,
 			       nilfs->ns_blocksize);
 		if (unlikely(!*pbh))
 			return NULL;
@@ -289,7 +289,7 @@ static void nilfs_skip_summary_info(struct the_nilfs *nilfs,
 		*offset = bytes * (count - (bcnt - 1) * nitem_per_block);
 
 		brelse(*pbh);
-		*pbh = __bread(nilfs->ns_bdev, blocknr + bcnt,
+		*pbh = __bread(nilfs->ns_f_bdev, blocknr + bcnt,
 			       nilfs->ns_blocksize);
 	}
 }
@@ -318,7 +318,7 @@ static int nilfs_scan_dsync_log(struct the_nilfs *nilfs, sector_t start_blocknr,
 
 	sumbytes = le32_to_cpu(sum->ss_sumbytes);
 	blocknr = start_blocknr + DIV_ROUND_UP(sumbytes, nilfs->ns_blocksize);
-	bh = __bread(nilfs->ns_bdev, start_blocknr, nilfs->ns_blocksize);
+	bh = __bread(nilfs->ns_f_bdev, start_blocknr, nilfs->ns_blocksize);
 	if (unlikely(!bh))
 		goto out;
 
@@ -477,7 +477,7 @@ static int nilfs_recovery_copy_block(struct the_nilfs *nilfs,
 	struct buffer_head *bh_org;
 	void *kaddr;
 
-	bh_org = __bread(nilfs->ns_bdev, rb->blocknr, nilfs->ns_blocksize);
+	bh_org = __bread(nilfs->ns_f_bdev, rb->blocknr, nilfs->ns_blocksize);
 	if (unlikely(!bh_org))
 		return -EIO;
 
@@ -696,7 +696,7 @@ static void nilfs_finish_roll_forward(struct the_nilfs *nilfs,
 	    nilfs_get_segnum_of_block(nilfs, ri->ri_super_root))
 		return;
 
-	bh = __getblk(nilfs->ns_bdev, ri->ri_lsegs_start, nilfs->ns_blocksize);
+	bh = __getblk(nilfs->ns_f_bdev, ri->ri_lsegs_start, nilfs->ns_blocksize);
 	BUG_ON(!bh);
 	memset(bh->b_data, 0, bh->b_size);
 	set_buffer_dirty(bh);
@@ -822,7 +822,7 @@ int nilfs_search_super_root(struct the_nilfs *nilfs,
 	/* Read ahead segment */
 	b = seg_start;
 	while (b <= seg_end)
-		__breadahead(nilfs->ns_bdev, b++, nilfs->ns_blocksize);
+		__breadahead(nilfs->ns_f_bdev, b++, nilfs->ns_blocksize);
 
 	for (;;) {
 		brelse(bh_sum);
@@ -868,7 +868,7 @@ int nilfs_search_super_root(struct the_nilfs *nilfs,
 		if (pseg_start == seg_start) {
 			nilfs_get_segment_range(nilfs, nextnum, &b, &end);
 			while (b <= end)
-				__breadahead(nilfs->ns_bdev, b++,
+				__breadahead(nilfs->ns_f_bdev, b++,
 					     nilfs->ns_blocksize);
 		}
 		if (!(flags & NILFS_SS_SR)) {
fs/nilfs2/the_nilfs.c +1 -0
index 71400496ed36..6908dd87f44c 100644
@@ -63,6 +63,7 @@ struct the_nilfs *alloc_nilfs(struct super_block *sb)
 
 	nilfs->ns_sb = sb;
 	nilfs->ns_bdev = sb->s_bdev;
+	nilfs->ns_f_bdev = sb->s_f_bdev;
 	atomic_set(&nilfs->ns_ndirtyblks, 0);
 	init_rwsem(&nilfs->ns_sem);
 	mutex_init(&nilfs->ns_snapshot_mount_mutex);
fs/ntfs/aops.c +3 -0
index 548f3b51aa5f..cc31e38479ac 100644
@@ -228,6 +228,7 @@ static int ntfs_read_block(struct folio *folio)
 			continue;
 		}
 		bh->b_bdev = vol->sb->s_bdev;
+		bh->f_b_bdev = vol->sb->s_f_bdev;
 		/* Is the block within the allowed limits? */
 		if (iblock < lblock) {
 			bool is_retry = false;
@@ -679,6 +680,7 @@ static int ntfs_write_block(struct folio *folio, struct writeback_control *wbc)
 
 		/* Unmapped, dirty buffer. Need to map it. */
 		bh->b_bdev = vol->sb->s_bdev;
+		bh->f_b_bdev = vol->sb->s_f_bdev;
 
 		/* Convert block into corresponding vcn and offset. */
 		vcn = (VCN)block << blocksize_bits;
@@ -989,6 +991,7 @@ static int ntfs_write_mst_block(struct page *page,
 			unsigned int vcn_ofs;
 
 			bh->b_bdev = vol->sb->s_bdev;
+			bh->f_b_bdev = vol->sb->s_f_bdev;
 			/* Obtain the vcn and offset of the current block. */
 			vcn = (VCN)block << bh_size_bits;
 			vcn_ofs = vcn & vol->cluster_size_mask;
fs/ntfs/file.c +1 -0
index 297c0b9db621..e3f35d1550ed 100644
@@ -681,6 +681,7 @@ static int ntfs_prepare_pages_for_non_resident_write(struct page **pages,
 		}
 		/* Unmapped buffer.  Need to map it. */
 		bh->b_bdev = vol->sb->s_bdev;
+		bh->f_b_bdev = vol->sb->s_f_bdev;
 		/*
 		 * If the current buffer is in the same clusters as the map
 		 * cache, there is no need to check the runlist again.  The
fs/ntfs/mft.c +2 -0
index 6fd1dc4b08c8..9193f2516d06 100644
@@ -527,6 +527,7 @@ int ntfs_sync_mft_mirror(ntfs_volume *vol, const unsigned long mft_no,
 			unsigned int vcn_ofs;
 
 			bh->b_bdev = vol->sb->s_bdev;
+			bh->f_b_bdev = vol->sb->s_f_bdev;
 			/* Obtain the vcn and offset of the current block. */
 			vcn = ((VCN)mft_no << vol->mft_record_size_bits) +
 					(block_start - m_start);
@@ -720,6 +721,7 @@ int write_mft_record_nolock(ntfs_inode *ni, MFT_RECORD *m, int sync)
 			unsigned int vcn_ofs;
 
 			bh->b_bdev = vol->sb->s_bdev;
+			bh->f_b_bdev = vol->sb->s_f_bdev;
 			/* Obtain the vcn and offset of the current block. */
 			vcn = ((VCN)ni->mft_no << vol->mft_record_size_bits) +
 					(block_start - m_start);
fs/ntfs3/fsntfs.c +4 -4
index fbfe21dbb425..c58efca1427b 100644
@@ -1015,7 +1015,7 @@ int ntfs_sb_read(struct super_block *sb, u64 lbo, size_t bytes, void *buffer)
 	u32 op = blocksize - off;
 
 	for (; bytes; block += 1, off = 0, op = blocksize) {
-		struct buffer_head *bh = __bread(bdev, block, blocksize);
+		struct buffer_head *bh = __bread(sb->s_f_bdev, block, blocksize);
 
 		if (!bh)
 			return -EIO;
@@ -1052,14 +1052,14 @@ int ntfs_sb_write(struct super_block *sb, u64 lbo, size_t bytes,
 			op = bytes;
 
 		if (op < blocksize) {
-			bh = __bread(bdev, block, blocksize);
+			bh = __bread(sb->s_f_bdev, block, blocksize);
 			if (!bh) {
 				ntfs_err(sb, "failed to read block %llx",
 					 (u64)block);
 				return -EIO;
 			}
 		} else {
-			bh = __getblk(bdev, block, blocksize);
+			bh = __getblk(sb->s_f_bdev, block, blocksize);
 			if (!bh)
 				return -ENOMEM;
 		}
@@ -2673,4 +2673,4 @@ int ntfs_set_label(struct ntfs_sb_info *sbi, u8 *label, int len)
 out:
 	__putname(uni);
 	return err;
-}
\ No newline at end of file
+}
fs/ntfs3/inode.c +1 -0
index 5e3d71374918..daa8976c137c 100644
@@ -612,6 +612,7 @@ static noinline int ntfs_get_block_vbo(struct inode *inode, u64 vbo,
 
 	set_buffer_mapped(bh);
 	bh->b_bdev = sb->s_bdev;
+	bh->f_b_bdev = sb->s_f_bdev;
 	bh->b_blocknr = lbo >> sb->s_blocksize_bits;
 
 	valid = ni->i_valid;
fs/ntfs3/super.c +1 -1
index 9153dffde950..f0f969d35b83 100644
@@ -1632,7 +1632,7 @@ void ntfs_unmap_meta(struct super_block *sb, CLST lcn, CLST len)
 		limit >>= 1;
 
 	while (blocks--) {
-		clean_bdev_aliases(bdev, devblock++, 1);
+		clean_bdev_aliases(sb->s_f_bdev, devblock++, 1);
 		if (cnt++ >= limit) {
 			sync_blockdev(bdev);
 			cnt = 0;
fs/ocfs2/journal.c +1 -1
index 604fea3a26ff..20485bac26d2 100644
@@ -1209,7 +1209,7 @@ static int ocfs2_force_read_journal(struct inode *inode)
 		}
 
 		for (i = 0; i < p_blocks; i++, p_blkno++) {
-			bh = __find_get_block(osb->sb->s_bdev, p_blkno,
+			bh = __find_get_block(osb->sb->s_f_bdev, p_blkno,
 					osb->sb->s_blocksize);
 			/* block not cached. */
 			if (!bh)
fs/reiserfs/journal.c +4 -4
index 177ccb4d9bc3..94b2663130c2 100644
@@ -2315,7 +2315,7 @@ static int journal_read_transaction(struct super_block *sb,
  * from other places.
  * Note: Do not use journal_getblk/sb_getblk functions here!
  */
-static struct buffer_head *reiserfs_breada(struct block_device *dev,
+static struct buffer_head *reiserfs_breada(struct file *f_dev,
 					   b_blocknr_t block, int bufsize,
 					   b_blocknr_t max_block)
 {
@@ -2324,7 +2324,7 @@ static struct buffer_head *reiserfs_breada(struct block_device *dev,
 	struct buffer_head *bh;
 	int i, j;
 
-	bh = __getblk(dev, block, bufsize);
+	bh = __getblk(f_dev, block, bufsize);
 	if (!bh || buffer_uptodate(bh))
 		return (bh);
 
@@ -2334,7 +2334,7 @@ static struct buffer_head *reiserfs_breada(struct block_device *dev,
 	bhlist[0] = bh;
 	j = 1;
 	for (i = 1; i < blocks; i++) {
-		bh = __getblk(dev, block + i, bufsize);
+		bh = __getblk(f_dev, block + i, bufsize);
 		if (!bh)
 			break;
 		if (buffer_uptodate(bh)) {
@@ -2447,7 +2447,7 @@ static int journal_read(struct super_block *sb)
 		 * device and journal device to be the same
 		 */
 		d_bh =
-		    reiserfs_breada(F_BDEV(journal->j_f_bdev), cur_dblock,
+		    reiserfs_breada(journal->j_f_bdev, cur_dblock,
 				    sb->s_blocksize,
 				    SB_ONDISK_JOURNAL_1st_BLOCK(sb) +
 				    SB_ONDISK_JOURNAL_SIZE(sb));
fs/reiserfs/reiserfs.h +3 -3
index ea2f5950e5c6..61f5146e876f 100644
@@ -2810,10 +2810,10 @@ struct reiserfs_journal_header {
 
 /* We need these to make journal.c code more readable */
 #define journal_find_get_block(s, block) __find_get_block(\
-		F_BDEV(SB_JOURNAL(s)->j_f_bdev), block, s->s_blocksize)
-#define journal_getblk(s, block) __getblk(F_BDEV(SB_JOURNAL(s)->j_f_bdev),\
+		SB_JOURNAL(s)->j_f_bdev, block, s->s_blocksize)
+#define journal_getblk(s, block) __getblk(SB_JOURNAL(s)->j_f_bdev,\
 		block, s->s_blocksize)
-#define journal_bread(s, block) __bread(F_BDEV(SB_JOURNAL(s)->j_f_bdev),\
+#define journal_bread(s, block) __bread(SB_JOURNAL(s)->j_f_bdev,\
 		block, s->s_blocksize)
 
 enum reiserfs_bh_state_bits {
fs/reiserfs/tail_conversion.c +1 -0
index 2cec61af2a9e..0978a0a73a64 100644
@@ -188,6 +188,7 @@ void reiserfs_unmap_buffer(struct buffer_head *bh)
 	clear_buffer_req(bh);
 	clear_buffer_new(bh);
 	bh->b_bdev = NULL;
+	bh->f_b_bdev = NULL;
 	unlock_buffer(bh);
 }
 
fs/xfs/xfs_iomap.c +5 -2
index 18c8f168b153..e0f38fafc5df 100644
@@ -122,10 +122,12 @@ xfs_bmbt_to_iomap(
 	}
 	iomap->offset = XFS_FSB_TO_B(mp, imap->br_startoff);
 	iomap->length = XFS_FSB_TO_B(mp, imap->br_blockcount);
-	if (mapping_flags & IOMAP_DAX)
+	if (mapping_flags & IOMAP_DAX) {
 		iomap->dax_dev = target->bt_daxdev;
-	else
+	} else {
 		iomap->bdev = target->bt_bdev;
+		iomap->f_bdev = target->bt_f_bdev;
+	}
 	iomap->flags = iomap_flags;
 
 	if (xfs_ipincount(ip) &&
@@ -151,6 +153,7 @@ xfs_hole_to_iomap(
 	iomap->offset = XFS_FSB_TO_B(ip->i_mount, offset_fsb);
 	iomap->length = XFS_FSB_TO_B(ip->i_mount, end_fsb - offset_fsb);
 	iomap->bdev = target->bt_bdev;
+	iomap->f_bdev = target->bt_f_bdev;
 	iomap->dax_dev = target->bt_daxdev;
 }
 
fs/zonefs/file.c +2 -0
index b2c9b35df8f7..2c79506ca7b6 100644
@@ -39,6 +39,7 @@ static int zonefs_read_iomap_begin(struct inode *inode, loff_t offset,
 	 */
 	mutex_lock(&zi->i_truncate_mutex);
 	iomap->bdev = inode->i_sb->s_bdev;
+	iomap->f_bdev = inode->i_sb->s_f_bdev;
 	iomap->offset = ALIGN_DOWN(offset, sb->s_blocksize);
 	isize = i_size_read(inode);
 	if (iomap->offset >= isize) {
@@ -89,6 +90,7 @@ static int zonefs_write_iomap_begin(struct inode *inode, loff_t offset,
 	 */
 	mutex_lock(&zi->i_truncate_mutex);
 	iomap->bdev = inode->i_sb->s_bdev;
+	iomap->f_bdev = inode->i_sb->s_f_bdev;
 	iomap->offset = ALIGN_DOWN(offset, sb->s_blocksize);
 	iomap->addr = (z->z_sector << SECTOR_SHIFT) + iomap->offset;
 	isize = i_size_read(inode);
include/linux/buffer_head.h +24 -21

141 lines not on this page · raw message

include/linux/iomap.h +1 -0
index 96dd0acbba44..91f1e434cab3 100644
@@ -97,6 +97,7 @@ struct iomap {
 	u64			length;	/* length of mapping, bytes */
 	u16			type;	/* type of mapping */
 	u16			flags;	/* flags for mapping */
+	struct file		*f_bdev;
 	struct block_device	*bdev;	/* block device for I/O */
 	struct dax_device	*dax_dev; /* dax_dev for dax operations */
 	void			*inline_data;
include/linux/jbd2.h +4 -2
index beb30719ee16..d357ba510df6 100644
@@ -972,6 +972,7 @@ struct journal_s
 	 * @j_dev: Device where we store the journal.
 	 */
 	struct block_device	*j_dev;
+	struct file		*f_j_dev;
 
 	/**
 	 * @j_blocksize: Block size for the location where we store the journal.
@@ -997,6 +998,7 @@ struct journal_s
 	 * equal to j_dev.
 	 */
 	struct block_device	*j_fs_dev;
+	struct file		*f_j_fs_dev;
 
 	/**
 	 * @j_total_len: Total maximum capacity of the journal region on disk.
@@ -1537,8 +1539,8 @@ extern void	 jbd2_journal_unlock_updates (journal_t *);
 
 void jbd2_journal_wait_updates(journal_t *);
 
-extern journal_t * jbd2_journal_init_dev(struct block_device *bdev,
-				struct block_device *fs_dev,
+extern journal_t * jbd2_journal_init_dev(struct file *f_bdev,
+				struct file *fs_dev,
 				unsigned long long start, int len, int bsize);
 extern journal_t * jbd2_journal_init_inode (struct inode *);
 extern int	   jbd2_journal_update_format (journal_t *);
Signature · 1 line
2.42.0
#12 lore raw

Re: [PATCH RFC 07/34] xfs: port block device access to files

In reply to Christian Brauner
Quoted 12 lines · Christian Brauner
---
 fs/xfs/xfs_buf.c   | 10 +++++-----
 fs/xfs/xfs_buf.h   |  4 ++--
 fs/xfs/xfs_super.c | 43 +++++++++++++++++++++----------------------
 3 files changed, 28 insertions(+), 29 deletions(-)
fs/xfs/xfs_buf.c +0 -0
index 545c7991b9b5..685eb2a9f9d2 100644

fs/xfs/xfs_buf.c xfs_free_buftarg( · line 1954

Quoted 5 lines
fs/xfs/xfs_buf.c +1 -1
@@ -1951,7 +1951,7 @@ xfs_free_buftarg(
 	fs_put_dax(btp->bt_daxdev, btp->bt_mount);
 	/* the main block device is closed by kill_block_super */
 	if (btp->bt_bdev != btp->bt_mount->m_super->s_bdev)
-		bdev_release(btp->bt_bdev_handle);
+		fput(btp->bt_f_bdev);

bt_bdev_file, please.

"_f_" is not a meaningful prefix, and if we fill the code up with single letter prefixes is becomes completely unreadable.

fs/xfs/xfs_buf.c xfs_setsize_buftarg_early( · line 1997

Quoted 9 lines
fs/xfs/xfs_buf.c +1 -1
 	kmem_free(btp);
 }
@@ -1994,7 +1994,7 @@ xfs_setsize_buftarg_early(
 struct xfs_buftarg *
 xfs_alloc_buftarg(
 	struct xfs_mount	*mp,
-	struct bdev_handle	*bdev_handle)
+	struct file		*f_bdev)

struct file *bdev_file)

fs/xfs/xfs_buf.c xfs_alloc_buftarg( · line 2009

Quoted 12 lines
fs/xfs/xfs_buf.c +2 -3
 {
 	xfs_buftarg_t		*btp;
 	const struct dax_holder_operations *ops = NULL;
@@ -2005,9 +2005,9 @@ xfs_alloc_buftarg(
 	btp = kmem_zalloc(sizeof(*btp), KM_NOFS);
 
 	btp->bt_mount = mp;
-	btp->bt_bdev_handle = bdev_handle;
-	btp->bt_dev = bdev_handle->bdev->bd_dev;
-	btp->bt_bdev = bdev_handle->bdev;
+	btp->bt_f_bdev = f_bdev;
+	btp->bt_bdev = F_BDEV(f_bdev);

file_bdev(), please. i.e. similar to file_inode().

fs/xfs/xfs_super.c STATIC int · line 365

Quoted 10 lines
fs/xfs/xfs_super.c +1 -1
index 0e64220bffdc..01ef0ef83c41 100644
@@ -362,16 +362,16 @@ STATIC int
 xfs_blkdev_get(
 	xfs_mount_t		*mp,
 	const char		*name,
-	struct bdev_handle	**handlep)
+	struct file		**f_bdevp)

struct file **filep

Quoted 17 lines
fs/xfs/xfs_super.c +4 -4
 {
 	int			error = 0;
 
-	*handlep = bdev_open_by_path(name,
+	*f_bdevp = bdev_file_open_by_path(name,
 		BLK_OPEN_READ | BLK_OPEN_WRITE | BLK_OPEN_RESTRICT_WRITES,
 		mp->m_super, &fs_holder_ops);
-	if (IS_ERR(*handlep)) {
-		error = PTR_ERR(*handlep);
-		*handlep = NULL;
+	if (IS_ERR(*f_bdevp)) {
+		error = PTR_ERR(*f_bdevp);
+		*f_bdevp = NULL;
 		xfs_warn(mp, "Invalid device [%s], error=%d", name, error);
 	}
 

fs/xfs/xfs_super.c xfs_open_devices( · line 439

Quoted 5 lines
fs/xfs/xfs_super.c +1 -1
@@ -436,26 +436,25 @@ xfs_open_devices(
 {
 	struct super_block	*sb = mp->m_super;
 	struct block_device	*ddev = sb->s_bdev;
-	struct bdev_handle	*logdev_handle = NULL, *rtdev_handle = NULL;
+	struct file		*f_logdev = NULL, *f_rtdev = NULL;
	struct file		*logdev_file = NULL;
	struct file		*rtdev_file = NULL;

...

-Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#2 lore raw

Re: [PATCH RFC 01/34] bdev: open block device as files

In reply to Christian Brauner
Quoted 7 lines · Christian Brauner

---

include/linux/fs.h +0 -0
index 8e0d77f9464e..b0a5e94e8c3a 100644

include/linux/fs.h struct super_block { · line 1231

Quoted 7 lines
include/linux/fs.h +2 -2
@@ -1227,8 +1227,8 @@ struct super_block {
 #endif
 	struct hlist_bl_head	s_roots;	/* alternate root dentries for NFS */
 	struct list_head	s_mounts;	/* list of mounts; _not_ for fs use */
-	struct block_device	*s_bdev;
-	struct bdev_handle	*s_bdev_handle;
+	struct block_device	*s_bdev;	/* can go away once we use an accessor for @s_f_bdev */
+	struct file		*s_f_bdev;
	struct file		*s_bdev_file;

Because then the reader knows exactly what the object type and what it refers to is when they read "sb->s_bdev_file" in the code.

-Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#41 lore raw

Re: [PATCH DRAFT RFC 34/34] buffer: port block device access to files and get rid of bd_inode access

In reply to Christian Brauner
Quoted 54 lines · Christian Brauner
---
 block/fops.c                  |  1 +
 drivers/md/md-bitmap.c        |  1 +
 fs/affs/file.c                |  1 +
 fs/btrfs/inode.c              |  1 +
 fs/buffer.c                   | 69 ++++++++++++++++++++++---------------------
 fs/direct-io.c                |  2 +-
 fs/erofs/data.c               |  7 +++--
 fs/erofs/internal.h           |  1 +
 fs/erofs/zmap.c               |  1 +
 fs/ext2/inode.c               |  8 +++--
 fs/ext4/inode.c               |  6 ++--
 fs/ext4/super.c               |  6 ++--
 fs/f2fs/data.c                |  6 +++-
 fs/f2fs/f2fs.h                |  1 +
 fs/fuse/dax.c                 |  1 +
 fs/gfs2/aops.c                |  1 +
 fs/gfs2/bmap.c                |  1 +
 fs/hpfs/file.c                |  1 +
 fs/jbd2/commit.c              |  1 +
 fs/jbd2/journal.c             | 26 +++++++++-------
 fs/jbd2/recovery.c            |  6 ++--
 fs/jbd2/revoke.c              | 10 +++----
 fs/jbd2/transaction.c         |  1 +
 fs/mpage.c                    |  5 +++-
 fs/nilfs2/btnode.c            |  2 ++
 fs/nilfs2/gcinode.c           |  1 +
 fs/nilfs2/mdt.c               |  1 +
 fs/nilfs2/page.c              |  2 ++
 fs/nilfs2/recovery.c          | 20 ++++++-------
 fs/nilfs2/the_nilfs.c         |  1 +
 fs/ntfs/aops.c                |  3 ++
 fs/ntfs/file.c                |  1 +
 fs/ntfs/mft.c                 |  2 ++
 fs/ntfs3/fsntfs.c             |  8 ++---
 fs/ntfs3/inode.c              |  1 +
 fs/ntfs3/super.c              |  2 +-
 fs/ocfs2/journal.c            |  2 +-
 fs/reiserfs/journal.c         |  8 ++---
 fs/reiserfs/reiserfs.h        |  6 ++--
 fs/reiserfs/tail_conversion.c |  1 +
 fs/xfs/xfs_iomap.c            |  7 +++--
 fs/zonefs/file.c              |  2 ++
 include/linux/buffer_head.h   | 45 +++++++++++++++-------------
 include/linux/iomap.h         |  1 +
 include/linux/jbd2.h          |  6 ++--
 45 files changed, 172 insertions(+), 114 deletions(-)
block/fops.c +0 -0
index e831196dafac..6557b71c7657 100644

block/fops.c static int blkdev_iomap_begin(struct inode *inode, loff_t offset, loff_t length, · line 384

Quoted 4 lines
block/fops.c +1 -0
@@ -381,6 +381,7 @@ static int blkdev_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
 	loff_t isize = i_size_read(inode);
 
 	iomap->bdev = bdev;
+	BUG_ON(true /* TODO(brauner): This is the only place where we don't go from inode->i_sb->s_f_bdev for obvious reasons. Thoughts? */);

Maybe block devices should have their own struct file created when the block device is instantiated and torn down when the block device is trashed?

Quoted 20 lines
fs/xfs/xfs_iomap.c +4 -2
index 18c8f168b153..e0f38fafc5df 100644
@@ -122,10 +122,12 @@ xfs_bmbt_to_iomap(
 	}
 	iomap->offset = XFS_FSB_TO_B(mp, imap->br_startoff);
 	iomap->length = XFS_FSB_TO_B(mp, imap->br_blockcount);
-	if (mapping_flags & IOMAP_DAX)
+	if (mapping_flags & IOMAP_DAX) {
 		iomap->dax_dev = target->bt_daxdev;
-	else
+	} else {
 		iomap->bdev = target->bt_bdev;
+		iomap->f_bdev = target->bt_f_bdev;
+	}
 	iomap->flags = iomap_flags;
 
 	if (xfs_ipincount(ip) &&

fs/xfs/xfs_iomap.c xfs_hole_to_iomap( · line 157

Quoted 5 lines
fs/xfs/xfs_iomap.c +1 -0
@@ -151,6 +153,7 @@ xfs_hole_to_iomap(
 	iomap->offset = XFS_FSB_TO_B(ip->i_mount, offset_fsb);
 	iomap->length = XFS_FSB_TO_B(ip->i_mount, end_fsb - offset_fsb);
 	iomap->bdev = target->bt_bdev;
+	iomap->f_bdev = target->bt_f_bdev;
 	iomap->dax_dev = target->bt_daxdev;

Why are we passing both iomap->bdev and the bdev file pointer? I didn't see anything that uses the bdev file pointer, so I'm not sure why this is being added if iomap->bdev is not getting removed....

include/linux/iomap.h struct iomap { · line 100

Quoted 9 lines
include/linux/iomap.h +1 -0
index 96dd0acbba44..91f1e434cab3 100644
@@ -97,6 +97,7 @@ struct iomap {
 	u64			length;	/* length of mapping, bytes */
 	u16			type;	/* type of mapping */
 	u16			flags;	/* flags for mapping */
+	struct file		*f_bdev;

struct file *bdev_file; /* block device for I/O */

include/linux/iomap.h struct iomap { · line 103

Quoted 3 lines
include/linux/iomap.h +0 -0
 	struct block_device	*bdev;	/* block device for I/O */
 	struct dax_device	*dax_dev; /* dax_dev for dax operations */
 	void			*inline_data;

-Dave.

Signature · 2 lines
Dave Chinner
[email protected]
author maintainer
#3 lore raw

Re: [PATCH RFC 01/34] bdev: open block device as files

In reply to Dave Chinner
Quoted 18 lines · Dave Chinner
Quoted 7 lines · Christian Brauner

---

include/linux/fs.h +0 -0
index 8e0d77f9464e..b0a5e94e8c3a 100644

include/linux/fs.h struct super_block { · line 1231

Quoted 7 lines
include/linux/fs.h +2 -2
@@ -1227,8 +1227,8 @@ struct super_block {
 #endif
 	struct hlist_bl_head	s_roots;	/* alternate root dentries for NFS */
 	struct list_head	s_mounts;	/* list of mounts; _not_ for fs use */
-	struct block_device	*s_bdev;
-	struct bdev_handle	*s_bdev_handle;
+	struct block_device	*s_bdev;	/* can go away once we use an accessor for @s_f_bdev */
+	struct file		*s_f_bdev;
	struct file		*s_bdev_file;
Quoted 3 lines

Because then the reader knows exactly what the object type and what it refers to is when they read "sb->s_bdev_file" in the code.

Fair!

author maintainer
#13 lore raw

Re: [PATCH RFC 07/34] xfs: port block device access to files

In reply to Dave Chinner
Quoted 21 lines · Dave Chinner
Quoted 12 lines · Christian Brauner
---
 fs/xfs/xfs_buf.c   | 10 +++++-----
 fs/xfs/xfs_buf.h   |  4 ++--
 fs/xfs/xfs_super.c | 43 +++++++++++++++++++++----------------------
 3 files changed, 28 insertions(+), 29 deletions(-)
fs/xfs/xfs_buf.c +0 -0
index 545c7991b9b5..685eb2a9f9d2 100644

fs/xfs/xfs_buf.c xfs_free_buftarg( · line 1954

Quoted 5 lines
fs/xfs/xfs_buf.c +1 -1
@@ -1951,7 +1951,7 @@ xfs_free_buftarg(
 	fs_put_dax(btp->bt_daxdev, btp->bt_mount);
 	/* the main block device is closed by kill_block_super */
 	if (btp->bt_bdev != btp->bt_mount->m_super->s_bdev)
-		bdev_release(btp->bt_bdev_handle);
+		fput(btp->bt_f_bdev);

bt_bdev_file, please.

Quoted 2 lines

"_f_" is not a meaningful prefix, and if we fill the code up with single letter prefixes is becomes completely unreadable.

Ack to all suggestions.

Quoted 72 lines

fs/xfs/xfs_buf.c xfs_setsize_buftarg_early( · line 1997

Quoted 10 lines
fs/xfs/xfs_buf.c +1 -1
 	kmem_free(btp);
 }
@@ -1994,7 +1994,7 @@ xfs_setsize_buftarg_early(
 struct xfs_buftarg *
 xfs_alloc_buftarg(
 	struct xfs_mount	*mp,
-	struct bdev_handle	*bdev_handle)
+	struct file		*f_bdev)

struct file *bdev_file)

fs/xfs/xfs_buf.c xfs_alloc_buftarg( · line 2009

Quoted 12 lines
fs/xfs/xfs_buf.c +2 -3
 {
 	xfs_buftarg_t		*btp;
 	const struct dax_holder_operations *ops = NULL;
@@ -2005,9 +2005,9 @@ xfs_alloc_buftarg(
 	btp = kmem_zalloc(sizeof(*btp), KM_NOFS);
 
 	btp->bt_mount = mp;
-	btp->bt_bdev_handle = bdev_handle;
-	btp->bt_dev = bdev_handle->bdev->bd_dev;
-	btp->bt_bdev = bdev_handle->bdev;
+	btp->bt_f_bdev = f_bdev;
+	btp->bt_bdev = F_BDEV(f_bdev);

file_bdev(), please. i.e. similar to file_inode().

fs/xfs/xfs_super.c STATIC int · line 365

Quoted 10 lines
fs/xfs/xfs_super.c +1 -1
index 0e64220bffdc..01ef0ef83c41 100644
@@ -362,16 +362,16 @@ STATIC int
 xfs_blkdev_get(
 	xfs_mount_t		*mp,
 	const char		*name,
-	struct bdev_handle	**handlep)
+	struct file		**f_bdevp)

struct file **filep

Quoted 17 lines
fs/xfs/xfs_super.c +4 -4
 {
 	int			error = 0;
 
-	*handlep = bdev_open_by_path(name,
+	*f_bdevp = bdev_file_open_by_path(name,
 		BLK_OPEN_READ | BLK_OPEN_WRITE | BLK_OPEN_RESTRICT_WRITES,
 		mp->m_super, &fs_holder_ops);
-	if (IS_ERR(*handlep)) {
-		error = PTR_ERR(*handlep);
-		*handlep = NULL;
+	if (IS_ERR(*f_bdevp)) {
+		error = PTR_ERR(*f_bdevp);
+		*f_bdevp = NULL;
 		xfs_warn(mp, "Invalid device [%s], error=%d", name, error);
 	}
 

fs/xfs/xfs_super.c xfs_open_devices( · line 439

Quoted 5 lines
fs/xfs/xfs_super.c +1 -1
@@ -436,26 +436,25 @@ xfs_open_devices(
 {
 	struct super_block	*sb = mp->m_super;
 	struct block_device	*ddev = sb->s_bdev;
-	struct bdev_handle	*logdev_handle = NULL, *rtdev_handle = NULL;
+	struct file		*f_logdev = NULL, *f_rtdev = NULL;
	struct file		*logdev_file = NULL;
	struct file		*rtdev_file = NULL;

...

-Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#48 lore raw
In reply to Christian Brauner
Quoted 3 lines · Christian Brauner

I wanted to see whether we can make struct bdev_handle completely private to the block layer in the next cycle and unexport low-level helpers such as bdev_release() - formerly blkdev_put() - completely.

I think we can actually kill bdev_handle entirely. We can get the bdev from the bdev inode using I_BDEV already, so no need to store the bdev. We don't need the mode field as we known an exlusive open is equivalent to having a holder. So just store the older in file->private_data and the bdev_handle can be removed again.

reviewer
#49 lore raw
Quoted 10 lines · Christoph Hellwig
Quoted 3 lines · Christian Brauner

I wanted to see whether we can make struct bdev_handle completely private to the block layer in the next cycle and unexport low-level helpers such as bdev_release() - formerly blkdev_put() - completely.

I think we can actually kill bdev_handle entirely. We can get the bdev from the bdev inode using I_BDEV already, so no need to store the bdev. We don't need the mode field as we known an exlusive open is equivalent to having a holder. So just store the older in file->private_data and the bdev_handle can be removed again.

Well, we also need the read-write mode of the handle in some places but that could be stored in file->f_mode (not sure if it really gets stored there in this patch set - still need to read the details) so in principle I agree that bdev_handle should not be necessary.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
author maintainer
#50 lore raw
Quoted 12 lines · Jan Kara
Quoted 10 lines · Christoph Hellwig
Quoted 3 lines · Christian Brauner

I wanted to see whether we can make struct bdev_handle completely private to the block layer in the next cycle and unexport low-level helpers such as bdev_release() - formerly blkdev_put() - completely.

I think we can actually kill bdev_handle entirely. We can get the bdev from the bdev inode using I_BDEV already, so no need to store the bdev. We don't need the mode field as we known an exlusive open is equivalent to having a holder. So just store the older in file->private_data and the bdev_handle can be removed again.

Quoted 4 lines

Well, we also need the read-write mode of the handle in some places but that could be stored in file->f_mode (not sure if it really gets stored there in this patch set - still need to read the details) so in principle I agree that bdev_handle should not be necessary.

So I think I've found a way to not even use a new fmode flag for this. We can just use a set of file operations def_blk_fops_restricted to detect when a block device was opened with restricted write access. def_blk_fops isn't needed to check whether something is a block device IS_BLK() is enough for that. And def_blk_fops_restricted can be kept completely local to block/.

reviewer
#4 lore raw

Re: [PATCH RFC 01/34] bdev: open block device as files

In reply to Christian Brauner
Quoted 18 lines · Christian Brauner
block/bdev.c +18 -0
+struct file *bdev_file_open_by_dev(dev_t dev, blk_mode_t mode, void *holder,
+				   const struct blk_holder_ops *hops)
+{
+	struct file *file;
+	struct bdev_handle *handle;
+	unsigned int flags;
+
+	handle = bdev_open_by_dev(dev, mode, holder, hops);
+	if (IS_ERR(handle))
+		return ERR_CAST(handle);
+
+	flags = blk_to_file_flags(mode);
+	file = alloc_file_pseudo(handle->bdev->bd_inode, blockdev_mnt, "",
+				 flags | O_LARGEFILE, &def_blk_fops);
+	if (IS_ERR(file)) {
+		bdev_release(handle);
+		return file;
+	}

block/bdev.c struct bdev_handle *bdev_open_by_dev(dev_t dev, blk_mode_t mode, void *holder, · line 981

Quoted 10 lines
block/bdev.c +10 -0
+	ihold(handle->bdev->bd_inode);
+
+	file->f_mode |= FMODE_BUF_RASYNC | FMODE_CAN_ODIRECT | FMODE_NOACCOUNT;
+	if (bdev_nowait(handle->bdev))
+		file->f_mode |= FMODE_NOWAIT;
+
+	file->f_mapping = handle->bdev->bd_inode->i_mapping;
+	file->f_wb_err = filemap_sample_wb_err(file->f_mapping);
+	file->private_data = handle;
+	return file;

Maybe I'm dense but when the file is closed where do we drop the bdev_handle?

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
reviewer
#42 lore raw

Re: [PATCH DRAFT RFC 34/34] buffer: port block device access to files and get rid of bd_inode access

In reply to Dave Chinner
Quoted 57 lines · Dave Chinner
Quoted 56 lines · Christian Brauner
---
 block/fops.c                  |  1 +
 drivers/md/md-bitmap.c        |  1 +
 fs/affs/file.c                |  1 +
 fs/btrfs/inode.c              |  1 +
 fs/buffer.c                   | 69 ++++++++++++++++++++++---------------------
 fs/direct-io.c                |  2 +-
 fs/erofs/data.c               |  7 +++--
 fs/erofs/internal.h           |  1 +
 fs/erofs/zmap.c               |  1 +
 fs/ext2/inode.c               |  8 +++--
 fs/ext4/inode.c               |  6 ++--
 fs/ext4/super.c               |  6 ++--
 fs/f2fs/data.c                |  6 +++-
 fs/f2fs/f2fs.h                |  1 +
 fs/fuse/dax.c                 |  1 +
 fs/gfs2/aops.c                |  1 +
 fs/gfs2/bmap.c                |  1 +
 fs/hpfs/file.c                |  1 +
 fs/jbd2/commit.c              |  1 +
 fs/jbd2/journal.c             | 26 +++++++++-------
 fs/jbd2/recovery.c            |  6 ++--
 fs/jbd2/revoke.c              | 10 +++----
 fs/jbd2/transaction.c         |  1 +
 fs/mpage.c                    |  5 +++-
 fs/nilfs2/btnode.c            |  2 ++
 fs/nilfs2/gcinode.c           |  1 +
 fs/nilfs2/mdt.c               |  1 +
 fs/nilfs2/page.c              |  2 ++
 fs/nilfs2/recovery.c          | 20 ++++++-------
 fs/nilfs2/the_nilfs.c         |  1 +
 fs/ntfs/aops.c                |  3 ++
 fs/ntfs/file.c                |  1 +
 fs/ntfs/mft.c                 |  2 ++
 fs/ntfs3/fsntfs.c             |  8 ++---
 fs/ntfs3/inode.c              |  1 +
 fs/ntfs3/super.c              |  2 +-
 fs/ocfs2/journal.c            |  2 +-
 fs/reiserfs/journal.c         |  8 ++---
 fs/reiserfs/reiserfs.h        |  6 ++--
 fs/reiserfs/tail_conversion.c |  1 +
 fs/xfs/xfs_iomap.c            |  7 +++--
 fs/zonefs/file.c              |  2 ++
 include/linux/buffer_head.h   | 45 +++++++++++++++-------------
 include/linux/iomap.h         |  1 +
 include/linux/jbd2.h          |  6 ++--
 45 files changed, 172 insertions(+), 114 deletions(-)
block/fops.c +0 -0
index e831196dafac..6557b71c7657 100644
@@ -381,6 +381,7 @@ static int blkdev_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
 	loff_t isize = i_size_read(inode);
 
Quoted 6 lines

block/fops.c static int blkdev_iomap_begin(struct inode *inode, loff_t offset, loff_t length, · line 384

Quoted 2 lines
block/fops.c +1 -0
 	iomap->bdev = bdev;
+	BUG_ON(true /* TODO(brauner): This is the only place where we don't go from inode->i_sb->s_f_bdev for obvious reasons. Thoughts? */);

Maybe block devices should have their own struct file created when the block device is instantiated and torn down when the block device is trashed?

OK, but is there a problem with I_BDEV() which is currently used in blkdev_iomap_begin()?

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#43 lore raw

Re: [PATCH DRAFT RFC 34/34] buffer: port block device access to files and get rid of bd_inode access

Quoted 9 lines · Jan Kara
Quoted 6 lines

block/fops.c static int blkdev_iomap_begin(struct inode *inode, loff_t offset, loff_t length, · line 384

Quoted 2 lines
block/fops.c +1 -0
 	iomap->bdev = bdev;
+	BUG_ON(true /* TODO(brauner): This is the only place where we don't go from inode->i_sb->s_f_bdev for obvious reasons. Thoughts? */);

Maybe block devices should have their own struct file created when the block device is instantiated and torn down when the block device is trashed?

OK, but is there a problem with I_BDEV() which is currently used in blkdev_iomap_begin()?

Well, blkdev_iomap_begin is always called on the the actual bdev fs inode that is allocated together with the bdev itself. So we'll always be able to get to it using container_of variants.

reviewer
#46 lore raw

Re: [PATCH DRAFT RFC 34/34] buffer: port block device access to files and get rid of bd_inode access

In reply to Christian Brauner

include/linux/buffer_head.h struct buffer_head { · line 75

Quoted 8 lines
include/linux/buffer_head.h +1 -0
@@ -68,6 +69,7 @@ struct buffer_head {
 	size_t b_size;			/* size of mapping */
 	char *b_data;			/* pointer to data within the page */
 
+	struct file *f_b_bdev;
 	struct block_device *b_bdev;
 	bh_end_io_t *b_end_io;		/* I/O completion */
  	void *b_private;		/* reserved for b_end_io */

It is kind of annoying to have bdev duplicated in every buffer_head. Perhaps we can get rid of b_bdev?

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
reviewer
#44 lore raw

Re: [PATCH DRAFT RFC 34/34] buffer: port block device access to files and get rid of bd_inode access

In reply to Christoph Hellwig
Quoted 8 lines · Christoph Hellwig
Quoted 7 lines · Jan Kara
Quoted 6 lines

block/fops.c static int blkdev_iomap_begin(struct inode *inode, loff_t offset, loff_t length, · line 384

Quoted 2 lines
block/fops.c +1 -0
 	iomap->bdev = bdev;
+	BUG_ON(true /* TODO(brauner): This is the only place where we don't go from inode->i_sb->s_f_bdev for obvious reasons. Thoughts? */);

Maybe block devices should have their own struct file created when the block device is instantiated and torn down when the block device is trashed?

Quoted 6 lines
Quoted 2 lines

OK, but is there a problem with I_BDEV() which is currently used in blkdev_iomap_begin()?

Well, blkdev_iomap_begin is always called on the the actual bdev fs inode that is allocated together with the bdev itself. So we'll always be able to get to it using container_of variants.

Yes, that was exactly my point.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
reviewer
#51 lore raw
In reply to Christian Brauner
Quoted 9 lines · Christian Brauner

I wanted to see whether we can make struct bdev_handle completely private to the block layer in the next cycle and unexport low-level helpers such as bdev_release() - formerly blkdev_put() - completely.

And afaict, we can actually get that to work. Simply put instead of doing this bdev_open_by_*() dance where we return a struct block_device we can just make bdev_file_open_by_*() return a struct file. Opening and closing a block device from setup_bdev_super() and in all other places just becomes equivalent to opening and closing a file.

So I've checked the patchset (not too carefully) and overall I like the direction. I've commented on the few things I didn't quite understand / like but overall I like this.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
author maintainer
#5 lore raw

Re: [PATCH RFC 01/34] bdev: open block device as files

In reply to Jan Kara
Quoted 24 lines · Jan Kara
Quoted 23 lines · Christian Brauner
block/bdev.c +23 -0
+struct file *bdev_file_open_by_dev(dev_t dev, blk_mode_t mode, void *holder,
+				   const struct blk_holder_ops *hops)
+{
+	struct file *file;
+	struct bdev_handle *handle;
+	unsigned int flags;
+
+	handle = bdev_open_by_dev(dev, mode, holder, hops);
+	if (IS_ERR(handle))
+		return ERR_CAST(handle);
+
+	flags = blk_to_file_flags(mode);
+	file = alloc_file_pseudo(handle->bdev->bd_inode, blockdev_mnt, "",
+				 flags | O_LARGEFILE, &def_blk_fops);
+	if (IS_ERR(file)) {
+		bdev_release(handle);
+		return file;
+	}
+	ihold(handle->bdev->bd_inode);
+
+	file->f_mode |= FMODE_BUF_RASYNC | FMODE_CAN_ODIRECT | FMODE_NOACCOUNT;
+	if (bdev_nowait(handle->bdev))
+		file->f_mode |= FMODE_NOWAIT;
Quoted 8 lines

block/bdev.c struct bdev_handle *bdev_open_by_dev(dev_t dev, blk_mode_t mode, void *holder, · line 981

Quoted 5 lines
block/bdev.c +5 -0
+
+	file->f_mapping = handle->bdev->bd_inode->i_mapping;
+	file->f_wb_err = filemap_sample_wb_err(file->f_mapping);
+	file->private_data = handle;
+	return file;

Maybe I'm dense but when the file is closed where do we drop the bdev_handle?

It's just a bit hidden. blkdev_release() wraps bdev_release():
file->f_op->release::blkdev_release()
-> bdev_release()
But in the updated version the handle is removed completely.

author maintainer
#45 lore raw

Re: [PATCH DRAFT RFC 34/34] buffer: port block device access to files and get rid of bd_inode access

In reply to Jan Kara
Quoted 9 lines · Jan Kara
Quoted 8 lines · Christoph Hellwig
Quoted 7 lines · Jan Kara
Quoted 6 lines

block/fops.c static int blkdev_iomap_begin(struct inode *inode, loff_t offset, loff_t length, · line 384

Quoted 2 lines
block/fops.c +1 -0
 	iomap->bdev = bdev;
+	BUG_ON(true /* TODO(brauner): This is the only place where we don't go from inode->i_sb->s_f_bdev for obvious reasons. Thoughts? */);

Maybe block devices should have their own struct file created when the block device is instantiated and torn down when the block device is trashed?

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

OK, but is there a problem with I_BDEV() which is currently used in blkdev_iomap_begin()?

Well, blkdev_iomap_begin is always called on the the actual bdev fs inode that is allocated together with the bdev itself. So we'll always be able to get to it using container_of variants.

Yes, that was exactly my point.

So my point is that if we want to have all code pass a file and we have code in fs/buffer.c like iomap_to_bh():

iomap_to_bh(struct inode *inode, sector_t block, struct buffer_head *bh,

        loff_t offset = block << inode->i_blkbits;

        bh->b_bdev = iomap->bdev;

+ bh->f_b_bdev = iomap->f_bdev;

While that works for every single filesystem that uses block devices because they stash them somewhere (like s_bdev_file) it doesn't work for the bdev filesystem itself. So if the bdev filesystem calls into helpers that expect e.g., buffer_head->s_f_bdev to have been initialized from iomap->f_bdev this wouldn't work.

So if we want to remove b_bdev from struct buffer_head and fully rely on f_b_bdev - and similar in iomap - then we need a story for the bdev fs itself. And I wasn't clear on what that would be. Dave's suggestion would obviously work iirc. Maybe you're poking my nose at something very obvious and I don't see it yet?

Fyi, I had planned to leave that patch out of the next revision anyway because I can merge the generic part without it as it stands on its own.

author maintainer
#47 lore raw

Re: [PATCH DRAFT RFC 34/34] buffer: port block device access to files and get rid of bd_inode access

In reply to Jan Kara
Quoted 11 lines · Jan Kara

include/linux/buffer_head.h struct buffer_head { · line 75

Quoted 8 lines
include/linux/buffer_head.h +1 -0
@@ -68,6 +69,7 @@ struct buffer_head {
 	size_t b_size;			/* size of mapping */
 	char *b_data;			/* pointer to data within the page */
 
+	struct file *f_b_bdev;
 	struct block_device *b_bdev;
 	bh_end_io_t *b_end_io;		/* I/O completion */
  	void *b_private;		/* reserved for b_end_io */

It is kind of annoying to have bdev duplicated in every buffer_head. Perhaps we can get rid of b_bdev?

Yes, that's ultimately the goal similar for struct super_block, I think and struct iomap. But please see:
https://lore.kernel.org/r/20240118-gemustert-aalen-ee71d0c69826@brauner
as I'm still not yet clear on some details there.