History

Merge tag 'vfs-6.9.super' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs

Pull block handle updates from Christian Brauner: "Last cycle we changed opening of block devices, and opening a block device would return a bdev_handle. This allowed us to implement support for restricting and forbidding writes to mounted block devices. It was accompanied by converting and adding helpers to operate on bdev_handles instead of plain block devices. That was already a good step forward but ultimately it isn't necessary to have special purpose helpers for opening block devices internally that return a bdev_handle. Fundamentally, opening a block device internally should just be equivalent to opening files. So now all internal opens of block devices return files just as a userspace open would. Instead of introducing a separate indirection into bdev_open_by_*() via struct bdev_handle bdev_file_open_by_*() is made to just return a struct file. Opening and closing a block device just becomes equivalent to opening and closing a file. This all works well because internally we already have a pseudo fs for block devices and so opening block devices is simple. There's a few places where we needed to be careful such as during boot when the kernel is supposed to mount the rootfs directly without init doing it. Here we need to take care to ensure that we flush out any asynchronous file close. That's what we already do for opening, unpacking, and closing the initramfs. So nothing new here. The equivalence of opening and closing block devices to regular files is a win in and of itself. But it also has various other advantages. We can remove struct bdev_handle completely. Various low-level helpers are now private to the block layer. Other helpers were simply removable completely. A follow-up series that is already reviewed build on this and makes it possible to remove bdev->bd_inode and allows various clean ups of the buffer head code as well. All places where we stashed a bdev_handle now just stash a file and use simple accessors to get to the actual block device which was already the case for bdev_handle" * tag 'vfs-6.9.super' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs: (35 commits) block: remove bdev_handle completely block: don't rely on BLK_OPEN_RESTRICT_WRITES when yielding write access bdev: remove bdev pointer from struct bdev_handle bdev: make struct bdev_handle private to the block layer bdev: make bdev_{release, open_by_dev}() private to block layer bdev: remove bdev_open_by_path() reiserfs: port block device access to file ocfs2: port block device access to file nfs: port block device access to files jfs: port block device access to file f2fs: port block device access to files ext4: port block device access to file erofs: port device access to file btrfs: port device access to file bcachefs: port block device access to file target: port block device access to file s390: port block device access to file nvme: port block device access to file block2mtd: port device access to files bcache: port block device access to files ...

Linus Torvalds committed 2 years ago

Commit 910202f2 parents 0c75001 40ebc1872 files · +812 −703Browse files

Unified · Split

72 files
  1. block/bdev.c +155 −97
  2. block/blk.h +4 −0
  3. block/fops.c +20 −26
  4. block/genhd.c +6 −6
  5. block/ioctl.c +4 −5
  6. drivers/block/drbd/drbd_int.h +2 −2
  7. drivers/block/drbd/drbd_nl.c +29 −29
  8. drivers/block/pktcdvd.c +34 −34
  9. drivers/block/rnbd/rnbd-srv.c +14 −14
  10. drivers/block/rnbd/rnbd-srv.h +1 −1
  11. drivers/block/xen-blkback/blkback.c +2 −2
  12. drivers/block/xen-blkback/common.h +2 −2
  13. drivers/block/xen-blkback/xenbus.c +18 −19
  14. drivers/block/zram/zram_drv.c +13 −13
  15. drivers/block/zram/zram_drv.h +1 −1
  16. drivers/md/bcache/bcache.h +2 −2
  17. drivers/md/bcache/super.c +37 −37
  18. drivers/md/dm.c +13 −10
  19. drivers/md/md.c +6 −6
  20. drivers/md/md.h +1 −1
  21. drivers/mtd/devices/block2mtd.c +21 −25
  22. drivers/nvme/target/io-cmd-bdev.c +8 −8
  23. drivers/nvme/target/nvmet.h +1 −1
  24. drivers/s390/block/dasd.c +5 −5
  25. drivers/s390/block/dasd_genhd.c +18 −18
  26. drivers/s390/block/dasd_int.h +1 −1
  27. drivers/s390/block/dasd_ioctl.c +1 −1
  28. drivers/target/target_core_iblock.c +9 −9
  29. drivers/target/target_core_iblock.h +1 −1
  30. drivers/target/target_core_pscsi.c +11 −11
  31. drivers/target/target_core_pscsi.h +1 −1
  32. fs/bcachefs/super-io.c +10 −10
  33. fs/bcachefs/super_types.h +1 −1
  34. fs/btrfs/dev-replace.c +7 −7
  35. fs/btrfs/ioctl.c +8 −8
  36. fs/btrfs/volumes.c +46 −46
  37. fs/btrfs/volumes.h +2 −2
  38. fs/cramfs/inode.c +1 −1
  39. fs/erofs/data.c +3 −3
  40. fs/erofs/internal.h +1 −1
  41. fs/erofs/super.c +8 −8
  42. fs/ext4/ext4.h +1 −1
  43. fs/ext4/fsmap.c +4 −4
  44. fs/ext4/super.c +26 −26
  45. fs/f2fs/f2fs.h +1 −1
  46. fs/f2fs/super.c +6 −6
  47. fs/file_table.c +65 −18
  48. fs/jfs/jfs_logmgr.c +13 −13
  49. fs/jfs/jfs_logmgr.h +1 −1
  50. fs/jfs/jfs_mount.c +1 −1
  51. fs/nfs/blocklayout/blocklayout.h +1 −1
  52. fs/nfs/blocklayout/dev.c +34 −34
  53. fs/ocfs2/cluster/heartbeat.c +16 −16
  54. fs/reiserfs/journal.c +19 −19
  55. fs/reiserfs/procfs.c +1 −1
  56. fs/reiserfs/reiserfs.h +4 −4
  57. fs/romfs/super.c +1 −1
  58. fs/super.c +9 −9
  59. fs/xfs/xfs_buf.c +5 −5
  60. fs/xfs/xfs_buf.h +2 −2
  61. fs/xfs/xfs_super.c +22 −22
  62. include/linux/blkdev.h +4 −9
  63. include/linux/device-mapper.h +1 −1
  64. include/linux/file.h +2 −0
  65. include/linux/fs.h +2 −2
  66. include/linux/pktcdvd.h +2 −2
  67. include/linux/swap.h +1 −1
  68. init/do_mounts.c +3 −0
  69. init/do_mounts.h +9 −0
  70. init/initramfs.c +3 −3
  71. kernel/power/swap.c +14 −14
  72. mm/swapfile.c +11 −11
block/bdev.c+155−97
@@ -49,6 +49,12 @@ struct block_device *I_BDEV(struct inode *inode) · 48 unmodified lines
4949 }
5050 EXPORT_SYMBOL(I_BDEV);
5151
52+struct block_device *file_bdev(struct file *bdev_file)
53+{
54+ return I_BDEV(bdev_file->f_mapping->host);
55+}
56+EXPORT_SYMBOL(file_bdev);
57+
5258 static void bdev_write_inode(struct block_device *bdev)
5359 {
5460 struct inode *inode = bdev->bd_inode;
@@ -368,12 +374,12 @@ static struct file_system_type bd_type = { · 313 unmodified lines
368374 };
369375
370376 struct super_block *blockdev_superblock __ro_after_init;
377+struct vfsmount *blockdev_mnt __ro_after_init;
371378 EXPORT_SYMBOL_GPL(blockdev_superblock);
372379
373380 void __init bdev_cache_init(void)
374381 {
375382 int err;
376− static struct vfsmount *bd_mnt __ro_after_init;
377383
378384 bdev_cachep = kmem_cache_create("bdev_cache", sizeof(struct bdev_inode),
379385 0, (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
@@ -382,10 +388,10 @@ void __init bdev_cache_init(void) · 2 unmodified lines
382388 err = register_filesystem(&bd_type);
383389 if (err)
384390 panic("Cannot register bdev pseudo-fs");
385− bd_mnt = kern_mount(&bd_type);
386− if (IS_ERR(bd_mnt))
391+ blockdev_mnt = kern_mount(&bd_type);
392+ if (IS_ERR(blockdev_mnt))
387393 panic("Cannot create bdev pseudo-fs");
388− blockdev_superblock = bd_mnt->mnt_sb; /* For writeback */
394+ blockdev_superblock = blockdev_mnt->mnt_sb; /* For writeback */
389395 }
390396
391397 struct block_device *bdev_alloc(struct gendisk *disk, u8 partno)
@@ -696,6 +702,31 @@ out_blkdev_put: · 304 unmodified lines
696702 return ret;
697703 }
698704
705+int bdev_permission(dev_t dev, blk_mode_t mode, void *holder)
706+{
707+ int ret;
708+
709+ ret = devcgroup_check_permission(DEVCG_DEV_BLOCK,
710+ MAJOR(dev), MINOR(dev),
711+ ((mode & BLK_OPEN_READ) ? DEVCG_ACC_READ : 0) |
712+ ((mode & BLK_OPEN_WRITE) ? DEVCG_ACC_WRITE : 0));
713+ if (ret)
714+ return ret;
715+
716+ /* Blocking writes requires exclusive opener */
717+ if (mode & BLK_OPEN_RESTRICT_WRITES && !holder)
718+ return -EINVAL;
719+
720+ /*
721+ * We're using error pointers to indicate to ->release() when we
722+ * failed to open that block device. Also this doesn't make sense.
723+ */
724+ if (WARN_ON_ONCE(IS_ERR(holder)))
725+ return -EINVAL;
726+
727+ return 0;
728+}
729+
699730 static void blkdev_put_part(struct block_device *part)
700731 {
701732 struct block_device *whole = bdev_whole(part);
@@ -775,83 +806,55 @@ static void bdev_claim_write_access(struct block_device *bdev, blk_mode_t mode) · 73 unmodified lines
775806 bdev->bd_writers++;
776807 }
777808
778−static void bdev_yield_write_access(struct block_device *bdev, blk_mode_t mode)
809+static void bdev_yield_write_access(struct file *bdev_file)
779810 {
811+ struct block_device *bdev;
812+
780813 if (bdev_allow_write_mounted)
781814 return;
782815
816+ bdev = file_bdev(bdev_file);
783817 /* Yield exclusive or shared write access. */
784− if (mode & BLK_OPEN_RESTRICT_WRITES)
785− bdev_unblock_writes(bdev);
786− else if (mode & BLK_OPEN_WRITE)
787− bdev->bd_writers--;
818+ if (bdev_file->f_mode & FMODE_WRITE) {
819+ if (bdev_writes_blocked(bdev))
820+ bdev_unblock_writes(bdev);
821+ else
822+ bdev->bd_writers--;
823+ }
788824 }
789825
790826 /**
791− * bdev_open_by_dev - open a block device by device number
792− * @dev: device number of block device to open
827+ * bdev_open - open a block device
828+ * @bdev: block device to open
793829 * @mode: open mode (BLK_OPEN_*)
794830 * @holder: exclusive holder identifier
795831 * @hops: holder operations
832+ * @bdev_file: file for the block device
796833 *
797− * Open the block device described by device number @dev. If @holder is not
798− * %NULL, the block device is opened with exclusive access. Exclusive opens may
799− * nest for the same @holder.
800− *
801− * Use this interface ONLY if you really do not have anything better - i.e. when
802− * you are behind a truly sucky interface and all you are given is a device
803− * number. Everything else should use bdev_open_by_path().
834+ * Open the block device. If @holder is not %NULL, the block device is opened
835+ * with exclusive access. Exclusive opens may nest for the same @holder.
804836 *
805837 * CONTEXT:
806838 * Might sleep.
807839 *
808840 * RETURNS:
809− * Handle with a reference to the block_device on success, ERR_PTR(-errno) on
810− * failure.
841+ * zero on success, -errno on failure.
811842 */
812−struct bdev_handle *bdev_open_by_dev(dev_t dev, blk_mode_t mode, void *holder,
813− const struct blk_holder_ops *hops)
843+int bdev_open(struct block_device *bdev, blk_mode_t mode, void *holder,
844+ const struct blk_holder_ops *hops, struct file *bdev_file)
814845 {
815− struct bdev_handle *handle = kmalloc(sizeof(struct bdev_handle),
816− GFP_KERNEL);
817− struct block_device *bdev;
818846 bool unblock_events = true;
819− struct gendisk *disk;
847+ struct gendisk *disk = bdev->bd_disk;
820848 int ret;
821849
822− if (!handle)
823− return ERR_PTR(-ENOMEM);
824−
825− ret = devcgroup_check_permission(DEVCG_DEV_BLOCK,
826− MAJOR(dev), MINOR(dev),
827− ((mode & BLK_OPEN_READ) ? DEVCG_ACC_READ : 0) |
828− ((mode & BLK_OPEN_WRITE) ? DEVCG_ACC_WRITE : 0));
829− if (ret)
830− goto free_handle;
831−
832− /* Blocking writes requires exclusive opener */
833− if (mode & BLK_OPEN_RESTRICT_WRITES && !holder) {
834− ret = -EINVAL;
835− goto free_handle;
836− }
837−
838− bdev = blkdev_get_no_open(dev);
839− if (!bdev) {
840− ret = -ENXIO;
841− goto free_handle;
842− }
843− disk = bdev->bd_disk;
844−
845850 if (holder) {
846851 mode |= BLK_OPEN_EXCL;
847852 ret = bd_prepare_to_claim(bdev, holder, hops);
848853 if (ret)
849− goto put_blkdev;
854+ return ret;
850855 } else {
851− if (WARN_ON_ONCE(mode & BLK_OPEN_EXCL)) {
852− ret = -EIO;
853− goto put_blkdev;
854− }
856+ if (WARN_ON_ONCE(mode & BLK_OPEN_EXCL))
857+ return -EIO;
855858 }
856859
857860 disk_block_events(disk);
@@ -892,10 +895,16 @@ struct bdev_handle *bdev_open_by_dev(dev_t dev, blk_mode_t mode, void *holder, · 34 unmodified lines
892895
893896 if (unblock_events)
894897 disk_unblock_events(disk);
895− handle->bdev = bdev;
896− handle->holder = holder;
897− handle->mode = mode;
898− return handle;
898+
899+ bdev_file->f_flags |= O_LARGEFILE;
900+ bdev_file->f_mode |= FMODE_BUF_RASYNC | FMODE_CAN_ODIRECT;
901+ if (bdev_nowait(bdev))
902+ bdev_file->f_mode |= FMODE_NOWAIT;
903+ bdev_file->f_mapping = bdev->bd_inode->i_mapping;
904+ bdev_file->f_wb_err = filemap_sample_wb_err(bdev_file->f_mapping);
905+ bdev_file->private_data = holder;
906+
907+ return 0;
899908 put_module:
900909 module_put(disk->fops->owner);
901910 abort_claiming:
@@ -903,36 +912,80 @@ abort_claiming: · 1 unmodified line
903912 bd_abort_claiming(bdev, holder);
904913 mutex_unlock(&disk->open_mutex);
905914 disk_unblock_events(disk);
906−put_blkdev:
907− blkdev_put_no_open(bdev);
908−free_handle:
909− kfree(handle);
910− return ERR_PTR(ret);
915+ return ret;
911916 }
912−EXPORT_SYMBOL(bdev_open_by_dev);
913917
914−/**
915− * bdev_open_by_path - open a block device by name
916− * @path: path to the block device to open
917− * @mode: open mode (BLK_OPEN_*)
918− * @holder: exclusive holder identifier
919− * @hops: holder operations
920− *
921− * Open the block device described by the device file at @path. If @holder is
922− * not %NULL, the block device is opened with exclusive access. Exclusive opens
923− * may nest for the same @holder.
924− *
925− * CONTEXT:
926− * Might sleep.
918+/*
919+ * If BLK_OPEN_WRITE_IOCTL is set then this is a historical quirk
920+ * associated with the floppy driver where it has allowed ioctls if the
921+ * file was opened for writing, but does not allow reads or writes.
922+ * Make sure that this quirk is reflected in @f_flags.
927923 *
928− * RETURNS:
929− * Handle with a reference to the block_device on success, ERR_PTR(-errno) on
930− * failure.
924+ * It can also happen if a block device is opened as O_RDWR | O_WRONLY.
931925 */
932−struct bdev_handle *bdev_open_by_path(const char *path, blk_mode_t mode,
933− void *holder, const struct blk_holder_ops *hops)
926+static unsigned blk_to_file_flags(blk_mode_t mode)
927+{
928+ unsigned int flags = 0;
929+
930+ if ((mode & (BLK_OPEN_READ | BLK_OPEN_WRITE)) ==
931+ (BLK_OPEN_READ | BLK_OPEN_WRITE))
932+ flags |= O_RDWR;
933+ else if (mode & BLK_OPEN_WRITE_IOCTL)
934+ flags |= O_RDWR | O_WRONLY;
935+ else if (mode & BLK_OPEN_WRITE)
936+ flags |= O_WRONLY;
937+ else if (mode & BLK_OPEN_READ)
938+ flags |= O_RDONLY; /* homeopathic, because O_RDONLY is 0 */
939+ else
940+ WARN_ON_ONCE(true);
941+
942+ if (mode & BLK_OPEN_NDELAY)
943+ flags |= O_NDELAY;
944+
945+ return flags;
946+}
947+
948+struct file *bdev_file_open_by_dev(dev_t dev, blk_mode_t mode, void *holder,
949+ const struct blk_holder_ops *hops)
934950 {
935− struct bdev_handle *handle;
951+ struct file *bdev_file;
952+ struct block_device *bdev;
953+ unsigned int flags;
954+ int ret;
955+
956+ ret = bdev_permission(dev, mode, holder);
957+ if (ret)
958+ return ERR_PTR(ret);
959+
960+ bdev = blkdev_get_no_open(dev);
961+ if (!bdev)
962+ return ERR_PTR(-ENXIO);
963+
964+ flags = blk_to_file_flags(mode);
965+ bdev_file = alloc_file_pseudo_noaccount(bdev->bd_inode,
966+ blockdev_mnt, "", flags | O_LARGEFILE, &def_blk_fops);
967+ if (IS_ERR(bdev_file)) {
968+ blkdev_put_no_open(bdev);
969+ return bdev_file;
970+ }
971+ ihold(bdev->bd_inode);
972+
973+ ret = bdev_open(bdev, mode, holder, hops, bdev_file);
974+ if (ret) {
975+ /* We failed to open the block device. Let ->release() know. */
976+ bdev_file->private_data = ERR_PTR(ret);
977+ fput(bdev_file);
978+ return ERR_PTR(ret);
979+ }
980+ return bdev_file;
981+}
982+EXPORT_SYMBOL(bdev_file_open_by_dev);
983+
984+struct file *bdev_file_open_by_path(const char *path, blk_mode_t mode,
985+ void *holder,
986+ const struct blk_holder_ops *hops)
987+{
988+ struct file *file;
936989 dev_t dev;
937990 int error;
938991
@@ -940,22 +993,28 @@ struct bdev_handle *bdev_open_by_path(const char *path, blk_mode_t mode, · 1 unmodified line
940993 if (error)
941994 return ERR_PTR(error);
942995
943− handle = bdev_open_by_dev(dev, mode, holder, hops);
944− if (!IS_ERR(handle) && (mode & BLK_OPEN_WRITE) &&
945− bdev_read_only(handle->bdev)) {
946− bdev_release(handle);
947− return ERR_PTR(-EACCES);
996+ file = bdev_file_open_by_dev(dev, mode, holder, hops);
997+ if (!IS_ERR(file) && (mode & BLK_OPEN_WRITE)) {
998+ if (bdev_read_only(file_bdev(file))) {
999+ fput(file);
1000+ file = ERR_PTR(-EACCES);
1001+ }
9481002 }
9491003
950− return handle;
1004+ return file;
9511005 }
952−EXPORT_SYMBOL(bdev_open_by_path);
1006+EXPORT_SYMBOL(bdev_file_open_by_path);
9531007
954−void bdev_release(struct bdev_handle *handle)
1008+void bdev_release(struct file *bdev_file)
9551009 {
956− struct block_device *bdev = handle->bdev;
1010+ struct block_device *bdev = file_bdev(bdev_file);
1011+ void *holder = bdev_file->private_data;
9571012 struct gendisk *disk = bdev->bd_disk;
9581013
1014+ /* We failed to open that block device. */
1015+ if (IS_ERR(holder))
1016+ goto put_no_open;
1017+
9591018 /*
9601019 * Sync early if it looks like we're the last one. If someone else
9611020 * opens the block device between now and the decrement of bd_openers
@@ -967,10 +1026,10 @@ void bdev_release(struct bdev_handle *handle) · 5 unmodified lines
9671026 sync_blockdev(bdev);
9681027
9691028 mutex_lock(&disk->open_mutex);
970− bdev_yield_write_access(bdev, handle->mode);
1029+ bdev_yield_write_access(bdev_file);
9711030
972− if (handle->holder)
973− bd_end_claim(bdev, handle->holder);
1031+ if (holder)
1032+ bd_end_claim(bdev, holder);
9741033
9751034 /*
9761035 * Trigger event checking and tell drivers to flush MEDIA_CHANGE
@@ -986,10 +1045,9 @@ void bdev_release(struct bdev_handle *handle) · 9 unmodified lines
9861045 mutex_unlock(&disk->open_mutex);
9871046
9881047 module_put(disk->fops->owner);
1048+put_no_open:
9891049 blkdev_put_no_open(bdev);
990− kfree(handle);
9911050 }
992−EXPORT_SYMBOL(bdev_release);
9931051
9941052 /**
9951053 * lookup_bdev() - Look up a struct block_device by name.
block/blk.h+4−0
@@ -516,4 +516,8 @@ static inline int req_ref_read(struct request *req) · 515 unmodified lines
516516 return atomic_read(&req->ref);
517517 }
518518
519+void bdev_release(struct file *bdev_file);
520+int bdev_open(struct block_device *bdev, blk_mode_t mode, void *holder,
521+ const struct blk_holder_ops *hops, struct file *bdev_file);
522+int bdev_permission(dev_t dev, blk_mode_t mode, void *holder);
519523 #endif /* BLK_INTERNAL_H */
block/fops.c+20−26
@@ -572,18 +572,17 @@ static int blkdev_fsync(struct file *filp, loff_t start, loff_t end, · 571 unmodified lines
572572 blk_mode_t file_to_blk_mode(struct file *file)
573573 {
574574 blk_mode_t mode = 0;
575− struct bdev_handle *handle = file->private_data;
576575
577576 if (file->f_mode & FMODE_READ)
578577 mode |= BLK_OPEN_READ;
579578 if (file->f_mode & FMODE_WRITE)
580579 mode |= BLK_OPEN_WRITE;
581580 /*
582− * do_dentry_open() clears O_EXCL from f_flags, use handle->mode to
583− * determine whether the open was exclusive for already open files.
581+ * do_dentry_open() clears O_EXCL from f_flags, use file->private_data
582+ * to determine whether the open was exclusive for already open files.
584583 */
585− if (handle)
586− mode |= handle->mode & BLK_OPEN_EXCL;
584+ if (file->private_data)
585+ mode |= BLK_OPEN_EXCL;
587586 else if (file->f_flags & O_EXCL)
588587 mode |= BLK_OPEN_EXCL;
589588 if (file->f_flags & O_NDELAY)
@@ -602,36 +601,31 @@ blk_mode_t file_to_blk_mode(struct file *file) · 12 unmodified lines
602601
603602 static int blkdev_open(struct inode *inode, struct file *filp)
604603 {
605− struct bdev_handle *handle;
604+ struct block_device *bdev;
606605 blk_mode_t mode;
607−
608− /*
609− * Preserve backwards compatibility and allow large file access
610− * even if userspace doesn't ask for it explicitly. Some mkfs
611− * binary needs it. We might want to drop this workaround
612− * during an unstable branch.
613− */
614− filp->f_flags |= O_LARGEFILE;
615− filp->f_mode |= FMODE_BUF_RASYNC | FMODE_CAN_ODIRECT;
606+ int ret;
616607
617608 mode = file_to_blk_mode(filp);
618− handle = bdev_open_by_dev(inode->i_rdev, mode,
619− mode & BLK_OPEN_EXCL ? filp : NULL, NULL);
620− if (IS_ERR(handle))
621− return PTR_ERR(handle);
609+ /* Use the file as the holder. */
610+ if (mode & BLK_OPEN_EXCL)
611+ filp->private_data = filp;
612+ ret = bdev_permission(inode->i_rdev, mode, filp->private_data);
613+ if (ret)
614+ return ret;
622615
623− if (bdev_nowait(handle->bdev))
624− filp->f_mode |= FMODE_NOWAIT;
616+ bdev = blkdev_get_no_open(inode->i_rdev);
617+ if (!bdev)
618+ return -ENXIO;
625619
626− filp->f_mapping = handle->bdev->bd_inode->i_mapping;
627− filp->f_wb_err = filemap_sample_wb_err(filp->f_mapping);
628− filp->private_data = handle;
629− return 0;
620+ ret = bdev_open(bdev, mode, filp->private_data, NULL, filp);
621+ if (ret)
622+ blkdev_put_no_open(bdev);
623+ return ret;
630624 }
631625
632626 static int blkdev_release(struct inode *inode, struct file *filp)
633627 {
634− bdev_release(filp->private_data);
628+ bdev_release(filp);
635629 return 0;
636630 }
637631
block/genhd.c+6−6
@@ -342,7 +342,7 @@ EXPORT_SYMBOL_GPL(disk_uevent); · 341 unmodified lines
342342
343343 int disk_scan_partitions(struct gendisk *disk, blk_mode_t mode)
344344 {
345− struct bdev_handle *handle;
345+ struct file *file;
346346 int ret = 0;
347347
348348 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) · 17 unmodified lines
366366 }
367367
368368 set_bit(GD_NEED_PART_SCAN, &disk->state);
369− handle = bdev_open_by_dev(disk_devt(disk), mode & ~BLK_OPEN_EXCL, NULL,
370− NULL);
371− if (IS_ERR(handle))
372− ret = PTR_ERR(handle);
369+ file = bdev_file_open_by_dev(disk_devt(disk), mode & ~BLK_OPEN_EXCL,
370+ NULL, NULL);
371+ if (IS_ERR(file))
372+ ret = PTR_ERR(file);
373373 else
374− bdev_release(handle);
374+ fput(file);
375375
376376 /*
377377 * If blkdev_get_by_dev() failed early, GD_NEED_PART_SCAN is still set,
block/ioctl.c+4−5
@@ -469,7 +469,7 @@ static int blkdev_bszset(struct block_device *bdev, blk_mode_t mode, · 468 unmodified lines
469469 int __user *argp)
470470 {
471471 int ret, n;
472− struct bdev_handle *handle;
472+ struct file *file;
473473
474474 if (!capable(CAP_SYS_ADMIN))
475475 return -EACCES;
@@ -481,12 +481,11 @@ static int blkdev_bszset(struct block_device *bdev, blk_mode_t mode, · 5 unmodified lines
481481 if (mode & BLK_OPEN_EXCL)
482482 return set_blocksize(bdev, n);
483483
484− handle = bdev_open_by_dev(bdev->bd_dev, mode, &bdev, NULL);
485− if (IS_ERR(handle))
484+ file = bdev_file_open_by_dev(bdev->bd_dev, mode, &bdev, NULL);
485+ if (IS_ERR(file))
486486 return -EBUSY;
487487 ret = set_blocksize(bdev, n);
488− bdev_release(handle);
489−
488+ fput(file);
490489 return ret;
491490 }
492491
drivers/block/drbd/drbd_int.h+2−2
@@ -524,9 +524,9 @@ struct drbd_md { · 523 unmodified lines
524524
525525 struct drbd_backing_dev {
526526 struct block_device *backing_bdev;
527− struct bdev_handle *backing_bdev_handle;
527+ struct file *backing_bdev_file;
528528 struct block_device *md_bdev;
529− struct bdev_handle *md_bdev_handle;
529+ struct file *f_md_bdev;
530530 struct drbd_md md;
531531 struct disk_conf *disk_conf; /* RCU, for updates: resource->conf_update */
532532 sector_t known_size; /* last known size of that backing device */
drivers/block/drbd/drbd_nl.c+29−29
@@ -1635,45 +1635,45 @@ success: · 1634 unmodified lines
16351635 return 0;
16361636 }
16371637
1638−static struct bdev_handle *open_backing_dev(struct drbd_device *device,
1638+static struct file *open_backing_dev(struct drbd_device *device,
16391639 const char *bdev_path, void *claim_ptr, bool do_bd_link)
16401640 {
1641− struct bdev_handle *handle;
1641+ struct file *file;
16421642 int err = 0;
16431643
1644− handle = bdev_open_by_path(bdev_path, BLK_OPEN_READ | BLK_OPEN_WRITE,
1645− claim_ptr, NULL);
1646− if (IS_ERR(handle)) {
1644+ file = bdev_file_open_by_path(bdev_path, BLK_OPEN_READ | BLK_OPEN_WRITE,
1645+ claim_ptr, NULL);
1646+ if (IS_ERR(file)) {
16471647 drbd_err(device, "open(\"%s\") failed with %ld\n",
1648− bdev_path, PTR_ERR(handle));
1649− return handle;
1648+ bdev_path, PTR_ERR(file));
1649+ return file;
16501650 }
16511651
16521652 if (!do_bd_link)
1653− return handle;
1653+ return file;
16541654
1655− err = bd_link_disk_holder(handle->bdev, device->vdisk);
1655+ err = bd_link_disk_holder(file_bdev(file), device->vdisk);
16561656 if (err) {
1657− bdev_release(handle);
1657+ fput(file);
16581658 drbd_err(device, "bd_link_disk_holder(\"%s\", ...) failed with %d\n",
16591659 bdev_path, err);
1660− handle = ERR_PTR(err);
1660+ file = ERR_PTR(err);
16611661 }
1662− return handle;
1662+ return file;
16631663 }
16641664
16651665 static int open_backing_devices(struct drbd_device *device,
16661666 struct disk_conf *new_disk_conf,
16671667 struct drbd_backing_dev *nbc)
16681668 {
1669− struct bdev_handle *handle;
1669+ struct file *file;
16701670
1671− handle = open_backing_dev(device, new_disk_conf->backing_dev, device,
1671+ file = open_backing_dev(device, new_disk_conf->backing_dev, device,
16721672 true);
1673− if (IS_ERR(handle))
1673+ if (IS_ERR(file))
16741674 return ERR_OPEN_DISK;
1675− nbc->backing_bdev = handle->bdev;
1676− nbc->backing_bdev_handle = handle;
1675+ nbc->backing_bdev = file_bdev(file);
1676+ nbc->backing_bdev_file = file;
16771677
16781678 /*
16791679 * meta_dev_idx >= 0: external fixed size, possibly multiple
@@ -1683,7 +1683,7 @@ static int open_backing_devices(struct drbd_device *device, · 3 unmodified lines
16831683 * should check it for you already; but if you don't, or
16841684 * someone fooled it, we need to double check here)
16851685 */
1686− handle = open_backing_dev(device, new_disk_conf->meta_dev,
1686+ file = open_backing_dev(device, new_disk_conf->meta_dev,
16871687 /* claim ptr: device, if claimed exclusively; shared drbd_m_holder,
16881688 * if potentially shared with other drbd minors */
16891689 (new_disk_conf->meta_dev_idx < 0) ? (void*)device : (void*)drbd_m_holder,
@@ -1691,21 +1691,21 @@ static int open_backing_devices(struct drbd_device *device, · 1 unmodified line
16911691 * as would happen with internal metadata. */
16921692 (new_disk_conf->meta_dev_idx != DRBD_MD_INDEX_FLEX_INT &&
16931693 new_disk_conf->meta_dev_idx != DRBD_MD_INDEX_INTERNAL));
1694− if (IS_ERR(handle))
1694+ if (IS_ERR(file))
16951695 return ERR_OPEN_MD_DISK;
1696− nbc->md_bdev = handle->bdev;
1697− nbc->md_bdev_handle = handle;
1696+ nbc->md_bdev = file_bdev(file);
1697+ nbc->f_md_bdev = file;
16981698 return NO_ERROR;
16991699 }
17001700
17011701 static void close_backing_dev(struct drbd_device *device,
1702− struct bdev_handle *handle, bool do_bd_unlink)
1702+ struct file *bdev_file, bool do_bd_unlink)
17031703 {
1704− if (!handle)
1704+ if (!bdev_file)
17051705 return;
17061706 if (do_bd_unlink)
1707− bd_unlink_disk_holder(handle->bdev, device->vdisk);
1708− bdev_release(handle);
1707+ bd_unlink_disk_holder(file_bdev(bdev_file), device->vdisk);
1708+ fput(bdev_file);
17091709 }
17101710
17111711 void drbd_backing_dev_free(struct drbd_device *device, struct drbd_backing_dev *ldev)
@@ -1713,9 +1713,9 @@ void drbd_backing_dev_free(struct drbd_device *device, struct drbd_backing_dev * · 1 unmodified line
17131713 if (ldev == NULL)
17141714 return;
17151715
1716− close_backing_dev(device, ldev->md_bdev_handle,
1716+ close_backing_dev(device, ldev->f_md_bdev,
17171717 ldev->md_bdev != ldev->backing_bdev);
1718− close_backing_dev(device, ldev->backing_bdev_handle, true);
1718+ close_backing_dev(device, ldev->backing_bdev_file, true);
17191719
17201720 kfree(ldev->disk_conf);
17211721 kfree(ldev);
@@ -2131,9 +2131,9 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info) · 409 unmodified lines
21312131 fail:
21322132 conn_reconfig_done(connection);
21332133 if (nbc) {
2134− close_backing_dev(device, nbc->md_bdev_handle,
2134+ close_backing_dev(device, nbc->f_md_bdev,
21352135 nbc->md_bdev != nbc->backing_bdev);
2136− close_backing_dev(device, nbc->backing_bdev_handle, true);
2136+ close_backing_dev(device, nbc->backing_bdev_file, true);
21372137 kfree(nbc);
21382138 }
21392139 kfree(new_disk_conf);
drivers/block/pktcdvd.c+34−34
@@ -340,8 +340,8 @@ static ssize_t device_map_show(const struct class *c, const struct class_attribu · 339 unmodified lines
340340 n += sysfs_emit_at(data, n, "%s %u:%u %u:%u\n",
341341 pd->disk->disk_name,
342342 MAJOR(pd->pkt_dev), MINOR(pd->pkt_dev),
343− MAJOR(pd->bdev_handle->bdev->bd_dev),
344− MINOR(pd->bdev_handle->bdev->bd_dev));
343+ MAJOR(file_bdev(pd->bdev_file)->bd_dev),
344+ MINOR(file_bdev(pd->bdev_file)->bd_dev));
345345 }
346346 mutex_unlock(&ctl_mutex);
347347 return n;
@@ -438,7 +438,7 @@ static int pkt_seq_show(struct seq_file *m, void *p) · 90 unmodified lines
438438 int states[PACKET_NUM_STATES];
439439
440440 seq_printf(m, "Writer %s mapped to %pg:\n", pd->disk->disk_name,
441− pd->bdev_handle->bdev);
441+ file_bdev(pd->bdev_file));
442442
443443 seq_printf(m, "\nSettings:\n");
444444 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 · 270 unmodified lines
715715 */
716716 static int pkt_generic_packet(struct pktcdvd_device *pd, struct packet_command *cgc)
717717 {
718− struct request_queue *q = bdev_get_queue(pd->bdev_handle->bdev);
718+ struct request_queue *q = bdev_get_queue(file_bdev(pd->bdev_file));
719719 struct scsi_cmnd *scmd;
720720 struct request *rq;
721721 int ret = 0;
@@ -1048,7 +1048,7 @@ static void pkt_gather_data(struct pktcdvd_device *pd, struct packet_data *pkt) · 326 unmodified lines
10481048 continue;
10491049
10501050 bio = pkt->r_bios[f];
1051− bio_init(bio, pd->bdev_handle->bdev, bio->bi_inline_vecs, 1,
1051+ bio_init(bio, file_bdev(pd->bdev_file), bio->bi_inline_vecs, 1,
10521052 REQ_OP_READ);
10531053 bio->bi_iter.bi_sector = pkt->sector + f * (CD_FRAMESIZE >> 9);
10541054 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) · 209 unmodified lines
12641264 struct device *ddev = disk_to_dev(pd->disk);
12651265 int f;
12661266
1267− bio_init(pkt->w_bio, pd->bdev_handle->bdev, pkt->w_bio->bi_inline_vecs,
1267+ bio_init(pkt->w_bio, file_bdev(pd->bdev_file), pkt->w_bio->bi_inline_vecs,
12681268 pkt->frames, REQ_OP_WRITE);
12691269 pkt->w_bio->bi_iter.bi_sector = pkt->sector;
12701270 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) · 891 unmodified lines
21622162 int ret;
21632163 long lba;
21642164 struct request_queue *q;
2165− struct bdev_handle *bdev_handle;
2165+ struct file *bdev_file;
21662166
21672167 /*
21682168 * We need to re-open the cdrom device without O_NONBLOCK to be able
21692169 * to read/write from/to it. It is already opened in O_NONBLOCK mode
21702170 * so open should not fail.
21712171 */
2172− bdev_handle = bdev_open_by_dev(pd->bdev_handle->bdev->bd_dev,
2172+ bdev_file = bdev_file_open_by_dev(file_bdev(pd->bdev_file)->bd_dev,
21732173 BLK_OPEN_READ, pd, NULL);
2174− if (IS_ERR(bdev_handle)) {
2175− ret = PTR_ERR(bdev_handle);
2174+ if (IS_ERR(bdev_file)) {
2175+ ret = PTR_ERR(bdev_file);
21762176 goto out;
21772177 }
2178− pd->open_bdev_handle = bdev_handle;
2178+ pd->f_open_bdev = bdev_file;
21792179
21802180 ret = pkt_get_last_written(pd, &lba);
21812181 if (ret) {
@@ -2184,9 +2184,9 @@ static int pkt_open_dev(struct pktcdvd_device *pd, bool write) · 2 unmodified lines
21842184 }
21852185
21862186 set_capacity(pd->disk, lba << 2);
2187− set_capacity_and_notify(pd->bdev_handle->bdev->bd_disk, lba << 2);
2187+ set_capacity_and_notify(file_bdev(pd->bdev_file)->bd_disk, lba << 2);
21882188
2189− q = bdev_get_queue(pd->bdev_handle->bdev);
2189+ q = bdev_get_queue(file_bdev(pd->bdev_file));
21902190 if (write) {
21912191 ret = pkt_open_write(pd);
21922192 if (ret)
@@ -2218,7 +2218,7 @@ static int pkt_open_dev(struct pktcdvd_device *pd, bool write) · 25 unmodified lines
22182218 return 0;
22192219
22202220 out_putdev:
2221− bdev_release(bdev_handle);
2221+ fput(bdev_file);
22222222 out:
22232223 return ret;
22242224 }
@@ -2237,8 +2237,8 @@ static void pkt_release_dev(struct pktcdvd_device *pd, int flush) · 12 unmodified lines
22372237 pkt_lock_door(pd, 0);
22382238
22392239 pkt_set_speed(pd, MAX_SPEED, MAX_SPEED);
2240− bdev_release(pd->open_bdev_handle);
2241− pd->open_bdev_handle = NULL;
2240+ fput(pd->f_open_bdev);
2241+ pd->f_open_bdev = NULL;
22422242
22432243 pkt_shrink_pktlist(pd);
22442244 }
@@ -2326,7 +2326,7 @@ static void pkt_end_io_read_cloned(struct bio *bio) · 81 unmodified lines
23262326
23272327 static void pkt_make_request_read(struct pktcdvd_device *pd, struct bio *bio)
23282328 {
2329− struct bio *cloned_bio = bio_alloc_clone(pd->bdev_handle->bdev, bio,
2329+ struct bio *cloned_bio = bio_alloc_clone(file_bdev(pd->bdev_file), bio,
23302330 GFP_NOIO, &pkt_bio_set);
23312331 struct packet_stacked_data *psd = mempool_alloc(&psd_pool, GFP_NOIO);
23322332
@@ -2497,7 +2497,7 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev) · 164 unmodified lines
24972497 {
24982498 struct device *ddev = disk_to_dev(pd->disk);
24992499 int i;
2500− struct bdev_handle *bdev_handle;
2500+ struct file *bdev_file;
25012501 struct scsi_device *sdev;
25022502
25032503 if (pd->pkt_dev == dev) {
@@ -2508,9 +2508,9 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev) · 4 unmodified lines
25082508 struct pktcdvd_device *pd2 = pkt_devs[i];
25092509 if (!pd2)
25102510 continue;
2511− if (pd2->bdev_handle->bdev->bd_dev == dev) {
2511+ if (file_bdev(pd2->bdev_file)->bd_dev == dev) {
25122512 dev_err(ddev, "%pg already setup\n",
2513− pd2->bdev_handle->bdev);
2513+ file_bdev(pd2->bdev_file));
25142514 return -EBUSY;
25152515 }
25162516 if (pd2->pkt_dev == dev) {
@@ -2519,13 +2519,13 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev) · 2 unmodified lines
25192519 }
25202520 }
25212521
2522− bdev_handle = bdev_open_by_dev(dev, BLK_OPEN_READ | BLK_OPEN_NDELAY,
2522+ bdev_file = bdev_file_open_by_dev(dev, BLK_OPEN_READ | BLK_OPEN_NDELAY,
25232523 NULL, NULL);
2524− if (IS_ERR(bdev_handle))
2525− return PTR_ERR(bdev_handle);
2526− sdev = scsi_device_from_queue(bdev_handle->bdev->bd_disk->queue);
2524+ if (IS_ERR(bdev_file))
2525+ return PTR_ERR(bdev_file);
2526+ sdev = scsi_device_from_queue(file_bdev(bdev_file)->bd_disk->queue);
25272527 if (!sdev) {
2528− bdev_release(bdev_handle);
2528+ fput(bdev_file);
25292529 return -EINVAL;
25302530 }
25312531 put_device(&sdev->sdev_gendev);
@@ -2533,8 +2533,8 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev) · 1 unmodified line
25332533 /* This is safe, since we have a reference from open(). */
25342534 __module_get(THIS_MODULE);
25352535
2536− pd->bdev_handle = bdev_handle;
2537− set_blocksize(bdev_handle->bdev, CD_FRAMESIZE);
2536+ pd->bdev_file = bdev_file;
2537+ set_blocksize(file_bdev(bdev_file), CD_FRAMESIZE);
25382538
25392539 pkt_init_queue(pd);
25402540
@@ -2546,11 +2546,11 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev) · 5 unmodified lines
25462546 }
25472547
25482548 proc_create_single_data(pd->disk->disk_name, 0, pkt_proc, pkt_seq_show, pd);
2549− dev_notice(ddev, "writer mapped to %pg\n", bdev_handle->bdev);
2549+ dev_notice(ddev, "writer mapped to %pg\n", file_bdev(bdev_file));
25502550 return 0;
25512551
25522552 out_mem:
2553− bdev_release(bdev_handle);
2553+ fput(bdev_file);
25542554 /* This is safe: open() is still holding a reference. */
25552555 module_put(THIS_MODULE);
25562556 return -ENOMEM;
@@ -2605,9 +2605,9 @@ static unsigned int pkt_check_events(struct gendisk *disk, · 48 unmodified lines
26052605
26062606 if (!pd)
26072607 return 0;
2608− if (!pd->bdev_handle)
2608+ if (!pd->bdev_file)
26092609 return 0;
2610− attached_disk = pd->bdev_handle->bdev->bd_disk;
2610+ attached_disk = file_bdev(pd->bdev_file)->bd_disk;
26112611 if (!attached_disk || !attached_disk->fops->check_events)
26122612 return 0;
26132613 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) · 78 unmodified lines
26922692 goto out_mem2;
26932693
26942694 /* inherit events of the host device */
2695− disk->events = pd->bdev_handle->bdev->bd_disk->events;
2695+ disk->events = file_bdev(pd->bdev_file)->bd_disk->events;
26962696
26972697 ret = add_disk(disk);
26982698 if (ret)
@@ -2757,7 +2757,7 @@ static int pkt_remove_dev(dev_t pkt_dev) · 58 unmodified lines
27572757 pkt_debugfs_dev_remove(pd);
27582758 pkt_sysfs_dev_remove(pd);
27592759
2760− bdev_release(pd->bdev_handle);
2760+ fput(pd->bdev_file);
27612761
27622762 remove_proc_entry(pd->disk->disk_name, pkt_proc);
27632763 dev_notice(ddev, "writer unmapped\n");
@@ -2784,7 +2784,7 @@ static void pkt_get_status(struct pkt_ctrl_command *ctrl_cmd) · 20 unmodified lines
27842784
27852785 pd = pkt_find_dev_from_minor(ctrl_cmd->dev_index);
27862786 if (pd) {
2787− ctrl_cmd->dev = new_encode_dev(pd->bdev_handle->bdev->bd_dev);
2787+ ctrl_cmd->dev = new_encode_dev(file_bdev(pd->bdev_file)->bd_dev);
27882788 ctrl_cmd->pkt_dev = new_encode_dev(pd->pkt_dev);
27892789 } else {
27902790 ctrl_cmd->dev = 0;
drivers/block/rnbd/rnbd-srv.c+14−14
@@ -145,7 +145,7 @@ static int process_rdma(struct rnbd_srv_session *srv_sess, · 144 unmodified lines
145145 priv->sess_dev = sess_dev;
146146 priv->id = id;
147147
148− bio = bio_alloc(sess_dev->bdev_handle->bdev, 1,
148+ bio = bio_alloc(file_bdev(sess_dev->bdev_file), 1,
149149 rnbd_to_bio_flags(le32_to_cpu(msg->rw)), GFP_KERNEL);
150150 if (bio_add_page(bio, virt_to_page(data), datalen,
151151 offset_in_page(data)) != datalen) {
@@ -219,7 +219,7 @@ void rnbd_destroy_sess_dev(struct rnbd_srv_sess_dev *sess_dev, bool keep_id) · 67 unmodified lines
219219 rnbd_put_sess_dev(sess_dev);
220220 wait_for_completion(&dc); /* wait for inflights to drop to zero */
221221
222− bdev_release(sess_dev->bdev_handle);
222+ fput(sess_dev->bdev_file);
223223 mutex_lock(&sess_dev->dev->lock);
224224 list_del(&sess_dev->dev_list);
225225 if (!sess_dev->readonly)
@@ -534,7 +534,7 @@ rnbd_srv_get_or_create_srv_dev(struct block_device *bdev, · 308 unmodified lines
534534 static void rnbd_srv_fill_msg_open_rsp(struct rnbd_msg_open_rsp *rsp,
535535 struct rnbd_srv_sess_dev *sess_dev)
536536 {
537− struct block_device *bdev = sess_dev->bdev_handle->bdev;
537+ struct block_device *bdev = file_bdev(sess_dev->bdev_file);
538538
539539 rsp->hdr.type = cpu_to_le16(RNBD_MSG_OPEN_RSP);
540540 rsp->device_id = cpu_to_le32(sess_dev->device_id);
@@ -560,7 +560,7 @@ static void rnbd_srv_fill_msg_open_rsp(struct rnbd_msg_open_rsp *rsp, · 19 unmodified lines
560560 static struct rnbd_srv_sess_dev *
561561 rnbd_srv_create_set_sess_dev(struct rnbd_srv_session *srv_sess,
562562 const struct rnbd_msg_open *open_msg,
563− struct bdev_handle *handle, bool readonly,
563+ struct file *bdev_file, bool readonly,
564564 struct rnbd_srv_dev *srv_dev)
565565 {
566566 struct rnbd_srv_sess_dev *sdev = rnbd_sess_dev_alloc(srv_sess);
@@ -572,7 +572,7 @@ rnbd_srv_create_set_sess_dev(struct rnbd_srv_session *srv_sess, · 5 unmodified lines
572572
573573 strscpy(sdev->pathname, open_msg->dev_name, sizeof(sdev->pathname));
574574
575− sdev->bdev_handle = handle;
575+ sdev->bdev_file = bdev_file;
576576 sdev->sess = srv_sess;
577577 sdev->dev = srv_dev;
578578 sdev->readonly = readonly;
@@ -678,7 +678,7 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess, · 99 unmodified lines
678678 struct rnbd_srv_dev *srv_dev;
679679 struct rnbd_srv_sess_dev *srv_sess_dev;
680680 const struct rnbd_msg_open *open_msg = msg;
681− struct bdev_handle *bdev_handle;
681+ struct file *bdev_file;
682682 blk_mode_t open_flags = BLK_OPEN_READ;
683683 char *full_path;
684684 struct rnbd_msg_open_rsp *rsp = data;
@@ -716,15 +716,15 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess, · 31 unmodified lines
716716 goto reject;
717717 }
718718
719− bdev_handle = bdev_open_by_path(full_path, open_flags, NULL, NULL);
720− if (IS_ERR(bdev_handle)) {
721− ret = PTR_ERR(bdev_handle);
719+ bdev_file = bdev_file_open_by_path(full_path, open_flags, NULL, NULL);
720+ if (IS_ERR(bdev_file)) {
721+ ret = PTR_ERR(bdev_file);
722722 pr_err("Opening device '%s' on session %s failed, failed to open the block device, err: %pe\n",
723− full_path, srv_sess->sessname, bdev_handle);
723+ full_path, srv_sess->sessname, bdev_file);
724724 goto free_path;
725725 }
726726
727− srv_dev = rnbd_srv_get_or_create_srv_dev(bdev_handle->bdev, srv_sess,
727+ srv_dev = rnbd_srv_get_or_create_srv_dev(file_bdev(bdev_file), srv_sess,
728728 open_msg->access_mode);
729729 if (IS_ERR(srv_dev)) {
730730 pr_err("Opening device '%s' on session %s failed, creating srv_dev failed, err: %pe\n",
@@ -734,7 +734,7 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess, · 3 unmodified lines
734734 }
735735
736736 srv_sess_dev = rnbd_srv_create_set_sess_dev(srv_sess, open_msg,
737− bdev_handle,
737+ bdev_file,
738738 open_msg->access_mode == RNBD_ACCESS_RO,
739739 srv_dev);
740740 if (IS_ERR(srv_sess_dev)) {
@@ -750,7 +750,7 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess, · 9 unmodified lines
750750 */
751751 mutex_lock(&srv_dev->lock);
752752 if (!srv_dev->dev_kobj.state_in_sysfs) {
753− ret = rnbd_srv_create_dev_sysfs(srv_dev, bdev_handle->bdev);
753+ ret = rnbd_srv_create_dev_sysfs(srv_dev, file_bdev(bdev_file));
754754 if (ret) {
755755 mutex_unlock(&srv_dev->lock);
756756 rnbd_srv_err(srv_sess_dev,
@@ -793,7 +793,7 @@ srv_dev_put: · 36 unmodified lines
793793 }
794794 rnbd_put_srv_dev(srv_dev);
795795 blkdev_put:
796− bdev_release(bdev_handle);
796+ fput(bdev_file);
797797 free_path:
798798 kfree(full_path);
799799 reject:
drivers/block/rnbd/rnbd-srv.h+1−1
@@ -46,7 +46,7 @@ struct rnbd_srv_dev { · 45 unmodified lines
4646 struct rnbd_srv_sess_dev {
4747 /* Entry inside rnbd_srv_dev struct */
4848 struct list_head dev_list;
49− struct bdev_handle *bdev_handle;
49+ struct file *bdev_file;
5050 struct rnbd_srv_session *sess;
5151 struct rnbd_srv_dev *dev;
5252 struct kobject kobj;
drivers/block/xen-blkback/blkback.c+2−2
@@ -465,7 +465,7 @@ static int xen_vbd_translate(struct phys_req *req, struct xen_blkif *blkif, · 464 unmodified lines
465465 }
466466
467467 req->dev = vbd->pdevice;
468− req->bdev = vbd->bdev_handle->bdev;
468+ req->bdev = file_bdev(vbd->bdev_file);
469469 rc = 0;
470470
471471 out:
@@ -969,7 +969,7 @@ static int dispatch_discard_io(struct xen_blkif_ring *ring, · 497 unmodified lines
969969 int err = 0;
970970 int status = BLKIF_RSP_OKAY;
971971 struct xen_blkif *blkif = ring->blkif;
972− struct block_device *bdev = blkif->vbd.bdev_handle->bdev;
972+ struct block_device *bdev = file_bdev(blkif->vbd.bdev_file);
973973 struct phys_req preq;
974974
975975 xen_blkif_get(blkif);
drivers/block/xen-blkback/common.h+2−2
@@ -221,7 +221,7 @@ struct xen_vbd { · 220 unmodified lines
221221 unsigned char type;
222222 /* phys device that this vbd maps to. */
223223 u32 pdevice;
224− struct bdev_handle *bdev_handle;
224+ struct file *bdev_file;
225225 /* Cached size parameter. */
226226 sector_t size;
227227 unsigned int flush_support:1;
@@ -360,7 +360,7 @@ struct pending_req { · 132 unmodified lines
360360 };
361361
362362
363−#define vbd_sz(_v) bdev_nr_sectors((_v)->bdev_handle->bdev)
363+#define vbd_sz(_v) bdev_nr_sectors(file_bdev((_v)->bdev_file))
364364
365365 #define xen_blkif_get(_b) (atomic_inc(&(_b)->refcnt))
366366 #define xen_blkif_put(_b) \
drivers/block/xen-blkback/xenbus.c+18−19
@@ -81,7 +81,7 @@ static void xen_update_blkif_status(struct xen_blkif *blkif) · 80 unmodified lines
8181 int i;
8282
8383 /* Not ready to connect? */
84− if (!blkif->rings || !blkif->rings[0].irq || !blkif->vbd.bdev_handle)
84+ if (!blkif->rings || !blkif->rings[0].irq || !blkif->vbd.bdev_file)
8585 return;
8686
8787 /* Already connected? */
@@ -99,13 +99,12 @@ static void xen_update_blkif_status(struct xen_blkif *blkif) · 11 unmodified lines
9999 return;
100100 }
101101
102− err = sync_blockdev(blkif->vbd.bdev_handle->bdev);
102+ err = sync_blockdev(file_bdev(blkif->vbd.bdev_file));
103103 if (err) {
104104 xenbus_dev_error(blkif->be->dev, err, "block flush");
105105 return;
106106 }
107− invalidate_inode_pages2(
108− blkif->vbd.bdev_handle->bdev->bd_inode->i_mapping);
107+ invalidate_inode_pages2(blkif->vbd.bdev_file->f_mapping);
109108
110109 for (i = 0; i < blkif->nr_rings; i++) {
111110 ring = &blkif->rings[i];
@@ -473,9 +472,9 @@ static void xenvbd_sysfs_delif(struct xenbus_device *dev) · 361 unmodified lines
473472
474473 static void xen_vbd_free(struct xen_vbd *vbd)
475474 {
476− if (vbd->bdev_handle)
477− bdev_release(vbd->bdev_handle);
478− vbd->bdev_handle = NULL;
475+ if (vbd->bdev_file)
476+ fput(vbd->bdev_file);
477+ vbd->bdev_file = NULL;
479478 }
480479
481480 static int xen_vbd_create(struct xen_blkif *blkif, blkif_vdev_t handle,
@@ -483,7 +482,7 @@ static int xen_vbd_create(struct xen_blkif *blkif, blkif_vdev_t handle, · 1 unmodified line
483482 int cdrom)
484483 {
485484 struct xen_vbd *vbd;
486− struct bdev_handle *bdev_handle;
485+ struct file *bdev_file;
487486
488487 vbd = &blkif->vbd;
489488 vbd->handle = handle;
@@ -492,17 +491,17 @@ static int xen_vbd_create(struct xen_blkif *blkif, blkif_vdev_t handle, · 2 unmodified lines
492491
493492 vbd->pdevice = MKDEV(major, minor);
494493
495− bdev_handle = bdev_open_by_dev(vbd->pdevice, vbd->readonly ?
494+ bdev_file = bdev_file_open_by_dev(vbd->pdevice, vbd->readonly ?
496495 BLK_OPEN_READ : BLK_OPEN_WRITE, NULL, NULL);
497496
498− if (IS_ERR(bdev_handle)) {
497+ if (IS_ERR(bdev_file)) {
499498 pr_warn("xen_vbd_create: device %08x could not be opened\n",
500499 vbd->pdevice);
501500 return -ENOENT;
502501 }
503502
504− vbd->bdev_handle = bdev_handle;
505− if (vbd->bdev_handle->bdev->bd_disk == NULL) {
503+ vbd->bdev_file = bdev_file;
504+ if (file_bdev(vbd->bdev_file)->bd_disk == NULL) {
506505 pr_warn("xen_vbd_create: device %08x doesn't exist\n",
507506 vbd->pdevice);
508507 xen_vbd_free(vbd);
@@ -510,14 +509,14 @@ static int xen_vbd_create(struct xen_blkif *blkif, blkif_vdev_t handle, · 1 unmodified line
510509 }
511510 vbd->size = vbd_sz(vbd);
512511
513− if (cdrom || disk_to_cdi(vbd->bdev_handle->bdev->bd_disk))
512+ if (cdrom || disk_to_cdi(file_bdev(vbd->bdev_file)->bd_disk))
514513 vbd->type |= VDISK_CDROM;
515− if (vbd->bdev_handle->bdev->bd_disk->flags & GENHD_FL_REMOVABLE)
514+ if (file_bdev(vbd->bdev_file)->bd_disk->flags & GENHD_FL_REMOVABLE)
516515 vbd->type |= VDISK_REMOVABLE;
517516
518− if (bdev_write_cache(bdev_handle->bdev))
517+ if (bdev_write_cache(file_bdev(bdev_file)))
519518 vbd->flush_support = true;
520− if (bdev_max_secure_erase_sectors(bdev_handle->bdev))
519+ if (bdev_max_secure_erase_sectors(file_bdev(bdev_file)))
521520 vbd->discard_secure = true;
522521
523522 pr_debug("Successful creation of handle=%04x (dom=%u)\n",
@@ -570,7 +569,7 @@ static void xen_blkbk_discard(struct xenbus_transaction xbt, struct backend_info · 46 unmodified lines
570569 struct xen_blkif *blkif = be->blkif;
571570 int err;
572571 int state = 0;
573− struct block_device *bdev = be->blkif->vbd.bdev_handle->bdev;
572+ struct block_device *bdev = file_bdev(be->blkif->vbd.bdev_file);
574573
575574 if (!xenbus_read_unsigned(dev->nodename, "discard-enable", 1))
576575 return;
@@ -932,7 +931,7 @@ again: · 355 unmodified lines
932931 }
933932 err = xenbus_printf(xbt, dev->nodename, "sector-size", "%lu",
934933 (unsigned long)bdev_logical_block_size(
935− be->blkif->vbd.bdev_handle->bdev));
934+ file_bdev(be->blkif->vbd.bdev_file)));
936935 if (err) {
937936 xenbus_dev_fatal(dev, err, "writing %s/sector-size",
938937 dev->nodename);
@@ -940,7 +939,7 @@ again: · 1 unmodified line
940939 }
941940 err = xenbus_printf(xbt, dev->nodename, "physical-sector-size", "%u",
942941 bdev_physical_block_size(
943− be->blkif->vbd.bdev_handle->bdev));
942+ file_bdev(be->blkif->vbd.bdev_file)));
944943 if (err)
945944 xenbus_dev_error(dev, err, "writing %s/physical-sector-size",
946945 dev->nodename);
drivers/block/zram/zram_drv.c+13−13
@@ -426,11 +426,11 @@ static void reset_bdev(struct zram *zram) · 425 unmodified lines
426426 if (!zram->backing_dev)
427427 return;
428428
429− bdev_release(zram->bdev_handle);
429+ fput(zram->bdev_file);
430430 /* hope filp_close flush all of IO */
431431 filp_close(zram->backing_dev, NULL);
432432 zram->backing_dev = NULL;
433− zram->bdev_handle = NULL;
433+ zram->bdev_file = NULL;
434434 zram->disk->fops = &zram_devops;
435435 kvfree(zram->bitmap);
436436 zram->bitmap = NULL;
@@ -476,7 +476,7 @@ static ssize_t backing_dev_store(struct device *dev, · 39 unmodified lines
476476 struct address_space *mapping;
477477 unsigned int bitmap_sz;
478478 unsigned long nr_pages, *bitmap = NULL;
479− struct bdev_handle *bdev_handle = NULL;
479+ struct file *bdev_file = NULL;
480480 int err;
481481 struct zram *zram = dev_to_zram(dev);
482482
@@ -513,11 +513,11 @@ static ssize_t backing_dev_store(struct device *dev, · 30 unmodified lines
513513 goto out;
514514 }
515515
516− bdev_handle = bdev_open_by_dev(inode->i_rdev,
516+ bdev_file = bdev_file_open_by_dev(inode->i_rdev,
517517 BLK_OPEN_READ | BLK_OPEN_WRITE, zram, NULL);
518− if (IS_ERR(bdev_handle)) {
519− err = PTR_ERR(bdev_handle);
520− bdev_handle = NULL;
518+ if (IS_ERR(bdev_file)) {
519+ err = PTR_ERR(bdev_file);
520+ bdev_file = NULL;
521521 goto out;
522522 }
523523
@@ -531,7 +531,7 @@ static ssize_t backing_dev_store(struct device *dev, · 7 unmodified lines
531531
532532 reset_bdev(zram);
533533
534− zram->bdev_handle = bdev_handle;
534+ zram->bdev_file = bdev_file;
535535 zram->backing_dev = backing_dev;
536536 zram->bitmap = bitmap;
537537 zram->nr_pages = nr_pages;
@@ -544,8 +544,8 @@ static ssize_t backing_dev_store(struct device *dev, · 6 unmodified lines
544544 out:
545545 kvfree(bitmap);
546546
547− if (bdev_handle)
548− bdev_release(bdev_handle);
547+ if (bdev_file)
548+ fput(bdev_file);
549549
550550 if (backing_dev)
551551 filp_close(backing_dev, NULL);
@@ -587,7 +587,7 @@ static void read_from_bdev_async(struct zram *zram, struct page *page, · 35 unmodified lines
587587 {
588588 struct bio *bio;
589589
590− bio = bio_alloc(zram->bdev_handle->bdev, 1, parent->bi_opf, GFP_NOIO);
590+ bio = bio_alloc(file_bdev(zram->bdev_file), 1, parent->bi_opf, GFP_NOIO);
591591 bio->bi_iter.bi_sector = entry * (PAGE_SIZE >> 9);
592592 __bio_add_page(bio, page, PAGE_SIZE, 0);
593593 bio_chain(bio, parent);
@@ -703,7 +703,7 @@ static ssize_t writeback_store(struct device *dev, · 109 unmodified lines
703703 continue;
704704 }
705705
706− bio_init(&bio, zram->bdev_handle->bdev, &bio_vec, 1,
706+ bio_init(&bio, file_bdev(zram->bdev_file), &bio_vec, 1,
707707 REQ_OP_WRITE | REQ_SYNC);
708708 bio.bi_iter.bi_sector = blk_idx * (PAGE_SIZE >> 9);
709709 __bio_add_page(&bio, page, PAGE_SIZE, 0);
@@ -785,7 +785,7 @@ static void zram_sync_read(struct work_struct *work) · 75 unmodified lines
785785 struct bio_vec bv;
786786 struct bio bio;
787787
788− bio_init(&bio, zw->zram->bdev_handle->bdev, &bv, 1, REQ_OP_READ);
788+ bio_init(&bio, file_bdev(zw->zram->bdev_file), &bv, 1, REQ_OP_READ);
789789 bio.bi_iter.bi_sector = zw->entry * (PAGE_SIZE >> 9);
790790 __bio_add_page(&bio, zw->page, PAGE_SIZE, 0);
791791 zw->error = submit_bio_wait(&bio);
drivers/block/zram/zram_drv.h+1−1
@@ -132,7 +132,7 @@ struct zram { · 131 unmodified lines
132132 spinlock_t wb_limit_lock;
133133 bool wb_limit_enable;
134134 u64 bd_wb_limit;
135− struct bdev_handle *bdev_handle;
135+ struct file *bdev_file;
136136 unsigned long *bitmap;
137137 unsigned long nr_pages;
138138 #endif
drivers/md/bcache/bcache.h+2−2
@@ -300,7 +300,7 @@ struct cached_dev { · 299 unmodified lines
300300 struct list_head list;
301301 struct bcache_device disk;
302302 struct block_device *bdev;
303− struct bdev_handle *bdev_handle;
303+ struct file *bdev_file;
304304
305305 struct cache_sb sb;
306306 struct cache_sb_disk *sb_disk;
@@ -423,7 +423,7 @@ struct cache { · 116 unmodified lines
423423
424424 struct kobject kobj;
425425 struct block_device *bdev;
426− struct bdev_handle *bdev_handle;
426+ struct file *bdev_file;
427427
428428 struct task_struct *alloc_thread;
429429
drivers/md/bcache/super.c+37−37
@@ -1369,8 +1369,8 @@ static CLOSURE_CALLBACK(cached_dev_free) · 1368 unmodified lines
13691369 if (dc->sb_disk)
13701370 put_page(virt_to_page(dc->sb_disk));
13711371
1372− if (dc->bdev_handle)
1373− bdev_release(dc->bdev_handle);
1372+ if (dc->bdev_file)
1373+ fput(dc->bdev_file);
13741374
13751375 wake_up(&unregister_wait);
13761376
@@ -1445,7 +1445,7 @@ static int cached_dev_init(struct cached_dev *dc, unsigned int block_size) · 68 unmodified lines
14451445 /* Cached device - bcache superblock */
14461446
14471447 static int register_bdev(struct cache_sb *sb, struct cache_sb_disk *sb_disk,
1448− struct bdev_handle *bdev_handle,
1448+ struct file *bdev_file,
14491449 struct cached_dev *dc)
14501450 {
14511451 const char *err = "cannot allocate memory";
@@ -1453,8 +1453,8 @@ static int register_bdev(struct cache_sb *sb, struct cache_sb_disk *sb_disk, · 1 unmodified line
14531453 int ret = -ENOMEM;
14541454
14551455 memcpy(&dc->sb, sb, sizeof(struct cache_sb));
1456− dc->bdev_handle = bdev_handle;
1457− dc->bdev = bdev_handle->bdev;
1456+ dc->bdev_file = bdev_file;
1457+ dc->bdev = file_bdev(bdev_file);
14581458 dc->sb_disk = sb_disk;
14591459
14601460 if (cached_dev_init(dc, sb->block_size << 9))
@@ -2218,8 +2218,8 @@ void bch_cache_release(struct kobject *kobj) · 757 unmodified lines
22182218 if (ca->sb_disk)
22192219 put_page(virt_to_page(ca->sb_disk));
22202220
2221− if (ca->bdev_handle)
2222− bdev_release(ca->bdev_handle);
2221+ if (ca->bdev_file)
2222+ fput(ca->bdev_file);
22232223
22242224 kfree(ca);
22252225 module_put(THIS_MODULE);
@@ -2339,18 +2339,18 @@ err_free: · 113 unmodified lines
23392339 }
23402340
23412341 static int register_cache(struct cache_sb *sb, struct cache_sb_disk *sb_disk,
2342− struct bdev_handle *bdev_handle,
2342+ struct file *bdev_file,
23432343 struct cache *ca)
23442344 {
23452345 const char *err = NULL; /* must be set for any error case */
23462346 int ret = 0;
23472347
23482348 memcpy(&ca->sb, sb, sizeof(struct cache_sb));
2349− ca->bdev_handle = bdev_handle;
2350− ca->bdev = bdev_handle->bdev;
2349+ ca->bdev_file = bdev_file;
2350+ ca->bdev = file_bdev(bdev_file);
23512351 ca->sb_disk = sb_disk;
23522352
2353− if (bdev_max_discard_sectors((bdev_handle->bdev)))
2353+ if (bdev_max_discard_sectors(file_bdev(bdev_file)))
23542354 ca->discard = CACHE_DISCARD(&ca->sb);
23552355
23562356 ret = cache_alloc(ca);
@@ -2361,20 +2361,20 @@ static int register_cache(struct cache_sb *sb, struct cache_sb_disk *sb_disk, · 4 unmodified lines
23612361 err = "cache_alloc(): cache device is too small";
23622362 else
23632363 err = "cache_alloc(): unknown error";
2364− pr_notice("error %pg: %s\n", bdev_handle->bdev, err);
2364+ pr_notice("error %pg: %s\n", file_bdev(bdev_file), err);
23652365 /*
23662366 * If we failed here, it means ca->kobj is not initialized yet,
23672367 * kobject_put() won't be called and there is no chance to
2368− * call bdev_release() to bdev in bch_cache_release(). So
2369− * we explicitly call bdev_release() here.
2368+ * call fput() to bdev in bch_cache_release(). So
2369+ * we explicitly call fput() on the block device here.
23702370 */
2371− bdev_release(bdev_handle);
2371+ fput(bdev_file);
23722372 return ret;
23732373 }
23742374
2375− if (kobject_add(&ca->kobj, bdev_kobj(bdev_handle->bdev), "bcache")) {
2375+ if (kobject_add(&ca->kobj, bdev_kobj(file_bdev(bdev_file)), "bcache")) {
23762376 pr_notice("error %pg: error calling kobject_add\n",
2377− bdev_handle->bdev);
2377+ file_bdev(bdev_file));
23782378 ret = -ENOMEM;
23792379 goto out;
23802380 }
@@ -2388,7 +2388,7 @@ static int register_cache(struct cache_sb *sb, struct cache_sb_disk *sb_disk, · 7 unmodified lines
23882388 goto out;
23892389 }
23902390
2391− pr_info("registered cache device %pg\n", ca->bdev_handle->bdev);
2391+ pr_info("registered cache device %pg\n", file_bdev(ca->bdev_file));
23922392
23932393 out:
23942394 kobject_put(&ca->kobj);
@@ -2446,7 +2446,7 @@ struct async_reg_args { · 51 unmodified lines
24462446 char *path;
24472447 struct cache_sb *sb;
24482448 struct cache_sb_disk *sb_disk;
2449− struct bdev_handle *bdev_handle;
2449+ struct file *bdev_file;
24502450 void *holder;
24512451 };
24522452
@@ -2457,7 +2457,7 @@ static void register_bdev_worker(struct work_struct *work) · 4 unmodified lines
24572457 container_of(work, struct async_reg_args, reg_work.work);
24582458
24592459 mutex_lock(&bch_register_lock);
2460− if (register_bdev(args->sb, args->sb_disk, args->bdev_handle,
2460+ if (register_bdev(args->sb, args->sb_disk, args->bdev_file,
24612461 args->holder) < 0)
24622462 fail = true;
24632463 mutex_unlock(&bch_register_lock);
@@ -2478,7 +2478,7 @@ static void register_cache_worker(struct work_struct *work) · 14 unmodified lines
24782478 container_of(work, struct async_reg_args, reg_work.work);
24792479
24802480 /* blkdev_put() will be called in bch_cache_release() */
2481− if (register_cache(args->sb, args->sb_disk, args->bdev_handle,
2481+ if (register_cache(args->sb, args->sb_disk, args->bdev_file,
24822482 args->holder))
24832483 fail = true;
24842484
@@ -2516,7 +2516,7 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr, · 31 unmodified lines
25162516 char *path = NULL;
25172517 struct cache_sb *sb;
25182518 struct cache_sb_disk *sb_disk;
2519− struct bdev_handle *bdev_handle, *bdev_handle2;
2519+ struct file *bdev_file, *bdev_file2;
25202520 void *holder = NULL;
25212521 ssize_t ret;
25222522 bool async_registration = false;
@@ -2549,15 +2549,15 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr, · 26 unmodified lines
25492549
25502550 ret = -EINVAL;
25512551 err = "failed to open device";
2552− bdev_handle = bdev_open_by_path(strim(path), BLK_OPEN_READ, NULL, NULL);
2553− if (IS_ERR(bdev_handle))
2552+ bdev_file = bdev_file_open_by_path(strim(path), BLK_OPEN_READ, NULL, NULL);
2553+ if (IS_ERR(bdev_file))
25542554 goto out_free_sb;
25552555
25562556 err = "failed to set blocksize";
2557− if (set_blocksize(bdev_handle->bdev, 4096))
2557+ if (set_blocksize(file_bdev(bdev_file), 4096))
25582558 goto out_blkdev_put;
25592559
2560− err = read_super(sb, bdev_handle->bdev, &sb_disk);
2560+ err = read_super(sb, file_bdev(bdev_file), &sb_disk);
25612561 if (err)
25622562 goto out_blkdev_put;
25632563
@@ -2569,13 +2569,13 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr, · 5 unmodified lines
25692569 }
25702570
25712571 /* Now reopen in exclusive mode with proper holder */
2572− bdev_handle2 = bdev_open_by_dev(bdev_handle->bdev->bd_dev,
2572+ bdev_file2 = bdev_file_open_by_dev(file_bdev(bdev_file)->bd_dev,
25732573 BLK_OPEN_READ | BLK_OPEN_WRITE, holder, NULL);
2574− bdev_release(bdev_handle);
2575− bdev_handle = bdev_handle2;
2576− if (IS_ERR(bdev_handle)) {
2577− ret = PTR_ERR(bdev_handle);
2578− bdev_handle = NULL;
2574+ fput(bdev_file);
2575+ bdev_file = bdev_file2;
2576+ if (IS_ERR(bdev_file)) {
2577+ ret = PTR_ERR(bdev_file);
2578+ bdev_file = NULL;
25792579 if (ret == -EBUSY) {
25802580 dev_t dev;
25812581
@@ -2610,7 +2610,7 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr, · 28 unmodified lines
26102610 args->path = path;
26112611 args->sb = sb;
26122612 args->sb_disk = sb_disk;
2613− args->bdev_handle = bdev_handle;
2613+ args->bdev_file = bdev_file;
26142614 args->holder = holder;
26152615 register_device_async(args);
26162616 /* No wait and returns to user space */
@@ -2619,14 +2619,14 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr, · 2 unmodified lines
26192619
26202620 if (SB_IS_BDEV(sb)) {
26212621 mutex_lock(&bch_register_lock);
2622− ret = register_bdev(sb, sb_disk, bdev_handle, holder);
2622+ ret = register_bdev(sb, sb_disk, bdev_file, holder);
26232623 mutex_unlock(&bch_register_lock);
26242624 /* blkdev_put() will be called in cached_dev_free() */
26252625 if (ret < 0)
26262626 goto out_free_sb;
26272627 } else {
26282628 /* blkdev_put() will be called in bch_cache_release() */
2629− ret = register_cache(sb, sb_disk, bdev_handle, holder);
2629+ ret = register_cache(sb, sb_disk, bdev_file, holder);
26302630 if (ret)
26312631 goto out_free_sb;
26322632 }
@@ -2642,8 +2642,8 @@ out_free_holder: · 9 unmodified lines
26422642 out_put_sb_page:
26432643 put_page(virt_to_page(sb_disk));
26442644 out_blkdev_put:
2645− if (bdev_handle)
2646− bdev_release(bdev_handle);
2645+ if (bdev_file)
2646+ fput(bdev_file);
26472647 out_free_sb:
26482648 kfree(sb);
26492649 out_free_path:
drivers/md/dm.c+13−10
@@ -726,7 +726,8 @@ static struct table_device *open_table_device(struct mapped_device *md, · 725 unmodified lines
726726 dev_t dev, blk_mode_t mode)
727727 {
728728 struct table_device *td;
729− struct bdev_handle *bdev_handle;
729+ struct file *bdev_file;
730+ struct block_device *bdev;
730731 u64 part_off;
731732 int r;
732733
@@ -735,34 +736,36 @@ static struct table_device *open_table_device(struct mapped_device *md, · 2 unmodified lines
735736 return ERR_PTR(-ENOMEM);
736737 refcount_set(&td->count, 1);
737738
738− bdev_handle = bdev_open_by_dev(dev, mode, _dm_claim_ptr, NULL);
739− if (IS_ERR(bdev_handle)) {
740− r = PTR_ERR(bdev_handle);
739+ bdev_file = bdev_file_open_by_dev(dev, mode, _dm_claim_ptr, NULL);
740+ if (IS_ERR(bdev_file)) {
741+ r = PTR_ERR(bdev_file);
741742 goto out_free_td;
742743 }
743744
745+ bdev = file_bdev(bdev_file);
746+
744747 /*
745748 * We can be called before the dm disk is added. In that case we can't
746749 * register the holder relation here. It will be done once add_disk was
747750 * called.
748751 */
749752 if (md->disk->slave_dir) {
750− r = bd_link_disk_holder(bdev_handle->bdev, md->disk);
753+ r = bd_link_disk_holder(bdev, md->disk);
751754 if (r)
752755 goto out_blkdev_put;
753756 }
754757
755758 td->dm_dev.mode = mode;
756− td->dm_dev.bdev = bdev_handle->bdev;
757− td->dm_dev.bdev_handle = bdev_handle;
758− td->dm_dev.dax_dev = fs_dax_get_by_bdev(bdev_handle->bdev, &part_off,
759+ td->dm_dev.bdev = bdev;
760+ td->dm_dev.bdev_file = bdev_file;
761+ td->dm_dev.dax_dev = fs_dax_get_by_bdev(bdev, &part_off,
759762 NULL, NULL);
760763 format_dev_t(td->dm_dev.name, dev);
761764 list_add(&td->list, &md->table_devices);
762765 return td;
763766
764767 out_blkdev_put:
765− bdev_release(bdev_handle);
768+ fput(bdev_file);
766769 out_free_td:
767770 kfree(td);
768771 return ERR_PTR(r);
@@ -775,7 +778,7 @@ static void close_table_device(struct table_device *td, struct mapped_device *md · 6 unmodified lines
775778 {
776779 if (md->disk->slave_dir)
777780 bd_unlink_disk_holder(td->dm_dev.bdev, md->disk);
778− bdev_release(td->dm_dev.bdev_handle);
781+ fput(td->dm_dev.bdev_file);
779782 put_dax(td->dm_dev.dax_dev);
780783 list_del(&td->list);
781784 kfree(td);
drivers/md/md.c+6−6
@@ -2582,7 +2582,7 @@ static void export_rdev(struct md_rdev *rdev, struct mddev *mddev) · 2581 unmodified lines
25822582 if (test_bit(AutoDetected, &rdev->flags))
25832583 md_autodetect_dev(rdev->bdev->bd_dev);
25842584 #endif
2585− bdev_release(rdev->bdev_handle);
2585+ fput(rdev->bdev_file);
25862586 rdev->bdev = NULL;
25872587 kobject_put(&rdev->kobj);
25882588 }
@@ -3777,16 +3777,16 @@ static struct md_rdev *md_import_device(dev_t newdev, int super_format, int supe · 1188 unmodified lines
37773777 if (err)
37783778 goto out_clear_rdev;
37793779
3780− rdev->bdev_handle = bdev_open_by_dev(newdev,
3780+ rdev->bdev_file = bdev_file_open_by_dev(newdev,
37813781 BLK_OPEN_READ | BLK_OPEN_WRITE,
37823782 super_format == -2 ? &claim_rdev : rdev, NULL);
3783− if (IS_ERR(rdev->bdev_handle)) {
3783+ if (IS_ERR(rdev->bdev_file)) {
37843784 pr_warn("md: could not open device unknown-block(%u,%u).\n",
37853785 MAJOR(newdev), MINOR(newdev));
3786− err = PTR_ERR(rdev->bdev_handle);
3786+ err = PTR_ERR(rdev->bdev_file);
37873787 goto out_clear_rdev;
37883788 }
3789− rdev->bdev = rdev->bdev_handle->bdev;
3789+ rdev->bdev = file_bdev(rdev->bdev_file);
37903790
37913791 kobject_init(&rdev->kobj, &rdev_ktype);
37923792
@@ -3817,7 +3817,7 @@ static struct md_rdev *md_import_device(dev_t newdev, int super_format, int supe · 24 unmodified lines
38173817 return rdev;
38183818
38193819 out_blkdev_put:
3820− bdev_release(rdev->bdev_handle);
3820+ fput(rdev->bdev_file);
38213821 out_clear_rdev:
38223822 md_rdev_clear(rdev);
38233823 out_free_rdev:
drivers/md/md.h+1−1
@@ -59,7 +59,7 @@ struct md_rdev { · 58 unmodified lines
5959 */
6060 struct block_device *meta_bdev;
6161 struct block_device *bdev; /* block device handle */
62− struct bdev_handle *bdev_handle; /* Handle from open for bdev */
62+ struct file *bdev_file; /* Handle from open for bdev */
6363
6464 struct page *sb_page, *bb_page;
6565 int sb_loaded;
drivers/mtd/devices/block2mtd.c+21−25
@@ -37,7 +37,7 @@ · 36 unmodified lines
3737 /* Info for the block device */
3838 struct block2mtd_dev {
3939 struct list_head list;
40− struct bdev_handle *bdev_handle;
40+ struct file *bdev_file;
4141 struct mtd_info mtd;
4242 struct mutex write_mutex;
4343 };
@@ -55,8 +55,7 @@ static struct page *page_read(struct address_space *mapping, pgoff_t index) · 11 unmodified lines
5555 /* erase a specified part of the device */
5656 static int _block2mtd_erase(struct block2mtd_dev *dev, loff_t to, size_t len)
5757 {
58− struct address_space *mapping =
59− dev->bdev_handle->bdev->bd_inode->i_mapping;
58+ struct address_space *mapping = dev->bdev_file->f_mapping;
6059 struct page *page;
6160 pgoff_t index = to >> PAGE_SHIFT; // page index
6261 int pages = len >> PAGE_SHIFT;
@@ -106,8 +105,7 @@ static int block2mtd_read(struct mtd_info *mtd, loff_t from, size_t len, · 43 unmodified lines
106105 size_t *retlen, u_char *buf)
107106 {
108107 struct block2mtd_dev *dev = mtd->priv;
109− struct address_space *mapping =
110− dev->bdev_handle->bdev->bd_inode->i_mapping;
108+ struct address_space *mapping = dev->bdev_file->f_mapping;
111109 struct page *page;
112110 pgoff_t index = from >> PAGE_SHIFT;
113111 int offset = from & (PAGE_SIZE-1);
@@ -142,8 +140,7 @@ static int _block2mtd_write(struct block2mtd_dev *dev, const u_char *buf, · 28 unmodified lines
142140 loff_t to, size_t len, size_t *retlen)
143141 {
144142 struct page *page;
145− struct address_space *mapping =
146− dev->bdev_handle->bdev->bd_inode->i_mapping;
143+ struct address_space *mapping = dev->bdev_file->f_mapping;
147144 pgoff_t index = to >> PAGE_SHIFT; // page index
148145 int offset = to & ~PAGE_MASK; // page offset
149146 int cpylen;
@@ -198,7 +195,7 @@ static int block2mtd_write(struct mtd_info *mtd, loff_t to, size_t len, · 48 unmodified lines
198195 static void block2mtd_sync(struct mtd_info *mtd)
199196 {
200197 struct block2mtd_dev *dev = mtd->priv;
201− sync_blockdev(dev->bdev_handle->bdev);
198+ sync_blockdev(file_bdev(dev->bdev_file));
202199 return;
203200 }
204201
@@ -210,10 +207,9 @@ static void block2mtd_free_device(struct block2mtd_dev *dev) · 5 unmodified lines
210207
211208 kfree(dev->mtd.name);
212209
213− if (dev->bdev_handle) {
214− invalidate_mapping_pages(
215− dev->bdev_handle->bdev->bd_inode->i_mapping, 0, -1);
216− bdev_release(dev->bdev_handle);
210+ if (dev->bdev_file) {
211+ invalidate_mapping_pages(dev->bdev_file->f_mapping, 0, -1);
212+ fput(dev->bdev_file);
217213 }
218214
219215 kfree(dev);
@@ -223,10 +219,10 @@ static void block2mtd_free_device(struct block2mtd_dev *dev) · 3 unmodified lines
223219 * This function is marked __ref because it calls the __init marked
224220 * early_lookup_bdev when called from the early boot code.
225221 */
226−static struct bdev_handle __ref *mdtblock_early_get_bdev(const char *devname,
222+static struct file __ref *mdtblock_early_get_bdev(const char *devname,
227223 blk_mode_t mode, int timeout, struct block2mtd_dev *dev)
228224 {
229− struct bdev_handle *bdev_handle = ERR_PTR(-ENODEV);
225+ struct file *bdev_file = ERR_PTR(-ENODEV);
230226 #ifndef MODULE
231227 int i;
232228
@@ -234,7 +230,7 @@ static struct bdev_handle __ref *mdtblock_early_get_bdev(const char *devname, · 1 unmodified line
234230 * We can't use early_lookup_bdev from a running system.
235231 */
236232 if (system_state >= SYSTEM_RUNNING)
237− return bdev_handle;
233+ return bdev_file;
238234
239235 /*
240236 * We might not have the root device mounted at this point.
@@ -253,20 +249,20 @@ static struct bdev_handle __ref *mdtblock_early_get_bdev(const char *devname, · 12 unmodified lines
253249 wait_for_device_probe();
254250
255251 if (!early_lookup_bdev(devname, &devt)) {
256− bdev_handle = bdev_open_by_dev(devt, mode, dev, NULL);
257− if (!IS_ERR(bdev_handle))
252+ bdev_file = bdev_file_open_by_dev(devt, mode, dev, NULL);
253+ if (!IS_ERR(bdev_file))
258254 break;
259255 }
260256 }
261257 #endif
262− return bdev_handle;
258+ return bdev_file;
263259 }
264260
265261 static struct block2mtd_dev *add_device(char *devname, int erase_size,
266262 char *label, int timeout)
267263 {
268264 const blk_mode_t mode = BLK_OPEN_READ | BLK_OPEN_WRITE;
269− struct bdev_handle *bdev_handle;
265+ struct file *bdev_file;
270266 struct block_device *bdev;
271267 struct block2mtd_dev *dev;
272268 char *name;
@@ -279,16 +275,16 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size, · 6 unmodified lines
279275 return NULL;
280276
281277 /* Get a handle on the device */
282− bdev_handle = bdev_open_by_path(devname, mode, dev, NULL);
283− if (IS_ERR(bdev_handle))
284− bdev_handle = mdtblock_early_get_bdev(devname, mode, timeout,
278+ bdev_file = bdev_file_open_by_path(devname, mode, dev, NULL);
279+ if (IS_ERR(bdev_file))
280+ bdev_file = mdtblock_early_get_bdev(devname, mode, timeout,
285281 dev);
286− if (IS_ERR(bdev_handle)) {
282+ if (IS_ERR(bdev_file)) {
287283 pr_err("error: cannot open device %s\n", devname);
288284 goto err_free_block2mtd;
289285 }
290− dev->bdev_handle = bdev_handle;
291− bdev = bdev_handle->bdev;
286+ dev->bdev_file = bdev_file;
287+ bdev = file_bdev(bdev_file);
292288
293289 if (MAJOR(bdev->bd_dev) == MTD_BLOCK_MAJOR) {
294290 pr_err("attempting to use an MTD device as a block device\n");
drivers/nvme/target/io-cmd-bdev.c+8−8
@@ -50,10 +50,10 @@ void nvmet_bdev_set_limits(struct block_device *bdev, struct nvme_id_ns *id) · 49 unmodified lines
5050
5151 void nvmet_bdev_ns_disable(struct nvmet_ns *ns)
5252 {
53− if (ns->bdev_handle) {
54− bdev_release(ns->bdev_handle);
53+ if (ns->bdev_file) {
54+ fput(ns->bdev_file);
5555 ns->bdev = NULL;
56− ns->bdev_handle = NULL;
56+ ns->bdev_file = NULL;
5757 }
5858 }
5959
@@ -85,18 +85,18 @@ int nvmet_bdev_ns_enable(struct nvmet_ns *ns) · 25 unmodified lines
8585 if (ns->buffered_io)
8686 return -ENOTBLK;
8787
88− ns->bdev_handle = bdev_open_by_path(ns->device_path,
88+ ns->bdev_file = bdev_file_open_by_path(ns->device_path,
8989 BLK_OPEN_READ | BLK_OPEN_WRITE, NULL, NULL);
90− if (IS_ERR(ns->bdev_handle)) {
91− ret = PTR_ERR(ns->bdev_handle);
90+ if (IS_ERR(ns->bdev_file)) {
91+ ret = PTR_ERR(ns->bdev_file);
9292 if (ret != -ENOTBLK) {
9393 pr_err("failed to open block device %s: (%d)\n",
9494 ns->device_path, ret);
9595 }
96− ns->bdev_handle = NULL;
96+ ns->bdev_file = NULL;
9797 return ret;
9898 }
99− ns->bdev = ns->bdev_handle->bdev;
99+ ns->bdev = file_bdev(ns->bdev_file);
100100 ns->size = bdev_nr_bytes(ns->bdev);
101101 ns->blksize_shift = blksize_bits(bdev_logical_block_size(ns->bdev));
102102
drivers/nvme/target/nvmet.h+1−1
@@ -58,7 +58,7 @@ · 57 unmodified lines
5858
5959 struct nvmet_ns {
6060 struct percpu_ref ref;
61− struct bdev_handle *bdev_handle;
61+ struct file *bdev_file;
6262 struct block_device *bdev;
6363 struct file *file;
6464 bool readonly;
drivers/s390/block/dasd.c+5−5
@@ -412,7 +412,7 @@ dasd_state_ready_to_online(struct dasd_device * device) · 411 unmodified lines
412412 KOBJ_CHANGE);
413413 return 0;
414414 }
415− disk_uevent(device->block->bdev_handle->bdev->bd_disk,
415+ disk_uevent(file_bdev(device->block->bdev_file)->bd_disk,
416416 KOBJ_CHANGE);
417417 }
418418 return 0;
@@ -433,7 +433,7 @@ static int dasd_state_online_to_ready(struct dasd_device *device) · 14 unmodified lines
433433
434434 device->state = DASD_STATE_READY;
435435 if (device->block && !(device->features & DASD_FEATURE_USERAW))
436− disk_uevent(device->block->bdev_handle->bdev->bd_disk,
436+ disk_uevent(file_bdev(device->block->bdev_file)->bd_disk,
437437 KOBJ_CHANGE);
438438 return 0;
439439 }
@@ -3588,7 +3588,7 @@ int dasd_generic_set_offline(struct ccw_device *cdev) · 3148 unmodified lines
35883588 * in the other openers.
35893589 */
35903590 if (device->block) {
3591− max_count = device->block->bdev_handle ? 0 : -1;
3591+ max_count = device->block->bdev_file ? 0 : -1;
35923592 open_count = atomic_read(&device->block->open_count);
35933593 if (open_count > max_count) {
35943594 if (open_count > 0)
@@ -3634,8 +3634,8 @@ int dasd_generic_set_offline(struct ccw_device *cdev) · 39 unmodified lines
36343634 * so sync bdev first and then wait for our queues to become
36353635 * empty
36363636 */
3637− if (device->block && device->block->bdev_handle)
3638− bdev_mark_dead(device->block->bdev_handle->bdev, false);
3637+ if (device->block && device->block->bdev_file)
3638+ bdev_mark_dead(file_bdev(device->block->bdev_file), false);
36393639 dasd_schedule_device_bh(device);
36403640 rc = wait_event_interruptible(shutdown_waitq,
36413641 _wait_for_empty_queues(device));
drivers/s390/block/dasd_genhd.c+18−18
@@ -127,15 +127,15 @@ void dasd_gendisk_free(struct dasd_block *block) · 126 unmodified lines
127127 */
128128 int dasd_scan_partitions(struct dasd_block *block)
129129 {
130− struct bdev_handle *bdev_handle;
130+ struct file *bdev_file;
131131 int rc;
132132
133− bdev_handle = bdev_open_by_dev(disk_devt(block->gdp), BLK_OPEN_READ,
133+ bdev_file = bdev_file_open_by_dev(disk_devt(block->gdp), BLK_OPEN_READ,
134134 NULL, NULL);
135− if (IS_ERR(bdev_handle)) {
135+ if (IS_ERR(bdev_file)) {
136136 DBF_DEV_EVENT(DBF_ERR, block->base,
137137 "scan partitions error, blkdev_get returned %ld",
138− PTR_ERR(bdev_handle));
138+ PTR_ERR(bdev_file));
139139 return -ENODEV;
140140 }
141141
@@ -147,15 +147,15 @@ int dasd_scan_partitions(struct dasd_block *block) · 5 unmodified lines
147147 "scan partitions error, rc %d", rc);
148148
149149 /*
150− * Since the matching bdev_release() call to the
151− * bdev_open_by_path() in this function is not called before
150+ * Since the matching fput() call to the
151+ * bdev_file_open_by_path() in this function is not called before
152152 * dasd_destroy_partitions the offline open_count limit needs to be
153− * increased from 0 to 1. This is done by setting device->bdev_handle
153+ * increased from 0 to 1. This is done by setting device->bdev_file
154154 * (see dasd_generic_set_offline). As long as the partition detection
155155 * is running no offline should be allowed. That is why the assignment
156− * to block->bdev_handle is done AFTER the BLKRRPART ioctl.
156+ * to block->bdev_file is done AFTER the BLKRRPART ioctl.
157157 */
158− block->bdev_handle = bdev_handle;
158+ block->bdev_file = bdev_file;
159159 return 0;
160160 }
161161
@@ -165,21 +165,21 @@ int dasd_scan_partitions(struct dasd_block *block) · 3 unmodified lines
165165 */
166166 void dasd_destroy_partitions(struct dasd_block *block)
167167 {
168− struct bdev_handle *bdev_handle;
168+ struct file *bdev_file;
169169
170170 /*
171− * Get the bdev_handle pointer from the device structure and clear
172− * device->bdev_handle to lower the offline open_count limit again.
171+ * Get the bdev_file pointer from the device structure and clear
172+ * device->bdev_file to lower the offline open_count limit again.
173173 */
174− bdev_handle = block->bdev_handle;
175− block->bdev_handle = NULL;
174+ bdev_file = block->bdev_file;
175+ block->bdev_file = NULL;
176176
177− mutex_lock(&bdev_handle->bdev->bd_disk->open_mutex);
178− bdev_disk_changed(bdev_handle->bdev->bd_disk, true);
179− mutex_unlock(&bdev_handle->bdev->bd_disk->open_mutex);
177+ mutex_lock(&file_bdev(bdev_file)->bd_disk->open_mutex);
178+ bdev_disk_changed(file_bdev(bdev_file)->bd_disk, true);
179+ mutex_unlock(&file_bdev(bdev_file)->bd_disk->open_mutex);
180180
181181 /* Matching blkdev_put to the blkdev_get in dasd_scan_partitions. */
182− bdev_release(bdev_handle);
182+ fput(bdev_file);
183183 }
184184
185185 int dasd_gendisk_init(void)
drivers/s390/block/dasd_int.h+1−1
@@ -650,7 +650,7 @@ struct dasd_block { · 649 unmodified lines
650650 struct gendisk *gdp;
651651 spinlock_t request_queue_lock;
652652 struct blk_mq_tag_set tag_set;
653− struct bdev_handle *bdev_handle;
653+ struct file *bdev_file;
654654 atomic_t open_count;
655655
656656 unsigned long blocks; /* size of volume in blocks */
drivers/s390/block/dasd_ioctl.c+1−1
@@ -537,7 +537,7 @@ static int __dasd_ioctl_information(struct dasd_block *block, · 536 unmodified lines
537537 * This must be hidden from user-space.
538538 */
539539 dasd_info->open_count = atomic_read(&block->open_count);
540− if (!block->bdev_handle)
540+ if (!block->bdev_file)
541541 dasd_info->open_count++;
542542
543543 /*
drivers/target/target_core_iblock.c+9−9
@@ -91,7 +91,7 @@ static int iblock_configure_device(struct se_device *dev) · 90 unmodified lines
9191 {
9292 struct iblock_dev *ib_dev = IBLOCK_DEV(dev);
9393 struct request_queue *q;
94− struct bdev_handle *bdev_handle;
94+ struct file *bdev_file;
9595 struct block_device *bd;
9696 struct blk_integrity *bi;
9797 blk_mode_t mode = BLK_OPEN_READ;
@@ -117,14 +117,14 @@ static int iblock_configure_device(struct se_device *dev) · 19 unmodified lines
117117 else
118118 dev->dev_flags |= DF_READ_ONLY;
119119
120− bdev_handle = bdev_open_by_path(ib_dev->ibd_udev_path, mode, ib_dev,
120+ bdev_file = bdev_file_open_by_path(ib_dev->ibd_udev_path, mode, ib_dev,
121121 NULL);
122− if (IS_ERR(bdev_handle)) {
123− ret = PTR_ERR(bdev_handle);
122+ if (IS_ERR(bdev_file)) {
123+ ret = PTR_ERR(bdev_file);
124124 goto out_free_bioset;
125125 }
126− ib_dev->ibd_bdev_handle = bdev_handle;
127− ib_dev->ibd_bd = bd = bdev_handle->bdev;
126+ ib_dev->ibd_bdev_file = bdev_file;
127+ ib_dev->ibd_bd = bd = file_bdev(bdev_file);
128128
129129 q = bdev_get_queue(bd);
130130
@@ -180,7 +180,7 @@ static int iblock_configure_device(struct se_device *dev) · 49 unmodified lines
180180 return 0;
181181
182182 out_blkdev_put:
183− bdev_release(ib_dev->ibd_bdev_handle);
183+ fput(ib_dev->ibd_bdev_file);
184184 out_free_bioset:
185185 bioset_exit(&ib_dev->ibd_bio_set);
186186 out:
@@ -205,8 +205,8 @@ static void iblock_destroy_device(struct se_device *dev) · 18 unmodified lines
205205 {
206206 struct iblock_dev *ib_dev = IBLOCK_DEV(dev);
207207
208− if (ib_dev->ibd_bdev_handle)
209− bdev_release(ib_dev->ibd_bdev_handle);
208+ if (ib_dev->ibd_bdev_file)
209+ fput(ib_dev->ibd_bdev_file);
210210 bioset_exit(&ib_dev->ibd_bio_set);
211211 }
212212
drivers/target/target_core_iblock.h+1−1
@@ -32,7 +32,7 @@ struct iblock_dev { · 31 unmodified lines
3232 u32 ibd_flags;
3333 struct bio_set ibd_bio_set;
3434 struct block_device *ibd_bd;
35− struct bdev_handle *ibd_bdev_handle;
35+ struct file *ibd_bdev_file;
3636 bool ibd_readonly;
3737 struct iblock_dev_plug *ibd_plug;
3838 } ____cacheline_aligned;
drivers/target/target_core_pscsi.c+11−11
@@ -352,7 +352,7 @@ static int pscsi_create_type_disk(struct se_device *dev, struct scsi_device *sd) · 351 unmodified lines
352352 struct pscsi_hba_virt *phv = dev->se_hba->hba_ptr;
353353 struct pscsi_dev_virt *pdv = PSCSI_DEV(dev);
354354 struct Scsi_Host *sh = sd->host;
355− struct bdev_handle *bdev_handle;
355+ struct file *bdev_file;
356356 int ret;
357357
358358 if (scsi_device_get(sd)) {
@@ -366,18 +366,18 @@ static int pscsi_create_type_disk(struct se_device *dev, struct scsi_device *sd) · 7 unmodified lines
366366 * Claim exclusive struct block_device access to struct scsi_device
367367 * for TYPE_DISK and TYPE_ZBC using supplied udev_path
368368 */
369− bdev_handle = bdev_open_by_path(dev->udev_path,
369+ bdev_file = bdev_file_open_by_path(dev->udev_path,
370370 BLK_OPEN_WRITE | BLK_OPEN_READ, pdv, NULL);
371− if (IS_ERR(bdev_handle)) {
371+ if (IS_ERR(bdev_file)) {
372372 pr_err("pSCSI: bdev_open_by_path() failed\n");
373373 scsi_device_put(sd);
374− return PTR_ERR(bdev_handle);
374+ return PTR_ERR(bdev_file);
375375 }
376− pdv->pdv_bdev_handle = bdev_handle;
376+ pdv->pdv_bdev_file = bdev_file;
377377
378378 ret = pscsi_add_device_to_list(dev, sd);
379379 if (ret) {
380− bdev_release(bdev_handle);
380+ fput(bdev_file);
381381 scsi_device_put(sd);
382382 return ret;
383383 }
@@ -564,9 +564,9 @@ static void pscsi_destroy_device(struct se_device *dev) · 180 unmodified lines
564564 * from pscsi_create_type_disk()
565565 */
566566 if ((sd->type == TYPE_DISK || sd->type == TYPE_ZBC) &&
567− pdv->pdv_bdev_handle) {
568− bdev_release(pdv->pdv_bdev_handle);
569− pdv->pdv_bdev_handle = NULL;
567+ pdv->pdv_bdev_file) {
568+ fput(pdv->pdv_bdev_file);
569+ pdv->pdv_bdev_file = NULL;
570570 }
571571 /*
572572 * For HBA mode PHV_LLD_SCSI_HOST_NO, release the reference
@@ -997,8 +997,8 @@ static sector_t pscsi_get_blocks(struct se_device *dev) · 424 unmodified lines
997997 {
998998 struct pscsi_dev_virt *pdv = PSCSI_DEV(dev);
999999
1000− if (pdv->pdv_bdev_handle)
1001− return bdev_nr_sectors(pdv->pdv_bdev_handle->bdev);
1000+ if (pdv->pdv_bdev_file)
1001+ return bdev_nr_sectors(file_bdev(pdv->pdv_bdev_file));
10021002 return 0;
10031003 }
10041004
drivers/target/target_core_pscsi.h+1−1
@@ -37,7 +37,7 @@ struct pscsi_dev_virt { · 36 unmodified lines
3737 int pdv_channel_id;
3838 int pdv_target_id;
3939 int pdv_lun_id;
40− struct bdev_handle *pdv_bdev_handle;
40+ struct file *pdv_bdev_file;
4141 struct scsi_device *pdv_sd;
4242 struct Scsi_Host *pdv_lld_host;
4343 } ____cacheline_aligned;
fs/bcachefs/super-io.c+10−10
@@ -142,8 +142,8 @@ void bch2_sb_field_delete(struct bch_sb_handle *sb, · 141 unmodified lines
142142 void bch2_free_super(struct bch_sb_handle *sb)
143143 {
144144 kfree(sb->bio);
145− if (!IS_ERR_OR_NULL(sb->bdev_handle))
146− bdev_release(sb->bdev_handle);
145+ if (!IS_ERR_OR_NULL(sb->s_bdev_file))
146+ fput(sb->s_bdev_file);
147147 kfree(sb->holder);
148148 kfree(sb->sb_name);
149149
@@ -704,22 +704,22 @@ retry: · 554 unmodified lines
704704 if (!opt_get(*opts, nochanges))
705705 sb->mode |= BLK_OPEN_WRITE;
706706
707− sb->bdev_handle = bdev_open_by_path(path, sb->mode, sb->holder, &bch2_sb_handle_bdev_ops);
708− if (IS_ERR(sb->bdev_handle) &&
709− PTR_ERR(sb->bdev_handle) == -EACCES &&
707+ sb->s_bdev_file = bdev_file_open_by_path(path, sb->mode, sb->holder, &bch2_sb_handle_bdev_ops);
708+ if (IS_ERR(sb->s_bdev_file) &&
709+ PTR_ERR(sb->s_bdev_file) == -EACCES &&
710710 opt_get(*opts, read_only)) {
711711 sb->mode &= ~BLK_OPEN_WRITE;
712712
713− sb->bdev_handle = bdev_open_by_path(path, sb->mode, sb->holder, &bch2_sb_handle_bdev_ops);
714− if (!IS_ERR(sb->bdev_handle))
713+ sb->s_bdev_file = bdev_file_open_by_path(path, sb->mode, sb->holder, &bch2_sb_handle_bdev_ops);
714+ if (!IS_ERR(sb->s_bdev_file))
715715 opt_set(*opts, nochanges, true);
716716 }
717717
718− if (IS_ERR(sb->bdev_handle)) {
719− ret = PTR_ERR(sb->bdev_handle);
718+ if (IS_ERR(sb->s_bdev_file)) {
719+ ret = PTR_ERR(sb->s_bdev_file);
720720 goto err;
721721 }
722− sb->bdev = sb->bdev_handle->bdev;
722+ sb->bdev = file_bdev(sb->s_bdev_file);
723723
724724 ret = bch2_sb_realloc(sb, 0);
725725 if (ret) {
fs/bcachefs/super_types.h+1−1
@@ -4,7 +4,7 @@ · 3 unmodified lines
44
55 struct bch_sb_handle {
66 struct bch_sb *sb;
7− struct bdev_handle *bdev_handle;
7+ struct file *s_bdev_file;
88 struct block_device *bdev;
99 char *sb_name;
1010 struct bio *bio;
fs/btrfs/dev-replace.c+7−7
@@ -246,7 +246,7 @@ static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, · 245 unmodified lines
246246 {
247247 struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
248248 struct btrfs_device *device;
249− struct bdev_handle *bdev_handle;
249+ struct file *bdev_file;
250250 struct block_device *bdev;
251251 u64 devid = BTRFS_DEV_REPLACE_DEVID;
252252 int ret = 0;
@@ -257,13 +257,13 @@ static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, · 4 unmodified lines
257257 return -EINVAL;
258258 }
259259
260− bdev_handle = bdev_open_by_path(device_path, BLK_OPEN_WRITE,
260+ bdev_file = bdev_file_open_by_path(device_path, BLK_OPEN_WRITE,
261261 fs_info->bdev_holder, NULL);
262− if (IS_ERR(bdev_handle)) {
262+ if (IS_ERR(bdev_file)) {
263263 btrfs_err(fs_info, "target device %s is invalid!", device_path);
264− return PTR_ERR(bdev_handle);
264+ return PTR_ERR(bdev_file);
265265 }
266− bdev = bdev_handle->bdev;
266+ bdev = file_bdev(bdev_file);
267267
268268 if (!btrfs_check_device_zone_type(fs_info, bdev)) {
269269 btrfs_err(fs_info,
@@ -314,7 +314,7 @@ static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, · 44 unmodified lines
314314 device->commit_bytes_used = device->bytes_used;
315315 device->fs_info = fs_info;
316316 device->bdev = bdev;
317− device->bdev_handle = bdev_handle;
317+ device->bdev_file = bdev_file;
318318 set_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state);
319319 set_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state);
320320 device->dev_stats_valid = 1;
@@ -335,7 +335,7 @@ static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, · 14 unmodified lines
335335 return 0;
336336
337337 error:
338− bdev_release(bdev_handle);
338+ fput(bdev_file);
339339 return ret;
340340 }
341341
fs/btrfs/ioctl.c+8−8
@@ -2698,7 +2698,7 @@ static long btrfs_ioctl_rm_dev_v2(struct file *file, void __user *arg) · 2697 unmodified lines
26982698 struct inode *inode = file_inode(file);
26992699 struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
27002700 struct btrfs_ioctl_vol_args_v2 *vol_args;
2701− struct bdev_handle *bdev_handle = NULL;
2701+ struct file *bdev_file = NULL;
27022702 int ret;
27032703 bool cancel = false;
27042704
@@ -2735,7 +2735,7 @@ static long btrfs_ioctl_rm_dev_v2(struct file *file, void __user *arg) · 30 unmodified lines
27352735 goto err_drop;
27362736
27372737 /* Exclusive operation is now claimed */
2738− ret = btrfs_rm_device(fs_info, &args, &bdev_handle);
2738+ ret = btrfs_rm_device(fs_info, &args, &bdev_file);
27392739
27402740 btrfs_exclop_finish(fs_info);
27412741
@@ -2749,8 +2749,8 @@ static long btrfs_ioctl_rm_dev_v2(struct file *file, void __user *arg) · 7 unmodified lines
27492749 }
27502750 err_drop:
27512751 mnt_drop_write_file(file);
2752− if (bdev_handle)
2753− bdev_release(bdev_handle);
2752+ if (bdev_file)
2753+ fput(bdev_file);
27542754 out:
27552755 btrfs_put_dev_args_from_path(&args);
27562756 kfree(vol_args);
@@ -2763,7 +2763,7 @@ static long btrfs_ioctl_rm_dev(struct file *file, void __user *arg) · 6 unmodified lines
27632763 struct inode *inode = file_inode(file);
27642764 struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
27652765 struct btrfs_ioctl_vol_args *vol_args;
2766− struct bdev_handle *bdev_handle = NULL;
2766+ struct file *bdev_file = NULL;
27672767 int ret;
27682768 bool cancel = false;
27692769
@@ -2790,15 +2790,15 @@ static long btrfs_ioctl_rm_dev(struct file *file, void __user *arg) · 20 unmodified lines
27902790 ret = exclop_start_or_cancel_reloc(fs_info, BTRFS_EXCLOP_DEV_REMOVE,
27912791 cancel);
27922792 if (ret == 0) {
2793− ret = btrfs_rm_device(fs_info, &args, &bdev_handle);
2793+ ret = btrfs_rm_device(fs_info, &args, &bdev_file);
27942794 if (!ret)
27952795 btrfs_info(fs_info, "disk deleted %s", vol_args->name);
27962796 btrfs_exclop_finish(fs_info);
27972797 }
27982798
27992799 mnt_drop_write_file(file);
2800− if (bdev_handle)
2801− bdev_release(bdev_handle);
2800+ if (bdev_file)
2801+ fput(bdev_file);
28022802 out:
28032803 btrfs_put_dev_args_from_path(&args);
28042804 kfree(vol_args);
fs/btrfs/volumes.c+46−46
@@ -468,39 +468,39 @@ static noinline struct btrfs_fs_devices *find_fsid( · 467 unmodified lines
468468
469469 static int
470470 btrfs_get_bdev_and_sb(const char *device_path, blk_mode_t flags, void *holder,
471− int flush, struct bdev_handle **bdev_handle,
471+ int flush, struct file **bdev_file,
472472 struct btrfs_super_block **disk_super)
473473 {
474474 struct block_device *bdev;
475475 int ret;
476476
477− *bdev_handle = bdev_open_by_path(device_path, flags, holder, NULL);
477+ *bdev_file = bdev_file_open_by_path(device_path, flags, holder, NULL);
478478
479− if (IS_ERR(*bdev_handle)) {
480− ret = PTR_ERR(*bdev_handle);
479+ if (IS_ERR(*bdev_file)) {
480+ ret = PTR_ERR(*bdev_file);
481481 goto error;
482482 }
483− bdev = (*bdev_handle)->bdev;
483+ bdev = file_bdev(*bdev_file);
484484
485485 if (flush)
486486 sync_blockdev(bdev);
487487 ret = set_blocksize(bdev, BTRFS_BDEV_BLOCKSIZE);
488488 if (ret) {
489− bdev_release(*bdev_handle);
489+ fput(*bdev_file);
490490 goto error;
491491 }
492492 invalidate_bdev(bdev);
493493 *disk_super = btrfs_read_dev_super(bdev);
494494 if (IS_ERR(*disk_super)) {
495495 ret = PTR_ERR(*disk_super);
496− bdev_release(*bdev_handle);
496+ fput(*bdev_file);
497497 goto error;
498498 }
499499
500500 return 0;
501501
502502 error:
503− *bdev_handle = NULL;
503+ *bdev_file = NULL;
504504 return ret;
505505 }
506506
@@ -643,7 +643,7 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices, · 136 unmodified lines
643643 struct btrfs_device *device, blk_mode_t flags,
644644 void *holder)
645645 {
646− struct bdev_handle *bdev_handle;
646+ struct file *bdev_file;
647647 struct btrfs_super_block *disk_super;
648648 u64 devid;
649649 int ret;
@@ -654,7 +654,7 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices, · 4 unmodified lines
654654 return -EINVAL;
655655
656656 ret = btrfs_get_bdev_and_sb(device->name->str, flags, holder, 1,
657− &bdev_handle, &disk_super);
657+ &bdev_file, &disk_super);
658658 if (ret)
659659 return ret;
660660
@@ -678,20 +678,20 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices, · 17 unmodified lines
678678 clear_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state);
679679 fs_devices->seeding = true;
680680 } else {
681− if (bdev_read_only(bdev_handle->bdev))
681+ if (bdev_read_only(file_bdev(bdev_file)))
682682 clear_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state);
683683 else
684684 set_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state);
685685 }
686686
687− if (!bdev_nonrot(bdev_handle->bdev))
687+ if (!bdev_nonrot(file_bdev(bdev_file)))
688688 fs_devices->rotating = true;
689689
690− if (bdev_max_discard_sectors(bdev_handle->bdev))
690+ if (bdev_max_discard_sectors(file_bdev(bdev_file)))
691691 fs_devices->discardable = true;
692692
693− device->bdev_handle = bdev_handle;
694− device->bdev = bdev_handle->bdev;
693+ device->bdev_file = bdev_file;
694+ device->bdev = file_bdev(bdev_file);
695695 clear_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state);
696696
697697 fs_devices->open_devices++;
@@ -706,7 +706,7 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices, · 8 unmodified lines
706706
707707 error_free_page:
708708 btrfs_release_disk_super(disk_super);
709− bdev_release(bdev_handle);
709+ fput(bdev_file);
710710
711711 return -EINVAL;
712712 }
@@ -1015,10 +1015,10 @@ static void __btrfs_free_extra_devids(struct btrfs_fs_devices *fs_devices, · 302 unmodified lines
10151015 if (device->devid == BTRFS_DEV_REPLACE_DEVID)
10161016 continue;
10171017
1018− if (device->bdev_handle) {
1019− bdev_release(device->bdev_handle);
1018+ if (device->bdev_file) {
1019+ fput(device->bdev_file);
10201020 device->bdev = NULL;
1021− device->bdev_handle = NULL;
1021+ device->bdev_file = NULL;
10221022 fs_devices->open_devices--;
10231023 }
10241024 if (test_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state)) {
@@ -1063,7 +1063,7 @@ static void btrfs_close_bdev(struct btrfs_device *device) · 38 unmodified lines
10631063 invalidate_bdev(device->bdev);
10641064 }
10651065
1066− bdev_release(device->bdev_handle);
1066+ fput(device->bdev_file);
10671067 }
10681068
10691069 static void btrfs_close_one_device(struct btrfs_device *device)
@@ -1316,7 +1316,7 @@ struct btrfs_device *btrfs_scan_one_device(const char *path, blk_mode_t flags, · 246 unmodified lines
13161316 struct btrfs_super_block *disk_super;
13171317 bool new_device_added = false;
13181318 struct btrfs_device *device = NULL;
1319− struct bdev_handle *bdev_handle;
1319+ struct file *bdev_file;
13201320 u64 bytenr, bytenr_orig;
13211321 int ret;
13221322
@@ -1339,18 +1339,18 @@ struct btrfs_device *btrfs_scan_one_device(const char *path, blk_mode_t flags, · 16 unmodified lines
13391339 * values temporarily, as the device paths of the fsid are the only
13401340 * required information for assembling the volume.
13411341 */
1342− bdev_handle = bdev_open_by_path(path, flags, NULL, NULL);
1343− if (IS_ERR(bdev_handle))
1344− return ERR_CAST(bdev_handle);
1342+ bdev_file = bdev_file_open_by_path(path, flags, NULL, NULL);
1343+ if (IS_ERR(bdev_file))
1344+ return ERR_CAST(bdev_file);
13451345
13461346 bytenr_orig = btrfs_sb_offset(0);
1347− ret = btrfs_sb_log_location_bdev(bdev_handle->bdev, 0, READ, &bytenr);
1347+ ret = btrfs_sb_log_location_bdev(file_bdev(bdev_file), 0, READ, &bytenr);
13481348 if (ret) {
13491349 device = ERR_PTR(ret);
13501350 goto error_bdev_put;
13511351 }
13521352
1353− disk_super = btrfs_read_disk_super(bdev_handle->bdev, bytenr,
1353+ disk_super = btrfs_read_disk_super(file_bdev(bdev_file), bytenr,
13541354 bytenr_orig);
13551355 if (IS_ERR(disk_super)) {
13561356 device = ERR_CAST(disk_super);
@@ -1381,7 +1381,7 @@ free_disk_super: · 24 unmodified lines
13811381 btrfs_release_disk_super(disk_super);
13821382
13831383 error_bdev_put:
1384− bdev_release(bdev_handle);
1384+ fput(bdev_file);
13851385
13861386 return device;
13871387 }
@@ -2057,7 +2057,7 @@ void btrfs_scratch_superblocks(struct btrfs_fs_info *fs_info, · 669 unmodified lines
20572057
20582058 int btrfs_rm_device(struct btrfs_fs_info *fs_info,
20592059 struct btrfs_dev_lookup_args *args,
2060− struct bdev_handle **bdev_handle)
2060+ struct file **bdev_file)
20612061 {
20622062 struct btrfs_trans_handle *trans;
20632063 struct btrfs_device *device;
@@ -2166,7 +2166,7 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info, · 102 unmodified lines
21662166
21672167 btrfs_assign_next_active_device(device, NULL);
21682168
2169− if (device->bdev_handle) {
2169+ if (device->bdev_file) {
21702170 cur_devices->open_devices--;
21712171 /* remove sysfs entry */
21722172 btrfs_sysfs_remove_device(device);
@@ -2182,9 +2182,9 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info, · 9 unmodified lines
21822182 * free the device.
21832183 *
21842184 * We cannot call btrfs_close_bdev() here because we're holding the sb
2185− * write lock, and bdev_release() will pull in the ->open_mutex on
2186− * the block device and it's dependencies. Instead just flush the
2187− * device and let the caller do the final bdev_release.
2185+ * write lock, and fput() on the block device will pull in the
2186+ * ->open_mutex on the block device and it's dependencies. Instead
2187+ * just flush the device and let the caller do the final bdev_release.
21882188 */
21892189 if (test_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state)) {
21902190 btrfs_scratch_superblocks(fs_info, device->bdev,
@@ -2195,7 +2195,7 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info, · 4 unmodified lines
21952195 }
21962196 }
21972197
2198− *bdev_handle = device->bdev_handle;
2198+ *bdev_file = device->bdev_file;
21992199 synchronize_rcu();
22002200 btrfs_free_device(device);
22012201
@@ -2332,7 +2332,7 @@ int btrfs_get_dev_args_from_path(struct btrfs_fs_info *fs_info, · 130 unmodified lines
23322332 const char *path)
23332333 {
23342334 struct btrfs_super_block *disk_super;
2335− struct bdev_handle *bdev_handle;
2335+ struct file *bdev_file;
23362336 int ret;
23372337
23382338 if (!path || !path[0])
@@ -2350,7 +2350,7 @@ int btrfs_get_dev_args_from_path(struct btrfs_fs_info *fs_info, · 11 unmodified lines
23502350 }
23512351
23522352 ret = btrfs_get_bdev_and_sb(path, BLK_OPEN_READ, NULL, 0,
2353− &bdev_handle, &disk_super);
2353+ &bdev_file, &disk_super);
23542354 if (ret) {
23552355 btrfs_put_dev_args_from_path(args);
23562356 return ret;
@@ -2363,7 +2363,7 @@ int btrfs_get_dev_args_from_path(struct btrfs_fs_info *fs_info, · 6 unmodified lines
23632363 else
23642364 memcpy(args->fsid, disk_super->fsid, BTRFS_FSID_SIZE);
23652365 btrfs_release_disk_super(disk_super);
2366− bdev_release(bdev_handle);
2366+ fput(bdev_file);
23672367 return 0;
23682368 }
23692369
@@ -2583,7 +2583,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path · 213 unmodified lines
25832583 struct btrfs_root *root = fs_info->dev_root;
25842584 struct btrfs_trans_handle *trans;
25852585 struct btrfs_device *device;
2586− struct bdev_handle *bdev_handle;
2586+ struct file *bdev_file;
25872587 struct super_block *sb = fs_info->sb;
25882588 struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
25892589 struct btrfs_fs_devices *seed_devices = NULL;
@@ -2596,12 +2596,12 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path · 6 unmodified lines
25962596 if (sb_rdonly(sb) && !fs_devices->seeding)
25972597 return -EROFS;
25982598
2599− bdev_handle = bdev_open_by_path(device_path, BLK_OPEN_WRITE,
2599+ bdev_file = bdev_file_open_by_path(device_path, BLK_OPEN_WRITE,
26002600 fs_info->bdev_holder, NULL);
2601− if (IS_ERR(bdev_handle))
2602− return PTR_ERR(bdev_handle);
2601+ if (IS_ERR(bdev_file))
2602+ return PTR_ERR(bdev_file);
26032603
2604− if (!btrfs_check_device_zone_type(fs_info, bdev_handle->bdev)) {
2604+ if (!btrfs_check_device_zone_type(fs_info, file_bdev(bdev_file))) {
26052605 ret = -EINVAL;
26062606 goto error;
26072607 }
@@ -2613,11 +2613,11 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path · 5 unmodified lines
26132613 locked = true;
26142614 }
26152615
2616− sync_blockdev(bdev_handle->bdev);
2616+ sync_blockdev(file_bdev(bdev_file));
26172617
26182618 rcu_read_lock();
26192619 list_for_each_entry_rcu(device, &fs_devices->devices, dev_list) {
2620− if (device->bdev == bdev_handle->bdev) {
2620+ if (device->bdev == file_bdev(bdev_file)) {
26212621 ret = -EEXIST;
26222622 rcu_read_unlock();
26232623 goto error;
@@ -2633,8 +2633,8 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path · 9 unmodified lines
26332633 }
26342634
26352635 device->fs_info = fs_info;
2636− device->bdev_handle = bdev_handle;
2637− device->bdev = bdev_handle->bdev;
2636+ device->bdev_file = bdev_file;
2637+ device->bdev = file_bdev(bdev_file);
26382638 ret = lookup_bdev(device_path, &device->devt);
26392639 if (ret)
26402640 goto error_free_device;
@@ -2817,7 +2817,7 @@ error_free_zone: · 176 unmodified lines
28172817 error_free_device:
28182818 btrfs_free_device(device);
28192819 error:
2820− bdev_release(bdev_handle);
2820+ fput(bdev_file);
28212821 if (locked) {
28222822 mutex_unlock(&uuid_mutex);
28232823 up_write(&sb->s_umount);
fs/btrfs/volumes.h+2−2
@@ -90,7 +90,7 @@ struct btrfs_device { · 89 unmodified lines
9090
9191 u64 generation;
9292
93− struct bdev_handle *bdev_handle;
93+ struct file *bdev_file;
9494 struct block_device *bdev;
9595
9696 struct btrfs_zoned_device_info *zone_info;
@@ -661,7 +661,7 @@ struct btrfs_device *btrfs_alloc_device(struct btrfs_fs_info *fs_info, · 564 unmodified lines
661661 void btrfs_put_dev_args_from_path(struct btrfs_dev_lookup_args *args);
662662 int btrfs_rm_device(struct btrfs_fs_info *fs_info,
663663 struct btrfs_dev_lookup_args *args,
664− struct bdev_handle **bdev_handle);
664+ struct file **bdev_file);
665665 void __exit btrfs_cleanup_fs_uuids(void);
666666 int btrfs_num_copies(struct btrfs_fs_info *fs_info, u64 logical, u64 len);
667667 int btrfs_grow_device(struct btrfs_trans_handle *trans,
fs/cramfs/inode.c+1−1
@@ -495,7 +495,7 @@ static void cramfs_kill_sb(struct super_block *sb) · 494 unmodified lines
495495 sb->s_mtd = NULL;
496496 } else if (IS_ENABLED(CONFIG_CRAMFS_BLOCKDEV) && sb->s_bdev) {
497497 sync_blockdev(sb->s_bdev);
498− bdev_release(sb->s_bdev_handle);
498+ fput(sb->s_bdev_file);
499499 }
500500 kfree(sbi);
501501 }
fs/erofs/data.c+3−3
@@ -220,7 +220,7 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *map) · 219 unmodified lines
220220 up_read(&devs->rwsem);
221221 return 0;
222222 }
223− map->m_bdev = dif->bdev_handle ? dif->bdev_handle->bdev : NULL;
223+ map->m_bdev = dif->bdev_file ? file_bdev(dif->bdev_file) : NULL;
224224 map->m_daxdev = dif->dax_dev;
225225 map->m_dax_part_off = dif->dax_part_off;
226226 map->m_fscache = dif->fscache;
@@ -238,8 +238,8 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *map) · 11 unmodified lines
238238 if (map->m_pa >= startoff &&
239239 map->m_pa < startoff + length) {
240240 map->m_pa -= startoff;
241− map->m_bdev = dif->bdev_handle ?
242− dif->bdev_handle->bdev : NULL;
241+ map->m_bdev = dif->bdev_file ?
242+ file_bdev(dif->bdev_file) : NULL;
243243 map->m_daxdev = dif->dax_dev;
244244 map->m_dax_part_off = dif->dax_part_off;
245245 map->m_fscache = dif->fscache;
fs/erofs/internal.h+1−1
@@ -49,7 +49,7 @@ typedef u32 erofs_blk_t; · 48 unmodified lines
4949 struct erofs_device_info {
5050 char *path;
5151 struct erofs_fscache *fscache;
52− struct bdev_handle *bdev_handle;
52+ struct file *bdev_file;
5353 struct dax_device *dax_dev;
5454 u64 dax_part_off;
5555
fs/erofs/super.c+8−8
@@ -177,7 +177,7 @@ static int erofs_init_device(struct erofs_buf *buf, struct super_block *sb, · 176 unmodified lines
177177 struct erofs_sb_info *sbi = EROFS_SB(sb);
178178 struct erofs_fscache *fscache;
179179 struct erofs_deviceslot *dis;
180− struct bdev_handle *bdev_handle;
180+ struct file *bdev_file;
181181 void *ptr;
182182
183183 ptr = erofs_read_metabuf(buf, sb, erofs_blknr(sb, *pos), EROFS_KMAP);
@@ -201,12 +201,12 @@ static int erofs_init_device(struct erofs_buf *buf, struct super_block *sb, · 17 unmodified lines
201201 return PTR_ERR(fscache);
202202 dif->fscache = fscache;
203203 } else if (!sbi->devs->flatdev) {
204− bdev_handle = bdev_open_by_path(dif->path, BLK_OPEN_READ,
204+ bdev_file = bdev_file_open_by_path(dif->path, BLK_OPEN_READ,
205205 sb->s_type, NULL);
206− if (IS_ERR(bdev_handle))
207− return PTR_ERR(bdev_handle);
208− dif->bdev_handle = bdev_handle;
209− dif->dax_dev = fs_dax_get_by_bdev(bdev_handle->bdev,
206+ if (IS_ERR(bdev_file))
207+ return PTR_ERR(bdev_file);
208+ dif->bdev_file = bdev_file;
209+ dif->dax_dev = fs_dax_get_by_bdev(file_bdev(bdev_file),
210210 &dif->dax_part_off, NULL, NULL);
211211 }
212212
@@ -754,8 +754,8 @@ static int erofs_release_device_info(int id, void *ptr, void *data) · 541 unmodified lines
754754 struct erofs_device_info *dif = ptr;
755755
756756 fs_put_dax(dif->dax_dev, NULL);
757− if (dif->bdev_handle)
758− bdev_release(dif->bdev_handle);
757+ if (dif->bdev_file)
758+ fput(dif->bdev_file);
759759 erofs_fscache_unregister_cookie(dif->fscache);
760760 dif->fscache = NULL;
761761 kfree(dif->path);
fs/ext4/ext4.h+1−1
@@ -1550,7 +1550,7 @@ struct ext4_sb_info { · 1549 unmodified lines
15501550 unsigned long s_commit_interval;
15511551 u32 s_max_batch_time;
15521552 u32 s_min_batch_time;
1553− struct bdev_handle *s_journal_bdev_handle;
1553+ struct file *s_journal_bdev_file;
15541554 #ifdef CONFIG_QUOTA
15551555 /* Names of quota files with journalled quota */
15561556 char __rcu *s_qf_names[EXT4_MAXQUOTAS];
fs/ext4/fsmap.c+4−4
@@ -576,9 +576,9 @@ static bool ext4_getfsmap_is_valid_device(struct super_block *sb, · 575 unmodified lines
576576 if (fm->fmr_device == 0 || fm->fmr_device == UINT_MAX ||
577577 fm->fmr_device == new_encode_dev(sb->s_bdev->bd_dev))
578578 return true;
579− if (EXT4_SB(sb)->s_journal_bdev_handle &&
579+ if (EXT4_SB(sb)->s_journal_bdev_file &&
580580 fm->fmr_device ==
581− new_encode_dev(EXT4_SB(sb)->s_journal_bdev_handle->bdev->bd_dev))
581+ new_encode_dev(file_bdev(EXT4_SB(sb)->s_journal_bdev_file)->bd_dev))
582582 return true;
583583 return false;
584584 }
@@ -648,9 +648,9 @@ int ext4_getfsmap(struct super_block *sb, struct ext4_fsmap_head *head, · 63 unmodified lines
648648 memset(handlers, 0, sizeof(handlers));
649649 handlers[0].gfd_dev = new_encode_dev(sb->s_bdev->bd_dev);
650650 handlers[0].gfd_fn = ext4_getfsmap_datadev;
651− if (EXT4_SB(sb)->s_journal_bdev_handle) {
651+ if (EXT4_SB(sb)->s_journal_bdev_file) {
652652 handlers[1].gfd_dev = new_encode_dev(
653− EXT4_SB(sb)->s_journal_bdev_handle->bdev->bd_dev);
653+ file_bdev(EXT4_SB(sb)->s_journal_bdev_file)->bd_dev);
654654 handlers[1].gfd_fn = ext4_getfsmap_logdev;
655655 }
656656
fs/ext4/super.c+26−26
@@ -1359,14 +1359,14 @@ static void ext4_put_super(struct super_block *sb) · 1358 unmodified lines
13591359
13601360 sync_blockdev(sb->s_bdev);
13611361 invalidate_bdev(sb->s_bdev);
1362− if (sbi->s_journal_bdev_handle) {
1362+ if (sbi->s_journal_bdev_file) {
13631363 /*
13641364 * Invalidate the journal device's buffers. We don't want them
13651365 * floating about in memory - the physical journal device may
13661366 * hotswapped, and it breaks the `ro-after' testing code.
13671367 */
1368− sync_blockdev(sbi->s_journal_bdev_handle->bdev);
1369− invalidate_bdev(sbi->s_journal_bdev_handle->bdev);
1368+ sync_blockdev(file_bdev(sbi->s_journal_bdev_file));
1369+ invalidate_bdev(file_bdev(sbi->s_journal_bdev_file));
13701370 }
13711371
13721372 ext4_xattr_destroy_cache(sbi->s_ea_inode_cache);
@@ -4233,7 +4233,7 @@ int ext4_calculate_overhead(struct super_block *sb) · 2860 unmodified lines
42334233 * Add the internal journal blocks whether the journal has been
42344234 * loaded or not
42354235 */
4236− if (sbi->s_journal && !sbi->s_journal_bdev_handle)
4236+ if (sbi->s_journal && !sbi->s_journal_bdev_file)
42374237 overhead += EXT4_NUM_B2C(sbi, sbi->s_journal->j_total_len);
42384238 else if (ext4_has_feature_journal(sb) && !sbi->s_journal && j_inum) {
42394239 /* j_inum for internal journal is non-zero */
@@ -5671,9 +5671,9 @@ failed_mount: · 1431 unmodified lines
56715671 #endif
56725672 fscrypt_free_dummy_policy(&sbi->s_dummy_enc_policy);
56735673 brelse(sbi->s_sbh);
5674− if (sbi->s_journal_bdev_handle) {
5675− invalidate_bdev(sbi->s_journal_bdev_handle->bdev);
5676− bdev_release(sbi->s_journal_bdev_handle);
5674+ if (sbi->s_journal_bdev_file) {
5675+ invalidate_bdev(file_bdev(sbi->s_journal_bdev_file));
5676+ fput(sbi->s_journal_bdev_file);
56775677 }
56785678 out_fail:
56795679 invalidate_bdev(sb->s_bdev);
@@ -5843,30 +5843,30 @@ static journal_t *ext4_open_inode_journal(struct super_block *sb, · 163 unmodified lines
58435843 return journal;
58445844 }
58455845
5846−static struct bdev_handle *ext4_get_journal_blkdev(struct super_block *sb,
5846+static struct file *ext4_get_journal_blkdev(struct super_block *sb,
58475847 dev_t j_dev, ext4_fsblk_t *j_start,
58485848 ext4_fsblk_t *j_len)
58495849 {
58505850 struct buffer_head *bh;
58515851 struct block_device *bdev;
5852− struct bdev_handle *bdev_handle;
5852+ struct file *bdev_file;
58535853 int hblock, blocksize;
58545854 ext4_fsblk_t sb_block;
58555855 unsigned long offset;
58565856 struct ext4_super_block *es;
58575857 int errno;
58585858
5859− bdev_handle = bdev_open_by_dev(j_dev,
5859+ bdev_file = bdev_file_open_by_dev(j_dev,
58605860 BLK_OPEN_READ | BLK_OPEN_WRITE | BLK_OPEN_RESTRICT_WRITES,
58615861 sb, &fs_holder_ops);
5862− if (IS_ERR(bdev_handle)) {
5862+ if (IS_ERR(bdev_file)) {
58635863 ext4_msg(sb, KERN_ERR,
58645864 "failed to open journal device unknown-block(%u,%u) %ld",
5865− MAJOR(j_dev), MINOR(j_dev), PTR_ERR(bdev_handle));
5866− return bdev_handle;
5865+ MAJOR(j_dev), MINOR(j_dev), PTR_ERR(bdev_file));
5866+ return bdev_file;
58675867 }
58685868
5869− bdev = bdev_handle->bdev;
5869+ bdev = file_bdev(bdev_file);
58705870 blocksize = sb->s_blocksize;
58715871 hblock = bdev_logical_block_size(bdev);
58725872 if (blocksize < hblock) {
@@ -5913,12 +5913,12 @@ static struct bdev_handle *ext4_get_journal_blkdev(struct super_block *sb, · 40 unmodified lines
59135913 *j_start = sb_block + 1;
59145914 *j_len = ext4_blocks_count(es);
59155915 brelse(bh);
5916− return bdev_handle;
5916+ return bdev_file;
59175917
59185918 out_bh:
59195919 brelse(bh);
59205920 out_bdev:
5921− bdev_release(bdev_handle);
5921+ fput(bdev_file);
59225922 return ERR_PTR(errno);
59235923 }
59245924
@@ -5928,14 +5928,14 @@ static journal_t *ext4_open_dev_journal(struct super_block *sb, · 3 unmodified lines
59285928 journal_t *journal;
59295929 ext4_fsblk_t j_start;
59305930 ext4_fsblk_t j_len;
5931− struct bdev_handle *bdev_handle;
5931+ struct file *bdev_file;
59325932 int errno = 0;
59335933
5934− bdev_handle = ext4_get_journal_blkdev(sb, j_dev, &j_start, &j_len);
5935− if (IS_ERR(bdev_handle))
5936− return ERR_CAST(bdev_handle);
5934+ bdev_file = ext4_get_journal_blkdev(sb, j_dev, &j_start, &j_len);
5935+ if (IS_ERR(bdev_file))
5936+ return ERR_CAST(bdev_file);
59375937
5938− journal = jbd2_journal_init_dev(bdev_handle->bdev, sb->s_bdev, j_start,
5938+ journal = jbd2_journal_init_dev(file_bdev(bdev_file), sb->s_bdev, j_start,
59395939 j_len, sb->s_blocksize);
59405940 if (IS_ERR(journal)) {
59415941 ext4_msg(sb, KERN_ERR, "failed to create device journal");
@@ -5950,14 +5950,14 @@ static journal_t *ext4_open_dev_journal(struct super_block *sb, · 8 unmodified lines
59505950 goto out_journal;
59515951 }
59525952 journal->j_private = sb;
5953− EXT4_SB(sb)->s_journal_bdev_handle = bdev_handle;
5953+ EXT4_SB(sb)->s_journal_bdev_file = bdev_file;
59545954 ext4_init_journal_params(sb, journal);
59555955 return journal;
59565956
59575957 out_journal:
59585958 jbd2_journal_destroy(journal);
59595959 out_bdev:
5960− bdev_release(bdev_handle);
5960+ fput(bdev_file);
59615961 return ERR_PTR(errno);
59625962 }
59635963
@@ -7315,12 +7315,12 @@ static inline int ext3_feature_set_ok(struct super_block *sb) · 1351 unmodified lines
73157315 static void ext4_kill_sb(struct super_block *sb)
73167316 {
73177317 struct ext4_sb_info *sbi = EXT4_SB(sb);
7318− struct bdev_handle *handle = sbi ? sbi->s_journal_bdev_handle : NULL;
7318+ struct file *bdev_file = sbi ? sbi->s_journal_bdev_file : NULL;
73197319
73207320 kill_block_super(sb);
73217321
7322− if (handle)
7323− bdev_release(handle);
7322+ if (bdev_file)
7323+ fput(bdev_file);
73247324 }
73257325
73267326 static struct file_system_type ext4_fs_type = {
fs/f2fs/f2fs.h+1−1
@@ -1240,7 +1240,7 @@ struct f2fs_bio_info { · 1239 unmodified lines
12401240 #define FDEV(i) (sbi->devs[i])
12411241 #define RDEV(i) (raw_super->devs[i])
12421242 struct f2fs_dev_info {
1243− struct bdev_handle *bdev_handle;
1243+ struct file *bdev_file;
12441244 struct block_device *bdev;
12451245 char path[MAX_PATH_LEN];
12461246 unsigned int total_segments;
fs/f2fs/super.c+6−6
@@ -1605,7 +1605,7 @@ static void destroy_device_list(struct f2fs_sb_info *sbi) · 1604 unmodified lines
16051605
16061606 for (i = 0; i < sbi->s_ndevs; i++) {
16071607 if (i > 0)
1608− bdev_release(FDEV(i).bdev_handle);
1608+ fput(FDEV(i).bdev_file);
16091609 #ifdef CONFIG_BLK_DEV_ZONED
16101610 kvfree(FDEV(i).blkz_seq);
16111611 #endif
@@ -4247,7 +4247,7 @@ static int f2fs_scan_devices(struct f2fs_sb_info *sbi) · 2635 unmodified lines
42474247
42484248 for (i = 0; i < max_devices; i++) {
42494249 if (i == 0)
4250− FDEV(0).bdev_handle = sbi->sb->s_bdev_handle;
4250+ FDEV(0).bdev_file = sbi->sb->s_bdev_file;
42514251 else if (!RDEV(i).path[0])
42524252 break;
42534253
@@ -4267,14 +4267,14 @@ static int f2fs_scan_devices(struct f2fs_sb_info *sbi) · 13 unmodified lines
42674267 FDEV(i).end_blk = FDEV(i).start_blk +
42684268 (FDEV(i).total_segments <<
42694269 sbi->log_blocks_per_seg) - 1;
4270− FDEV(i).bdev_handle = bdev_open_by_path(
4270+ FDEV(i).bdev_file = bdev_file_open_by_path(
42714271 FDEV(i).path, mode, sbi->sb, NULL);
42724272 }
42734273 }
4274− if (IS_ERR(FDEV(i).bdev_handle))
4275− return PTR_ERR(FDEV(i).bdev_handle);
4274+ if (IS_ERR(FDEV(i).bdev_file))
4275+ return PTR_ERR(FDEV(i).bdev_file);
42764276
4277− FDEV(i).bdev = FDEV(i).bdev_handle->bdev;
4277+ FDEV(i).bdev = file_bdev(FDEV(i).bdev_file);
42784278 /* to release errored devices */
42794279 sbi->s_ndevs = i + 1;
42804280
fs/file_table.c+65−18
@@ -276,21 +276,15 @@ struct file *alloc_empty_backing_file(int flags, const struct cred *cred) · 275 unmodified lines
276276 }
277277
278278 /**
279− * alloc_file - allocate and initialize a 'struct file'
279+ * file_init_path - initialize a 'struct file' based on path
280280 *
281+ * @file: the file to set up
281282 * @path: the (dentry, vfsmount) pair for the new file
282− * @flags: O_... flags with which the new file will be opened
283283 * @fop: the 'struct file_operations' for the new file
284284 */
285−static struct file *alloc_file(const struct path *path, int flags,
286− const struct file_operations *fop)
285+static void file_init_path(struct file *file, const struct path *path,
286+ const struct file_operations *fop)
287287 {
288− struct file *file;
289−
290− file = alloc_empty_file(flags, current_cred());
291− if (IS_ERR(file))
292− return file;
293−
294288 file->f_path = *path;
295289 file->f_inode = path->dentry->d_inode;
296290 file->f_mapping = path->dentry->d_inode->i_mapping;
@@ -309,22 +303,51 @@ static struct file *alloc_file(const struct path *path, int flags, · 12 unmodified lines
309303 file->f_op = fop;
310304 if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
311305 i_readcount_inc(path->dentry->d_inode);
306+}
307+
308+/**
309+ * alloc_file - allocate and initialize a 'struct file'
310+ *
311+ * @path: the (dentry, vfsmount) pair for the new file
312+ * @flags: O_... flags with which the new file will be opened
313+ * @fop: the 'struct file_operations' for the new file
314+ */
315+static struct file *alloc_file(const struct path *path, int flags,
316+ const struct file_operations *fop)
317+{
318+ struct file *file;
319+
320+ file = alloc_empty_file(flags, current_cred());
321+ if (!IS_ERR(file))
322+ file_init_path(file, path, fop);
312323 return file;
313324 }
314325
315−struct file *alloc_file_pseudo(struct inode *inode, struct vfsmount *mnt,
316− const char *name, int flags,
317− const struct file_operations *fops)
326+static inline int alloc_path_pseudo(const char *name, struct inode *inode,
327+ struct vfsmount *mnt, struct path *path)
318328 {
319329 struct qstr this = QSTR_INIT(name, strlen(name));
330+
331+ path->dentry = d_alloc_pseudo(mnt->mnt_sb, &this);
332+ if (!path->dentry)
333+ return -ENOMEM;
334+ path->mnt = mntget(mnt);
335+ d_instantiate(path->dentry, inode);
336+ return 0;
337+}
338+
339+struct file *alloc_file_pseudo(struct inode *inode, struct vfsmount *mnt,
340+ const char *name, int flags,
341+ const struct file_operations *fops)
342+{
343+ int ret;
320344 struct path path;
321345 struct file *file;
322346
323− path.dentry = d_alloc_pseudo(mnt->mnt_sb, &this);
324− if (!path.dentry)
325− return ERR_PTR(-ENOMEM);
326− path.mnt = mntget(mnt);
327− d_instantiate(path.dentry, inode);
347+ ret = alloc_path_pseudo(name, inode, mnt, &path);
348+ if (ret)
349+ return ERR_PTR(ret);
350+
328351 file = alloc_file(&path, flags, fops);
329352 if (IS_ERR(file)) {
330353 ihold(inode);
@@ -334,6 +357,30 @@ struct file *alloc_file_pseudo(struct inode *inode, struct vfsmount *mnt, · 3 unmodified lines
334357 }
335358 EXPORT_SYMBOL(alloc_file_pseudo);
336359
360+struct file *alloc_file_pseudo_noaccount(struct inode *inode,
361+ struct vfsmount *mnt, const char *name,
362+ int flags,
363+ const struct file_operations *fops)
364+{
365+ int ret;
366+ struct path path;
367+ struct file *file;
368+
369+ ret = alloc_path_pseudo(name, inode, mnt, &path);
370+ if (ret)
371+ return ERR_PTR(ret);
372+
373+ file = alloc_empty_file_noaccount(flags, current_cred());
374+ if (IS_ERR(file)) {
375+ ihold(inode);
376+ path_put(&path);
377+ return file;
378+ }
379+ file_init_path(file, &path, fops);
380+ return file;
381+}
382+EXPORT_SYMBOL_GPL(alloc_file_pseudo_noaccount);
383+
337384 struct file *alloc_file_clone(struct file *base, int flags,
338385 const struct file_operations *fops)
339386 {
fs/jfs/jfs_logmgr.c+13−13
@@ -1058,7 +1058,7 @@ void jfs_syncpt(struct jfs_log *log, int hard_sync) · 1057 unmodified lines
10581058 int lmLogOpen(struct super_block *sb)
10591059 {
10601060 int rc;
1061− struct bdev_handle *bdev_handle;
1061+ struct file *bdev_file;
10621062 struct jfs_log *log;
10631063 struct jfs_sb_info *sbi = JFS_SBI(sb);
10641064
@@ -1070,7 +1070,7 @@ int lmLogOpen(struct super_block *sb) · 5 unmodified lines
10701070
10711071 mutex_lock(&jfs_log_mutex);
10721072 list_for_each_entry(log, &jfs_external_logs, journal_list) {
1073− if (log->bdev_handle->bdev->bd_dev == sbi->logdev) {
1073+ if (file_bdev(log->bdev_file)->bd_dev == sbi->logdev) {
10741074 if (!uuid_equal(&log->uuid, &sbi->loguuid)) {
10751075 jfs_warn("wrong uuid on JFS journal");
10761076 mutex_unlock(&jfs_log_mutex);
@@ -1100,14 +1100,14 @@ int lmLogOpen(struct super_block *sb) · 23 unmodified lines
11001100 * file systems to log may have n-to-1 relationship;
11011101 */
11021102
1103− bdev_handle = bdev_open_by_dev(sbi->logdev,
1103+ bdev_file = bdev_file_open_by_dev(sbi->logdev,
11041104 BLK_OPEN_READ | BLK_OPEN_WRITE, log, NULL);
1105− if (IS_ERR(bdev_handle)) {
1106− rc = PTR_ERR(bdev_handle);
1105+ if (IS_ERR(bdev_file)) {
1106+ rc = PTR_ERR(bdev_file);
11071107 goto free;
11081108 }
11091109
1110− log->bdev_handle = bdev_handle;
1110+ log->bdev_file = bdev_file;
11111111 uuid_copy(&log->uuid, &sbi->loguuid);
11121112
11131113 /*
@@ -1141,7 +1141,7 @@ journal_found: · 27 unmodified lines
11411141 lbmLogShutdown(log);
11421142
11431143 close: /* close external log device */
1144− bdev_release(bdev_handle);
1144+ fput(bdev_file);
11451145
11461146 free: /* free log descriptor */
11471147 mutex_unlock(&jfs_log_mutex);
@@ -1162,7 +1162,7 @@ static int open_inline_log(struct super_block *sb) · 14 unmodified lines
11621162 init_waitqueue_head(&log->syncwait);
11631163
11641164 set_bit(log_INLINELOG, &log->flag);
1165− log->bdev_handle = sb->s_bdev_handle;
1165+ log->bdev_file = sb->s_bdev_file;
11661166 log->base = addressPXD(&JFS_SBI(sb)->logpxd);
11671167 log->size = lengthPXD(&JFS_SBI(sb)->logpxd) >>
11681168 (L2LOGPSIZE - sb->s_blocksize_bits);
@@ -1436,7 +1436,7 @@ int lmLogClose(struct super_block *sb) · 267 unmodified lines
14361436 {
14371437 struct jfs_sb_info *sbi = JFS_SBI(sb);
14381438 struct jfs_log *log = sbi->log;
1439− struct bdev_handle *bdev_handle;
1439+ struct file *bdev_file;
14401440 int rc = 0;
14411441
14421442 jfs_info("lmLogClose: log:0x%p", log);
@@ -1482,10 +1482,10 @@ int lmLogClose(struct super_block *sb) · 39 unmodified lines
14821482 * external log as separate logical volume
14831483 */
14841484 list_del(&log->journal_list);
1485− bdev_handle = log->bdev_handle;
1485+ bdev_file = log->bdev_file;
14861486 rc = lmLogShutdown(log);
14871487
1488− bdev_release(bdev_handle);
1488+ fput(bdev_file);
14891489
14901490 kfree(log);
14911491
@@ -1972,7 +1972,7 @@ static int lbmRead(struct jfs_log * log, int pn, struct lbuf ** bpp) · 480 unmodified lines
19721972
19731973 bp->l_flag |= lbmREAD;
19741974
1975− bio = bio_alloc(log->bdev_handle->bdev, 1, REQ_OP_READ, GFP_NOFS);
1975+ bio = bio_alloc(file_bdev(log->bdev_file), 1, REQ_OP_READ, GFP_NOFS);
19761976 bio->bi_iter.bi_sector = bp->l_blkno << (log->l2bsize - 9);
19771977 __bio_add_page(bio, bp->l_page, LOGPSIZE, bp->l_offset);
19781978 BUG_ON(bio->bi_iter.bi_size != LOGPSIZE);
@@ -2115,7 +2115,7 @@ static void lbmStartIO(struct lbuf * bp) · 136 unmodified lines
21152115 jfs_info("lbmStartIO");
21162116
21172117 if (!log->no_integrity)
2118− bdev = log->bdev_handle->bdev;
2118+ bdev = file_bdev(log->bdev_file);
21192119
21202120 bio = bio_alloc(bdev, 1, REQ_OP_WRITE | REQ_SYNC,
21212121 GFP_NOFS);
fs/jfs/jfs_logmgr.h+1−1
@@ -356,7 +356,7 @@ struct jfs_log { · 355 unmodified lines
356356 * before writing syncpt.
357357 */
358358 struct list_head journal_list; /* Global list */
359− struct bdev_handle *bdev_handle; /* 4: log lv pointer */
359+ struct file *bdev_file; /* 4: log lv pointer */
360360 int serial; /* 4: log mount serial number */
361361
362362 s64 base; /* @8: log extent address (inline log ) */
fs/jfs/jfs_mount.c+1−1
@@ -431,7 +431,7 @@ int updateSuper(struct super_block *sb, uint state) · 430 unmodified lines
431431 if (state == FM_MOUNT) {
432432 /* record log's dev_t and mount serial number */
433433 j_sb->s_logdev = cpu_to_le32(
434− new_encode_dev(sbi->log->bdev_handle->bdev->bd_dev));
434+ new_encode_dev(file_bdev(sbi->log->bdev_file)->bd_dev));
435435 j_sb->s_logserial = cpu_to_le32(sbi->log->serial);
436436 } else if (state == FM_CLEAN) {
437437 /*
fs/nfs/blocklayout/blocklayout.h+1−1
@@ -108,7 +108,7 @@ struct pnfs_block_dev { · 107 unmodified lines
108108 struct pnfs_block_dev *children;
109109 u64 chunk_size;
110110
111− struct bdev_handle *bdev_handle;
111+ struct file *bdev_file;
112112 u64 disk_offset;
113113
114114 u64 pr_key;
fs/nfs/blocklayout/dev.c+34−34
@@ -25,17 +25,17 @@ bl_free_device(struct pnfs_block_dev *dev) · 24 unmodified lines
2525 } else {
2626 if (dev->pr_registered) {
2727 const struct pr_ops *ops =
28− dev->bdev_handle->bdev->bd_disk->fops->pr_ops;
28+ file_bdev(dev->bdev_file)->bd_disk->fops->pr_ops;
2929 int error;
3030
31− error = ops->pr_register(dev->bdev_handle->bdev,
31+ error = ops->pr_register(file_bdev(dev->bdev_file),
3232 dev->pr_key, 0, false);
3333 if (error)
3434 pr_err("failed to unregister PR key.\n");
3535 }
3636
37− if (dev->bdev_handle)
38− bdev_release(dev->bdev_handle);
37+ if (dev->bdev_file)
38+ fput(dev->bdev_file);
3939 }
4040 }
4141
@@ -169,7 +169,7 @@ static bool bl_map_simple(struct pnfs_block_dev *dev, u64 offset, · 127 unmodified lines
169169 map->start = dev->start;
170170 map->len = dev->len;
171171 map->disk_offset = dev->disk_offset;
172− map->bdev = dev->bdev_handle->bdev;
172+ map->bdev = file_bdev(dev->bdev_file);
173173 return true;
174174 }
175175
@@ -236,26 +236,26 @@ bl_parse_simple(struct nfs_server *server, struct pnfs_block_dev *d, · 60 unmodified lines
236236 struct pnfs_block_volume *volumes, int idx, gfp_t gfp_mask)
237237 {
238238 struct pnfs_block_volume *v = &volumes[idx];
239− struct bdev_handle *bdev_handle;
239+ struct file *bdev_file;
240240 dev_t dev;
241241
242242 dev = bl_resolve_deviceid(server, v, gfp_mask);
243243 if (!dev)
244244 return -EIO;
245245
246− bdev_handle = bdev_open_by_dev(dev, BLK_OPEN_READ | BLK_OPEN_WRITE,
246+ bdev_file = bdev_file_open_by_dev(dev, BLK_OPEN_READ | BLK_OPEN_WRITE,
247247 NULL, NULL);
248− if (IS_ERR(bdev_handle)) {
248+ if (IS_ERR(bdev_file)) {
249249 printk(KERN_WARNING "pNFS: failed to open device %d:%d (%ld)\n",
250− MAJOR(dev), MINOR(dev), PTR_ERR(bdev_handle));
251− return PTR_ERR(bdev_handle);
250+ MAJOR(dev), MINOR(dev), PTR_ERR(bdev_file));
251+ return PTR_ERR(bdev_file);
252252 }
253− d->bdev_handle = bdev_handle;
254− d->len = bdev_nr_bytes(bdev_handle->bdev);
253+ d->bdev_file = bdev_file;
254+ d->len = bdev_nr_bytes(file_bdev(bdev_file));
255255 d->map = bl_map_simple;
256256
257257 printk(KERN_INFO "pNFS: using block device %s\n",
258− bdev_handle->bdev->bd_disk->disk_name);
258+ file_bdev(bdev_file)->bd_disk->disk_name);
259259 return 0;
260260 }
261261
@@ -300,10 +300,10 @@ bl_validate_designator(struct pnfs_block_volume *v) · 38 unmodified lines
300300 }
301301 }
302302
303−static struct bdev_handle *
303+static struct file *
304304 bl_open_path(struct pnfs_block_volume *v, const char *prefix)
305305 {
306− struct bdev_handle *bdev_handle;
306+ struct file *bdev_file;
307307 const char *devname;
308308
309309 devname = kasprintf(GFP_KERNEL, "/dev/disk/by-id/%s%*phN",
@@ -311,15 +311,15 @@ bl_open_path(struct pnfs_block_volume *v, const char *prefix) · 1 unmodified line
311311 if (!devname)
312312 return ERR_PTR(-ENOMEM);
313313
314− bdev_handle = bdev_open_by_path(devname, BLK_OPEN_READ | BLK_OPEN_WRITE,
314+ bdev_file = bdev_file_open_by_path(devname, BLK_OPEN_READ | BLK_OPEN_WRITE,
315315 NULL, NULL);
316− if (IS_ERR(bdev_handle)) {
316+ if (IS_ERR(bdev_file)) {
317317 pr_warn("pNFS: failed to open device %s (%ld)\n",
318− devname, PTR_ERR(bdev_handle));
318+ devname, PTR_ERR(bdev_file));
319319 }
320320
321321 kfree(devname);
322− return bdev_handle;
322+ return bdev_file;
323323 }
324324
325325 static int
@@ -327,7 +327,7 @@ bl_parse_scsi(struct nfs_server *server, struct pnfs_block_dev *d, · 1 unmodified line
327327 struct pnfs_block_volume *volumes, int idx, gfp_t gfp_mask)
328328 {
329329 struct pnfs_block_volume *v = &volumes[idx];
330− struct bdev_handle *bdev_handle;
330+ struct file *bdev_file;
331331 const struct pr_ops *ops;
332332 int error;
333333
@@ -340,14 +340,14 @@ bl_parse_scsi(struct nfs_server *server, struct pnfs_block_dev *d, · 6 unmodified lines
340340 * On other distributions like Debian, the default SCSI by-id path will
341341 * point to the dm-multipath device if one exists.
342342 */
343− bdev_handle = bl_open_path(v, "dm-uuid-mpath-0x");
344− if (IS_ERR(bdev_handle))
345− bdev_handle = bl_open_path(v, "wwn-0x");
346− if (IS_ERR(bdev_handle))
347− return PTR_ERR(bdev_handle);
348− d->bdev_handle = bdev_handle;
349−
350− d->len = bdev_nr_bytes(d->bdev_handle->bdev);
343+ bdev_file = bl_open_path(v, "dm-uuid-mpath-0x");
344+ if (IS_ERR(bdev_file))
345+ bdev_file = bl_open_path(v, "wwn-0x");
346+ if (IS_ERR(bdev_file))
347+ return PTR_ERR(bdev_file);
348+ d->bdev_file = bdev_file;
349+
350+ d->len = bdev_nr_bytes(file_bdev(d->bdev_file));
351351 d->map = bl_map_simple;
352352 d->pr_key = v->scsi.pr_key;
353353
@@ -355,20 +355,20 @@ bl_parse_scsi(struct nfs_server *server, struct pnfs_block_dev *d, · 1 unmodified line
355355 return -ENODEV;
356356
357357 pr_info("pNFS: using block device %s (reservation key 0x%llx)\n",
358− d->bdev_handle->bdev->bd_disk->disk_name, d->pr_key);
358+ file_bdev(d->bdev_file)->bd_disk->disk_name, d->pr_key);
359359
360− ops = d->bdev_handle->bdev->bd_disk->fops->pr_ops;
360+ ops = file_bdev(d->bdev_file)->bd_disk->fops->pr_ops;
361361 if (!ops) {
362362 pr_err("pNFS: block device %s does not support reservations.",
363− d->bdev_handle->bdev->bd_disk->disk_name);
363+ file_bdev(d->bdev_file)->bd_disk->disk_name);
364364 error = -EINVAL;
365365 goto out_blkdev_put;
366366 }
367367
368− error = ops->pr_register(d->bdev_handle->bdev, 0, d->pr_key, true);
368+ error = ops->pr_register(file_bdev(d->bdev_file), 0, d->pr_key, true);
369369 if (error) {
370370 pr_err("pNFS: failed to register key for block device %s.",
371− d->bdev_handle->bdev->bd_disk->disk_name);
371+ file_bdev(d->bdev_file)->bd_disk->disk_name);
372372 goto out_blkdev_put;
373373 }
374374
@@ -376,7 +376,7 @@ bl_parse_scsi(struct nfs_server *server, struct pnfs_block_dev *d, · 1 unmodified line
376376 return 0;
377377
378378 out_blkdev_put:
379− bdev_release(d->bdev_handle);
379+ fput(d->bdev_file);
380380 return error;
381381 }
382382
fs/ocfs2/cluster/heartbeat.c+16−16
@@ -213,7 +213,7 @@ struct o2hb_region { · 212 unmodified lines
213213 unsigned int hr_num_pages;
214214
215215 struct page **hr_slot_data;
216− struct bdev_handle *hr_bdev_handle;
216+ struct file *hr_bdev_file;
217217 struct o2hb_disk_slot *hr_slots;
218218
219219 /* live node map of this region */
@@ -263,7 +263,7 @@ struct o2hb_region { · 43 unmodified lines
263263
264264 static inline struct block_device *reg_bdev(struct o2hb_region *reg)
265265 {
266− return reg->hr_bdev_handle ? reg->hr_bdev_handle->bdev : NULL;
266+ return reg->hr_bdev_file ? file_bdev(reg->hr_bdev_file) : NULL;
267267 }
268268
269269 struct o2hb_bio_wait_ctxt {
@@ -1509,8 +1509,8 @@ static void o2hb_region_release(struct config_item *item) · 1239 unmodified lines
15091509 kfree(reg->hr_slot_data);
15101510 }
15111511
1512− if (reg->hr_bdev_handle)
1513− bdev_release(reg->hr_bdev_handle);
1512+ if (reg->hr_bdev_file)
1513+ fput(reg->hr_bdev_file);
15141514
15151515 kfree(reg->hr_slots);
15161516
@@ -1569,7 +1569,7 @@ static ssize_t o2hb_region_block_bytes_store(struct config_item *item, · 52 unmodified lines
15691569 unsigned long block_bytes;
15701570 unsigned int block_bits;
15711571
1572− if (reg->hr_bdev_handle)
1572+ if (reg->hr_bdev_file)
15731573 return -EINVAL;
15741574
15751575 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, · 22 unmodified lines
15981598 char *p = (char *)page;
15991599 ssize_t ret;
16001600
1601− if (reg->hr_bdev_handle)
1601+ if (reg->hr_bdev_file)
16021602 return -EINVAL;
16031603
16041604 ret = kstrtoull(p, 0, &tmp);
@@ -1623,7 +1623,7 @@ static ssize_t o2hb_region_blocks_store(struct config_item *item, · 18 unmodified lines
16231623 unsigned long tmp;
16241624 char *p = (char *)page;
16251625
1626− if (reg->hr_bdev_handle)
1626+ if (reg->hr_bdev_file)
16271627 return -EINVAL;
16281628
16291629 tmp = simple_strtoul(p, &p, 0);
@@ -1642,7 +1642,7 @@ static ssize_t o2hb_region_dev_show(struct config_item *item, char *page) · 12 unmodified lines
16421642 {
16431643 unsigned int ret = 0;
16441644
1645− if (to_o2hb_region(item)->hr_bdev_handle)
1645+ if (to_o2hb_region(item)->hr_bdev_file)
16461646 ret = sprintf(page, "%pg\n", reg_bdev(to_o2hb_region(item)));
16471647
16481648 return ret;
@@ -1753,7 +1753,7 @@ out: · 104 unmodified lines
17531753 }
17541754
17551755 /*
1756− * this is acting as commit; we set up all of hr_bdev_handle and hr_task or
1756+ * this is acting as commit; we set up all of hr_bdev_file and hr_task or
17571757 * nothing
17581758 */
17591759 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, · 9 unmodified lines
17691769 ssize_t ret = -EINVAL;
17701770 int live_threshold;
17711771
1772− if (reg->hr_bdev_handle)
1772+ if (reg->hr_bdev_file)
17731773 goto out;
17741774
17751775 /* 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, · 19 unmodified lines
17951795 if (!S_ISBLK(f.file->f_mapping->host->i_mode))
17961796 goto out2;
17971797
1798− reg->hr_bdev_handle = bdev_open_by_dev(f.file->f_mapping->host->i_rdev,
1798+ reg->hr_bdev_file = bdev_file_open_by_dev(f.file->f_mapping->host->i_rdev,
17991799 BLK_OPEN_WRITE | BLK_OPEN_READ, NULL, NULL);
1800− if (IS_ERR(reg->hr_bdev_handle)) {
1801− ret = PTR_ERR(reg->hr_bdev_handle);
1802− reg->hr_bdev_handle = NULL;
1800+ if (IS_ERR(reg->hr_bdev_file)) {
1801+ ret = PTR_ERR(reg->hr_bdev_file);
1802+ reg->hr_bdev_file = NULL;
18031803 goto out2;
18041804 }
18051805
@@ -1903,8 +1903,8 @@ static ssize_t o2hb_region_dev_store(struct config_item *item, · 97 unmodified lines
19031903
19041904 out3:
19051905 if (ret < 0) {
1906− bdev_release(reg->hr_bdev_handle);
1907− reg->hr_bdev_handle = NULL;
1906+ fput(reg->hr_bdev_file);
1907+ reg->hr_bdev_file = NULL;
19081908 }
19091909 out2:
19101910 fdput(f);
fs/reiserfs/journal.c+19−19
@@ -2386,7 +2386,7 @@ static int journal_read(struct super_block *sb) · 2385 unmodified lines
23862386
23872387 cur_dblock = SB_ONDISK_JOURNAL_1st_BLOCK(sb);
23882388 reiserfs_info(sb, "checking transaction log (%pg)\n",
2389− journal->j_bdev_handle->bdev);
2389+ file_bdev(journal->j_bdev_file));
23902390 start = ktime_get_seconds();
23912391
23922392 /*
@@ -2447,7 +2447,7 @@ static int journal_read(struct super_block *sb) · 54 unmodified lines
24472447 * device and journal device to be the same
24482448 */
24492449 d_bh =
2450− reiserfs_breada(journal->j_bdev_handle->bdev, cur_dblock,
2450+ reiserfs_breada(file_bdev(journal->j_bdev_file), cur_dblock,
24512451 sb->s_blocksize,
24522452 SB_ONDISK_JOURNAL_1st_BLOCK(sb) +
24532453 SB_ONDISK_JOURNAL_SIZE(sb));
@@ -2588,9 +2588,9 @@ static void journal_list_init(struct super_block *sb) · 134 unmodified lines
25882588
25892589 static void release_journal_dev(struct reiserfs_journal *journal)
25902590 {
2591− if (journal->j_bdev_handle) {
2592− bdev_release(journal->j_bdev_handle);
2593− journal->j_bdev_handle = NULL;
2591+ if (journal->j_bdev_file) {
2592+ fput(journal->j_bdev_file);
2593+ journal->j_bdev_file = NULL;
25942594 }
25952595 }
25962596
@@ -2605,7 +2605,7 @@ static int journal_init_dev(struct super_block *super, · 8 unmodified lines
26052605
26062606 result = 0;
26072607
2608− journal->j_bdev_handle = NULL;
2608+ journal->j_bdev_file = NULL;
26092609 jdev = SB_ONDISK_JOURNAL_DEVICE(super) ?
26102610 new_decode_dev(SB_ONDISK_JOURNAL_DEVICE(super)) : super->s_dev;
26112611
@@ -2616,37 +2616,37 @@ static int journal_init_dev(struct super_block *super, · 4 unmodified lines
26162616 if ((!jdev_name || !jdev_name[0])) {
26172617 if (jdev == super->s_dev)
26182618 holder = NULL;
2619− journal->j_bdev_handle = bdev_open_by_dev(jdev, blkdev_mode,
2619+ journal->j_bdev_file = bdev_file_open_by_dev(jdev, blkdev_mode,
26202620 holder, NULL);
2621− if (IS_ERR(journal->j_bdev_handle)) {
2622− result = PTR_ERR(journal->j_bdev_handle);
2623− journal->j_bdev_handle = NULL;
2621+ if (IS_ERR(journal->j_bdev_file)) {
2622+ result = PTR_ERR(journal->j_bdev_file);
2623+ journal->j_bdev_file = NULL;
26242624 reiserfs_warning(super, "sh-458",
26252625 "cannot init journal device unknown-block(%u,%u): %i",
26262626 MAJOR(jdev), MINOR(jdev), result);
26272627 return result;
26282628 } else if (jdev != super->s_dev)
2629− set_blocksize(journal->j_bdev_handle->bdev,
2629+ set_blocksize(file_bdev(journal->j_bdev_file),
26302630 super->s_blocksize);
26312631
26322632 return 0;
26332633 }
26342634
2635− journal->j_bdev_handle = bdev_open_by_path(jdev_name, blkdev_mode,
2635+ journal->j_bdev_file = bdev_file_open_by_path(jdev_name, blkdev_mode,
26362636 holder, NULL);
2637− if (IS_ERR(journal->j_bdev_handle)) {
2638− result = PTR_ERR(journal->j_bdev_handle);
2639− journal->j_bdev_handle = NULL;
2637+ if (IS_ERR(journal->j_bdev_file)) {
2638+ result = PTR_ERR(journal->j_bdev_file);
2639+ journal->j_bdev_file = NULL;
26402640 reiserfs_warning(super, "sh-457",
26412641 "journal_init_dev: Cannot open '%s': %i",
26422642 jdev_name, result);
26432643 return result;
26442644 }
26452645
2646− set_blocksize(journal->j_bdev_handle->bdev, super->s_blocksize);
2646+ set_blocksize(file_bdev(journal->j_bdev_file), super->s_blocksize);
26472647 reiserfs_info(super,
26482648 "journal_init_dev: journal device: %pg\n",
2649− journal->j_bdev_handle->bdev);
2649+ file_bdev(journal->j_bdev_file));
26502650 return 0;
26512651 }
26522652
@@ -2804,7 +2804,7 @@ int journal_init(struct super_block *sb, const char *j_dev_name, · 151 unmodified lines
28042804 "journal header magic %x (device %pg) does "
28052805 "not match to magic found in super block %x",
28062806 jh->jh_journal.jp_journal_magic,
2807− journal->j_bdev_handle->bdev,
2807+ file_bdev(journal->j_bdev_file),
28082808 sb_jp_journal_magic(rs));
28092809 brelse(bhjh);
28102810 goto free_and_return;
@@ -2828,7 +2828,7 @@ int journal_init(struct super_block *sb, const char *j_dev_name, · 17 unmodified lines
28282828 reiserfs_info(sb, "journal params: device %pg, size %u, "
28292829 "journal first block %u, max trans len %u, max batch %u, "
28302830 "max commit age %u, max trans age %u\n",
2831− journal->j_bdev_handle->bdev,
2831+ file_bdev(journal->j_bdev_file),
28322832 SB_ONDISK_JOURNAL_SIZE(sb),
28332833 SB_ONDISK_JOURNAL_1st_BLOCK(sb),
28342834 journal->j_trans_max,
fs/reiserfs/procfs.c+1−1
@@ -354,7 +354,7 @@ static int show_journal(struct seq_file *m, void *unused) · 353 unmodified lines
354354 "prepare: \t%12lu\n"
355355 "prepare_retry: \t%12lu\n",
356356 DJP(jp_journal_1st_block),
357− SB_JOURNAL(sb)->j_bdev_handle->bdev,
357+ file_bdev(SB_JOURNAL(sb)->j_bdev_file),
358358 DJP(jp_journal_dev),
359359 DJP(jp_journal_size),
360360 DJP(jp_journal_trans_max),
fs/reiserfs/reiserfs.h+4−4
@@ -299,7 +299,7 @@ struct reiserfs_journal { · 298 unmodified lines
299299 /* oldest journal block. start here for traverse */
300300 struct reiserfs_journal_cnode *j_first;
301301
302− struct bdev_handle *j_bdev_handle;
302+ struct file *j_bdev_file;
303303
304304 /* first block on s_dev of reserved area journal */
305305 int j_1st_reserved_block;
@@ -2810,10 +2810,10 @@ struct reiserfs_journal_header { · 2504 unmodified lines
28102810
28112811 /* We need these to make journal.c code more readable */
28122812 #define journal_find_get_block(s, block) __find_get_block(\
2813− SB_JOURNAL(s)->j_bdev_handle->bdev, block, s->s_blocksize)
2814−#define journal_getblk(s, block) __getblk(SB_JOURNAL(s)->j_bdev_handle->bdev,\
2813+ file_bdev(SB_JOURNAL(s)->j_bdev_file), block, s->s_blocksize)
2814+#define journal_getblk(s, block) __getblk(file_bdev(SB_JOURNAL(s)->j_bdev_file),\
28152815 block, s->s_blocksize)
2816−#define journal_bread(s, block) __bread(SB_JOURNAL(s)->j_bdev_handle->bdev,\
2816+#define journal_bread(s, block) __bread(file_bdev(SB_JOURNAL(s)->j_bdev_file),\
28172817 block, s->s_blocksize)
28182818
28192819 enum reiserfs_bh_state_bits {
fs/romfs/super.c+1−1
@@ -594,7 +594,7 @@ static void romfs_kill_sb(struct super_block *sb) · 593 unmodified lines
594594 #ifdef CONFIG_ROMFS_ON_BLOCK
595595 if (sb->s_bdev) {
596596 sync_blockdev(sb->s_bdev);
597− bdev_release(sb->s_bdev_handle);
597+ fput(sb->s_bdev_file);
598598 }
599599 #endif
600600 }
fs/super.c+9−9
@@ -1527,16 +1527,16 @@ int setup_bdev_super(struct super_block *sb, int sb_flags, · 1526 unmodified lines
15271527 struct fs_context *fc)
15281528 {
15291529 blk_mode_t mode = sb_open_mode(sb_flags);
1530− struct bdev_handle *bdev_handle;
1530+ struct file *bdev_file;
15311531 struct block_device *bdev;
15321532
1533− bdev_handle = bdev_open_by_dev(sb->s_dev, mode, sb, &fs_holder_ops);
1534− if (IS_ERR(bdev_handle)) {
1533+ bdev_file = bdev_file_open_by_dev(sb->s_dev, mode, sb, &fs_holder_ops);
1534+ if (IS_ERR(bdev_file)) {
15351535 if (fc)
15361536 errorf(fc, "%s: Can't open blockdev", fc->source);
1537− return PTR_ERR(bdev_handle);
1537+ return PTR_ERR(bdev_file);
15381538 }
1539− bdev = bdev_handle->bdev;
1539+ bdev = file_bdev(bdev_file);
15401540
15411541 /*
15421542 * This really should be in blkdev_get_by_dev, but right now can't due
@@ -1544,7 +1544,7 @@ int setup_bdev_super(struct super_block *sb, int sb_flags, · 1 unmodified line
15441544 * writable from userspace even for a read-only block device.
15451545 */
15461546 if ((mode & BLK_OPEN_WRITE) && bdev_read_only(bdev)) {
1547− bdev_release(bdev_handle);
1547+ fput(bdev_file);
15481548 return -EACCES;
15491549 }
15501550
@@ -1555,11 +1555,11 @@ int setup_bdev_super(struct super_block *sb, int sb_flags, · 4 unmodified lines
15551555 if (atomic_read(&bdev->bd_fsfreeze_count) > 0) {
15561556 if (fc)
15571557 warnf(fc, "%pg: Can't mount, blockdev is frozen", bdev);
1558− bdev_release(bdev_handle);
1558+ fput(bdev_file);
15591559 return -EBUSY;
15601560 }
15611561 spin_lock(&sb_lock);
1562− sb->s_bdev_handle = bdev_handle;
1562+ sb->s_bdev_file = bdev_file;
15631563 sb->s_bdev = bdev;
15641564 sb->s_bdi = bdi_get(bdev->bd_disk->bdi);
15651565 if (bdev_stable_writes(bdev))
@@ -1675,7 +1675,7 @@ void kill_block_super(struct super_block *sb) · 109 unmodified lines
16751675 generic_shutdown_super(sb);
16761676 if (bdev) {
16771677 sync_blockdev(bdev);
1678− bdev_release(sb->s_bdev_handle);
1678+ fput(sb->s_bdev_file);
16791679 }
16801680 }
16811681
fs/xfs/xfs_buf.c+5−5
@@ -1951,7 +1951,7 @@ xfs_free_buftarg( · 1950 unmodified lines
19511951 fs_put_dax(btp->bt_daxdev, btp->bt_mount);
19521952 /* the main block device is closed by kill_block_super */
19531953 if (btp->bt_bdev != btp->bt_mount->m_super->s_bdev)
1954− bdev_release(btp->bt_bdev_handle);
1954+ fput(btp->bt_bdev_file);
19551955
19561956 kmem_free(btp);
19571957 }
@@ -1994,7 +1994,7 @@ xfs_setsize_buftarg_early( · 36 unmodified lines
19941994 struct xfs_buftarg *
19951995 xfs_alloc_buftarg(
19961996 struct xfs_mount *mp,
1997− struct bdev_handle *bdev_handle)
1997+ struct file *bdev_file)
19981998 {
19991999 xfs_buftarg_t *btp;
20002000 const struct dax_holder_operations *ops = NULL;
@@ -2005,9 +2005,9 @@ xfs_alloc_buftarg( · 4 unmodified lines
20052005 btp = kmem_zalloc(sizeof(*btp), KM_NOFS);
20062006
20072007 btp->bt_mount = mp;
2008− btp->bt_bdev_handle = bdev_handle;
2009− btp->bt_dev = bdev_handle->bdev->bd_dev;
2010− btp->bt_bdev = bdev_handle->bdev;
2008+ btp->bt_bdev_file = bdev_file;
2009+ btp->bt_bdev = file_bdev(bdev_file);
2010+ btp->bt_dev = btp->bt_bdev->bd_dev;
20112011 btp->bt_daxdev = fs_dax_get_by_bdev(btp->bt_bdev, &btp->bt_dax_part_off,
20122012 mp, ops);
20132013
fs/xfs/xfs_buf.h+2−2
@@ -98,7 +98,7 @@ typedef unsigned int xfs_buf_flags_t; · 97 unmodified lines
9898 */
9999 typedef struct xfs_buftarg {
100100 dev_t bt_dev;
101− struct bdev_handle *bt_bdev_handle;
101+ struct file *bt_bdev_file;
102102 struct block_device *bt_bdev;
103103 struct dax_device *bt_daxdev;
104104 u64 bt_dax_part_off;
@@ -366,7 +366,7 @@ xfs_buf_update_cksum(struct xfs_buf *bp, unsigned long cksum_offset) · 261 unmodified lines
366366 * Handling of buftargs.
367367 */
368368 struct xfs_buftarg *xfs_alloc_buftarg(struct xfs_mount *mp,
369− struct bdev_handle *bdev_handle);
369+ struct file *bdev_file);
370370 extern void xfs_free_buftarg(struct xfs_buftarg *);
371371 extern void xfs_buftarg_wait(struct xfs_buftarg *);
372372 extern void xfs_buftarg_drain(struct xfs_buftarg *);
fs/xfs/xfs_super.c+22−22
@@ -361,16 +361,16 @@ STATIC int · 360 unmodified lines
361361 xfs_blkdev_get(
362362 xfs_mount_t *mp,
363363 const char *name,
364− struct bdev_handle **handlep)
364+ struct file **bdev_filep)
365365 {
366366 int error = 0;
367367
368− *handlep = bdev_open_by_path(name,
368+ *bdev_filep = bdev_file_open_by_path(name,
369369 BLK_OPEN_READ | BLK_OPEN_WRITE | BLK_OPEN_RESTRICT_WRITES,
370370 mp->m_super, &fs_holder_ops);
371− if (IS_ERR(*handlep)) {
372− error = PTR_ERR(*handlep);
373− *handlep = NULL;
371+ if (IS_ERR(*bdev_filep)) {
372+ error = PTR_ERR(*bdev_filep);
373+ *bdev_filep = NULL;
374374 xfs_warn(mp, "Invalid device [%s], error=%d", name, error);
375375 }
376376
@@ -435,26 +435,26 @@ xfs_open_devices( · 58 unmodified lines
435435 {
436436 struct super_block *sb = mp->m_super;
437437 struct block_device *ddev = sb->s_bdev;
438− struct bdev_handle *logdev_handle = NULL, *rtdev_handle = NULL;
438+ struct file *logdev_file = NULL, *rtdev_file = NULL;
439439 int error;
440440
441441 /*
442442 * Open real time and log devices - order is important.
443443 */
444444 if (mp->m_logname) {
445− error = xfs_blkdev_get(mp, mp->m_logname, &logdev_handle);
445+ error = xfs_blkdev_get(mp, mp->m_logname, &logdev_file);
446446 if (error)
447447 return error;
448448 }
449449
450450 if (mp->m_rtname) {
451− error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev_handle);
451+ error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev_file);
452452 if (error)
453453 goto out_close_logdev;
454454
455− if (rtdev_handle->bdev == ddev ||
456− (logdev_handle &&
457− rtdev_handle->bdev == logdev_handle->bdev)) {
455+ if (file_bdev(rtdev_file) == ddev ||
456+ (logdev_file &&
457+ file_bdev(rtdev_file) == file_bdev(logdev_file))) {
458458 xfs_warn(mp,
459459 "Cannot mount filesystem with identical rtdev and ddev/logdev.");
460460 error = -EINVAL;
@@ -466,25 +466,25 @@ xfs_open_devices( · 5 unmodified lines
466466 * Setup xfs_mount buffer target pointers
467467 */
468468 error = -ENOMEM;
469− mp->m_ddev_targp = xfs_alloc_buftarg(mp, sb->s_bdev_handle);
469+ mp->m_ddev_targp = xfs_alloc_buftarg(mp, sb->s_bdev_file);
470470 if (!mp->m_ddev_targp)
471471 goto out_close_rtdev;
472472
473− if (rtdev_handle) {
474− mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev_handle);
473+ if (rtdev_file) {
474+ mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev_file);
475475 if (!mp->m_rtdev_targp)
476476 goto out_free_ddev_targ;
477477 }
478478
479− if (logdev_handle && logdev_handle->bdev != ddev) {
480− mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev_handle);
479+ if (logdev_file && file_bdev(logdev_file) != ddev) {
480+ mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev_file);
481481 if (!mp->m_logdev_targp)
482482 goto out_free_rtdev_targ;
483483 } else {
484484 mp->m_logdev_targp = mp->m_ddev_targp;
485485 /* Handle won't be used, drop it */
486− if (logdev_handle)
487− bdev_release(logdev_handle);
486+ if (logdev_file)
487+ fput(logdev_file);
488488 }
489489
490490 return 0;
@@ -495,11 +495,11 @@ xfs_open_devices( · 4 unmodified lines
495495 out_free_ddev_targ:
496496 xfs_free_buftarg(mp->m_ddev_targp);
497497 out_close_rtdev:
498− if (rtdev_handle)
499− bdev_release(rtdev_handle);
498+ if (rtdev_file)
499+ fput(rtdev_file);
500500 out_close_logdev:
501− if (logdev_handle)
502− bdev_release(logdev_handle);
501+ if (logdev_file)
502+ fput(logdev_file);
503503 return error;
504504 }
505505
include/linux/blkdev.h+4−9
@@ -24,6 +24,7 @@ · 23 unmodified lines
2424 #include <linux/sbitmap.h>
2525 #include <linux/uuid.h>
2626 #include <linux/xarray.h>
27+#include <linux/file.h>
2728
2829 struct module;
2930 struct request_queue;
@@ -1474,26 +1475,20 @@ extern const struct blk_holder_ops fs_holder_ops; · 1444 unmodified lines
14741475 (BLK_OPEN_READ | BLK_OPEN_RESTRICT_WRITES | \
14751476 (((flags) & SB_RDONLY) ? 0 : BLK_OPEN_WRITE))
14761477
1477−struct bdev_handle {
1478− struct block_device *bdev;
1479− void *holder;
1480− blk_mode_t mode;
1481−};
1482−
1483−struct bdev_handle *bdev_open_by_dev(dev_t dev, blk_mode_t mode, void *holder,
1478+struct file *bdev_file_open_by_dev(dev_t dev, blk_mode_t mode, void *holder,
14841479 const struct blk_holder_ops *hops);
1485−struct bdev_handle *bdev_open_by_path(const char *path, blk_mode_t mode,
1480+struct file *bdev_file_open_by_path(const char *path, blk_mode_t mode,
14861481 void *holder, const struct blk_holder_ops *hops);
14871482 int bd_prepare_to_claim(struct block_device *bdev, void *holder,
14881483 const struct blk_holder_ops *hops);
14891484 void bd_abort_claiming(struct block_device *bdev, void *holder);
1490−void bdev_release(struct bdev_handle *handle);
14911485
14921486 /* just for blk-cgroup, don't use elsewhere */
14931487 struct block_device *blkdev_get_no_open(dev_t dev);
14941488 void blkdev_put_no_open(struct block_device *bdev);
14951489
14961490 struct block_device *I_BDEV(struct inode *inode);
1491+struct block_device *file_bdev(struct file *bdev_file);
14971492
14981493 #ifdef CONFIG_BLOCK
14991494 void invalidate_bdev(struct block_device *bdev);
include/linux/device-mapper.h+1−1
@@ -165,7 +165,7 @@ void dm_error(const char *message); · 164 unmodified lines
165165
166166 struct dm_dev {
167167 struct block_device *bdev;
168− struct bdev_handle *bdev_handle;
168+ struct file *bdev_file;
169169 struct dax_device *dax_dev;
170170 blk_mode_t mode;
171171 char name[16];
include/linux/file.h+2−0
@@ -24,6 +24,8 @@ struct inode; · 23 unmodified lines
2424 struct path;
2525 extern struct file *alloc_file_pseudo(struct inode *, struct vfsmount *,
2626 const char *, int flags, const struct file_operations *);
27+extern struct file *alloc_file_pseudo_noaccount(struct inode *, struct vfsmount *,
28+ const char *, int flags, const struct file_operations *);
2729 extern struct file *alloc_file_clone(struct file *, int flags,
2830 const struct file_operations *);
2931
include/linux/fs.h+2−2
@@ -1237,8 +1237,8 @@ struct super_block { · 1236 unmodified lines
12371237 #endif
12381238 struct hlist_bl_head s_roots; /* alternate root dentries for NFS */
12391239 struct list_head s_mounts; /* list of mounts; _not_ for fs use */
1240− struct block_device *s_bdev;
1241− struct bdev_handle *s_bdev_handle;
1240+ struct block_device *s_bdev; /* can go away once we use an accessor for @s_bdev_file */
1241+ struct file *s_bdev_file;
12421242 struct backing_dev_info *s_bdi;
12431243 struct mtd_info *s_mtd;
12441244 struct hlist_node s_instances;
include/linux/pktcdvd.h+2−2
@@ -154,9 +154,9 @@ struct packet_stacked_data · 153 unmodified lines
154154
155155 struct pktcdvd_device
156156 {
157− struct bdev_handle *bdev_handle; /* dev attached */
157+ struct file *bdev_file; /* dev attached */
158158 /* handle acquired for bdev during pkt_open_dev() */
159− struct bdev_handle *open_bdev_handle;
159+ struct file *f_open_bdev;
160160 dev_t pkt_dev; /* our dev */
161161 struct packet_settings settings;
162162 struct packet_stats stats;
include/linux/swap.h+1−1
@@ -298,7 +298,7 @@ struct swap_info_struct { · 297 unmodified lines
298298 unsigned int __percpu *cluster_next_cpu; /*percpu index for next allocation */
299299 struct percpu_cluster __percpu *percpu_cluster; /* per cpu's swap location */
300300 struct rb_root swap_extent_root;/* root of the swap extent rbtree */
301− struct bdev_handle *bdev_handle;/* open handle of the bdev */
301+ struct file *bdev_file; /* open handle of the bdev */
302302 struct block_device *bdev; /* swap device or bdev of swap file */
303303 struct file *swap_file; /* seldom referenced */
304304 unsigned int old_block_size; /* seldom referenced */
init/do_mounts.c+3−0
@@ -208,6 +208,9 @@ retry: · 207 unmodified lines
208208 goto out;
209209 case -EACCES:
210210 case -EINVAL:
211+#ifdef CONFIG_BLOCK
212+ init_flush_fput();
213+#endif
211214 continue;
212215 }
213216 /*
init/do_mounts.h+9−0
@@ -9,6 +9,8 @@ · 8 unmodified lines
99 #include <linux/major.h>
1010 #include <linux/root_dev.h>
1111 #include <linux/init_syscalls.h>
12+#include <linux/task_work.h>
13+#include <linux/file.h>
1214
1315 void mount_root_generic(char *name, char *pretty_name, int flags);
1416 void mount_root(char *root_device_name);
@@ -41,3 +43,10 @@ static inline bool initrd_load(char *root_device_name) · 26 unmodified lines
4143 }
4244
4345 #endif
46+
47+/* Ensure that async file closing finished to prevent spurious errors. */
48+static inline void init_flush_fput(void)
49+{
50+ flush_delayed_fput();
51+ task_work_run();
52+}
init/initramfs.c+3−3
@@ -16,9 +16,10 @@ · 15 unmodified lines
1616 #include <linux/mm.h>
1717 #include <linux/namei.h>
1818 #include <linux/init_syscalls.h>
19−#include <linux/task_work.h>
2019 #include <linux/umh.h>
2120
21+#include "do_mounts.h"
22+
2223 static __initdata bool csum_present;
2324 static __initdata u32 io_csum;
2425
@@ -734,8 +735,7 @@ done: · 709 unmodified lines
734735 initrd_start = 0;
735736 initrd_end = 0;
736737
737− flush_delayed_fput();
738− task_work_run();
738+ init_flush_fput();
739739 }
740740
741741 static ASYNC_DOMAIN_EXCLUSIVE(initramfs_domain);
kernel/power/swap.c+14−14
@@ -222,7 +222,7 @@ int swsusp_swap_in_use(void) · 221 unmodified lines
222222 */
223223
224224 static unsigned short root_swap = 0xffff;
225−static struct bdev_handle *hib_resume_bdev_handle;
225+static struct file *hib_resume_bdev_file;
226226
227227 struct hib_bio_batch {
228228 atomic_t count;
@@ -276,7 +276,7 @@ static int hib_submit_io(blk_opf_t opf, pgoff_t page_off, void *addr, · 47 unmodified lines
276276 struct bio *bio;
277277 int error = 0;
278278
279− bio = bio_alloc(hib_resume_bdev_handle->bdev, 1, opf,
279+ bio = bio_alloc(file_bdev(hib_resume_bdev_file), 1, opf,
280280 GFP_NOIO | __GFP_HIGH);
281281 bio->bi_iter.bi_sector = page_off * (PAGE_SIZE >> 9);
282282
@@ -357,14 +357,14 @@ static int swsusp_swap_check(void) · 74 unmodified lines
357357 return res;
358358 root_swap = res;
359359
360− hib_resume_bdev_handle = bdev_open_by_dev(swsusp_resume_device,
360+ hib_resume_bdev_file = bdev_file_open_by_dev(swsusp_resume_device,
361361 BLK_OPEN_WRITE, NULL, NULL);
362− if (IS_ERR(hib_resume_bdev_handle))
363− return PTR_ERR(hib_resume_bdev_handle);
362+ if (IS_ERR(hib_resume_bdev_file))
363+ return PTR_ERR(hib_resume_bdev_file);
364364
365− res = set_blocksize(hib_resume_bdev_handle->bdev, PAGE_SIZE);
365+ res = set_blocksize(file_bdev(hib_resume_bdev_file), PAGE_SIZE);
366366 if (res < 0)
367− bdev_release(hib_resume_bdev_handle);
367+ fput(hib_resume_bdev_file);
368368
369369 return res;
370370 }
@@ -1523,10 +1523,10 @@ int swsusp_check(bool exclusive) · 1152 unmodified lines
15231523 void *holder = exclusive ? &swsusp_holder : NULL;
15241524 int error;
15251525
1526− hib_resume_bdev_handle = bdev_open_by_dev(swsusp_resume_device,
1526+ hib_resume_bdev_file = bdev_file_open_by_dev(swsusp_resume_device,
15271527 BLK_OPEN_READ, holder, NULL);
1528− if (!IS_ERR(hib_resume_bdev_handle)) {
1529− set_blocksize(hib_resume_bdev_handle->bdev, PAGE_SIZE);
1528+ if (!IS_ERR(hib_resume_bdev_file)) {
1529+ set_blocksize(file_bdev(hib_resume_bdev_file), PAGE_SIZE);
15301530 clear_page(swsusp_header);
15311531 error = hib_submit_io(REQ_OP_READ, swsusp_resume_block,
15321532 swsusp_header, NULL);
@@ -1551,11 +1551,11 @@ int swsusp_check(bool exclusive) · 18 unmodified lines
15511551
15521552 put:
15531553 if (error)
1554− bdev_release(hib_resume_bdev_handle);
1554+ fput(hib_resume_bdev_file);
15551555 else
15561556 pr_debug("Image signature found, resuming\n");
15571557 } else {
1558− error = PTR_ERR(hib_resume_bdev_handle);
1558+ error = PTR_ERR(hib_resume_bdev_file);
15591559 }
15601560
15611561 if (error)
@@ -1570,12 +1570,12 @@ put: · 8 unmodified lines
15701570
15711571 void swsusp_close(void)
15721572 {
1573− if (IS_ERR(hib_resume_bdev_handle)) {
1573+ if (IS_ERR(hib_resume_bdev_file)) {
15741574 pr_debug("Image device not initialised\n");
15751575 return;
15761576 }
15771577
1578− bdev_release(hib_resume_bdev_handle);
1578+ fput(hib_resume_bdev_file);
15791579 }
15801580
15811581 /**
mm/swapfile.c+11−11
@@ -2532,10 +2532,10 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile) · 2531 unmodified lines
25322532 exit_swap_address_space(p->type);
25332533
25342534 inode = mapping->host;
2535− if (p->bdev_handle) {
2535+ if (p->bdev_file) {
25362536 set_blocksize(p->bdev, old_block_size);
2537− bdev_release(p->bdev_handle);
2538− p->bdev_handle = NULL;
2537+ fput(p->bdev_file);
2538+ p->bdev_file = NULL;
25392539 }
25402540
25412541 inode_lock(inode);
@@ -2765,14 +2765,14 @@ static int claim_swapfile(struct swap_info_struct *p, struct inode *inode) · 223 unmodified lines
27652765 int error;
27662766
27672767 if (S_ISBLK(inode->i_mode)) {
2768− p->bdev_handle = bdev_open_by_dev(inode->i_rdev,
2768+ p->bdev_file = bdev_file_open_by_dev(inode->i_rdev,
27692769 BLK_OPEN_READ | BLK_OPEN_WRITE, p, NULL);
2770− if (IS_ERR(p->bdev_handle)) {
2771− error = PTR_ERR(p->bdev_handle);
2772− p->bdev_handle = NULL;
2770+ if (IS_ERR(p->bdev_file)) {
2771+ error = PTR_ERR(p->bdev_file);
2772+ p->bdev_file = NULL;
27732773 return error;
27742774 }
2775− p->bdev = p->bdev_handle->bdev;
2775+ p->bdev = file_bdev(p->bdev_file);
27762776 p->old_block_size = block_size(p->bdev);
27772777 error = set_blocksize(p->bdev, PAGE_SIZE);
27782778 if (error < 0)
@@ -3208,10 +3208,10 @@ bad_swap: · 429 unmodified lines
32083208 p->percpu_cluster = NULL;
32093209 free_percpu(p->cluster_next_cpu);
32103210 p->cluster_next_cpu = NULL;
3211− if (p->bdev_handle) {
3211+ if (p->bdev_file) {
32123212 set_blocksize(p->bdev, p->old_block_size);
3213− bdev_release(p->bdev_handle);
3214− p->bdev_handle = NULL;
3213+ fput(p->bdev_file);
3214+ p->bdev_file = NULL;
32153215 }
32163216 inode = NULL;
32173217 destroy_swap_extents(p);