Skip to content

Open block devices as files

Christian Brauner dm-devel linux-block linux-fsdevel 2 versions – In review

Get series with b4
b4 am [email protected] change-id 20240103-vfs-bdev-file-1208da73d7ea

Versions newest first

  1. v2 Latest34 patches 93 repliesIn review
  2. v1 RFC34 patches 17 repliesSuperseded

Changes in v2 from the cover letter

- This is not an RFC anymore.
- The patches to convert all of fs/buffer.c and associated helpers to
struct file have been split out of the core infrastructure.
- Various renaming of helpers in response to v1.
- Link to v1: https://lore.kernel.org/r/[email protected]

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/34bdev: open block device as filesblock/bdev.c fs/cramfs/inode.c fs/f2fs/super.c +8 more+160 -2718 replies
2/34block/ioctl: port blkdev_bszset() to fileblock/ioctl.c+4 -52 replies
3/34block/genhd: port disk_scan_partitions() to fileblock/genhd.c+6 -62 replies
4/34md: port block device access to filedrivers/md/dm.c drivers/md/md.c drivers/md/md.h +1 more+21 -1811 replies
5/34swap: port block device usage to fileinclude/linux/swap.h mm/swapfile.c+12 -122 replies
6/34power: port block device access to filekernel/power/swap.c+14 -142 replies
7/34xfs: port block device access to filesfs/xfs/xfs_buf.c fs/xfs/xfs_buf.h fs/xfs/xfs_super.c+28 -293 replies
8/34drbd: port block device access to filedrivers/block/drbd/drbd_int.h drivers/block/drbd/drbd_nl.c+31 -311 reply
9/34pktcdvd: port block device access to filedrivers/block/pktcdvd.c include/linux/pktcdvd.h+36 -361 reply
10/34rnbd: port block device access to filedrivers/block/rnbd/rnbd-srv.c drivers/block/rnbd/rnbd-srv.h+15 -151 reply
11/34xen: port block device access to filedrivers/block/xen-blkback/blkback.c drivers/block/xen-blkback/common.h drivers/block/xen-blkback/xenbus.c+22 -231 reply
12/34zram: port block device access to filedrivers/block/zram/zram_drv.c drivers/block/zram/zram_drv.h+14 -141 reply
13/34bcache: port block device access to filesdrivers/md/bcache/bcache.h drivers/md/bcache/super.c+39 -391 reply
14/34block2mtd: port device access to filesdrivers/mtd/devices/block2mtd.c+21 -251 reply
15/34nvme: port block device access to filedrivers/nvme/target/io-cmd-bdev.c drivers/nvme/target/nvmet.h+9 -91 reply
16/34s390: port block device access to filedrivers/s390/block/dasd.c drivers/s390/block/dasd_genhd.c drivers/s390/block/dasd_int.h +1 more+25 -251 reply
17/34target: port block device access to filedrivers/target/target_core_iblock.c drivers/target/target_core_iblock.h drivers/target/target_core_pscsi.c +1 more+22 -221 reply
18/34bcachefs: port block device access to filefs/bcachefs/super-io.c fs/bcachefs/super_types.h+11 -111 reply
19/34btrfs: port device access to filefs/btrfs/dev-replace.c fs/btrfs/ioctl.c fs/btrfs/volumes.c +1 more+63 -631 reply
20/34erofs: port device access to filefs/erofs/data.c fs/erofs/internal.h fs/erofs/super.c+12 -121 reply
21/34ext4: port block device access to filefs/ext4/ext4.h fs/ext4/fsmap.c fs/ext4/super.c+31 -311 reply
22/34f2fs: port block device access to filesfs/f2fs/f2fs.h fs/f2fs/super.c+7 -71 reply
23/34jfs: port block device access to filefs/jfs/jfs_logmgr.c fs/jfs/jfs_logmgr.h fs/jfs/jfs_mount.c+15 -151 reply
24/34nfs: port block device access to filesfs/nfs/blocklayout/blocklayout.h fs/nfs/blocklayout/dev.c+35 -351 reply
25/34ocfs2: port block device access to filefs/ocfs2/cluster/heartbeat.c+16 -161 reply
26/34reiserfs: port block device access to filefs/reiserfs/journal.c fs/reiserfs/procfs.c fs/reiserfs/reiserfs.h+24 -241 reply
27/34bdev: remove bdev_open_by_path()block/bdev.c include/linux/blkdev.h+0 -422 replies
28/34bdev: make bdev_release() private to block layerblock/bdev.c block/blk.h include/linux/blkdev.h+4 -53 replies
29/34bdev: make struct bdev_handle private to the block layerblock/bdev.c block/blk.h block/fops.c +2 more+92 -927 replies
30/34bdev: remove bdev pointer from struct bdev_handleblock/bdev.c block/blk.h block/fops.c+14 -172 replies
31/34block: use file->f_op to indicate restricted writesblock/bdev.c block/blk.h block/fops.c+17 -49 replies
32/34block: remove bdev_handle completelyblock/bdev.c block/blk.h block/fops.c+18 -293 replies
33/34block: expose bdev_file_inode()block/bdev.c block/fops.c include/linux/blkdev.h+6 -61 reply
34/34ext4: rely on sb->f_bdev onlyfs/ext4/dir.c fs/ext4/ext4_jbd2.c fs/ext4/fast_commit.c +1 more+22 -212 replies

Reviews trailers per patch

31 of 34 patches have a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchChristoph HellwigJan KaraYi Zhang
SeriesR-b
1/34R-b R-b T-b
2/34R-b R-b
3/34R-b R-b
4/34R-b R-b
5/34R-b R-b
6/34R-b R-b
7/34R-b R-b
8/34R-b
9/34R-b
10/34R-b
11/34R-b
12/34R-b
13/34R-b
14/34R-b
15/34R-b
16/34R-b
17/34R-b
18/34R-b
19/34R-b
20/34R-b
21/34R-b
22/34R-b
23/34R-b
24/34R-b
25/34R-b
26/34R-b
27/34R-b R-b
28/34R-b R-b
29/34R-b
30/34R-b R-b
31/34
32/34R-b
33/34
34/34

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v2 thread

Cover letter [PATCH v2 00/34] Open block devices as files

Hey Christoph,
Hey Jan,
Hey Jens,

This opens block devices as files. Instead of introducing a separate indirection into bdev_open_by_*() vis struct bdev_handle 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 do away with struct bdev_handle completely and make various low-level helpers private to the block layer.

All places were we currently stash a struct bdev_handle we just stash a file and use an accessor such as file_bdev() akin to I_BDEV() to get to the block device.

It's now also possible to use file->f_mapping as a replacement for bdev->bd_inode->i_mapping and file->f_inode or file->f_mapping->host as an alternative to bdev->bd_inode allowing us to significantly reduce or even fully remove bdev->bd_inode in follow-up patches.

In addition, we could get rid of sb->s_bdev and various other places that stash the block device directly and instead stash the block device file. Again, this is follow-up work.

Thanks!
Christian

---
Changes in v2:
- This is not an RFC anymore.
- The patches to convert all of fs/buffer.c and associated helpers to
struct file have been split out of the core infrastructure.
- Various renaming of helpers in response to v1.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
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: remove bdev pointer from struct bdev_handle
block: use file->f_op to indicate restricted writes
block: remove bdev_handle completely
block: expose bdev_file_inode()
ext4: rely on sb->f_bdev only

 block/bdev.c                        | 249 ++++++++++++++++++++++--------------
 block/blk.h                         |   6 +
 block/fops.c                        |  48 ++++---
 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       |  28 ++--
 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  |  37 +++---
 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.c                     |  12 +-
 drivers/md/md.h                     |   2 +-
 drivers/mtd/devices/block2mtd.c     |  46 +++----
 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/bcachefs/super-io.c              |  20 +--
 fs/bcachefs/super_types.h           |   2 +-
 fs/btrfs/dev-replace.c              |  14 +-
 fs/btrfs/ioctl.c                    |  16 +--
 fs/btrfs/volumes.c                  |  92 ++++++-------
 fs/btrfs/volumes.h                  |   4 +-
 fs/cramfs/inode.c                   |   2 +-
 fs/erofs/data.c                     |   6 +-
 fs/erofs/internal.h                 |   2 +-
 fs/erofs/super.c                    |  16 +--
 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/super.c                     |  87 ++++++-------
 fs/f2fs/f2fs.h                      |   2 +-
 fs/f2fs/super.c                     |  12 +-
 fs/file_table.c                     |  36 +++++-
 fs/jfs/jfs_logmgr.c                 |  26 ++--
 fs/jfs/jfs_logmgr.h                 |   2 +-
 fs/jfs/jfs_mount.c                  |   2 +-
 fs/nfs/blocklayout/blocklayout.h    |   2 +-
 fs/nfs/blocklayout/dev.c            |  68 +++++-----
 fs/ocfs2/cluster/heartbeat.c        |  32 ++---
 fs/reiserfs/journal.c               |  38 +++---
 fs/reiserfs/procfs.c                |   2 +-
 fs/reiserfs/reiserfs.h              |   8 +-
 fs/romfs/super.c                    |   2 +-
 fs/super.c                          |  18 +--
 fs/xfs/xfs_buf.c                    |  10 +-
 fs/xfs/xfs_buf.h                    |   4 +-
 fs/xfs/xfs_super.c                  |  43 +++----
 include/linux/blkdev.h              |  18 +--
 include/linux/device-mapper.h       |   2 +-
 include/linux/file.h                |   2 +
 include/linux/fs.h                  |   4 +-
 include/linux/pktcdvd.h             |   4 +-
 include/linux/swap.h                |   2 +-
 kernel/power/swap.c                 |  28 ++--
 mm/swapfile.c                       |  22 ++--
 72 files changed, 791 insertions(+), 705 deletions(-)

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