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
49}49}
50EXPORT_SYMBOL(I_BDEV);50EXPORT_SYMBOL(I_BDEV);
51 51
52struct block_device *file_bdev(struct file *bdev_file)
53{
54 return I_BDEV(bdev_file->f_mapping->host);
55}
56EXPORT_SYMBOL(file_bdev);
57
52static void bdev_write_inode(struct block_device *bdev)58static void bdev_write_inode(struct block_device *bdev)
53{59{
54 struct inode *inode = bdev->bd_inode;60 struct inode *inode = bdev->bd_inode;
@@ -368,12 +374,12 @@ static struct file_system_type bd_type = { · 313 unmodified lines
368};374};
369 375
370struct super_block *blockdev_superblock __ro_after_init;376struct super_block *blockdev_superblock __ro_after_init;
377struct vfsmount *blockdev_mnt __ro_after_init;
371EXPORT_SYMBOL_GPL(blockdev_superblock);378EXPORT_SYMBOL_GPL(blockdev_superblock);
372 379
373void __init bdev_cache_init(void)380void __init bdev_cache_init(void)
374{381{
375 int err;382 int err;
376 static struct vfsmount *bd_mnt __ro_after_init;
377 383
378 bdev_cachep = kmem_cache_create("bdev_cache", sizeof(struct bdev_inode),384 bdev_cachep = kmem_cache_create("bdev_cache", sizeof(struct bdev_inode),
379 0, (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|385 0, (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
@@ -382,10 +388,10 @@ void __init bdev_cache_init(void) · 2 unmodified lines
382 err = register_filesystem(&bd_type);388 err = register_filesystem(&bd_type);
383 if (err)389 if (err)
384 panic("Cannot register bdev pseudo-fs");390 panic("Cannot register bdev pseudo-fs");
385 bd_mnt = kern_mount(&bd_type);391 blockdev_mnt = kern_mount(&bd_type);
386 if (IS_ERR(bd_mnt))392 if (IS_ERR(blockdev_mnt))
387 panic("Cannot create bdev pseudo-fs");393 panic("Cannot create bdev pseudo-fs");
388 blockdev_superblock = bd_mnt->mnt_sb; /* For writeback */394 blockdev_superblock = blockdev_mnt->mnt_sb; /* For writeback */
389}395}
390 396
391struct block_device *bdev_alloc(struct gendisk *disk, u8 partno)397struct block_device *bdev_alloc(struct gendisk *disk, u8 partno)
@@ -696,6 +702,31 @@ out_blkdev_put: · 304 unmodified lines
696 return ret;702 return ret;
697}703}
698 704
705int 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
699static void blkdev_put_part(struct block_device *part)730static void blkdev_put_part(struct block_device *part)
700{731{
701 struct block_device *whole = bdev_whole(part);732 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
775 bdev->bd_writers++;806 bdev->bd_writers++;
776}807}
777 808
778static void bdev_yield_write_access(struct block_device *bdev, blk_mode_t mode)809static void bdev_yield_write_access(struct file *bdev_file)
779{810{
811 struct block_device *bdev;
812
780 if (bdev_allow_write_mounted)813 if (bdev_allow_write_mounted)
781 return;814 return;
782 815
816 bdev = file_bdev(bdev_file);
783 /* Yield exclusive or shared write access. */817 /* Yield exclusive or shared write access. */
784 if (mode & BLK_OPEN_RESTRICT_WRITES)818 if (bdev_file->f_mode & FMODE_WRITE) {
785 bdev_unblock_writes(bdev);819 if (bdev_writes_blocked(bdev))
786 else if (mode & BLK_OPEN_WRITE)820 bdev_unblock_writes(bdev);
787 bdev->bd_writers--;821 else
822 bdev->bd_writers--;
823 }
788}824}
789 825
790/**826/**
791 * bdev_open_by_dev - open a block device by device number827 * bdev_open - open a block device
792 * @dev: device number of block device to open828 * @bdev: block device to open
793 * @mode: open mode (BLK_OPEN_*)829 * @mode: open mode (BLK_OPEN_*)
794 * @holder: exclusive holder identifier830 * @holder: exclusive holder identifier
795 * @hops: holder operations831 * @hops: holder operations
832 * @bdev_file: file for the block device
796 *833 *
797 * Open the block device described by device number @dev. If @holder is not834 * Open the block device. If @holder is not %NULL, the block device is opened
798 * %NULL, the block device is opened with exclusive access. Exclusive opens may835 * with exclusive access. Exclusive opens may nest for the same @holder.
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().
804 *836 *
805 * CONTEXT:837 * CONTEXT:
806 * Might sleep.838 * Might sleep.
807 *839 *
808 * RETURNS:840 * RETURNS:
809 * Handle with a reference to the block_device on success, ERR_PTR(-errno) on841 * zero on success, -errno on failure.
810 * failure.
811 */842 */
812struct bdev_handle *bdev_open_by_dev(dev_t dev, blk_mode_t mode, void *holder,843int bdev_open(struct block_device *bdev, blk_mode_t mode, void *holder,
813 const struct blk_holder_ops *hops)844 const struct blk_holder_ops *hops, struct file *bdev_file)
814{845{
815 struct bdev_handle *handle = kmalloc(sizeof(struct bdev_handle),
816 GFP_KERNEL);
817 struct block_device *bdev;
818 bool unblock_events = true;846 bool unblock_events = true;
819 struct gendisk *disk;847 struct gendisk *disk = bdev->bd_disk;
820 int ret;848 int ret;
821 849
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
845 if (holder) {850 if (holder) {
846 mode |= BLK_OPEN_EXCL;851 mode |= BLK_OPEN_EXCL;
847 ret = bd_prepare_to_claim(bdev, holder, hops);852 ret = bd_prepare_to_claim(bdev, holder, hops);
848 if (ret)853 if (ret)
849 goto put_blkdev;854 return ret;
850 } else {855 } else {
851 if (WARN_ON_ONCE(mode & BLK_OPEN_EXCL)) {856 if (WARN_ON_ONCE(mode & BLK_OPEN_EXCL))
852 ret = -EIO;857 return -EIO;
853 goto put_blkdev;
854 }
855 }858 }
856 859
857 disk_block_events(disk);860 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
892 895
893 if (unblock_events)896 if (unblock_events)
894 disk_unblock_events(disk);897 disk_unblock_events(disk);
895 handle->bdev = bdev;898
896 handle->holder = holder;899 bdev_file->f_flags |= O_LARGEFILE;
897 handle->mode = mode;900 bdev_file->f_mode |= FMODE_BUF_RASYNC | FMODE_CAN_ODIRECT;
898 return handle;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;
899put_module:908put_module:
900 module_put(disk->fops->owner);909 module_put(disk->fops->owner);
901abort_claiming:910abort_claiming:
@@ -903,36 +912,80 @@ abort_claiming: · 1 unmodified line
903 bd_abort_claiming(bdev, holder);912 bd_abort_claiming(bdev, holder);
904 mutex_unlock(&disk->open_mutex);913 mutex_unlock(&disk->open_mutex);
905 disk_unblock_events(disk);914 disk_unblock_events(disk);
906put_blkdev:915 return ret;
907 blkdev_put_no_open(bdev);
908free_handle:
909 kfree(handle);
910 return ERR_PTR(ret);
911}916}
912EXPORT_SYMBOL(bdev_open_by_dev);
913 917
914/**918/*
915 * bdev_open_by_path - open a block device by name919 * If BLK_OPEN_WRITE_IOCTL is set then this is a historical quirk
916 * @path: path to the block device to open920 * associated with the floppy driver where it has allowed ioctls if the
917 * @mode: open mode (BLK_OPEN_*)921 * file was opened for writing, but does not allow reads or writes.
918 * @holder: exclusive holder identifier922 * Make sure that this quirk is reflected in @f_flags.
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.
927 *923 *
928 * RETURNS:924 * It can also happen if a block device is opened as O_RDWR | O_WRONLY.
929 * Handle with a reference to the block_device on success, ERR_PTR(-errno) on
930 * failure.
931 */925 */
932struct bdev_handle *bdev_open_by_path(const char *path, blk_mode_t mode,926static unsigned blk_to_file_flags(blk_mode_t mode)
933 void *holder, const struct blk_holder_ops *hops)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
948struct file *bdev_file_open_by_dev(dev_t dev, blk_mode_t mode, void *holder,
949 const struct blk_holder_ops *hops)
934{950{
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}
982EXPORT_SYMBOL(bdev_file_open_by_dev);
983
984struct 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;
936 dev_t dev;989 dev_t dev;
937 int error;990 int error;
938 991
@@ -940,22 +993,28 @@ struct bdev_handle *bdev_open_by_path(const char *path, blk_mode_t mode, · 1 unmodified line
940 if (error)993 if (error)
941 return ERR_PTR(error);994 return ERR_PTR(error);
942 995
943 handle = bdev_open_by_dev(dev, mode, holder, hops);996 file = bdev_file_open_by_dev(dev, mode, holder, hops);
944 if (!IS_ERR(handle) && (mode & BLK_OPEN_WRITE) &&997 if (!IS_ERR(file) && (mode & BLK_OPEN_WRITE)) {
945 bdev_read_only(handle->bdev)) {998 if (bdev_read_only(file_bdev(file))) {
946 bdev_release(handle);999 fput(file);
947 return ERR_PTR(-EACCES);1000 file = ERR_PTR(-EACCES);
1001 }
948 }1002 }
949 1003
950 return handle;1004 return file;
951}1005}
952EXPORT_SYMBOL(bdev_open_by_path);1006EXPORT_SYMBOL(bdev_file_open_by_path);
953 1007
954void bdev_release(struct bdev_handle *handle)1008void bdev_release(struct file *bdev_file)
955{1009{
956 struct block_device *bdev = handle->bdev;1010 struct block_device *bdev = file_bdev(bdev_file);
1011 void *holder = bdev_file->private_data;
957 struct gendisk *disk = bdev->bd_disk;1012 struct gendisk *disk = bdev->bd_disk;
958 1013
1014 /* We failed to open that block device. */
1015 if (IS_ERR(holder))
1016 goto put_no_open;
1017
959 /*1018 /*
960 * Sync early if it looks like we're the last one. If someone else1019 * Sync early if it looks like we're the last one. If someone else
961 * opens the block device between now and the decrement of bd_openers1020 * 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
967 sync_blockdev(bdev);1026 sync_blockdev(bdev);
968 1027
969 mutex_lock(&disk->open_mutex);1028 mutex_lock(&disk->open_mutex);
970 bdev_yield_write_access(bdev, handle->mode);1029 bdev_yield_write_access(bdev_file);
971 1030
972 if (handle->holder)1031 if (holder)
973 bd_end_claim(bdev, handle->holder);1032 bd_end_claim(bdev, holder);
974 1033
975 /*1034 /*
976 * Trigger event checking and tell drivers to flush MEDIA_CHANGE1035 * Trigger event checking and tell drivers to flush MEDIA_CHANGE
@@ -986,10 +1045,9 @@ void bdev_release(struct bdev_handle *handle) · 9 unmodified lines
986 mutex_unlock(&disk->open_mutex);1045 mutex_unlock(&disk->open_mutex);
987 1046
988 module_put(disk->fops->owner);1047 module_put(disk->fops->owner);
1048put_no_open:
989 blkdev_put_no_open(bdev);1049 blkdev_put_no_open(bdev);
990 kfree(handle);
991}1050}
992EXPORT_SYMBOL(bdev_release);
993 1051
994/**1052/**
995 * lookup_bdev() - Look up a struct block_device by name.1053 * 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
516 return atomic_read(&req->ref);516 return atomic_read(&req->ref);
517}517}
518 518
519void bdev_release(struct file *bdev_file);
520int bdev_open(struct block_device *bdev, blk_mode_t mode, void *holder,
521 const struct blk_holder_ops *hops, struct file *bdev_file);
522int bdev_permission(dev_t dev, blk_mode_t mode, void *holder);
519#endif /* BLK_INTERNAL_H */523#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
572blk_mode_t file_to_blk_mode(struct file *file)572blk_mode_t file_to_blk_mode(struct file *file)
573{573{
574 blk_mode_t mode = 0;574 blk_mode_t mode = 0;
575 struct bdev_handle *handle = file->private_data;
576 575
577 if (file->f_mode & FMODE_READ)576 if (file->f_mode & FMODE_READ)
578 mode |= BLK_OPEN_READ;577 mode |= BLK_OPEN_READ;
579 if (file->f_mode & FMODE_WRITE)578 if (file->f_mode & FMODE_WRITE)
580 mode |= BLK_OPEN_WRITE;579 mode |= BLK_OPEN_WRITE;
581 /*580 /*
582 * do_dentry_open() clears O_EXCL from f_flags, use handle->mode to581 * do_dentry_open() clears O_EXCL from f_flags, use file->private_data
583 * determine whether the open was exclusive for already open files.582 * to determine whether the open was exclusive for already open files.
584 */583 */
585 if (handle)584 if (file->private_data)
586 mode |= handle->mode & BLK_OPEN_EXCL;585 mode |= BLK_OPEN_EXCL;
587 else if (file->f_flags & O_EXCL)586 else if (file->f_flags & O_EXCL)
588 mode |= BLK_OPEN_EXCL;587 mode |= BLK_OPEN_EXCL;
589 if (file->f_flags & O_NDELAY)588 if (file->f_flags & O_NDELAY)
@@ -602,36 +601,31 @@ blk_mode_t file_to_blk_mode(struct file *file) · 12 unmodified lines
602 601
603static int blkdev_open(struct inode *inode, struct file *filp)602static int blkdev_open(struct inode *inode, struct file *filp)
604{603{
605 struct bdev_handle *handle;604 struct block_device *bdev;
606 blk_mode_t mode;605 blk_mode_t mode;
607 606 int ret;
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;
616 607
617 mode = file_to_blk_mode(filp);608 mode = file_to_blk_mode(filp);
618 handle = bdev_open_by_dev(inode->i_rdev, mode,609 /* Use the file as the holder. */
619 mode & BLK_OPEN_EXCL ? filp : NULL, NULL);610 if (mode & BLK_OPEN_EXCL)
620 if (IS_ERR(handle))611 filp->private_data = filp;
621 return PTR_ERR(handle);612 ret = bdev_permission(inode->i_rdev, mode, filp->private_data);
613 if (ret)
614 return ret;
622 615
623 if (bdev_nowait(handle->bdev))616 bdev = blkdev_get_no_open(inode->i_rdev);
624 filp->f_mode |= FMODE_NOWAIT;617 if (!bdev)
618 return -ENXIO;
625 619
626 filp->f_mapping = handle->bdev->bd_inode->i_mapping;620 ret = bdev_open(bdev, mode, filp->private_data, NULL, filp);
627 filp->f_wb_err = filemap_sample_wb_err(filp->f_mapping);621 if (ret)
628 filp->private_data = handle;622 blkdev_put_no_open(bdev);
629 return 0;623 return ret;
630}624}
631 625
632static int blkdev_release(struct inode *inode, struct file *filp)626static int blkdev_release(struct inode *inode, struct file *filp)
633{627{
634 bdev_release(filp->private_data);628 bdev_release(filp);
635 return 0;629 return 0;
636}630}
637 631
block/genhd.c+6−6
@@ -342,7 +342,7 @@ EXPORT_SYMBOL_GPL(disk_uevent); · 341 unmodified lines
342 342
343int disk_scan_partitions(struct gendisk *disk, blk_mode_t mode)343int disk_scan_partitions(struct gendisk *disk, blk_mode_t mode)
344{344{
345 struct bdev_handle *handle;345 struct file *file;
346 int ret = 0;346 int ret = 0;
347 347
348 if (disk->flags & (GENHD_FL_NO_PART | GENHD_FL_HIDDEN))348 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
366 }366 }
367 367
368 set_bit(GD_NEED_PART_SCAN, &disk->state);368 set_bit(GD_NEED_PART_SCAN, &disk->state);
369 handle = bdev_open_by_dev(disk_devt(disk), mode & ~BLK_OPEN_EXCL, NULL,369 file = bdev_file_open_by_dev(disk_devt(disk), mode & ~BLK_OPEN_EXCL,
370 NULL);370 NULL, NULL);
371 if (IS_ERR(handle))371 if (IS_ERR(file))
372 ret = PTR_ERR(handle);372 ret = PTR_ERR(file);
373 else373 else
374 bdev_release(handle);374 fput(file);
375 375
376 /*376 /*
377 * If blkdev_get_by_dev() failed early, GD_NEED_PART_SCAN is still set,377 * 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
469 int __user *argp)469 int __user *argp)
470{470{
471 int ret, n;471 int ret, n;
472 struct bdev_handle *handle;472 struct file *file;
473 473
474 if (!capable(CAP_SYS_ADMIN))474 if (!capable(CAP_SYS_ADMIN))
475 return -EACCES;475 return -EACCES;
@@ -481,12 +481,11 @@ static int blkdev_bszset(struct block_device *bdev, blk_mode_t mode, · 5 unmodified lines
481 if (mode & BLK_OPEN_EXCL)481 if (mode & BLK_OPEN_EXCL)
482 return set_blocksize(bdev, n);482 return set_blocksize(bdev, n);
483 483
484 handle = bdev_open_by_dev(bdev->bd_dev, mode, &bdev, NULL);484 file = bdev_file_open_by_dev(bdev->bd_dev, mode, &bdev, NULL);
485 if (IS_ERR(handle))485 if (IS_ERR(file))
486 return -EBUSY;486 return -EBUSY;
487 ret = set_blocksize(bdev, n);487 ret = set_blocksize(bdev, n);
488 bdev_release(handle);488 fput(file);
489
490 return ret;489 return ret;
491}490}
492 491
drivers/block/drbd/drbd_int.h+2−2
@@ -524,9 +524,9 @@ struct drbd_md { · 523 unmodified lines
524 524
525struct drbd_backing_dev {525struct drbd_backing_dev {
526 struct block_device *backing_bdev;526 struct block_device *backing_bdev;
527 struct bdev_handle *backing_bdev_handle;527 struct file *backing_bdev_file;
528 struct block_device *md_bdev;528 struct block_device *md_bdev;
529 struct bdev_handle *md_bdev_handle;529 struct file *f_md_bdev;
530 struct drbd_md md;530 struct drbd_md md;
531 struct disk_conf *disk_conf; /* RCU, for updates: resource->conf_update */531 struct disk_conf *disk_conf; /* RCU, for updates: resource->conf_update */
532 sector_t known_size; /* last known size of that backing device */532 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
1635 return 0;1635 return 0;
1636}1636}
1637 1637
1638static struct bdev_handle *open_backing_dev(struct drbd_device *device,1638static struct file *open_backing_dev(struct drbd_device *device,
1639 const char *bdev_path, void *claim_ptr, bool do_bd_link)1639 const char *bdev_path, void *claim_ptr, bool do_bd_link)
1640{1640{
1641 struct bdev_handle *handle;1641 struct file *file;
1642 int err = 0;1642 int err = 0;
1643 1643
1644 handle = bdev_open_by_path(bdev_path, BLK_OPEN_READ | BLK_OPEN_WRITE,1644 file = bdev_file_open_by_path(bdev_path, BLK_OPEN_READ | BLK_OPEN_WRITE,
1645 claim_ptr, NULL);1645 claim_ptr, NULL);
1646 if (IS_ERR(handle)) {1646 if (IS_ERR(file)) {
1647 drbd_err(device, "open(\"%s\") failed with %ld\n",1647 drbd_err(device, "open(\"%s\") failed with %ld\n",
1648 bdev_path, PTR_ERR(handle));1648 bdev_path, PTR_ERR(file));
1649 return handle;1649 return file;
1650 }1650 }
1651 1651
1652 if (!do_bd_link)1652 if (!do_bd_link)
1653 return handle;1653 return file;
1654 1654
1655 err = bd_link_disk_holder(handle->bdev, device->vdisk);1655 err = bd_link_disk_holder(file_bdev(file), device->vdisk);
1656 if (err) {1656 if (err) {
1657 bdev_release(handle);1657 fput(file);
1658 drbd_err(device, "bd_link_disk_holder(\"%s\", ...) failed with %d\n",1658 drbd_err(device, "bd_link_disk_holder(\"%s\", ...) failed with %d\n",
1659 bdev_path, err);1659 bdev_path, err);
1660 handle = ERR_PTR(err);1660 file = ERR_PTR(err);
1661 }1661 }
1662 return handle;1662 return file;
1663}1663}
1664 1664
1665static int open_backing_devices(struct drbd_device *device,1665static int open_backing_devices(struct drbd_device *device,
1666 struct disk_conf *new_disk_conf,1666 struct disk_conf *new_disk_conf,
1667 struct drbd_backing_dev *nbc)1667 struct drbd_backing_dev *nbc)
1668{1668{
1669 struct bdev_handle *handle;1669 struct file *file;
1670 1670
1671 handle = open_backing_dev(device, new_disk_conf->backing_dev, device,1671 file = open_backing_dev(device, new_disk_conf->backing_dev, device,
1672 true);1672 true);
1673 if (IS_ERR(handle))1673 if (IS_ERR(file))
1674 return ERR_OPEN_DISK;1674 return ERR_OPEN_DISK;
1675 nbc->backing_bdev = handle->bdev;1675 nbc->backing_bdev = file_bdev(file);
1676 nbc->backing_bdev_handle = handle;1676 nbc->backing_bdev_file = file;
1677 1677
1678 /*1678 /*
1679 * meta_dev_idx >= 0: external fixed size, possibly multiple1679 * 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
1683 * should check it for you already; but if you don't, or1683 * should check it for you already; but if you don't, or
1684 * someone fooled it, we need to double check here)1684 * someone fooled it, we need to double check here)
1685 */1685 */
1686 handle = open_backing_dev(device, new_disk_conf->meta_dev,1686 file = open_backing_dev(device, new_disk_conf->meta_dev,
1687 /* claim ptr: device, if claimed exclusively; shared drbd_m_holder,1687 /* claim ptr: device, if claimed exclusively; shared drbd_m_holder,
1688 * if potentially shared with other drbd minors */1688 * if potentially shared with other drbd minors */
1689 (new_disk_conf->meta_dev_idx < 0) ? (void*)device : (void*)drbd_m_holder,1689 (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
1691 * as would happen with internal metadata. */1691 * as would happen with internal metadata. */
1692 (new_disk_conf->meta_dev_idx != DRBD_MD_INDEX_FLEX_INT &&1692 (new_disk_conf->meta_dev_idx != DRBD_MD_INDEX_FLEX_INT &&
1693 new_disk_conf->meta_dev_idx != DRBD_MD_INDEX_INTERNAL));1693 new_disk_conf->meta_dev_idx != DRBD_MD_INDEX_INTERNAL));
1694 if (IS_ERR(handle))1694 if (IS_ERR(file))
1695 return ERR_OPEN_MD_DISK;1695 return ERR_OPEN_MD_DISK;
1696 nbc->md_bdev = handle->bdev;1696 nbc->md_bdev = file_bdev(file);
1697 nbc->md_bdev_handle = handle;1697 nbc->f_md_bdev = file;
1698 return NO_ERROR;1698 return NO_ERROR;
1699}1699}
1700 1700
1701static void close_backing_dev(struct drbd_device *device,1701static 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)
1703{1703{
1704 if (!handle)1704 if (!bdev_file)
1705 return;1705 return;
1706 if (do_bd_unlink)1706 if (do_bd_unlink)
1707 bd_unlink_disk_holder(handle->bdev, device->vdisk);1707 bd_unlink_disk_holder(file_bdev(bdev_file), device->vdisk);
1708 bdev_release(handle);1708 fput(bdev_file);
1709}1709}
1710 1710
1711void drbd_backing_dev_free(struct drbd_device *device, struct drbd_backing_dev *ldev)1711void 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
1713 if (ldev == NULL)1713 if (ldev == NULL)
1714 return;1714 return;
1715 1715
1716 close_backing_dev(device, ldev->md_bdev_handle,1716 close_backing_dev(device, ldev->f_md_bdev,
1717 ldev->md_bdev != ldev->backing_bdev);1717 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);
1719 1719
1720 kfree(ldev->disk_conf);1720 kfree(ldev->disk_conf);
1721 kfree(ldev);1721 kfree(ldev);
@@ -2131,9 +2131,9 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info) · 409 unmodified lines
2131 fail:2131 fail:
2132 conn_reconfig_done(connection);2132 conn_reconfig_done(connection);
2133 if (nbc) {2133 if (nbc) {
2134 close_backing_dev(device, nbc->md_bdev_handle,2134 close_backing_dev(device, nbc->f_md_bdev,
2135 nbc->md_bdev != nbc->backing_bdev);2135 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);
2137 kfree(nbc);2137 kfree(nbc);
2138 }2138 }
2139 kfree(new_disk_conf);2139 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
340 n += sysfs_emit_at(data, n, "%s %u:%u %u:%u\n",340 n += sysfs_emit_at(data, n, "%s %u:%u %u:%u\n",
341 pd->disk->disk_name,341 pd->disk->disk_name,
342 MAJOR(pd->pkt_dev), MINOR(pd->pkt_dev),342 MAJOR(pd->pkt_dev), MINOR(pd->pkt_dev),
343 MAJOR(pd->bdev_handle->bdev->bd_dev),343 MAJOR(file_bdev(pd->bdev_file)->bd_dev),
344 MINOR(pd->bdev_handle->bdev->bd_dev));344 MINOR(file_bdev(pd->bdev_file)->bd_dev));
345 }345 }
346 mutex_unlock(&ctl_mutex);346 mutex_unlock(&ctl_mutex);
347 return n;347 return n;
@@ -438,7 +438,7 @@ static int pkt_seq_show(struct seq_file *m, void *p) · 90 unmodified lines
438 int states[PACKET_NUM_STATES];438 int states[PACKET_NUM_STATES];
439 439
440 seq_printf(m, "Writer %s mapped to %pg:\n", pd->disk->disk_name,440 seq_printf(m, "Writer %s mapped to %pg:\n", pd->disk->disk_name,
441 pd->bdev_handle->bdev);441 file_bdev(pd->bdev_file));
442 442
443 seq_printf(m, "\nSettings:\n");443 seq_printf(m, "\nSettings:\n");
444 seq_printf(m, "\tpacket size:\t\t%dkB\n", pd->settings.size / 2);444 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
715 */715 */
716static int pkt_generic_packet(struct pktcdvd_device *pd, struct packet_command *cgc)716static int pkt_generic_packet(struct pktcdvd_device *pd, struct packet_command *cgc)
717{717{
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));
719 struct scsi_cmnd *scmd;719 struct scsi_cmnd *scmd;
720 struct request *rq;720 struct request *rq;
721 int ret = 0;721 int ret = 0;
@@ -1048,7 +1048,7 @@ static void pkt_gather_data(struct pktcdvd_device *pd, struct packet_data *pkt) · 326 unmodified lines
1048 continue;1048 continue;
1049 1049
1050 bio = pkt->r_bios[f];1050 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,
1052 REQ_OP_READ);1052 REQ_OP_READ);
1053 bio->bi_iter.bi_sector = pkt->sector + f * (CD_FRAMESIZE >> 9);1053 bio->bi_iter.bi_sector = pkt->sector + f * (CD_FRAMESIZE >> 9);
1054 bio->bi_end_io = pkt_end_io_read;1054 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
1264 struct device *ddev = disk_to_dev(pd->disk);1264 struct device *ddev = disk_to_dev(pd->disk);
1265 int f;1265 int f;
1266 1266
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,
1268 pkt->frames, REQ_OP_WRITE);1268 pkt->frames, REQ_OP_WRITE);
1269 pkt->w_bio->bi_iter.bi_sector = pkt->sector;1269 pkt->w_bio->bi_iter.bi_sector = pkt->sector;
1270 pkt->w_bio->bi_end_io = pkt_end_io_packet_write;1270 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
2162 int ret;2162 int ret;
2163 long lba;2163 long lba;
2164 struct request_queue *q;2164 struct request_queue *q;
2165 struct bdev_handle *bdev_handle;2165 struct file *bdev_file;
2166 2166
2167 /*2167 /*
2168 * We need to re-open the cdrom device without O_NONBLOCK to be able2168 * We need to re-open the cdrom device without O_NONBLOCK to be able
2169 * to read/write from/to it. It is already opened in O_NONBLOCK mode2169 * to read/write from/to it. It is already opened in O_NONBLOCK mode
2170 * so open should not fail.2170 * so open should not fail.
2171 */2171 */
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,
2173 BLK_OPEN_READ, pd, NULL);2173 BLK_OPEN_READ, pd, NULL);
2174 if (IS_ERR(bdev_handle)) {2174 if (IS_ERR(bdev_file)) {
2175 ret = PTR_ERR(bdev_handle);2175 ret = PTR_ERR(bdev_file);
2176 goto out;2176 goto out;
2177 }2177 }
2178 pd->open_bdev_handle = bdev_handle;2178 pd->f_open_bdev = bdev_file;
2179 2179
2180 ret = pkt_get_last_written(pd, &lba);2180 ret = pkt_get_last_written(pd, &lba);
2181 if (ret) {2181 if (ret) {
@@ -2184,9 +2184,9 @@ static int pkt_open_dev(struct pktcdvd_device *pd, bool write) · 2 unmodified lines
2184 }2184 }
2185 2185
2186 set_capacity(pd->disk, lba << 2);2186 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);
2188 2188
2189 q = bdev_get_queue(pd->bdev_handle->bdev);2189 q = bdev_get_queue(file_bdev(pd->bdev_file));
2190 if (write) {2190 if (write) {
2191 ret = pkt_open_write(pd);2191 ret = pkt_open_write(pd);
2192 if (ret)2192 if (ret)
@@ -2218,7 +2218,7 @@ static int pkt_open_dev(struct pktcdvd_device *pd, bool write) · 25 unmodified lines
2218 return 0;2218 return 0;
2219 2219
2220out_putdev:2220out_putdev:
2221 bdev_release(bdev_handle);2221 fput(bdev_file);
2222out:2222out:
2223 return ret;2223 return ret;
2224}2224}
@@ -2237,8 +2237,8 @@ static void pkt_release_dev(struct pktcdvd_device *pd, int flush) · 12 unmodified lines
2237 pkt_lock_door(pd, 0);2237 pkt_lock_door(pd, 0);
2238 2238
2239 pkt_set_speed(pd, MAX_SPEED, MAX_SPEED);2239 pkt_set_speed(pd, MAX_SPEED, MAX_SPEED);
2240 bdev_release(pd->open_bdev_handle);2240 fput(pd->f_open_bdev);
2241 pd->open_bdev_handle = NULL;2241 pd->f_open_bdev = NULL;
2242 2242
2243 pkt_shrink_pktlist(pd);2243 pkt_shrink_pktlist(pd);
2244}2244}
@@ -2326,7 +2326,7 @@ static void pkt_end_io_read_cloned(struct bio *bio) · 81 unmodified lines
2326 2326
2327static void pkt_make_request_read(struct pktcdvd_device *pd, struct bio *bio)2327static void pkt_make_request_read(struct pktcdvd_device *pd, struct bio *bio)
2328{2328{
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,
2330 GFP_NOIO, &pkt_bio_set);2330 GFP_NOIO, &pkt_bio_set);
2331 struct packet_stacked_data *psd = mempool_alloc(&psd_pool, GFP_NOIO);2331 struct packet_stacked_data *psd = mempool_alloc(&psd_pool, GFP_NOIO);
2332 2332
@@ -2497,7 +2497,7 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev) · 164 unmodified lines
2497{2497{
2498 struct device *ddev = disk_to_dev(pd->disk);2498 struct device *ddev = disk_to_dev(pd->disk);
2499 int i;2499 int i;
2500 struct bdev_handle *bdev_handle;2500 struct file *bdev_file;
2501 struct scsi_device *sdev;2501 struct scsi_device *sdev;
2502 2502
2503 if (pd->pkt_dev == dev) {2503 if (pd->pkt_dev == dev) {
@@ -2508,9 +2508,9 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev) · 4 unmodified lines
2508 struct pktcdvd_device *pd2 = pkt_devs[i];2508 struct pktcdvd_device *pd2 = pkt_devs[i];
2509 if (!pd2)2509 if (!pd2)
2510 continue;2510 continue;
2511 if (pd2->bdev_handle->bdev->bd_dev == dev) {2511 if (file_bdev(pd2->bdev_file)->bd_dev == dev) {
2512 dev_err(ddev, "%pg already setup\n",2512 dev_err(ddev, "%pg already setup\n",
2513 pd2->bdev_handle->bdev);2513 file_bdev(pd2->bdev_file));
2514 return -EBUSY;2514 return -EBUSY;
2515 }2515 }
2516 if (pd2->pkt_dev == dev) {2516 if (pd2->pkt_dev == dev) {
@@ -2519,13 +2519,13 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev) · 2 unmodified lines
2519 }2519 }
2520 }2520 }
2521 2521
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,
2523 NULL, NULL);2523 NULL, NULL);
2524 if (IS_ERR(bdev_handle))2524 if (IS_ERR(bdev_file))
2525 return PTR_ERR(bdev_handle);2525 return PTR_ERR(bdev_file);
2526 sdev = scsi_device_from_queue(bdev_handle->bdev->bd_disk->queue);2526 sdev = scsi_device_from_queue(file_bdev(bdev_file)->bd_disk->queue);
2527 if (!sdev) {2527 if (!sdev) {
2528 bdev_release(bdev_handle);2528 fput(bdev_file);
2529 return -EINVAL;2529 return -EINVAL;
2530 }2530 }
2531 put_device(&sdev->sdev_gendev);2531 put_device(&sdev->sdev_gendev);
@@ -2533,8 +2533,8 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev) · 1 unmodified line
2533 /* This is safe, since we have a reference from open(). */2533 /* This is safe, since we have a reference from open(). */
2534 __module_get(THIS_MODULE);2534 __module_get(THIS_MODULE);
2535 2535
2536 pd->bdev_handle = bdev_handle;2536 pd->bdev_file = bdev_file;
2537 set_blocksize(bdev_handle->bdev, CD_FRAMESIZE);2537 set_blocksize(file_bdev(bdev_file), CD_FRAMESIZE);
2538 2538
2539 pkt_init_queue(pd);2539 pkt_init_queue(pd);
2540 2540
@@ -2546,11 +2546,11 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev) · 5 unmodified lines
2546 }2546 }
2547 2547
2548 proc_create_single_data(pd->disk->disk_name, 0, pkt_proc, pkt_seq_show, pd);2548 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));
2550 return 0;2550 return 0;
2551 2551
2552out_mem:2552out_mem:
2553 bdev_release(bdev_handle);2553 fput(bdev_file);
2554 /* This is safe: open() is still holding a reference. */2554 /* This is safe: open() is still holding a reference. */
2555 module_put(THIS_MODULE);2555 module_put(THIS_MODULE);
2556 return -ENOMEM;2556 return -ENOMEM;
@@ -2605,9 +2605,9 @@ static unsigned int pkt_check_events(struct gendisk *disk, · 48 unmodified lines
2605 2605
2606 if (!pd)2606 if (!pd)
2607 return 0;2607 return 0;
2608 if (!pd->bdev_handle)2608 if (!pd->bdev_file)
2609 return 0;2609 return 0;
2610 attached_disk = pd->bdev_handle->bdev->bd_disk;2610 attached_disk = file_bdev(pd->bdev_file)->bd_disk;
2611 if (!attached_disk || !attached_disk->fops->check_events)2611 if (!attached_disk || !attached_disk->fops->check_events)
2612 return 0;2612 return 0;
2613 return attached_disk->fops->check_events(attached_disk, clearing);2613 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
2692 goto out_mem2;2692 goto out_mem2;
2693 2693
2694 /* inherit events of the host device */2694 /* 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;
2696 2696
2697 ret = add_disk(disk);2697 ret = add_disk(disk);
2698 if (ret)2698 if (ret)
@@ -2757,7 +2757,7 @@ static int pkt_remove_dev(dev_t pkt_dev) · 58 unmodified lines
2757 pkt_debugfs_dev_remove(pd);2757 pkt_debugfs_dev_remove(pd);
2758 pkt_sysfs_dev_remove(pd);2758 pkt_sysfs_dev_remove(pd);
2759 2759
2760 bdev_release(pd->bdev_handle);2760 fput(pd->bdev_file);
2761 2761
2762 remove_proc_entry(pd->disk->disk_name, pkt_proc);2762 remove_proc_entry(pd->disk->disk_name, pkt_proc);
2763 dev_notice(ddev, "writer unmapped\n");2763 dev_notice(ddev, "writer unmapped\n");
@@ -2784,7 +2784,7 @@ static void pkt_get_status(struct pkt_ctrl_command *ctrl_cmd) · 20 unmodified lines
2784 2784
2785 pd = pkt_find_dev_from_minor(ctrl_cmd->dev_index);2785 pd = pkt_find_dev_from_minor(ctrl_cmd->dev_index);
2786 if (pd) {2786 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);
2788 ctrl_cmd->pkt_dev = new_encode_dev(pd->pkt_dev);2788 ctrl_cmd->pkt_dev = new_encode_dev(pd->pkt_dev);
2789 } else {2789 } else {
2790 ctrl_cmd->dev = 0;2790 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
145 priv->sess_dev = sess_dev;145 priv->sess_dev = sess_dev;
146 priv->id = id;146 priv->id = id;
147 147
148 bio = bio_alloc(sess_dev->bdev_handle->bdev, 1,148 bio = bio_alloc(file_bdev(sess_dev->bdev_file), 1,
149 rnbd_to_bio_flags(le32_to_cpu(msg->rw)), GFP_KERNEL);149 rnbd_to_bio_flags(le32_to_cpu(msg->rw)), GFP_KERNEL);
150 if (bio_add_page(bio, virt_to_page(data), datalen,150 if (bio_add_page(bio, virt_to_page(data), datalen,
151 offset_in_page(data)) != datalen) {151 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
219 rnbd_put_sess_dev(sess_dev);219 rnbd_put_sess_dev(sess_dev);
220 wait_for_completion(&dc); /* wait for inflights to drop to zero */220 wait_for_completion(&dc); /* wait for inflights to drop to zero */
221 221
222 bdev_release(sess_dev->bdev_handle);222 fput(sess_dev->bdev_file);
223 mutex_lock(&sess_dev->dev->lock);223 mutex_lock(&sess_dev->dev->lock);
224 list_del(&sess_dev->dev_list);224 list_del(&sess_dev->dev_list);
225 if (!sess_dev->readonly)225 if (!sess_dev->readonly)
@@ -534,7 +534,7 @@ rnbd_srv_get_or_create_srv_dev(struct block_device *bdev, · 308 unmodified lines
534static void rnbd_srv_fill_msg_open_rsp(struct rnbd_msg_open_rsp *rsp,534static void rnbd_srv_fill_msg_open_rsp(struct rnbd_msg_open_rsp *rsp,
535 struct rnbd_srv_sess_dev *sess_dev)535 struct rnbd_srv_sess_dev *sess_dev)
536{536{
537 struct block_device *bdev = sess_dev->bdev_handle->bdev;537 struct block_device *bdev = file_bdev(sess_dev->bdev_file);
538 538
539 rsp->hdr.type = cpu_to_le16(RNBD_MSG_OPEN_RSP);539 rsp->hdr.type = cpu_to_le16(RNBD_MSG_OPEN_RSP);
540 rsp->device_id = cpu_to_le32(sess_dev->device_id);540 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
560static struct rnbd_srv_sess_dev *560static struct rnbd_srv_sess_dev *
561rnbd_srv_create_set_sess_dev(struct rnbd_srv_session *srv_sess,561rnbd_srv_create_set_sess_dev(struct rnbd_srv_session *srv_sess,
562 const struct rnbd_msg_open *open_msg,562 const struct rnbd_msg_open *open_msg,
563 struct bdev_handle *handle, bool readonly,563 struct file *bdev_file, bool readonly,
564 struct rnbd_srv_dev *srv_dev)564 struct rnbd_srv_dev *srv_dev)
565{565{
566 struct rnbd_srv_sess_dev *sdev = rnbd_sess_dev_alloc(srv_sess);566 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
572 572
573 strscpy(sdev->pathname, open_msg->dev_name, sizeof(sdev->pathname));573 strscpy(sdev->pathname, open_msg->dev_name, sizeof(sdev->pathname));
574 574
575 sdev->bdev_handle = handle;575 sdev->bdev_file = bdev_file;
576 sdev->sess = srv_sess;576 sdev->sess = srv_sess;
577 sdev->dev = srv_dev;577 sdev->dev = srv_dev;
578 sdev->readonly = readonly;578 sdev->readonly = readonly;
@@ -678,7 +678,7 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess, · 99 unmodified lines
678 struct rnbd_srv_dev *srv_dev;678 struct rnbd_srv_dev *srv_dev;
679 struct rnbd_srv_sess_dev *srv_sess_dev;679 struct rnbd_srv_sess_dev *srv_sess_dev;
680 const struct rnbd_msg_open *open_msg = msg;680 const struct rnbd_msg_open *open_msg = msg;
681 struct bdev_handle *bdev_handle;681 struct file *bdev_file;
682 blk_mode_t open_flags = BLK_OPEN_READ;682 blk_mode_t open_flags = BLK_OPEN_READ;
683 char *full_path;683 char *full_path;
684 struct rnbd_msg_open_rsp *rsp = data;684 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
716 goto reject;716 goto reject;
717 }717 }
718 718
719 bdev_handle = bdev_open_by_path(full_path, open_flags, NULL, NULL);719 bdev_file = bdev_file_open_by_path(full_path, open_flags, NULL, NULL);
720 if (IS_ERR(bdev_handle)) {720 if (IS_ERR(bdev_file)) {
721 ret = PTR_ERR(bdev_handle);721 ret = PTR_ERR(bdev_file);
722 pr_err("Opening device '%s' on session %s failed, failed to open the block device, err: %pe\n",722 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);
724 goto free_path;724 goto free_path;
725 }725 }
726 726
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,
728 open_msg->access_mode);728 open_msg->access_mode);
729 if (IS_ERR(srv_dev)) {729 if (IS_ERR(srv_dev)) {
730 pr_err("Opening device '%s' on session %s failed, creating srv_dev failed, err: %pe\n",730 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
734 }734 }
735 735
736 srv_sess_dev = rnbd_srv_create_set_sess_dev(srv_sess, open_msg,736 srv_sess_dev = rnbd_srv_create_set_sess_dev(srv_sess, open_msg,
737 bdev_handle,737 bdev_file,
738 open_msg->access_mode == RNBD_ACCESS_RO,738 open_msg->access_mode == RNBD_ACCESS_RO,
739 srv_dev);739 srv_dev);
740 if (IS_ERR(srv_sess_dev)) {740 if (IS_ERR(srv_sess_dev)) {
@@ -750,7 +750,7 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess, · 9 unmodified lines
750 */750 */
751 mutex_lock(&srv_dev->lock);751 mutex_lock(&srv_dev->lock);
752 if (!srv_dev->dev_kobj.state_in_sysfs) {752 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));
754 if (ret) {754 if (ret) {
755 mutex_unlock(&srv_dev->lock);755 mutex_unlock(&srv_dev->lock);
756 rnbd_srv_err(srv_sess_dev,756 rnbd_srv_err(srv_sess_dev,
@@ -793,7 +793,7 @@ srv_dev_put: · 36 unmodified lines
793 }793 }
794 rnbd_put_srv_dev(srv_dev);794 rnbd_put_srv_dev(srv_dev);
795blkdev_put:795blkdev_put:
796 bdev_release(bdev_handle);796 fput(bdev_file);
797free_path:797free_path:
798 kfree(full_path);798 kfree(full_path);
799reject:799reject:
drivers/block/rnbd/rnbd-srv.h+1−1
@@ -46,7 +46,7 @@ struct rnbd_srv_dev { · 45 unmodified lines
46struct rnbd_srv_sess_dev {46struct rnbd_srv_sess_dev {
47 /* Entry inside rnbd_srv_dev struct */47 /* Entry inside rnbd_srv_dev struct */
48 struct list_head dev_list;48 struct list_head dev_list;
49 struct bdev_handle *bdev_handle;49 struct file *bdev_file;
50 struct rnbd_srv_session *sess;50 struct rnbd_srv_session *sess;
51 struct rnbd_srv_dev *dev;51 struct rnbd_srv_dev *dev;
52 struct kobject kobj;52 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
465 }465 }
466 466
467 req->dev = vbd->pdevice;467 req->dev = vbd->pdevice;
468 req->bdev = vbd->bdev_handle->bdev;468 req->bdev = file_bdev(vbd->bdev_file);
469 rc = 0;469 rc = 0;
470 470
471 out:471 out:
@@ -969,7 +969,7 @@ static int dispatch_discard_io(struct xen_blkif_ring *ring, · 497 unmodified lines
969 int err = 0;969 int err = 0;
970 int status = BLKIF_RSP_OKAY;970 int status = BLKIF_RSP_OKAY;
971 struct xen_blkif *blkif = ring->blkif;971 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);
973 struct phys_req preq;973 struct phys_req preq;
974 974
975 xen_blkif_get(blkif);975 xen_blkif_get(blkif);
drivers/block/xen-blkback/common.h+2−2
@@ -221,7 +221,7 @@ struct xen_vbd { · 220 unmodified lines
221 unsigned char type;221 unsigned char type;
222 /* phys device that this vbd maps to. */222 /* phys device that this vbd maps to. */
223 u32 pdevice;223 u32 pdevice;
224 struct bdev_handle *bdev_handle;224 struct file *bdev_file;
225 /* Cached size parameter. */225 /* Cached size parameter. */
226 sector_t size;226 sector_t size;
227 unsigned int flush_support:1;227 unsigned int flush_support:1;
@@ -360,7 +360,7 @@ struct pending_req { · 132 unmodified lines
360};360};
361 361
362 362
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))
364 364
365#define xen_blkif_get(_b) (atomic_inc(&(_b)->refcnt))365#define xen_blkif_get(_b) (atomic_inc(&(_b)->refcnt))
366#define xen_blkif_put(_b) \366#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
81 int i;81 int i;
82 82
83 /* Not ready to connect? */83 /* 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)
85 return;85 return;
86 86
87 /* Already connected? */87 /* Already connected? */
@@ -99,13 +99,12 @@ static void xen_update_blkif_status(struct xen_blkif *blkif) · 11 unmodified lines
99 return;99 return;
100 }100 }
101 101
102 err = sync_blockdev(blkif->vbd.bdev_handle->bdev);102 err = sync_blockdev(file_bdev(blkif->vbd.bdev_file));
103 if (err) {103 if (err) {
104 xenbus_dev_error(blkif->be->dev, err, "block flush");104 xenbus_dev_error(blkif->be->dev, err, "block flush");
105 return;105 return;
106 }106 }
107 invalidate_inode_pages2(107 invalidate_inode_pages2(blkif->vbd.bdev_file->f_mapping);
108 blkif->vbd.bdev_handle->bdev->bd_inode->i_mapping);
109 108
110 for (i = 0; i < blkif->nr_rings; i++) {109 for (i = 0; i < blkif->nr_rings; i++) {
111 ring = &blkif->rings[i];110 ring = &blkif->rings[i];
@@ -473,9 +472,9 @@ static void xenvbd_sysfs_delif(struct xenbus_device *dev) · 361 unmodified lines
473 472
474static void xen_vbd_free(struct xen_vbd *vbd)473static void xen_vbd_free(struct xen_vbd *vbd)
475{474{
476 if (vbd->bdev_handle)475 if (vbd->bdev_file)
477 bdev_release(vbd->bdev_handle);476 fput(vbd->bdev_file);
478 vbd->bdev_handle = NULL;477 vbd->bdev_file = NULL;
479}478}
480 479
481static int xen_vbd_create(struct xen_blkif *blkif, blkif_vdev_t handle,480static 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
483 int cdrom)482 int cdrom)
484{483{
485 struct xen_vbd *vbd;484 struct xen_vbd *vbd;
486 struct bdev_handle *bdev_handle;485 struct file *bdev_file;
487 486
488 vbd = &blkif->vbd;487 vbd = &blkif->vbd;
489 vbd->handle = handle;488 vbd->handle = handle;
@@ -492,17 +491,17 @@ static int xen_vbd_create(struct xen_blkif *blkif, blkif_vdev_t handle, · 2 unmodified lines
492 491
493 vbd->pdevice = MKDEV(major, minor);492 vbd->pdevice = MKDEV(major, minor);
494 493
495 bdev_handle = bdev_open_by_dev(vbd->pdevice, vbd->readonly ?494 bdev_file = bdev_file_open_by_dev(vbd->pdevice, vbd->readonly ?
496 BLK_OPEN_READ : BLK_OPEN_WRITE, NULL, NULL);495 BLK_OPEN_READ : BLK_OPEN_WRITE, NULL, NULL);
497 496
498 if (IS_ERR(bdev_handle)) {497 if (IS_ERR(bdev_file)) {
499 pr_warn("xen_vbd_create: device %08x could not be opened\n",498 pr_warn("xen_vbd_create: device %08x could not be opened\n",
500 vbd->pdevice);499 vbd->pdevice);
501 return -ENOENT;500 return -ENOENT;
502 }501 }
503 502
504 vbd->bdev_handle = bdev_handle;503 vbd->bdev_file = bdev_file;
505 if (vbd->bdev_handle->bdev->bd_disk == NULL) {504 if (file_bdev(vbd->bdev_file)->bd_disk == NULL) {
506 pr_warn("xen_vbd_create: device %08x doesn't exist\n",505 pr_warn("xen_vbd_create: device %08x doesn't exist\n",
507 vbd->pdevice);506 vbd->pdevice);
508 xen_vbd_free(vbd);507 xen_vbd_free(vbd);
@@ -510,14 +509,14 @@ static int xen_vbd_create(struct xen_blkif *blkif, blkif_vdev_t handle, · 1 unmodified line
510 }509 }
511 vbd->size = vbd_sz(vbd);510 vbd->size = vbd_sz(vbd);
512 511
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))
514 vbd->type |= VDISK_CDROM;513 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)
516 vbd->type |= VDISK_REMOVABLE;515 vbd->type |= VDISK_REMOVABLE;
517 516
518 if (bdev_write_cache(bdev_handle->bdev))517 if (bdev_write_cache(file_bdev(bdev_file)))
519 vbd->flush_support = true;518 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)))
521 vbd->discard_secure = true;520 vbd->discard_secure = true;
522 521
523 pr_debug("Successful creation of handle=%04x (dom=%u)\n",522 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
570 struct xen_blkif *blkif = be->blkif;569 struct xen_blkif *blkif = be->blkif;
571 int err;570 int err;
572 int state = 0;571 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);
574 573
575 if (!xenbus_read_unsigned(dev->nodename, "discard-enable", 1))574 if (!xenbus_read_unsigned(dev->nodename, "discard-enable", 1))
576 return;575 return;
@@ -932,7 +931,7 @@ again: · 355 unmodified lines
932 }931 }
933 err = xenbus_printf(xbt, dev->nodename, "sector-size", "%lu",932 err = xenbus_printf(xbt, dev->nodename, "sector-size", "%lu",
934 (unsigned long)bdev_logical_block_size(933 (unsigned long)bdev_logical_block_size(
935 be->blkif->vbd.bdev_handle->bdev));934 file_bdev(be->blkif->vbd.bdev_file)));
936 if (err) {935 if (err) {
937 xenbus_dev_fatal(dev, err, "writing %s/sector-size",936 xenbus_dev_fatal(dev, err, "writing %s/sector-size",
938 dev->nodename);937 dev->nodename);
@@ -940,7 +939,7 @@ again: · 1 unmodified line
940 }939 }
941 err = xenbus_printf(xbt, dev->nodename, "physical-sector-size", "%u",940 err = xenbus_printf(xbt, dev->nodename, "physical-sector-size", "%u",
942 bdev_physical_block_size(941 bdev_physical_block_size(
943 be->blkif->vbd.bdev_handle->bdev));942 file_bdev(be->blkif->vbd.bdev_file)));
944 if (err)943 if (err)
945 xenbus_dev_error(dev, err, "writing %s/physical-sector-size",944 xenbus_dev_error(dev, err, "writing %s/physical-sector-size",
946 dev->nodename);945 dev->nodename);
drivers/block/zram/zram_drv.c+13−13
@@ -426,11 +426,11 @@ static void reset_bdev(struct zram *zram) · 425 unmodified lines
426 if (!zram->backing_dev)426 if (!zram->backing_dev)
427 return;427 return;
428 428
429 bdev_release(zram->bdev_handle);429 fput(zram->bdev_file);
430 /* hope filp_close flush all of IO */430 /* hope filp_close flush all of IO */
431 filp_close(zram->backing_dev, NULL);431 filp_close(zram->backing_dev, NULL);
432 zram->backing_dev = NULL;432 zram->backing_dev = NULL;
433 zram->bdev_handle = NULL;433 zram->bdev_file = NULL;
434 zram->disk->fops = &zram_devops;434 zram->disk->fops = &zram_devops;
435 kvfree(zram->bitmap);435 kvfree(zram->bitmap);
436 zram->bitmap = NULL;436 zram->bitmap = NULL;
@@ -476,7 +476,7 @@ static ssize_t backing_dev_store(struct device *dev, · 39 unmodified lines
476 struct address_space *mapping;476 struct address_space *mapping;
477 unsigned int bitmap_sz;477 unsigned int bitmap_sz;
478 unsigned long nr_pages, *bitmap = NULL;478 unsigned long nr_pages, *bitmap = NULL;
479 struct bdev_handle *bdev_handle = NULL;479 struct file *bdev_file = NULL;
480 int err;480 int err;
481 struct zram *zram = dev_to_zram(dev);481 struct zram *zram = dev_to_zram(dev);
482 482
@@ -513,11 +513,11 @@ static ssize_t backing_dev_store(struct device *dev, · 30 unmodified lines
513 goto out;513 goto out;
514 }514 }
515 515
516 bdev_handle = bdev_open_by_dev(inode->i_rdev,516 bdev_file = bdev_file_open_by_dev(inode->i_rdev,
517 BLK_OPEN_READ | BLK_OPEN_WRITE, zram, NULL);517 BLK_OPEN_READ | BLK_OPEN_WRITE, zram, NULL);
518 if (IS_ERR(bdev_handle)) {518 if (IS_ERR(bdev_file)) {
519 err = PTR_ERR(bdev_handle);519 err = PTR_ERR(bdev_file);
520 bdev_handle = NULL;520 bdev_file = NULL;
521 goto out;521 goto out;
522 }522 }
523 523
@@ -531,7 +531,7 @@ static ssize_t backing_dev_store(struct device *dev, · 7 unmodified lines
531 531
532 reset_bdev(zram);532 reset_bdev(zram);
533 533
534 zram->bdev_handle = bdev_handle;534 zram->bdev_file = bdev_file;
535 zram->backing_dev = backing_dev;535 zram->backing_dev = backing_dev;
536 zram->bitmap = bitmap;536 zram->bitmap = bitmap;
537 zram->nr_pages = nr_pages;537 zram->nr_pages = nr_pages;
@@ -544,8 +544,8 @@ static ssize_t backing_dev_store(struct device *dev, · 6 unmodified lines
544out:544out:
545 kvfree(bitmap);545 kvfree(bitmap);
546 546
547 if (bdev_handle)547 if (bdev_file)
548 bdev_release(bdev_handle);548 fput(bdev_file);
549 549
550 if (backing_dev)550 if (backing_dev)
551 filp_close(backing_dev, NULL);551 filp_close(backing_dev, NULL);
@@ -587,7 +587,7 @@ static void read_from_bdev_async(struct zram *zram, struct page *page, · 35 unmodified lines
587{587{
588 struct bio *bio;588 struct bio *bio;
589 589
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);
591 bio->bi_iter.bi_sector = entry * (PAGE_SIZE >> 9);591 bio->bi_iter.bi_sector = entry * (PAGE_SIZE >> 9);
592 __bio_add_page(bio, page, PAGE_SIZE, 0);592 __bio_add_page(bio, page, PAGE_SIZE, 0);
593 bio_chain(bio, parent);593 bio_chain(bio, parent);
@@ -703,7 +703,7 @@ static ssize_t writeback_store(struct device *dev, · 109 unmodified lines
703 continue;703 continue;
704 }704 }
705 705
706 bio_init(&bio, zram->bdev_handle->bdev, &bio_vec, 1,706 bio_init(&bio, file_bdev(zram->bdev_file), &bio_vec, 1,
707 REQ_OP_WRITE | REQ_SYNC);707 REQ_OP_WRITE | REQ_SYNC);
708 bio.bi_iter.bi_sector = blk_idx * (PAGE_SIZE >> 9);708 bio.bi_iter.bi_sector = blk_idx * (PAGE_SIZE >> 9);
709 __bio_add_page(&bio, page, PAGE_SIZE, 0);709 __bio_add_page(&bio, page, PAGE_SIZE, 0);
@@ -785,7 +785,7 @@ static void zram_sync_read(struct work_struct *work) · 75 unmodified lines
785 struct bio_vec bv;785 struct bio_vec bv;
786 struct bio bio;786 struct bio bio;
787 787
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);
789 bio.bi_iter.bi_sector = zw->entry * (PAGE_SIZE >> 9);789 bio.bi_iter.bi_sector = zw->entry * (PAGE_SIZE >> 9);
790 __bio_add_page(&bio, zw->page, PAGE_SIZE, 0);790 __bio_add_page(&bio, zw->page, PAGE_SIZE, 0);
791 zw->error = submit_bio_wait(&bio);791 zw->error = submit_bio_wait(&bio);
drivers/block/zram/zram_drv.h+1−1
@@ -132,7 +132,7 @@ struct zram { · 131 unmodified lines
132 spinlock_t wb_limit_lock;132 spinlock_t wb_limit_lock;
133 bool wb_limit_enable;133 bool wb_limit_enable;
134 u64 bd_wb_limit;134 u64 bd_wb_limit;
135 struct bdev_handle *bdev_handle;135 struct file *bdev_file;
136 unsigned long *bitmap;136 unsigned long *bitmap;
137 unsigned long nr_pages;137 unsigned long nr_pages;
138#endif138#endif
drivers/md/bcache/bcache.h+2−2
@@ -300,7 +300,7 @@ struct cached_dev { · 299 unmodified lines
300 struct list_head list;300 struct list_head list;
301 struct bcache_device disk;301 struct bcache_device disk;
302 struct block_device *bdev;302 struct block_device *bdev;
303 struct bdev_handle *bdev_handle;303 struct file *bdev_file;
304 304
305 struct cache_sb sb;305 struct cache_sb sb;
306 struct cache_sb_disk *sb_disk;306 struct cache_sb_disk *sb_disk;
@@ -423,7 +423,7 @@ struct cache { · 116 unmodified lines
423 423
424 struct kobject kobj;424 struct kobject kobj;
425 struct block_device *bdev;425 struct block_device *bdev;
426 struct bdev_handle *bdev_handle;426 struct file *bdev_file;
427 427
428 struct task_struct *alloc_thread;428 struct task_struct *alloc_thread;
429 429
drivers/md/bcache/super.c+37−37
@@ -1369,8 +1369,8 @@ static CLOSURE_CALLBACK(cached_dev_free) · 1368 unmodified lines
1369 if (dc->sb_disk)1369 if (dc->sb_disk)
1370 put_page(virt_to_page(dc->sb_disk));1370 put_page(virt_to_page(dc->sb_disk));
1371 1371
1372 if (dc->bdev_handle)1372 if (dc->bdev_file)
1373 bdev_release(dc->bdev_handle);1373 fput(dc->bdev_file);
1374 1374
1375 wake_up(&unregister_wait);1375 wake_up(&unregister_wait);
1376 1376
@@ -1445,7 +1445,7 @@ static int cached_dev_init(struct cached_dev *dc, unsigned int block_size) · 68 unmodified lines
1445/* Cached device - bcache superblock */1445/* Cached device - bcache superblock */
1446 1446
1447static int register_bdev(struct cache_sb *sb, struct cache_sb_disk *sb_disk,1447static int register_bdev(struct cache_sb *sb, struct cache_sb_disk *sb_disk,
1448 struct bdev_handle *bdev_handle,1448 struct file *bdev_file,
1449 struct cached_dev *dc)1449 struct cached_dev *dc)
1450{1450{
1451 const char *err = "cannot allocate memory";1451 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
1453 int ret = -ENOMEM;1453 int ret = -ENOMEM;
1454 1454
1455 memcpy(&dc->sb, sb, sizeof(struct cache_sb));1455 memcpy(&dc->sb, sb, sizeof(struct cache_sb));
1456 dc->bdev_handle = bdev_handle;1456 dc->bdev_file = bdev_file;
1457 dc->bdev = bdev_handle->bdev;1457 dc->bdev = file_bdev(bdev_file);
1458 dc->sb_disk = sb_disk;1458 dc->sb_disk = sb_disk;
1459 1459
1460 if (cached_dev_init(dc, sb->block_size << 9))1460 if (cached_dev_init(dc, sb->block_size << 9))
@@ -2218,8 +2218,8 @@ void bch_cache_release(struct kobject *kobj) · 757 unmodified lines
2218 if (ca->sb_disk)2218 if (ca->sb_disk)
2219 put_page(virt_to_page(ca->sb_disk));2219 put_page(virt_to_page(ca->sb_disk));
2220 2220
2221 if (ca->bdev_handle)2221 if (ca->bdev_file)
2222 bdev_release(ca->bdev_handle);2222 fput(ca->bdev_file);
2223 2223
2224 kfree(ca);2224 kfree(ca);
2225 module_put(THIS_MODULE);2225 module_put(THIS_MODULE);
@@ -2339,18 +2339,18 @@ err_free: · 113 unmodified lines
2339}2339}
2340 2340
2341static int register_cache(struct cache_sb *sb, struct cache_sb_disk *sb_disk,2341static int register_cache(struct cache_sb *sb, struct cache_sb_disk *sb_disk,
2342 struct bdev_handle *bdev_handle,2342 struct file *bdev_file,
2343 struct cache *ca)2343 struct cache *ca)
2344{2344{
2345 const char *err = NULL; /* must be set for any error case */2345 const char *err = NULL; /* must be set for any error case */
2346 int ret = 0;2346 int ret = 0;
2347 2347
2348 memcpy(&ca->sb, sb, sizeof(struct cache_sb));2348 memcpy(&ca->sb, sb, sizeof(struct cache_sb));
2349 ca->bdev_handle = bdev_handle;2349 ca->bdev_file = bdev_file;
2350 ca->bdev = bdev_handle->bdev;2350 ca->bdev = file_bdev(bdev_file);
2351 ca->sb_disk = sb_disk;2351 ca->sb_disk = sb_disk;
2352 2352
2353 if (bdev_max_discard_sectors((bdev_handle->bdev)))2353 if (bdev_max_discard_sectors(file_bdev(bdev_file)))
2354 ca->discard = CACHE_DISCARD(&ca->sb);2354 ca->discard = CACHE_DISCARD(&ca->sb);
2355 2355
2356 ret = cache_alloc(ca);2356 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
2361 err = "cache_alloc(): cache device is too small";2361 err = "cache_alloc(): cache device is too small";
2362 else2362 else
2363 err = "cache_alloc(): unknown error";2363 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);
2365 /*2365 /*
2366 * If we failed here, it means ca->kobj is not initialized yet,2366 * If we failed here, it means ca->kobj is not initialized yet,
2367 * kobject_put() won't be called and there is no chance to2367 * kobject_put() won't be called and there is no chance to
2368 * call bdev_release() to bdev in bch_cache_release(). So2368 * call fput() to bdev in bch_cache_release(). So
2369 * we explicitly call bdev_release() here.2369 * we explicitly call fput() on the block device here.
2370 */2370 */
2371 bdev_release(bdev_handle);2371 fput(bdev_file);
2372 return ret;2372 return ret;
2373 }2373 }
2374 2374
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")) {
2376 pr_notice("error %pg: error calling kobject_add\n",2376 pr_notice("error %pg: error calling kobject_add\n",
2377 bdev_handle->bdev);2377 file_bdev(bdev_file));
2378 ret = -ENOMEM;2378 ret = -ENOMEM;
2379 goto out;2379 goto out;
2380 }2380 }
@@ -2388,7 +2388,7 @@ static int register_cache(struct cache_sb *sb, struct cache_sb_disk *sb_disk, · 7 unmodified lines
2388 goto out;2388 goto out;
2389 }2389 }
2390 2390
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));
2392 2392
2393out:2393out:
2394 kobject_put(&ca->kobj);2394 kobject_put(&ca->kobj);
@@ -2446,7 +2446,7 @@ struct async_reg_args { · 51 unmodified lines
2446 char *path;2446 char *path;
2447 struct cache_sb *sb;2447 struct cache_sb *sb;
2448 struct cache_sb_disk *sb_disk;2448 struct cache_sb_disk *sb_disk;
2449 struct bdev_handle *bdev_handle;2449 struct file *bdev_file;
2450 void *holder;2450 void *holder;
2451};2451};
2452 2452
@@ -2457,7 +2457,7 @@ static void register_bdev_worker(struct work_struct *work) · 4 unmodified lines
2457 container_of(work, struct async_reg_args, reg_work.work);2457 container_of(work, struct async_reg_args, reg_work.work);
2458 2458
2459 mutex_lock(&bch_register_lock);2459 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,
2461 args->holder) < 0)2461 args->holder) < 0)
2462 fail = true;2462 fail = true;
2463 mutex_unlock(&bch_register_lock);2463 mutex_unlock(&bch_register_lock);
@@ -2478,7 +2478,7 @@ static void register_cache_worker(struct work_struct *work) · 14 unmodified lines
2478 container_of(work, struct async_reg_args, reg_work.work);2478 container_of(work, struct async_reg_args, reg_work.work);
2479 2479
2480 /* blkdev_put() will be called in bch_cache_release() */2480 /* 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,
2482 args->holder))2482 args->holder))
2483 fail = true;2483 fail = true;
2484 2484
@@ -2516,7 +2516,7 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr, · 31 unmodified lines
2516 char *path = NULL;2516 char *path = NULL;
2517 struct cache_sb *sb;2517 struct cache_sb *sb;
2518 struct cache_sb_disk *sb_disk;2518 struct cache_sb_disk *sb_disk;
2519 struct bdev_handle *bdev_handle, *bdev_handle2;2519 struct file *bdev_file, *bdev_file2;
2520 void *holder = NULL;2520 void *holder = NULL;
2521 ssize_t ret;2521 ssize_t ret;
2522 bool async_registration = false;2522 bool async_registration = false;
@@ -2549,15 +2549,15 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr, · 26 unmodified lines
2549 2549
2550 ret = -EINVAL;2550 ret = -EINVAL;
2551 err = "failed to open device";2551 err = "failed to open device";
2552 bdev_handle = bdev_open_by_path(strim(path), BLK_OPEN_READ, NULL, NULL);2552 bdev_file = bdev_file_open_by_path(strim(path), BLK_OPEN_READ, NULL, NULL);
2553 if (IS_ERR(bdev_handle))2553 if (IS_ERR(bdev_file))
2554 goto out_free_sb;2554 goto out_free_sb;
2555 2555
2556 err = "failed to set blocksize";2556 err = "failed to set blocksize";
2557 if (set_blocksize(bdev_handle->bdev, 4096))2557 if (set_blocksize(file_bdev(bdev_file), 4096))
2558 goto out_blkdev_put;2558 goto out_blkdev_put;
2559 2559
2560 err = read_super(sb, bdev_handle->bdev, &sb_disk);2560 err = read_super(sb, file_bdev(bdev_file), &sb_disk);
2561 if (err)2561 if (err)
2562 goto out_blkdev_put;2562 goto out_blkdev_put;
2563 2563
@@ -2569,13 +2569,13 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr, · 5 unmodified lines
2569 }2569 }
2570 2570
2571 /* Now reopen in exclusive mode with proper holder */2571 /* 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,
2573 BLK_OPEN_READ | BLK_OPEN_WRITE, holder, NULL);2573 BLK_OPEN_READ | BLK_OPEN_WRITE, holder, NULL);
2574 bdev_release(bdev_handle);2574 fput(bdev_file);
2575 bdev_handle = bdev_handle2;2575 bdev_file = bdev_file2;
2576 if (IS_ERR(bdev_handle)) {2576 if (IS_ERR(bdev_file)) {
2577 ret = PTR_ERR(bdev_handle);2577 ret = PTR_ERR(bdev_file);
2578 bdev_handle = NULL;2578 bdev_file = NULL;
2579 if (ret == -EBUSY) {2579 if (ret == -EBUSY) {
2580 dev_t dev;2580 dev_t dev;
2581 2581
@@ -2610,7 +2610,7 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr, · 28 unmodified lines
2610 args->path = path;2610 args->path = path;
2611 args->sb = sb;2611 args->sb = sb;
2612 args->sb_disk = sb_disk;2612 args->sb_disk = sb_disk;
2613 args->bdev_handle = bdev_handle;2613 args->bdev_file = bdev_file;
2614 args->holder = holder;2614 args->holder = holder;
2615 register_device_async(args);2615 register_device_async(args);
2616 /* No wait and returns to user space */2616 /* 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
2619 2619
2620 if (SB_IS_BDEV(sb)) {2620 if (SB_IS_BDEV(sb)) {
2621 mutex_lock(&bch_register_lock);2621 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);
2623 mutex_unlock(&bch_register_lock);2623 mutex_unlock(&bch_register_lock);
2624 /* blkdev_put() will be called in cached_dev_free() */2624 /* blkdev_put() will be called in cached_dev_free() */
2625 if (ret < 0)2625 if (ret < 0)
2626 goto out_free_sb;2626 goto out_free_sb;
2627 } else {2627 } else {
2628 /* blkdev_put() will be called in bch_cache_release() */2628 /* 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);
2630 if (ret)2630 if (ret)
2631 goto out_free_sb;2631 goto out_free_sb;
2632 }2632 }
@@ -2642,8 +2642,8 @@ out_free_holder: · 9 unmodified lines
2642out_put_sb_page:2642out_put_sb_page:
2643 put_page(virt_to_page(sb_disk));2643 put_page(virt_to_page(sb_disk));
2644out_blkdev_put:2644out_blkdev_put:
2645 if (bdev_handle)2645 if (bdev_file)
2646 bdev_release(bdev_handle);2646 fput(bdev_file);
2647out_free_sb:2647out_free_sb:
2648 kfree(sb);2648 kfree(sb);
2649out_free_path:2649out_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
726 dev_t dev, blk_mode_t mode)726 dev_t dev, blk_mode_t mode)
727{727{
728 struct table_device *td;728 struct table_device *td;
729 struct bdev_handle *bdev_handle;729 struct file *bdev_file;
730 struct block_device *bdev;
730 u64 part_off;731 u64 part_off;
731 int r;732 int r;
732 733
@@ -735,34 +736,36 @@ static struct table_device *open_table_device(struct mapped_device *md, · 2 unmodified lines
735 return ERR_PTR(-ENOMEM);736 return ERR_PTR(-ENOMEM);
736 refcount_set(&td->count, 1);737 refcount_set(&td->count, 1);
737 738
738 bdev_handle = bdev_open_by_dev(dev, mode, _dm_claim_ptr, NULL);739 bdev_file = bdev_file_open_by_dev(dev, mode, _dm_claim_ptr, NULL);
739 if (IS_ERR(bdev_handle)) {740 if (IS_ERR(bdev_file)) {
740 r = PTR_ERR(bdev_handle);741 r = PTR_ERR(bdev_file);
741 goto out_free_td;742 goto out_free_td;
742 }743 }
743 744
745 bdev = file_bdev(bdev_file);
746
744 /*747 /*
745 * We can be called before the dm disk is added. In that case we can't748 * We can be called before the dm disk is added. In that case we can't
746 * register the holder relation here. It will be done once add_disk was749 * register the holder relation here. It will be done once add_disk was
747 * called.750 * called.
748 */751 */
749 if (md->disk->slave_dir) {752 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);
751 if (r)754 if (r)
752 goto out_blkdev_put;755 goto out_blkdev_put;
753 }756 }
754 757
755 td->dm_dev.mode = mode;758 td->dm_dev.mode = mode;
756 td->dm_dev.bdev = bdev_handle->bdev;759 td->dm_dev.bdev = bdev;
757 td->dm_dev.bdev_handle = bdev_handle;760 td->dm_dev.bdev_file = bdev_file;
758 td->dm_dev.dax_dev = fs_dax_get_by_bdev(bdev_handle->bdev, &part_off,761 td->dm_dev.dax_dev = fs_dax_get_by_bdev(bdev, &part_off,
759 NULL, NULL);762 NULL, NULL);
760 format_dev_t(td->dm_dev.name, dev);763 format_dev_t(td->dm_dev.name, dev);
761 list_add(&td->list, &md->table_devices);764 list_add(&td->list, &md->table_devices);
762 return td;765 return td;
763 766
764out_blkdev_put:767out_blkdev_put:
765 bdev_release(bdev_handle);768 fput(bdev_file);
766out_free_td:769out_free_td:
767 kfree(td);770 kfree(td);
768 return ERR_PTR(r);771 return ERR_PTR(r);
@@ -775,7 +778,7 @@ static void close_table_device(struct table_device *td, struct mapped_device *md · 6 unmodified lines
775{778{
776 if (md->disk->slave_dir)779 if (md->disk->slave_dir)
777 bd_unlink_disk_holder(td->dm_dev.bdev, md->disk);780 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);
779 put_dax(td->dm_dev.dax_dev);782 put_dax(td->dm_dev.dax_dev);
780 list_del(&td->list);783 list_del(&td->list);
781 kfree(td);784 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
2582 if (test_bit(AutoDetected, &rdev->flags))2582 if (test_bit(AutoDetected, &rdev->flags))
2583 md_autodetect_dev(rdev->bdev->bd_dev);2583 md_autodetect_dev(rdev->bdev->bd_dev);
2584#endif2584#endif
2585 bdev_release(rdev->bdev_handle);2585 fput(rdev->bdev_file);
2586 rdev->bdev = NULL;2586 rdev->bdev = NULL;
2587 kobject_put(&rdev->kobj);2587 kobject_put(&rdev->kobj);
2588}2588}
@@ -3777,16 +3777,16 @@ static struct md_rdev *md_import_device(dev_t newdev, int super_format, int supe · 1188 unmodified lines
3777 if (err)3777 if (err)
3778 goto out_clear_rdev;3778 goto out_clear_rdev;
3779 3779
3780 rdev->bdev_handle = bdev_open_by_dev(newdev,3780 rdev->bdev_file = bdev_file_open_by_dev(newdev,
3781 BLK_OPEN_READ | BLK_OPEN_WRITE,3781 BLK_OPEN_READ | BLK_OPEN_WRITE,
3782 super_format == -2 ? &claim_rdev : rdev, NULL);3782 super_format == -2 ? &claim_rdev : rdev, NULL);
3783 if (IS_ERR(rdev->bdev_handle)) {3783 if (IS_ERR(rdev->bdev_file)) {
3784 pr_warn("md: could not open device unknown-block(%u,%u).\n",3784 pr_warn("md: could not open device unknown-block(%u,%u).\n",
3785 MAJOR(newdev), MINOR(newdev));3785 MAJOR(newdev), MINOR(newdev));
3786 err = PTR_ERR(rdev->bdev_handle);3786 err = PTR_ERR(rdev->bdev_file);
3787 goto out_clear_rdev;3787 goto out_clear_rdev;
3788 }3788 }
3789 rdev->bdev = rdev->bdev_handle->bdev;3789 rdev->bdev = file_bdev(rdev->bdev_file);
3790 3790
3791 kobject_init(&rdev->kobj, &rdev_ktype);3791 kobject_init(&rdev->kobj, &rdev_ktype);
3792 3792
@@ -3817,7 +3817,7 @@ static struct md_rdev *md_import_device(dev_t newdev, int super_format, int supe · 24 unmodified lines
3817 return rdev;3817 return rdev;
3818 3818
3819out_blkdev_put:3819out_blkdev_put:
3820 bdev_release(rdev->bdev_handle);3820 fput(rdev->bdev_file);
3821out_clear_rdev:3821out_clear_rdev:
3822 md_rdev_clear(rdev);3822 md_rdev_clear(rdev);
3823out_free_rdev:3823out_free_rdev:
drivers/md/md.h+1−1
@@ -59,7 +59,7 @@ struct md_rdev { · 58 unmodified lines
59 */59 */
60 struct block_device *meta_bdev;60 struct block_device *meta_bdev;
61 struct block_device *bdev; /* block device handle */61 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 */
63 63
64 struct page *sb_page, *bb_page;64 struct page *sb_page, *bb_page;
65 int sb_loaded;65 int sb_loaded;
drivers/mtd/devices/block2mtd.c+21−25
@@ -37,7 +37,7 @@ · 36 unmodified lines
37/* Info for the block device */37/* Info for the block device */
38struct block2mtd_dev {38struct block2mtd_dev {
39 struct list_head list;39 struct list_head list;
40 struct bdev_handle *bdev_handle;40 struct file *bdev_file;
41 struct mtd_info mtd;41 struct mtd_info mtd;
42 struct mutex write_mutex;42 struct mutex write_mutex;
43};43};
@@ -55,8 +55,7 @@ static struct page *page_read(struct address_space *mapping, pgoff_t index) · 11 unmodified lines
55/* erase a specified part of the device */55/* erase a specified part of the device */
56static int _block2mtd_erase(struct block2mtd_dev *dev, loff_t to, size_t len)56static int _block2mtd_erase(struct block2mtd_dev *dev, loff_t to, size_t len)
57{57{
58 struct address_space *mapping =58 struct address_space *mapping = dev->bdev_file->f_mapping;
59 dev->bdev_handle->bdev->bd_inode->i_mapping;
60 struct page *page;59 struct page *page;
61 pgoff_t index = to >> PAGE_SHIFT; // page index60 pgoff_t index = to >> PAGE_SHIFT; // page index
62 int pages = len >> PAGE_SHIFT;61 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
106 size_t *retlen, u_char *buf)105 size_t *retlen, u_char *buf)
107{106{
108 struct block2mtd_dev *dev = mtd->priv;107 struct block2mtd_dev *dev = mtd->priv;
109 struct address_space *mapping =108 struct address_space *mapping = dev->bdev_file->f_mapping;
110 dev->bdev_handle->bdev->bd_inode->i_mapping;
111 struct page *page;109 struct page *page;
112 pgoff_t index = from >> PAGE_SHIFT;110 pgoff_t index = from >> PAGE_SHIFT;
113 int offset = from & (PAGE_SIZE-1);111 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
142 loff_t to, size_t len, size_t *retlen)140 loff_t to, size_t len, size_t *retlen)
143{141{
144 struct page *page;142 struct page *page;
145 struct address_space *mapping =143 struct address_space *mapping = dev->bdev_file->f_mapping;
146 dev->bdev_handle->bdev->bd_inode->i_mapping;
147 pgoff_t index = to >> PAGE_SHIFT; // page index144 pgoff_t index = to >> PAGE_SHIFT; // page index
148 int offset = to & ~PAGE_MASK; // page offset145 int offset = to & ~PAGE_MASK; // page offset
149 int cpylen;146 int cpylen;
@@ -198,7 +195,7 @@ static int block2mtd_write(struct mtd_info *mtd, loff_t to, size_t len, · 48 unmodified lines
198static void block2mtd_sync(struct mtd_info *mtd)195static void block2mtd_sync(struct mtd_info *mtd)
199{196{
200 struct block2mtd_dev *dev = mtd->priv;197 struct block2mtd_dev *dev = mtd->priv;
201 sync_blockdev(dev->bdev_handle->bdev);198 sync_blockdev(file_bdev(dev->bdev_file));
202 return;199 return;
203}200}
204 201
@@ -210,10 +207,9 @@ static void block2mtd_free_device(struct block2mtd_dev *dev) · 5 unmodified lines
210 207
211 kfree(dev->mtd.name);208 kfree(dev->mtd.name);
212 209
213 if (dev->bdev_handle) {210 if (dev->bdev_file) {
214 invalidate_mapping_pages(211 invalidate_mapping_pages(dev->bdev_file->f_mapping, 0, -1);
215 dev->bdev_handle->bdev->bd_inode->i_mapping, 0, -1);212 fput(dev->bdev_file);
216 bdev_release(dev->bdev_handle);
217 }213 }
218 214
219 kfree(dev);215 kfree(dev);
@@ -223,10 +219,10 @@ static void block2mtd_free_device(struct block2mtd_dev *dev) · 3 unmodified lines
223 * This function is marked __ref because it calls the __init marked219 * This function is marked __ref because it calls the __init marked
224 * early_lookup_bdev when called from the early boot code.220 * early_lookup_bdev when called from the early boot code.
225 */221 */
226static struct bdev_handle __ref *mdtblock_early_get_bdev(const char *devname,222static struct file __ref *mdtblock_early_get_bdev(const char *devname,
227 blk_mode_t mode, int timeout, struct block2mtd_dev *dev)223 blk_mode_t mode, int timeout, struct block2mtd_dev *dev)
228{224{
229 struct bdev_handle *bdev_handle = ERR_PTR(-ENODEV);225 struct file *bdev_file = ERR_PTR(-ENODEV);
230#ifndef MODULE226#ifndef MODULE
231 int i;227 int i;
232 228
@@ -234,7 +230,7 @@ static struct bdev_handle __ref *mdtblock_early_get_bdev(const char *devname, · 1 unmodified line
234 * We can't use early_lookup_bdev from a running system.230 * We can't use early_lookup_bdev from a running system.
235 */231 */
236 if (system_state >= SYSTEM_RUNNING)232 if (system_state >= SYSTEM_RUNNING)
237 return bdev_handle;233 return bdev_file;
238 234
239 /*235 /*
240 * We might not have the root device mounted at this point.236 * 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
253 wait_for_device_probe();249 wait_for_device_probe();
254 250
255 if (!early_lookup_bdev(devname, &devt)) {251 if (!early_lookup_bdev(devname, &devt)) {
256 bdev_handle = bdev_open_by_dev(devt, mode, dev, NULL);252 bdev_file = bdev_file_open_by_dev(devt, mode, dev, NULL);
257 if (!IS_ERR(bdev_handle))253 if (!IS_ERR(bdev_file))
258 break;254 break;
259 }255 }
260 }256 }
261#endif257#endif
262 return bdev_handle;258 return bdev_file;
263}259}
264 260
265static struct block2mtd_dev *add_device(char *devname, int erase_size,261static struct block2mtd_dev *add_device(char *devname, int erase_size,
266 char *label, int timeout)262 char *label, int timeout)
267{263{
268 const blk_mode_t mode = BLK_OPEN_READ | BLK_OPEN_WRITE;264 const blk_mode_t mode = BLK_OPEN_READ | BLK_OPEN_WRITE;
269 struct bdev_handle *bdev_handle;265 struct file *bdev_file;
270 struct block_device *bdev;266 struct block_device *bdev;
271 struct block2mtd_dev *dev;267 struct block2mtd_dev *dev;
272 char *name;268 char *name;
@@ -279,16 +275,16 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size, · 6 unmodified lines
279 return NULL;275 return NULL;
280 276
281 /* Get a handle on the device */277 /* Get a handle on the device */
282 bdev_handle = bdev_open_by_path(devname, mode, dev, NULL);278 bdev_file = bdev_file_open_by_path(devname, mode, dev, NULL);
283 if (IS_ERR(bdev_handle))279 if (IS_ERR(bdev_file))
284 bdev_handle = mdtblock_early_get_bdev(devname, mode, timeout,280 bdev_file = mdtblock_early_get_bdev(devname, mode, timeout,
285 dev);281 dev);
286 if (IS_ERR(bdev_handle)) {282 if (IS_ERR(bdev_file)) {
287 pr_err("error: cannot open device %s\n", devname);283 pr_err("error: cannot open device %s\n", devname);
288 goto err_free_block2mtd;284 goto err_free_block2mtd;
289 }285 }
290 dev->bdev_handle = bdev_handle;286 dev->bdev_file = bdev_file;
291 bdev = bdev_handle->bdev;287 bdev = file_bdev(bdev_file);
292 288
293 if (MAJOR(bdev->bd_dev) == MTD_BLOCK_MAJOR) {289 if (MAJOR(bdev->bd_dev) == MTD_BLOCK_MAJOR) {
294 pr_err("attempting to use an MTD device as a block device\n");290 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
50 50
51void nvmet_bdev_ns_disable(struct nvmet_ns *ns)51void nvmet_bdev_ns_disable(struct nvmet_ns *ns)
52{52{
53 if (ns->bdev_handle) {53 if (ns->bdev_file) {
54 bdev_release(ns->bdev_handle);54 fput(ns->bdev_file);
55 ns->bdev = NULL;55 ns->bdev = NULL;
56 ns->bdev_handle = NULL;56 ns->bdev_file = NULL;
57 }57 }
58}58}
59 59
@@ -85,18 +85,18 @@ int nvmet_bdev_ns_enable(struct nvmet_ns *ns) · 25 unmodified lines
85 if (ns->buffered_io)85 if (ns->buffered_io)
86 return -ENOTBLK;86 return -ENOTBLK;
87 87
88 ns->bdev_handle = bdev_open_by_path(ns->device_path,88 ns->bdev_file = bdev_file_open_by_path(ns->device_path,
89 BLK_OPEN_READ | BLK_OPEN_WRITE, NULL, NULL);89 BLK_OPEN_READ | BLK_OPEN_WRITE, NULL, NULL);
90 if (IS_ERR(ns->bdev_handle)) {90 if (IS_ERR(ns->bdev_file)) {
91 ret = PTR_ERR(ns->bdev_handle);91 ret = PTR_ERR(ns->bdev_file);
92 if (ret != -ENOTBLK) {92 if (ret != -ENOTBLK) {
93 pr_err("failed to open block device %s: (%d)\n",93 pr_err("failed to open block device %s: (%d)\n",
94 ns->device_path, ret);94 ns->device_path, ret);
95 }95 }
96 ns->bdev_handle = NULL;96 ns->bdev_file = NULL;
97 return ret;97 return ret;
98 }98 }
99 ns->bdev = ns->bdev_handle->bdev;99 ns->bdev = file_bdev(ns->bdev_file);
100 ns->size = bdev_nr_bytes(ns->bdev);100 ns->size = bdev_nr_bytes(ns->bdev);
101 ns->blksize_shift = blksize_bits(bdev_logical_block_size(ns->bdev));101 ns->blksize_shift = blksize_bits(bdev_logical_block_size(ns->bdev));
102 102
drivers/nvme/target/nvmet.h+1−1
@@ -58,7 +58,7 @@ · 57 unmodified lines
58 58
59struct nvmet_ns {59struct nvmet_ns {
60 struct percpu_ref ref;60 struct percpu_ref ref;
61 struct bdev_handle *bdev_handle;61 struct file *bdev_file;
62 struct block_device *bdev;62 struct block_device *bdev;
63 struct file *file;63 struct file *file;
64 bool readonly;64 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
412 KOBJ_CHANGE);412 KOBJ_CHANGE);
413 return 0;413 return 0;
414 }414 }
415 disk_uevent(device->block->bdev_handle->bdev->bd_disk,415 disk_uevent(file_bdev(device->block->bdev_file)->bd_disk,
416 KOBJ_CHANGE);416 KOBJ_CHANGE);
417 }417 }
418 return 0;418 return 0;
@@ -433,7 +433,7 @@ static int dasd_state_online_to_ready(struct dasd_device *device) · 14 unmodified lines
433 433
434 device->state = DASD_STATE_READY;434 device->state = DASD_STATE_READY;
435 if (device->block && !(device->features & DASD_FEATURE_USERAW))435 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,
437 KOBJ_CHANGE);437 KOBJ_CHANGE);
438 return 0;438 return 0;
439}439}
@@ -3588,7 +3588,7 @@ int dasd_generic_set_offline(struct ccw_device *cdev) · 3148 unmodified lines
3588 * in the other openers.3588 * in the other openers.
3589 */3589 */
3590 if (device->block) {3590 if (device->block) {
3591 max_count = device->block->bdev_handle ? 0 : -1;3591 max_count = device->block->bdev_file ? 0 : -1;
3592 open_count = atomic_read(&device->block->open_count);3592 open_count = atomic_read(&device->block->open_count);
3593 if (open_count > max_count) {3593 if (open_count > max_count) {
3594 if (open_count > 0)3594 if (open_count > 0)
@@ -3634,8 +3634,8 @@ int dasd_generic_set_offline(struct ccw_device *cdev) · 39 unmodified lines
3634 * so sync bdev first and then wait for our queues to become3634 * so sync bdev first and then wait for our queues to become
3635 * empty3635 * empty
3636 */3636 */
3637 if (device->block && device->block->bdev_handle)3637 if (device->block && device->block->bdev_file)
3638 bdev_mark_dead(device->block->bdev_handle->bdev, false);3638 bdev_mark_dead(file_bdev(device->block->bdev_file), false);
3639 dasd_schedule_device_bh(device);3639 dasd_schedule_device_bh(device);
3640 rc = wait_event_interruptible(shutdown_waitq,3640 rc = wait_event_interruptible(shutdown_waitq,
3641 _wait_for_empty_queues(device));3641 _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
127 */127 */
128int dasd_scan_partitions(struct dasd_block *block)128int dasd_scan_partitions(struct dasd_block *block)
129{129{
130 struct bdev_handle *bdev_handle;130 struct file *bdev_file;
131 int rc;131 int rc;
132 132
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,
134 NULL, NULL);134 NULL, NULL);
135 if (IS_ERR(bdev_handle)) {135 if (IS_ERR(bdev_file)) {
136 DBF_DEV_EVENT(DBF_ERR, block->base,136 DBF_DEV_EVENT(DBF_ERR, block->base,
137 "scan partitions error, blkdev_get returned %ld",137 "scan partitions error, blkdev_get returned %ld",
138 PTR_ERR(bdev_handle));138 PTR_ERR(bdev_file));
139 return -ENODEV;139 return -ENODEV;
140 }140 }
141 141
@@ -147,15 +147,15 @@ int dasd_scan_partitions(struct dasd_block *block) · 5 unmodified lines
147 "scan partitions error, rc %d", rc);147 "scan partitions error, rc %d", rc);
148 148
149 /*149 /*
150 * Since the matching bdev_release() call to the150 * Since the matching fput() call to the
151 * bdev_open_by_path() in this function is not called before151 * bdev_file_open_by_path() in this function is not called before
152 * dasd_destroy_partitions the offline open_count limit needs to be152 * dasd_destroy_partitions the offline open_count limit needs to be
153 * increased from 0 to 1. This is done by setting device->bdev_handle153 * increased from 0 to 1. This is done by setting device->bdev_file
154 * (see dasd_generic_set_offline). As long as the partition detection154 * (see dasd_generic_set_offline). As long as the partition detection
155 * is running no offline should be allowed. That is why the assignment155 * 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.
157 */157 */
158 block->bdev_handle = bdev_handle;158 block->bdev_file = bdev_file;
159 return 0;159 return 0;
160}160}
161 161
@@ -165,21 +165,21 @@ int dasd_scan_partitions(struct dasd_block *block) · 3 unmodified lines
165 */165 */
166void dasd_destroy_partitions(struct dasd_block *block)166void dasd_destroy_partitions(struct dasd_block *block)
167{167{
168 struct bdev_handle *bdev_handle;168 struct file *bdev_file;
169 169
170 /*170 /*
171 * Get the bdev_handle pointer from the device structure and clear171 * Get the bdev_file pointer from the device structure and clear
172 * device->bdev_handle to lower the offline open_count limit again.172 * device->bdev_file to lower the offline open_count limit again.
173 */173 */
174 bdev_handle = block->bdev_handle;174 bdev_file = block->bdev_file;
175 block->bdev_handle = NULL;175 block->bdev_file = NULL;
176 176
177 mutex_lock(&bdev_handle->bdev->bd_disk->open_mutex);177 mutex_lock(&file_bdev(bdev_file)->bd_disk->open_mutex);
178 bdev_disk_changed(bdev_handle->bdev->bd_disk, true);178 bdev_disk_changed(file_bdev(bdev_file)->bd_disk, true);
179 mutex_unlock(&bdev_handle->bdev->bd_disk->open_mutex);179 mutex_unlock(&file_bdev(bdev_file)->bd_disk->open_mutex);
180 180
181 /* Matching blkdev_put to the blkdev_get in dasd_scan_partitions. */181 /* Matching blkdev_put to the blkdev_get in dasd_scan_partitions. */
182 bdev_release(bdev_handle);182 fput(bdev_file);
183}183}
184 184
185int dasd_gendisk_init(void)185int dasd_gendisk_init(void)
drivers/s390/block/dasd_int.h+1−1
@@ -650,7 +650,7 @@ struct dasd_block { · 649 unmodified lines
650 struct gendisk *gdp;650 struct gendisk *gdp;
651 spinlock_t request_queue_lock;651 spinlock_t request_queue_lock;
652 struct blk_mq_tag_set tag_set;652 struct blk_mq_tag_set tag_set;
653 struct bdev_handle *bdev_handle;653 struct file *bdev_file;
654 atomic_t open_count;654 atomic_t open_count;
655 655
656 unsigned long blocks; /* size of volume in blocks */656 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
537 * This must be hidden from user-space.537 * This must be hidden from user-space.
538 */538 */
539 dasd_info->open_count = atomic_read(&block->open_count);539 dasd_info->open_count = atomic_read(&block->open_count);
540 if (!block->bdev_handle)540 if (!block->bdev_file)
541 dasd_info->open_count++;541 dasd_info->open_count++;
542 542
543 /*543 /*
drivers/target/target_core_iblock.c+9−9
@@ -91,7 +91,7 @@ static int iblock_configure_device(struct se_device *dev) · 90 unmodified lines
91{91{
92 struct iblock_dev *ib_dev = IBLOCK_DEV(dev);92 struct iblock_dev *ib_dev = IBLOCK_DEV(dev);
93 struct request_queue *q;93 struct request_queue *q;
94 struct bdev_handle *bdev_handle;94 struct file *bdev_file;
95 struct block_device *bd;95 struct block_device *bd;
96 struct blk_integrity *bi;96 struct blk_integrity *bi;
97 blk_mode_t mode = BLK_OPEN_READ;97 blk_mode_t mode = BLK_OPEN_READ;
@@ -117,14 +117,14 @@ static int iblock_configure_device(struct se_device *dev) · 19 unmodified lines
117 else117 else
118 dev->dev_flags |= DF_READ_ONLY;118 dev->dev_flags |= DF_READ_ONLY;
119 119
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,
121 NULL);121 NULL);
122 if (IS_ERR(bdev_handle)) {122 if (IS_ERR(bdev_file)) {
123 ret = PTR_ERR(bdev_handle);123 ret = PTR_ERR(bdev_file);
124 goto out_free_bioset;124 goto out_free_bioset;
125 }125 }
126 ib_dev->ibd_bdev_handle = bdev_handle;126 ib_dev->ibd_bdev_file = bdev_file;
127 ib_dev->ibd_bd = bd = bdev_handle->bdev;127 ib_dev->ibd_bd = bd = file_bdev(bdev_file);
128 128
129 q = bdev_get_queue(bd);129 q = bdev_get_queue(bd);
130 130
@@ -180,7 +180,7 @@ static int iblock_configure_device(struct se_device *dev) · 49 unmodified lines
180 return 0;180 return 0;
181 181
182out_blkdev_put:182out_blkdev_put:
183 bdev_release(ib_dev->ibd_bdev_handle);183 fput(ib_dev->ibd_bdev_file);
184out_free_bioset:184out_free_bioset:
185 bioset_exit(&ib_dev->ibd_bio_set);185 bioset_exit(&ib_dev->ibd_bio_set);
186out:186out:
@@ -205,8 +205,8 @@ static void iblock_destroy_device(struct se_device *dev) · 18 unmodified lines
205{205{
206 struct iblock_dev *ib_dev = IBLOCK_DEV(dev);206 struct iblock_dev *ib_dev = IBLOCK_DEV(dev);
207 207
208 if (ib_dev->ibd_bdev_handle)208 if (ib_dev->ibd_bdev_file)
209 bdev_release(ib_dev->ibd_bdev_handle);209 fput(ib_dev->ibd_bdev_file);
210 bioset_exit(&ib_dev->ibd_bio_set);210 bioset_exit(&ib_dev->ibd_bio_set);
211}211}
212 212
drivers/target/target_core_iblock.h+1−1
@@ -32,7 +32,7 @@ struct iblock_dev { · 31 unmodified lines
32 u32 ibd_flags;32 u32 ibd_flags;
33 struct bio_set ibd_bio_set;33 struct bio_set ibd_bio_set;
34 struct block_device *ibd_bd;34 struct block_device *ibd_bd;
35 struct bdev_handle *ibd_bdev_handle;35 struct file *ibd_bdev_file;
36 bool ibd_readonly;36 bool ibd_readonly;
37 struct iblock_dev_plug *ibd_plug;37 struct iblock_dev_plug *ibd_plug;
38} ____cacheline_aligned;38} ____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
352 struct pscsi_hba_virt *phv = dev->se_hba->hba_ptr;352 struct pscsi_hba_virt *phv = dev->se_hba->hba_ptr;
353 struct pscsi_dev_virt *pdv = PSCSI_DEV(dev);353 struct pscsi_dev_virt *pdv = PSCSI_DEV(dev);
354 struct Scsi_Host *sh = sd->host;354 struct Scsi_Host *sh = sd->host;
355 struct bdev_handle *bdev_handle;355 struct file *bdev_file;
356 int ret;356 int ret;
357 357
358 if (scsi_device_get(sd)) {358 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
366 * Claim exclusive struct block_device access to struct scsi_device366 * Claim exclusive struct block_device access to struct scsi_device
367 * for TYPE_DISK and TYPE_ZBC using supplied udev_path367 * for TYPE_DISK and TYPE_ZBC using supplied udev_path
368 */368 */
369 bdev_handle = bdev_open_by_path(dev->udev_path,369 bdev_file = bdev_file_open_by_path(dev->udev_path,
370 BLK_OPEN_WRITE | BLK_OPEN_READ, pdv, NULL);370 BLK_OPEN_WRITE | BLK_OPEN_READ, pdv, NULL);
371 if (IS_ERR(bdev_handle)) {371 if (IS_ERR(bdev_file)) {
372 pr_err("pSCSI: bdev_open_by_path() failed\n");372 pr_err("pSCSI: bdev_open_by_path() failed\n");
373 scsi_device_put(sd);373 scsi_device_put(sd);
374 return PTR_ERR(bdev_handle);374 return PTR_ERR(bdev_file);
375 }375 }
376 pdv->pdv_bdev_handle = bdev_handle;376 pdv->pdv_bdev_file = bdev_file;
377 377
378 ret = pscsi_add_device_to_list(dev, sd);378 ret = pscsi_add_device_to_list(dev, sd);
379 if (ret) {379 if (ret) {
380 bdev_release(bdev_handle);380 fput(bdev_file);
381 scsi_device_put(sd);381 scsi_device_put(sd);
382 return ret;382 return ret;
383 }383 }
@@ -564,9 +564,9 @@ static void pscsi_destroy_device(struct se_device *dev) · 180 unmodified lines
564 * from pscsi_create_type_disk()564 * from pscsi_create_type_disk()
565 */565 */
566 if ((sd->type == TYPE_DISK || sd->type == TYPE_ZBC) &&566 if ((sd->type == TYPE_DISK || sd->type == TYPE_ZBC) &&
567 pdv->pdv_bdev_handle) {567 pdv->pdv_bdev_file) {
568 bdev_release(pdv->pdv_bdev_handle);568 fput(pdv->pdv_bdev_file);
569 pdv->pdv_bdev_handle = NULL;569 pdv->pdv_bdev_file = NULL;
570 }570 }
571 /*571 /*
572 * For HBA mode PHV_LLD_SCSI_HOST_NO, release the reference572 * 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
997{997{
998 struct pscsi_dev_virt *pdv = PSCSI_DEV(dev);998 struct pscsi_dev_virt *pdv = PSCSI_DEV(dev);
999 999
1000 if (pdv->pdv_bdev_handle)1000 if (pdv->pdv_bdev_file)
1001 return bdev_nr_sectors(pdv->pdv_bdev_handle->bdev);1001 return bdev_nr_sectors(file_bdev(pdv->pdv_bdev_file));
1002 return 0;1002 return 0;
1003}1003}
1004 1004
drivers/target/target_core_pscsi.h+1−1
@@ -37,7 +37,7 @@ struct pscsi_dev_virt { · 36 unmodified lines
37 int pdv_channel_id;37 int pdv_channel_id;
38 int pdv_target_id;38 int pdv_target_id;
39 int pdv_lun_id;39 int pdv_lun_id;
40 struct bdev_handle *pdv_bdev_handle;40 struct file *pdv_bdev_file;
41 struct scsi_device *pdv_sd;41 struct scsi_device *pdv_sd;
42 struct Scsi_Host *pdv_lld_host;42 struct Scsi_Host *pdv_lld_host;
43} ____cacheline_aligned;43} ____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
142void bch2_free_super(struct bch_sb_handle *sb)142void bch2_free_super(struct bch_sb_handle *sb)
143{143{
144 kfree(sb->bio);144 kfree(sb->bio);
145 if (!IS_ERR_OR_NULL(sb->bdev_handle))145 if (!IS_ERR_OR_NULL(sb->s_bdev_file))
146 bdev_release(sb->bdev_handle);146 fput(sb->s_bdev_file);
147 kfree(sb->holder);147 kfree(sb->holder);
148 kfree(sb->sb_name);148 kfree(sb->sb_name);
149 149
@@ -704,22 +704,22 @@ retry: · 554 unmodified lines
704 if (!opt_get(*opts, nochanges))704 if (!opt_get(*opts, nochanges))
705 sb->mode |= BLK_OPEN_WRITE;705 sb->mode |= BLK_OPEN_WRITE;
706 706
707 sb->bdev_handle = bdev_open_by_path(path, sb->mode, sb->holder, &bch2_sb_handle_bdev_ops);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->bdev_handle) &&708 if (IS_ERR(sb->s_bdev_file) &&
709 PTR_ERR(sb->bdev_handle) == -EACCES &&709 PTR_ERR(sb->s_bdev_file) == -EACCES &&
710 opt_get(*opts, read_only)) {710 opt_get(*opts, read_only)) {
711 sb->mode &= ~BLK_OPEN_WRITE;711 sb->mode &= ~BLK_OPEN_WRITE;
712 712
713 sb->bdev_handle = bdev_open_by_path(path, sb->mode, sb->holder, &bch2_sb_handle_bdev_ops);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->bdev_handle))714 if (!IS_ERR(sb->s_bdev_file))
715 opt_set(*opts, nochanges, true);715 opt_set(*opts, nochanges, true);
716 }716 }
717 717
718 if (IS_ERR(sb->bdev_handle)) {718 if (IS_ERR(sb->s_bdev_file)) {
719 ret = PTR_ERR(sb->bdev_handle);719 ret = PTR_ERR(sb->s_bdev_file);
720 goto err;720 goto err;
721 }721 }
722 sb->bdev = sb->bdev_handle->bdev;722 sb->bdev = file_bdev(sb->s_bdev_file);
723 723
724 ret = bch2_sb_realloc(sb, 0);724 ret = bch2_sb_realloc(sb, 0);
725 if (ret) {725 if (ret) {
fs/bcachefs/super_types.h+1−1
@@ -4,7 +4,7 @@ · 3 unmodified lines
4 4
5struct bch_sb_handle {5struct bch_sb_handle {
6 struct bch_sb *sb;6 struct bch_sb *sb;
7 struct bdev_handle *bdev_handle;7 struct file *s_bdev_file;
8 struct block_device *bdev;8 struct block_device *bdev;
9 char *sb_name;9 char *sb_name;
10 struct bio *bio;10 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
246{246{
247 struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;247 struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
248 struct btrfs_device *device;248 struct btrfs_device *device;
249 struct bdev_handle *bdev_handle;249 struct file *bdev_file;
250 struct block_device *bdev;250 struct block_device *bdev;
251 u64 devid = BTRFS_DEV_REPLACE_DEVID;251 u64 devid = BTRFS_DEV_REPLACE_DEVID;
252 int ret = 0;252 int ret = 0;
@@ -257,13 +257,13 @@ static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, · 4 unmodified lines
257 return -EINVAL;257 return -EINVAL;
258 }258 }
259 259
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,
261 fs_info->bdev_holder, NULL);261 fs_info->bdev_holder, NULL);
262 if (IS_ERR(bdev_handle)) {262 if (IS_ERR(bdev_file)) {
263 btrfs_err(fs_info, "target device %s is invalid!", device_path);263 btrfs_err(fs_info, "target device %s is invalid!", device_path);
264 return PTR_ERR(bdev_handle);264 return PTR_ERR(bdev_file);
265 }265 }
266 bdev = bdev_handle->bdev;266 bdev = file_bdev(bdev_file);
267 267
268 if (!btrfs_check_device_zone_type(fs_info, bdev)) {268 if (!btrfs_check_device_zone_type(fs_info, bdev)) {
269 btrfs_err(fs_info,269 btrfs_err(fs_info,
@@ -314,7 +314,7 @@ static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, · 44 unmodified lines
314 device->commit_bytes_used = device->bytes_used;314 device->commit_bytes_used = device->bytes_used;
315 device->fs_info = fs_info;315 device->fs_info = fs_info;
316 device->bdev = bdev;316 device->bdev = bdev;
317 device->bdev_handle = bdev_handle;317 device->bdev_file = bdev_file;
318 set_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state);318 set_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state);
319 set_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state);319 set_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state);
320 device->dev_stats_valid = 1;320 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
335 return 0;335 return 0;
336 336
337error:337error:
338 bdev_release(bdev_handle);338 fput(bdev_file);
339 return ret;339 return ret;
340}340}
341 341
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
2698 struct inode *inode = file_inode(file);2698 struct inode *inode = file_inode(file);
2699 struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);2699 struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
2700 struct btrfs_ioctl_vol_args_v2 *vol_args;2700 struct btrfs_ioctl_vol_args_v2 *vol_args;
2701 struct bdev_handle *bdev_handle = NULL;2701 struct file *bdev_file = NULL;
2702 int ret;2702 int ret;
2703 bool cancel = false;2703 bool cancel = false;
2704 2704
@@ -2735,7 +2735,7 @@ static long btrfs_ioctl_rm_dev_v2(struct file *file, void __user *arg) · 30 unmodified lines
2735 goto err_drop;2735 goto err_drop;
2736 2736
2737 /* Exclusive operation is now claimed */2737 /* 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);
2739 2739
2740 btrfs_exclop_finish(fs_info);2740 btrfs_exclop_finish(fs_info);
2741 2741
@@ -2749,8 +2749,8 @@ static long btrfs_ioctl_rm_dev_v2(struct file *file, void __user *arg) · 7 unmodified lines
2749 }2749 }
2750err_drop:2750err_drop:
2751 mnt_drop_write_file(file);2751 mnt_drop_write_file(file);
2752 if (bdev_handle)2752 if (bdev_file)
2753 bdev_release(bdev_handle);2753 fput(bdev_file);
2754out:2754out:
2755 btrfs_put_dev_args_from_path(&args);2755 btrfs_put_dev_args_from_path(&args);
2756 kfree(vol_args);2756 kfree(vol_args);
@@ -2763,7 +2763,7 @@ static long btrfs_ioctl_rm_dev(struct file *file, void __user *arg) · 6 unmodified lines
2763 struct inode *inode = file_inode(file);2763 struct inode *inode = file_inode(file);
2764 struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);2764 struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
2765 struct btrfs_ioctl_vol_args *vol_args;2765 struct btrfs_ioctl_vol_args *vol_args;
2766 struct bdev_handle *bdev_handle = NULL;2766 struct file *bdev_file = NULL;
2767 int ret;2767 int ret;
2768 bool cancel = false;2768 bool cancel = false;
2769 2769
@@ -2790,15 +2790,15 @@ static long btrfs_ioctl_rm_dev(struct file *file, void __user *arg) · 20 unmodified lines
2790 ret = exclop_start_or_cancel_reloc(fs_info, BTRFS_EXCLOP_DEV_REMOVE,2790 ret = exclop_start_or_cancel_reloc(fs_info, BTRFS_EXCLOP_DEV_REMOVE,
2791 cancel);2791 cancel);
2792 if (ret == 0) {2792 if (ret == 0) {
2793 ret = btrfs_rm_device(fs_info, &args, &bdev_handle);2793 ret = btrfs_rm_device(fs_info, &args, &bdev_file);
2794 if (!ret)2794 if (!ret)
2795 btrfs_info(fs_info, "disk deleted %s", vol_args->name);2795 btrfs_info(fs_info, "disk deleted %s", vol_args->name);
2796 btrfs_exclop_finish(fs_info);2796 btrfs_exclop_finish(fs_info);
2797 }2797 }
2798 2798
2799 mnt_drop_write_file(file);2799 mnt_drop_write_file(file);
2800 if (bdev_handle)2800 if (bdev_file)
2801 bdev_release(bdev_handle);2801 fput(bdev_file);
2802out:2802out:
2803 btrfs_put_dev_args_from_path(&args);2803 btrfs_put_dev_args_from_path(&args);
2804 kfree(vol_args);2804 kfree(vol_args);
fs/btrfs/volumes.c+46−46
@@ -468,39 +468,39 @@ static noinline struct btrfs_fs_devices *find_fsid( · 467 unmodified lines
468 468
469static int469static int
470btrfs_get_bdev_and_sb(const char *device_path, blk_mode_t flags, void *holder,470btrfs_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,
472 struct btrfs_super_block **disk_super)472 struct btrfs_super_block **disk_super)
473{473{
474 struct block_device *bdev;474 struct block_device *bdev;
475 int ret;475 int ret;
476 476
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);
478 478
479 if (IS_ERR(*bdev_handle)) {479 if (IS_ERR(*bdev_file)) {
480 ret = PTR_ERR(*bdev_handle);480 ret = PTR_ERR(*bdev_file);
481 goto error;481 goto error;
482 }482 }
483 bdev = (*bdev_handle)->bdev;483 bdev = file_bdev(*bdev_file);
484 484
485 if (flush)485 if (flush)
486 sync_blockdev(bdev);486 sync_blockdev(bdev);
487 ret = set_blocksize(bdev, BTRFS_BDEV_BLOCKSIZE);487 ret = set_blocksize(bdev, BTRFS_BDEV_BLOCKSIZE);
488 if (ret) {488 if (ret) {
489 bdev_release(*bdev_handle);489 fput(*bdev_file);
490 goto error;490 goto error;
491 }491 }
492 invalidate_bdev(bdev);492 invalidate_bdev(bdev);
493 *disk_super = btrfs_read_dev_super(bdev);493 *disk_super = btrfs_read_dev_super(bdev);
494 if (IS_ERR(*disk_super)) {494 if (IS_ERR(*disk_super)) {
495 ret = PTR_ERR(*disk_super);495 ret = PTR_ERR(*disk_super);
496 bdev_release(*bdev_handle);496 fput(*bdev_file);
497 goto error;497 goto error;
498 }498 }
499 499
500 return 0;500 return 0;
501 501
502error:502error:
503 *bdev_handle = NULL;503 *bdev_file = NULL;
504 return ret;504 return ret;
505}505}
506 506
@@ -643,7 +643,7 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices, · 136 unmodified lines
643 struct btrfs_device *device, blk_mode_t flags,643 struct btrfs_device *device, blk_mode_t flags,
644 void *holder)644 void *holder)
645{645{
646 struct bdev_handle *bdev_handle;646 struct file *bdev_file;
647 struct btrfs_super_block *disk_super;647 struct btrfs_super_block *disk_super;
648 u64 devid;648 u64 devid;
649 int ret;649 int ret;
@@ -654,7 +654,7 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices, · 4 unmodified lines
654 return -EINVAL;654 return -EINVAL;
655 655
656 ret = btrfs_get_bdev_and_sb(device->name->str, flags, holder, 1,656 ret = btrfs_get_bdev_and_sb(device->name->str, flags, holder, 1,
657 &bdev_handle, &disk_super);657 &bdev_file, &disk_super);
658 if (ret)658 if (ret)
659 return ret;659 return ret;
660 660
@@ -678,20 +678,20 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices, · 17 unmodified lines
678 clear_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state);678 clear_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state);
679 fs_devices->seeding = true;679 fs_devices->seeding = true;
680 } else {680 } else {
681 if (bdev_read_only(bdev_handle->bdev))681 if (bdev_read_only(file_bdev(bdev_file)))
682 clear_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state);682 clear_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state);
683 else683 else
684 set_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state);684 set_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state);
685 }685 }
686 686
687 if (!bdev_nonrot(bdev_handle->bdev))687 if (!bdev_nonrot(file_bdev(bdev_file)))
688 fs_devices->rotating = true;688 fs_devices->rotating = true;
689 689
690 if (bdev_max_discard_sectors(bdev_handle->bdev))690 if (bdev_max_discard_sectors(file_bdev(bdev_file)))
691 fs_devices->discardable = true;691 fs_devices->discardable = true;
692 692
693 device->bdev_handle = bdev_handle;693 device->bdev_file = bdev_file;
694 device->bdev = bdev_handle->bdev;694 device->bdev = file_bdev(bdev_file);
695 clear_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state);695 clear_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state);
696 696
697 fs_devices->open_devices++;697 fs_devices->open_devices++;
@@ -706,7 +706,7 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices, · 8 unmodified lines
706 706
707error_free_page:707error_free_page:
708 btrfs_release_disk_super(disk_super);708 btrfs_release_disk_super(disk_super);
709 bdev_release(bdev_handle);709 fput(bdev_file);
710 710
711 return -EINVAL;711 return -EINVAL;
712}712}
@@ -1015,10 +1015,10 @@ static void __btrfs_free_extra_devids(struct btrfs_fs_devices *fs_devices, · 302 unmodified lines
1015 if (device->devid == BTRFS_DEV_REPLACE_DEVID)1015 if (device->devid == BTRFS_DEV_REPLACE_DEVID)
1016 continue;1016 continue;
1017 1017
1018 if (device->bdev_handle) {1018 if (device->bdev_file) {
1019 bdev_release(device->bdev_handle);1019 fput(device->bdev_file);
1020 device->bdev = NULL;1020 device->bdev = NULL;
1021 device->bdev_handle = NULL;1021 device->bdev_file = NULL;
1022 fs_devices->open_devices--;1022 fs_devices->open_devices--;
1023 }1023 }
1024 if (test_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state)) {1024 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
1063 invalidate_bdev(device->bdev);1063 invalidate_bdev(device->bdev);
1064 }1064 }
1065 1065
1066 bdev_release(device->bdev_handle);1066 fput(device->bdev_file);
1067}1067}
1068 1068
1069static void btrfs_close_one_device(struct btrfs_device *device)1069static 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
1316 struct btrfs_super_block *disk_super;1316 struct btrfs_super_block *disk_super;
1317 bool new_device_added = false;1317 bool new_device_added = false;
1318 struct btrfs_device *device = NULL;1318 struct btrfs_device *device = NULL;
1319 struct bdev_handle *bdev_handle;1319 struct file *bdev_file;
1320 u64 bytenr, bytenr_orig;1320 u64 bytenr, bytenr_orig;
1321 int ret;1321 int ret;
1322 1322
@@ -1339,18 +1339,18 @@ struct btrfs_device *btrfs_scan_one_device(const char *path, blk_mode_t flags, · 16 unmodified lines
1339 * values temporarily, as the device paths of the fsid are the only1339 * values temporarily, as the device paths of the fsid are the only
1340 * required information for assembling the volume.1340 * required information for assembling the volume.
1341 */1341 */
1342 bdev_handle = bdev_open_by_path(path, flags, NULL, NULL);1342 bdev_file = bdev_file_open_by_path(path, flags, NULL, NULL);
1343 if (IS_ERR(bdev_handle))1343 if (IS_ERR(bdev_file))
1344 return ERR_CAST(bdev_handle);1344 return ERR_CAST(bdev_file);
1345 1345
1346 bytenr_orig = btrfs_sb_offset(0);1346 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);
1348 if (ret) {1348 if (ret) {
1349 device = ERR_PTR(ret);1349 device = ERR_PTR(ret);
1350 goto error_bdev_put;1350 goto error_bdev_put;
1351 }1351 }
1352 1352
1353 disk_super = btrfs_read_disk_super(bdev_handle->bdev, bytenr,1353 disk_super = btrfs_read_disk_super(file_bdev(bdev_file), bytenr,
1354 bytenr_orig);1354 bytenr_orig);
1355 if (IS_ERR(disk_super)) {1355 if (IS_ERR(disk_super)) {
1356 device = ERR_CAST(disk_super);1356 device = ERR_CAST(disk_super);
@@ -1381,7 +1381,7 @@ free_disk_super: · 24 unmodified lines
1381 btrfs_release_disk_super(disk_super);1381 btrfs_release_disk_super(disk_super);
1382 1382
1383error_bdev_put:1383error_bdev_put:
1384 bdev_release(bdev_handle);1384 fput(bdev_file);
1385 1385
1386 return device;1386 return device;
1387}1387}
@@ -2057,7 +2057,7 @@ void btrfs_scratch_superblocks(struct btrfs_fs_info *fs_info, · 669 unmodified lines
2057 2057
2058int btrfs_rm_device(struct btrfs_fs_info *fs_info,2058int btrfs_rm_device(struct btrfs_fs_info *fs_info,
2059 struct btrfs_dev_lookup_args *args,2059 struct btrfs_dev_lookup_args *args,
2060 struct bdev_handle **bdev_handle)2060 struct file **bdev_file)
2061{2061{
2062 struct btrfs_trans_handle *trans;2062 struct btrfs_trans_handle *trans;
2063 struct btrfs_device *device;2063 struct btrfs_device *device;
@@ -2166,7 +2166,7 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info, · 102 unmodified lines
2166 2166
2167 btrfs_assign_next_active_device(device, NULL);2167 btrfs_assign_next_active_device(device, NULL);
2168 2168
2169 if (device->bdev_handle) {2169 if (device->bdev_file) {
2170 cur_devices->open_devices--;2170 cur_devices->open_devices--;
2171 /* remove sysfs entry */2171 /* remove sysfs entry */
2172 btrfs_sysfs_remove_device(device);2172 btrfs_sysfs_remove_device(device);
@@ -2182,9 +2182,9 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info, · 9 unmodified lines
2182 * free the device.2182 * free the device.
2183 *2183 *
2184 * We cannot call btrfs_close_bdev() here because we're holding the sb2184 * 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 on2185 * write lock, and fput() on the block device will pull in the
2186 * the block device and it's dependencies. Instead just flush the2186 * ->open_mutex on the block device and it's dependencies. Instead
2187 * device and let the caller do the final bdev_release.2187 * just flush the device and let the caller do the final bdev_release.
2188 */2188 */
2189 if (test_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state)) {2189 if (test_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state)) {
2190 btrfs_scratch_superblocks(fs_info, device->bdev,2190 btrfs_scratch_superblocks(fs_info, device->bdev,
@@ -2195,7 +2195,7 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info, · 4 unmodified lines
2195 }2195 }
2196 }2196 }
2197 2197
2198 *bdev_handle = device->bdev_handle;2198 *bdev_file = device->bdev_file;
2199 synchronize_rcu();2199 synchronize_rcu();
2200 btrfs_free_device(device);2200 btrfs_free_device(device);
2201 2201
@@ -2332,7 +2332,7 @@ int btrfs_get_dev_args_from_path(struct btrfs_fs_info *fs_info, · 130 unmodified lines
2332 const char *path)2332 const char *path)
2333{2333{
2334 struct btrfs_super_block *disk_super;2334 struct btrfs_super_block *disk_super;
2335 struct bdev_handle *bdev_handle;2335 struct file *bdev_file;
2336 int ret;2336 int ret;
2337 2337
2338 if (!path || !path[0])2338 if (!path || !path[0])
@@ -2350,7 +2350,7 @@ int btrfs_get_dev_args_from_path(struct btrfs_fs_info *fs_info, · 11 unmodified lines
2350 }2350 }
2351 2351
2352 ret = btrfs_get_bdev_and_sb(path, BLK_OPEN_READ, NULL, 0,2352 ret = btrfs_get_bdev_and_sb(path, BLK_OPEN_READ, NULL, 0,
2353 &bdev_handle, &disk_super);2353 &bdev_file, &disk_super);
2354 if (ret) {2354 if (ret) {
2355 btrfs_put_dev_args_from_path(args);2355 btrfs_put_dev_args_from_path(args);
2356 return ret;2356 return ret;
@@ -2363,7 +2363,7 @@ int btrfs_get_dev_args_from_path(struct btrfs_fs_info *fs_info, · 6 unmodified lines
2363 else2363 else
2364 memcpy(args->fsid, disk_super->fsid, BTRFS_FSID_SIZE);2364 memcpy(args->fsid, disk_super->fsid, BTRFS_FSID_SIZE);
2365 btrfs_release_disk_super(disk_super);2365 btrfs_release_disk_super(disk_super);
2366 bdev_release(bdev_handle);2366 fput(bdev_file);
2367 return 0;2367 return 0;
2368}2368}
2369 2369
@@ -2583,7 +2583,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path · 213 unmodified lines
2583 struct btrfs_root *root = fs_info->dev_root;2583 struct btrfs_root *root = fs_info->dev_root;
2584 struct btrfs_trans_handle *trans;2584 struct btrfs_trans_handle *trans;
2585 struct btrfs_device *device;2585 struct btrfs_device *device;
2586 struct bdev_handle *bdev_handle;2586 struct file *bdev_file;
2587 struct super_block *sb = fs_info->sb;2587 struct super_block *sb = fs_info->sb;
2588 struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;2588 struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
2589 struct btrfs_fs_devices *seed_devices = NULL;2589 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
2596 if (sb_rdonly(sb) && !fs_devices->seeding)2596 if (sb_rdonly(sb) && !fs_devices->seeding)
2597 return -EROFS;2597 return -EROFS;
2598 2598
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,
2600 fs_info->bdev_holder, NULL);2600 fs_info->bdev_holder, NULL);
2601 if (IS_ERR(bdev_handle))2601 if (IS_ERR(bdev_file))
2602 return PTR_ERR(bdev_handle);2602 return PTR_ERR(bdev_file);
2603 2603
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))) {
2605 ret = -EINVAL;2605 ret = -EINVAL;
2606 goto error;2606 goto error;
2607 }2607 }
@@ -2613,11 +2613,11 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path · 5 unmodified lines
2613 locked = true;2613 locked = true;
2614 }2614 }
2615 2615
2616 sync_blockdev(bdev_handle->bdev);2616 sync_blockdev(file_bdev(bdev_file));
2617 2617
2618 rcu_read_lock();2618 rcu_read_lock();
2619 list_for_each_entry_rcu(device, &fs_devices->devices, dev_list) {2619 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)) {
2621 ret = -EEXIST;2621 ret = -EEXIST;
2622 rcu_read_unlock();2622 rcu_read_unlock();
2623 goto error;2623 goto error;
@@ -2633,8 +2633,8 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path · 9 unmodified lines
2633 }2633 }
2634 2634
2635 device->fs_info = fs_info;2635 device->fs_info = fs_info;
2636 device->bdev_handle = bdev_handle;2636 device->bdev_file = bdev_file;
2637 device->bdev = bdev_handle->bdev;2637 device->bdev = file_bdev(bdev_file);
2638 ret = lookup_bdev(device_path, &device->devt);2638 ret = lookup_bdev(device_path, &device->devt);
2639 if (ret)2639 if (ret)
2640 goto error_free_device;2640 goto error_free_device;
@@ -2817,7 +2817,7 @@ error_free_zone: · 176 unmodified lines
2817error_free_device:2817error_free_device:
2818 btrfs_free_device(device);2818 btrfs_free_device(device);
2819error:2819error:
2820 bdev_release(bdev_handle);2820 fput(bdev_file);
2821 if (locked) {2821 if (locked) {
2822 mutex_unlock(&uuid_mutex);2822 mutex_unlock(&uuid_mutex);
2823 up_write(&sb->s_umount);2823 up_write(&sb->s_umount);
fs/btrfs/volumes.h+2−2
@@ -90,7 +90,7 @@ struct btrfs_device { · 89 unmodified lines
90 90
91 u64 generation;91 u64 generation;
92 92
93 struct bdev_handle *bdev_handle;93 struct file *bdev_file;
94 struct block_device *bdev;94 struct block_device *bdev;
95 95
96 struct btrfs_zoned_device_info *zone_info;96 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
661void btrfs_put_dev_args_from_path(struct btrfs_dev_lookup_args *args);661void btrfs_put_dev_args_from_path(struct btrfs_dev_lookup_args *args);
662int btrfs_rm_device(struct btrfs_fs_info *fs_info,662int btrfs_rm_device(struct btrfs_fs_info *fs_info,
663 struct btrfs_dev_lookup_args *args,663 struct btrfs_dev_lookup_args *args,
664 struct bdev_handle **bdev_handle);664 struct file **bdev_file);
665void __exit btrfs_cleanup_fs_uuids(void);665void __exit btrfs_cleanup_fs_uuids(void);
666int btrfs_num_copies(struct btrfs_fs_info *fs_info, u64 logical, u64 len);666int btrfs_num_copies(struct btrfs_fs_info *fs_info, u64 logical, u64 len);
667int btrfs_grow_device(struct btrfs_trans_handle *trans,667int 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
495 sb->s_mtd = NULL;495 sb->s_mtd = NULL;
496 } else if (IS_ENABLED(CONFIG_CRAMFS_BLOCKDEV) && sb->s_bdev) {496 } else if (IS_ENABLED(CONFIG_CRAMFS_BLOCKDEV) && sb->s_bdev) {
497 sync_blockdev(sb->s_bdev);497 sync_blockdev(sb->s_bdev);
498 bdev_release(sb->s_bdev_handle);498 fput(sb->s_bdev_file);
499 }499 }
500 kfree(sbi);500 kfree(sbi);
501}501}
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
220 up_read(&devs->rwsem);220 up_read(&devs->rwsem);
221 return 0;221 return 0;
222 }222 }
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;
224 map->m_daxdev = dif->dax_dev;224 map->m_daxdev = dif->dax_dev;
225 map->m_dax_part_off = dif->dax_part_off;225 map->m_dax_part_off = dif->dax_part_off;
226 map->m_fscache = dif->fscache;226 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
238 if (map->m_pa >= startoff &&238 if (map->m_pa >= startoff &&
239 map->m_pa < startoff + length) {239 map->m_pa < startoff + length) {
240 map->m_pa -= startoff;240 map->m_pa -= startoff;
241 map->m_bdev = dif->bdev_handle ?241 map->m_bdev = dif->bdev_file ?
242 dif->bdev_handle->bdev : NULL;242 file_bdev(dif->bdev_file) : NULL;
243 map->m_daxdev = dif->dax_dev;243 map->m_daxdev = dif->dax_dev;
244 map->m_dax_part_off = dif->dax_part_off;244 map->m_dax_part_off = dif->dax_part_off;
245 map->m_fscache = dif->fscache;245 map->m_fscache = dif->fscache;
fs/erofs/internal.h+1−1
@@ -49,7 +49,7 @@ typedef u32 erofs_blk_t; · 48 unmodified lines
49struct erofs_device_info {49struct erofs_device_info {
50 char *path;50 char *path;
51 struct erofs_fscache *fscache;51 struct erofs_fscache *fscache;
52 struct bdev_handle *bdev_handle;52 struct file *bdev_file;
53 struct dax_device *dax_dev;53 struct dax_device *dax_dev;
54 u64 dax_part_off;54 u64 dax_part_off;
55 55
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
177 struct erofs_sb_info *sbi = EROFS_SB(sb);177 struct erofs_sb_info *sbi = EROFS_SB(sb);
178 struct erofs_fscache *fscache;178 struct erofs_fscache *fscache;
179 struct erofs_deviceslot *dis;179 struct erofs_deviceslot *dis;
180 struct bdev_handle *bdev_handle;180 struct file *bdev_file;
181 void *ptr;181 void *ptr;
182 182
183 ptr = erofs_read_metabuf(buf, sb, erofs_blknr(sb, *pos), EROFS_KMAP);183 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
201 return PTR_ERR(fscache);201 return PTR_ERR(fscache);
202 dif->fscache = fscache;202 dif->fscache = fscache;
203 } else if (!sbi->devs->flatdev) {203 } 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,
205 sb->s_type, NULL);205 sb->s_type, NULL);
206 if (IS_ERR(bdev_handle))206 if (IS_ERR(bdev_file))
207 return PTR_ERR(bdev_handle);207 return PTR_ERR(bdev_file);
208 dif->bdev_handle = bdev_handle;208 dif->bdev_file = bdev_file;
209 dif->dax_dev = fs_dax_get_by_bdev(bdev_handle->bdev,209 dif->dax_dev = fs_dax_get_by_bdev(file_bdev(bdev_file),
210 &dif->dax_part_off, NULL, NULL);210 &dif->dax_part_off, NULL, NULL);
211 }211 }
212 212
@@ -754,8 +754,8 @@ static int erofs_release_device_info(int id, void *ptr, void *data) · 541 unmodified lines
754 struct erofs_device_info *dif = ptr;754 struct erofs_device_info *dif = ptr;
755 755
756 fs_put_dax(dif->dax_dev, NULL);756 fs_put_dax(dif->dax_dev, NULL);
757 if (dif->bdev_handle)757 if (dif->bdev_file)
758 bdev_release(dif->bdev_handle);758 fput(dif->bdev_file);
759 erofs_fscache_unregister_cookie(dif->fscache);759 erofs_fscache_unregister_cookie(dif->fscache);
760 dif->fscache = NULL;760 dif->fscache = NULL;
761 kfree(dif->path);761 kfree(dif->path);
fs/ext4/ext4.h+1−1
@@ -1550,7 +1550,7 @@ struct ext4_sb_info { · 1549 unmodified lines
1550 unsigned long s_commit_interval;1550 unsigned long s_commit_interval;
1551 u32 s_max_batch_time;1551 u32 s_max_batch_time;
1552 u32 s_min_batch_time;1552 u32 s_min_batch_time;
1553 struct bdev_handle *s_journal_bdev_handle;1553 struct file *s_journal_bdev_file;
1554#ifdef CONFIG_QUOTA1554#ifdef CONFIG_QUOTA
1555 /* Names of quota files with journalled quota */1555 /* Names of quota files with journalled quota */
1556 char __rcu *s_qf_names[EXT4_MAXQUOTAS];1556 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
576 if (fm->fmr_device == 0 || fm->fmr_device == UINT_MAX ||576 if (fm->fmr_device == 0 || fm->fmr_device == UINT_MAX ||
577 fm->fmr_device == new_encode_dev(sb->s_bdev->bd_dev))577 fm->fmr_device == new_encode_dev(sb->s_bdev->bd_dev))
578 return true;578 return true;
579 if (EXT4_SB(sb)->s_journal_bdev_handle &&579 if (EXT4_SB(sb)->s_journal_bdev_file &&
580 fm->fmr_device ==580 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))
582 return true;582 return true;
583 return false;583 return false;
584}584}
@@ -648,9 +648,9 @@ int ext4_getfsmap(struct super_block *sb, struct ext4_fsmap_head *head, · 63 unmodified lines
648 memset(handlers, 0, sizeof(handlers));648 memset(handlers, 0, sizeof(handlers));
649 handlers[0].gfd_dev = new_encode_dev(sb->s_bdev->bd_dev);649 handlers[0].gfd_dev = new_encode_dev(sb->s_bdev->bd_dev);
650 handlers[0].gfd_fn = ext4_getfsmap_datadev;650 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) {
652 handlers[1].gfd_dev = new_encode_dev(652 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);
654 handlers[1].gfd_fn = ext4_getfsmap_logdev;654 handlers[1].gfd_fn = ext4_getfsmap_logdev;
655 }655 }
656 656
fs/ext4/super.c+26−26
@@ -1359,14 +1359,14 @@ static void ext4_put_super(struct super_block *sb) · 1358 unmodified lines
1359 1359
1360 sync_blockdev(sb->s_bdev);1360 sync_blockdev(sb->s_bdev);
1361 invalidate_bdev(sb->s_bdev);1361 invalidate_bdev(sb->s_bdev);
1362 if (sbi->s_journal_bdev_handle) {1362 if (sbi->s_journal_bdev_file) {
1363 /*1363 /*
1364 * Invalidate the journal device's buffers. We don't want them1364 * Invalidate the journal device's buffers. We don't want them
1365 * floating about in memory - the physical journal device may1365 * floating about in memory - the physical journal device may
1366 * hotswapped, and it breaks the `ro-after' testing code.1366 * hotswapped, and it breaks the `ro-after' testing code.
1367 */1367 */
1368 sync_blockdev(sbi->s_journal_bdev_handle->bdev);1368 sync_blockdev(file_bdev(sbi->s_journal_bdev_file));
1369 invalidate_bdev(sbi->s_journal_bdev_handle->bdev);1369 invalidate_bdev(file_bdev(sbi->s_journal_bdev_file));
1370 }1370 }
1371 1371
1372 ext4_xattr_destroy_cache(sbi->s_ea_inode_cache);1372 ext4_xattr_destroy_cache(sbi->s_ea_inode_cache);
@@ -4233,7 +4233,7 @@ int ext4_calculate_overhead(struct super_block *sb) · 2860 unmodified lines
4233 * Add the internal journal blocks whether the journal has been4233 * Add the internal journal blocks whether the journal has been
4234 * loaded or not4234 * loaded or not
4235 */4235 */
4236 if (sbi->s_journal && !sbi->s_journal_bdev_handle)4236 if (sbi->s_journal && !sbi->s_journal_bdev_file)
4237 overhead += EXT4_NUM_B2C(sbi, sbi->s_journal->j_total_len);4237 overhead += EXT4_NUM_B2C(sbi, sbi->s_journal->j_total_len);
4238 else if (ext4_has_feature_journal(sb) && !sbi->s_journal && j_inum) {4238 else if (ext4_has_feature_journal(sb) && !sbi->s_journal && j_inum) {
4239 /* j_inum for internal journal is non-zero */4239 /* j_inum for internal journal is non-zero */
@@ -5671,9 +5671,9 @@ failed_mount: · 1431 unmodified lines
5671#endif5671#endif
5672 fscrypt_free_dummy_policy(&sbi->s_dummy_enc_policy);5672 fscrypt_free_dummy_policy(&sbi->s_dummy_enc_policy);
5673 brelse(sbi->s_sbh);5673 brelse(sbi->s_sbh);
5674 if (sbi->s_journal_bdev_handle) {5674 if (sbi->s_journal_bdev_file) {
5675 invalidate_bdev(sbi->s_journal_bdev_handle->bdev);5675 invalidate_bdev(file_bdev(sbi->s_journal_bdev_file));
5676 bdev_release(sbi->s_journal_bdev_handle);5676 fput(sbi->s_journal_bdev_file);
5677 }5677 }
5678out_fail:5678out_fail:
5679 invalidate_bdev(sb->s_bdev);5679 invalidate_bdev(sb->s_bdev);
@@ -5843,30 +5843,30 @@ static journal_t *ext4_open_inode_journal(struct super_block *sb, · 163 unmodified lines
5843 return journal;5843 return journal;
5844}5844}
5845 5845
5846static struct bdev_handle *ext4_get_journal_blkdev(struct super_block *sb,5846static struct file *ext4_get_journal_blkdev(struct super_block *sb,
5847 dev_t j_dev, ext4_fsblk_t *j_start,5847 dev_t j_dev, ext4_fsblk_t *j_start,
5848 ext4_fsblk_t *j_len)5848 ext4_fsblk_t *j_len)
5849{5849{
5850 struct buffer_head *bh;5850 struct buffer_head *bh;
5851 struct block_device *bdev;5851 struct block_device *bdev;
5852 struct bdev_handle *bdev_handle;5852 struct file *bdev_file;
5853 int hblock, blocksize;5853 int hblock, blocksize;
5854 ext4_fsblk_t sb_block;5854 ext4_fsblk_t sb_block;
5855 unsigned long offset;5855 unsigned long offset;
5856 struct ext4_super_block *es;5856 struct ext4_super_block *es;
5857 int errno;5857 int errno;
5858 5858
5859 bdev_handle = bdev_open_by_dev(j_dev,5859 bdev_file = bdev_file_open_by_dev(j_dev,
5860 BLK_OPEN_READ | BLK_OPEN_WRITE | BLK_OPEN_RESTRICT_WRITES,5860 BLK_OPEN_READ | BLK_OPEN_WRITE | BLK_OPEN_RESTRICT_WRITES,
5861 sb, &fs_holder_ops);5861 sb, &fs_holder_ops);
5862 if (IS_ERR(bdev_handle)) {5862 if (IS_ERR(bdev_file)) {
5863 ext4_msg(sb, KERN_ERR,5863 ext4_msg(sb, KERN_ERR,
5864 "failed to open journal device unknown-block(%u,%u) %ld",5864 "failed to open journal device unknown-block(%u,%u) %ld",
5865 MAJOR(j_dev), MINOR(j_dev), PTR_ERR(bdev_handle));5865 MAJOR(j_dev), MINOR(j_dev), PTR_ERR(bdev_file));
5866 return bdev_handle;5866 return bdev_file;
5867 }5867 }
5868 5868
5869 bdev = bdev_handle->bdev;5869 bdev = file_bdev(bdev_file);
5870 blocksize = sb->s_blocksize;5870 blocksize = sb->s_blocksize;
5871 hblock = bdev_logical_block_size(bdev);5871 hblock = bdev_logical_block_size(bdev);
5872 if (blocksize < hblock) {5872 if (blocksize < hblock) {
@@ -5913,12 +5913,12 @@ static struct bdev_handle *ext4_get_journal_blkdev(struct super_block *sb, · 40 unmodified lines
5913 *j_start = sb_block + 1;5913 *j_start = sb_block + 1;
5914 *j_len = ext4_blocks_count(es);5914 *j_len = ext4_blocks_count(es);
5915 brelse(bh);5915 brelse(bh);
5916 return bdev_handle;5916 return bdev_file;
5917 5917
5918out_bh:5918out_bh:
5919 brelse(bh);5919 brelse(bh);
5920out_bdev:5920out_bdev:
5921 bdev_release(bdev_handle);5921 fput(bdev_file);
5922 return ERR_PTR(errno);5922 return ERR_PTR(errno);
5923}5923}
5924 5924
@@ -5928,14 +5928,14 @@ static journal_t *ext4_open_dev_journal(struct super_block *sb, · 3 unmodified lines
5928 journal_t *journal;5928 journal_t *journal;
5929 ext4_fsblk_t j_start;5929 ext4_fsblk_t j_start;
5930 ext4_fsblk_t j_len;5930 ext4_fsblk_t j_len;
5931 struct bdev_handle *bdev_handle;5931 struct file *bdev_file;
5932 int errno = 0;5932 int errno = 0;
5933 5933
5934 bdev_handle = ext4_get_journal_blkdev(sb, j_dev, &j_start, &j_len);5934 bdev_file = ext4_get_journal_blkdev(sb, j_dev, &j_start, &j_len);
5935 if (IS_ERR(bdev_handle))5935 if (IS_ERR(bdev_file))
5936 return ERR_CAST(bdev_handle);5936 return ERR_CAST(bdev_file);
5937 5937
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,
5939 j_len, sb->s_blocksize);5939 j_len, sb->s_blocksize);
5940 if (IS_ERR(journal)) {5940 if (IS_ERR(journal)) {
5941 ext4_msg(sb, KERN_ERR, "failed to create device journal");5941 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
5950 goto out_journal;5950 goto out_journal;
5951 }5951 }
5952 journal->j_private = sb;5952 journal->j_private = sb;
5953 EXT4_SB(sb)->s_journal_bdev_handle = bdev_handle;5953 EXT4_SB(sb)->s_journal_bdev_file = bdev_file;
5954 ext4_init_journal_params(sb, journal);5954 ext4_init_journal_params(sb, journal);
5955 return journal;5955 return journal;
5956 5956
5957out_journal:5957out_journal:
5958 jbd2_journal_destroy(journal);5958 jbd2_journal_destroy(journal);
5959out_bdev:5959out_bdev:
5960 bdev_release(bdev_handle);5960 fput(bdev_file);
5961 return ERR_PTR(errno);5961 return ERR_PTR(errno);
5962}5962}
5963 5963
@@ -7315,12 +7315,12 @@ static inline int ext3_feature_set_ok(struct super_block *sb) · 1351 unmodified lines
7315static void ext4_kill_sb(struct super_block *sb)7315static void ext4_kill_sb(struct super_block *sb)
7316{7316{
7317 struct ext4_sb_info *sbi = EXT4_SB(sb);7317 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;
7319 7319
7320 kill_block_super(sb);7320 kill_block_super(sb);
7321 7321
7322 if (handle)7322 if (bdev_file)
7323 bdev_release(handle);7323 fput(bdev_file);
7324}7324}
7325 7325
7326static struct file_system_type ext4_fs_type = {7326static struct file_system_type ext4_fs_type = {
fs/f2fs/f2fs.h+1−1
@@ -1240,7 +1240,7 @@ struct f2fs_bio_info { · 1239 unmodified lines
1240#define FDEV(i) (sbi->devs[i])1240#define FDEV(i) (sbi->devs[i])
1241#define RDEV(i) (raw_super->devs[i])1241#define RDEV(i) (raw_super->devs[i])
1242struct f2fs_dev_info {1242struct f2fs_dev_info {
1243 struct bdev_handle *bdev_handle;1243 struct file *bdev_file;
1244 struct block_device *bdev;1244 struct block_device *bdev;
1245 char path[MAX_PATH_LEN];1245 char path[MAX_PATH_LEN];
1246 unsigned int total_segments;1246 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
1605 1605
1606 for (i = 0; i < sbi->s_ndevs; i++) {1606 for (i = 0; i < sbi->s_ndevs; i++) {
1607 if (i > 0)1607 if (i > 0)
1608 bdev_release(FDEV(i).bdev_handle);1608 fput(FDEV(i).bdev_file);
1609#ifdef CONFIG_BLK_DEV_ZONED1609#ifdef CONFIG_BLK_DEV_ZONED
1610 kvfree(FDEV(i).blkz_seq);1610 kvfree(FDEV(i).blkz_seq);
1611#endif1611#endif
@@ -4247,7 +4247,7 @@ static int f2fs_scan_devices(struct f2fs_sb_info *sbi) · 2635 unmodified lines
4247 4247
4248 for (i = 0; i < max_devices; i++) {4248 for (i = 0; i < max_devices; i++) {
4249 if (i == 0)4249 if (i == 0)
4250 FDEV(0).bdev_handle = sbi->sb->s_bdev_handle;4250 FDEV(0).bdev_file = sbi->sb->s_bdev_file;
4251 else if (!RDEV(i).path[0])4251 else if (!RDEV(i).path[0])
4252 break;4252 break;
4253 4253
@@ -4267,14 +4267,14 @@ static int f2fs_scan_devices(struct f2fs_sb_info *sbi) · 13 unmodified lines
4267 FDEV(i).end_blk = FDEV(i).start_blk +4267 FDEV(i).end_blk = FDEV(i).start_blk +
4268 (FDEV(i).total_segments <<4268 (FDEV(i).total_segments <<
4269 sbi->log_blocks_per_seg) - 1;4269 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(
4271 FDEV(i).path, mode, sbi->sb, NULL);4271 FDEV(i).path, mode, sbi->sb, NULL);
4272 }4272 }
4273 }4273 }
4274 if (IS_ERR(FDEV(i).bdev_handle))4274 if (IS_ERR(FDEV(i).bdev_file))
4275 return PTR_ERR(FDEV(i).bdev_handle);4275 return PTR_ERR(FDEV(i).bdev_file);
4276 4276
4277 FDEV(i).bdev = FDEV(i).bdev_handle->bdev;4277 FDEV(i).bdev = file_bdev(FDEV(i).bdev_file);
4278 /* to release errored devices */4278 /* to release errored devices */
4279 sbi->s_ndevs = i + 1;4279 sbi->s_ndevs = i + 1;
4280 4280
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
276}276}
277 277
278/**278/**
279 * alloc_file - allocate and initialize a 'struct file'279 * file_init_path - initialize a 'struct file' based on path
280 *280 *
281 * @file: the file to set up
281 * @path: the (dentry, vfsmount) pair for the new file282 * @path: the (dentry, vfsmount) pair for the new file
282 * @flags: O_... flags with which the new file will be opened
283 * @fop: the 'struct file_operations' for the new file283 * @fop: the 'struct file_operations' for the new file
284 */284 */
285static struct file *alloc_file(const struct path *path, int flags,285static void file_init_path(struct file *file, const struct path *path,
286 const struct file_operations *fop)286 const struct file_operations *fop)
287{287{
288 struct file *file;
289
290 file = alloc_empty_file(flags, current_cred());
291 if (IS_ERR(file))
292 return file;
293
294 file->f_path = *path;288 file->f_path = *path;
295 file->f_inode = path->dentry->d_inode;289 file->f_inode = path->dentry->d_inode;
296 file->f_mapping = path->dentry->d_inode->i_mapping;290 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
309 file->f_op = fop;303 file->f_op = fop;
310 if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)304 if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
311 i_readcount_inc(path->dentry->d_inode);305 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 */
315static 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);
312 return file;323 return file;
313}324}
314 325
315struct file *alloc_file_pseudo(struct inode *inode, struct vfsmount *mnt,326static inline int alloc_path_pseudo(const char *name, struct inode *inode,
316 const char *name, int flags,327 struct vfsmount *mnt, struct path *path)
317 const struct file_operations *fops)
318{328{
319 struct qstr this = QSTR_INIT(name, strlen(name));329 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
339struct 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;
320 struct path path;344 struct path path;
321 struct file *file;345 struct file *file;
322 346
323 path.dentry = d_alloc_pseudo(mnt->mnt_sb, &this);347 ret = alloc_path_pseudo(name, inode, mnt, &path);
324 if (!path.dentry)348 if (ret)
325 return ERR_PTR(-ENOMEM);349 return ERR_PTR(ret);
326 path.mnt = mntget(mnt);350
327 d_instantiate(path.dentry, inode);
328 file = alloc_file(&path, flags, fops);351 file = alloc_file(&path, flags, fops);
329 if (IS_ERR(file)) {352 if (IS_ERR(file)) {
330 ihold(inode);353 ihold(inode);
@@ -334,6 +357,30 @@ struct file *alloc_file_pseudo(struct inode *inode, struct vfsmount *mnt, · 3 unmodified lines
334}357}
335EXPORT_SYMBOL(alloc_file_pseudo);358EXPORT_SYMBOL(alloc_file_pseudo);
336 359
360struct 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}
382EXPORT_SYMBOL_GPL(alloc_file_pseudo_noaccount);
383
337struct file *alloc_file_clone(struct file *base, int flags,384struct file *alloc_file_clone(struct file *base, int flags,
338 const struct file_operations *fops)385 const struct file_operations *fops)
339{386{
fs/jfs/jfs_logmgr.c+13−13
@@ -1058,7 +1058,7 @@ void jfs_syncpt(struct jfs_log *log, int hard_sync) · 1057 unmodified lines
1058int lmLogOpen(struct super_block *sb)1058int lmLogOpen(struct super_block *sb)
1059{1059{
1060 int rc;1060 int rc;
1061 struct bdev_handle *bdev_handle;1061 struct file *bdev_file;
1062 struct jfs_log *log;1062 struct jfs_log *log;
1063 struct jfs_sb_info *sbi = JFS_SBI(sb);1063 struct jfs_sb_info *sbi = JFS_SBI(sb);
1064 1064
@@ -1070,7 +1070,7 @@ int lmLogOpen(struct super_block *sb) · 5 unmodified lines
1070 1070
1071 mutex_lock(&jfs_log_mutex);1071 mutex_lock(&jfs_log_mutex);
1072 list_for_each_entry(log, &jfs_external_logs, journal_list) {1072 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) {
1074 if (!uuid_equal(&log->uuid, &sbi->loguuid)) {1074 if (!uuid_equal(&log->uuid, &sbi->loguuid)) {
1075 jfs_warn("wrong uuid on JFS journal");1075 jfs_warn("wrong uuid on JFS journal");
1076 mutex_unlock(&jfs_log_mutex);1076 mutex_unlock(&jfs_log_mutex);
@@ -1100,14 +1100,14 @@ int lmLogOpen(struct super_block *sb) · 23 unmodified lines
1100 * file systems to log may have n-to-1 relationship;1100 * file systems to log may have n-to-1 relationship;
1101 */1101 */
1102 1102
1103 bdev_handle = bdev_open_by_dev(sbi->logdev,1103 bdev_file = bdev_file_open_by_dev(sbi->logdev,
1104 BLK_OPEN_READ | BLK_OPEN_WRITE, log, NULL);1104 BLK_OPEN_READ | BLK_OPEN_WRITE, log, NULL);
1105 if (IS_ERR(bdev_handle)) {1105 if (IS_ERR(bdev_file)) {
1106 rc = PTR_ERR(bdev_handle);1106 rc = PTR_ERR(bdev_file);
1107 goto free;1107 goto free;
1108 }1108 }
1109 1109
1110 log->bdev_handle = bdev_handle;1110 log->bdev_file = bdev_file;
1111 uuid_copy(&log->uuid, &sbi->loguuid);1111 uuid_copy(&log->uuid, &sbi->loguuid);
1112 1112
1113 /*1113 /*
@@ -1141,7 +1141,7 @@ journal_found: · 27 unmodified lines
1141 lbmLogShutdown(log);1141 lbmLogShutdown(log);
1142 1142
1143 close: /* close external log device */1143 close: /* close external log device */
1144 bdev_release(bdev_handle);1144 fput(bdev_file);
1145 1145
1146 free: /* free log descriptor */1146 free: /* free log descriptor */
1147 mutex_unlock(&jfs_log_mutex);1147 mutex_unlock(&jfs_log_mutex);
@@ -1162,7 +1162,7 @@ static int open_inline_log(struct super_block *sb) · 14 unmodified lines
1162 init_waitqueue_head(&log->syncwait);1162 init_waitqueue_head(&log->syncwait);
1163 1163
1164 set_bit(log_INLINELOG, &log->flag);1164 set_bit(log_INLINELOG, &log->flag);
1165 log->bdev_handle = sb->s_bdev_handle;1165 log->bdev_file = sb->s_bdev_file;
1166 log->base = addressPXD(&JFS_SBI(sb)->logpxd);1166 log->base = addressPXD(&JFS_SBI(sb)->logpxd);
1167 log->size = lengthPXD(&JFS_SBI(sb)->logpxd) >>1167 log->size = lengthPXD(&JFS_SBI(sb)->logpxd) >>
1168 (L2LOGPSIZE - sb->s_blocksize_bits);1168 (L2LOGPSIZE - sb->s_blocksize_bits);
@@ -1436,7 +1436,7 @@ int lmLogClose(struct super_block *sb) · 267 unmodified lines
1436{1436{
1437 struct jfs_sb_info *sbi = JFS_SBI(sb);1437 struct jfs_sb_info *sbi = JFS_SBI(sb);
1438 struct jfs_log *log = sbi->log;1438 struct jfs_log *log = sbi->log;
1439 struct bdev_handle *bdev_handle;1439 struct file *bdev_file;
1440 int rc = 0;1440 int rc = 0;
1441 1441
1442 jfs_info("lmLogClose: log:0x%p", log);1442 jfs_info("lmLogClose: log:0x%p", log);
@@ -1482,10 +1482,10 @@ int lmLogClose(struct super_block *sb) · 39 unmodified lines
1482 * external log as separate logical volume1482 * external log as separate logical volume
1483 */1483 */
1484 list_del(&log->journal_list);1484 list_del(&log->journal_list);
1485 bdev_handle = log->bdev_handle;1485 bdev_file = log->bdev_file;
1486 rc = lmLogShutdown(log);1486 rc = lmLogShutdown(log);
1487 1487
1488 bdev_release(bdev_handle);1488 fput(bdev_file);
1489 1489
1490 kfree(log);1490 kfree(log);
1491 1491
@@ -1972,7 +1972,7 @@ static int lbmRead(struct jfs_log * log, int pn, struct lbuf ** bpp) · 480 unmodified lines
1972 1972
1973 bp->l_flag |= lbmREAD;1973 bp->l_flag |= lbmREAD;
1974 1974
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);
1976 bio->bi_iter.bi_sector = bp->l_blkno << (log->l2bsize - 9);1976 bio->bi_iter.bi_sector = bp->l_blkno << (log->l2bsize - 9);
1977 __bio_add_page(bio, bp->l_page, LOGPSIZE, bp->l_offset);1977 __bio_add_page(bio, bp->l_page, LOGPSIZE, bp->l_offset);
1978 BUG_ON(bio->bi_iter.bi_size != LOGPSIZE);1978 BUG_ON(bio->bi_iter.bi_size != LOGPSIZE);
@@ -2115,7 +2115,7 @@ static void lbmStartIO(struct lbuf * bp) · 136 unmodified lines
2115 jfs_info("lbmStartIO");2115 jfs_info("lbmStartIO");
2116 2116
2117 if (!log->no_integrity)2117 if (!log->no_integrity)
2118 bdev = log->bdev_handle->bdev;2118 bdev = file_bdev(log->bdev_file);
2119 2119
2120 bio = bio_alloc(bdev, 1, REQ_OP_WRITE | REQ_SYNC,2120 bio = bio_alloc(bdev, 1, REQ_OP_WRITE | REQ_SYNC,
2121 GFP_NOFS);2121 GFP_NOFS);
fs/jfs/jfs_logmgr.h+1−1
@@ -356,7 +356,7 @@ struct jfs_log { · 355 unmodified lines
356 * before writing syncpt.356 * before writing syncpt.
357 */357 */
358 struct list_head journal_list; /* Global list */358 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 */
360 int serial; /* 4: log mount serial number */360 int serial; /* 4: log mount serial number */
361 361
362 s64 base; /* @8: log extent address (inline log ) */362 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
431 if (state == FM_MOUNT) {431 if (state == FM_MOUNT) {
432 /* record log's dev_t and mount serial number */432 /* record log's dev_t and mount serial number */
433 j_sb->s_logdev = cpu_to_le32(433 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));
435 j_sb->s_logserial = cpu_to_le32(sbi->log->serial);435 j_sb->s_logserial = cpu_to_le32(sbi->log->serial);
436 } else if (state == FM_CLEAN) {436 } else if (state == FM_CLEAN) {
437 /*437 /*
fs/nfs/blocklayout/blocklayout.h+1−1
@@ -108,7 +108,7 @@ struct pnfs_block_dev { · 107 unmodified lines
108 struct pnfs_block_dev *children;108 struct pnfs_block_dev *children;
109 u64 chunk_size;109 u64 chunk_size;
110 110
111 struct bdev_handle *bdev_handle;111 struct file *bdev_file;
112 u64 disk_offset;112 u64 disk_offset;
113 113
114 u64 pr_key;114 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
25 } else {25 } else {
26 if (dev->pr_registered) {26 if (dev->pr_registered) {
27 const struct pr_ops *ops =27 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;
29 int error;29 int error;
30 30
31 error = ops->pr_register(dev->bdev_handle->bdev,31 error = ops->pr_register(file_bdev(dev->bdev_file),
32 dev->pr_key, 0, false);32 dev->pr_key, 0, false);
33 if (error)33 if (error)
34 pr_err("failed to unregister PR key.\n");34 pr_err("failed to unregister PR key.\n");
35 }35 }
36 36
37 if (dev->bdev_handle)37 if (dev->bdev_file)
38 bdev_release(dev->bdev_handle);38 fput(dev->bdev_file);
39 }39 }
40}40}
41 41
@@ -169,7 +169,7 @@ static bool bl_map_simple(struct pnfs_block_dev *dev, u64 offset, · 127 unmodified lines
169 map->start = dev->start;169 map->start = dev->start;
170 map->len = dev->len;170 map->len = dev->len;
171 map->disk_offset = dev->disk_offset;171 map->disk_offset = dev->disk_offset;
172 map->bdev = dev->bdev_handle->bdev;172 map->bdev = file_bdev(dev->bdev_file);
173 return true;173 return true;
174}174}
175 175
@@ -236,26 +236,26 @@ bl_parse_simple(struct nfs_server *server, struct pnfs_block_dev *d, · 60 unmodified lines
236 struct pnfs_block_volume *volumes, int idx, gfp_t gfp_mask)236 struct pnfs_block_volume *volumes, int idx, gfp_t gfp_mask)
237{237{
238 struct pnfs_block_volume *v = &volumes[idx];238 struct pnfs_block_volume *v = &volumes[idx];
239 struct bdev_handle *bdev_handle;239 struct file *bdev_file;
240 dev_t dev;240 dev_t dev;
241 241
242 dev = bl_resolve_deviceid(server, v, gfp_mask);242 dev = bl_resolve_deviceid(server, v, gfp_mask);
243 if (!dev)243 if (!dev)
244 return -EIO;244 return -EIO;
245 245
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,
247 NULL, NULL);247 NULL, NULL);
248 if (IS_ERR(bdev_handle)) {248 if (IS_ERR(bdev_file)) {
249 printk(KERN_WARNING "pNFS: failed to open device %d:%d (%ld)\n",249 printk(KERN_WARNING "pNFS: failed to open device %d:%d (%ld)\n",
250 MAJOR(dev), MINOR(dev), PTR_ERR(bdev_handle));250 MAJOR(dev), MINOR(dev), PTR_ERR(bdev_file));
251 return PTR_ERR(bdev_handle);251 return PTR_ERR(bdev_file);
252 }252 }
253 d->bdev_handle = bdev_handle;253 d->bdev_file = bdev_file;
254 d->len = bdev_nr_bytes(bdev_handle->bdev);254 d->len = bdev_nr_bytes(file_bdev(bdev_file));
255 d->map = bl_map_simple;255 d->map = bl_map_simple;
256 256
257 printk(KERN_INFO "pNFS: using block device %s\n",257 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);
259 return 0;259 return 0;
260}260}
261 261
@@ -300,10 +300,10 @@ bl_validate_designator(struct pnfs_block_volume *v) · 38 unmodified lines
300 }300 }
301}301}
302 302
303static struct bdev_handle *303static struct file *
304bl_open_path(struct pnfs_block_volume *v, const char *prefix)304bl_open_path(struct pnfs_block_volume *v, const char *prefix)
305{305{
306 struct bdev_handle *bdev_handle;306 struct file *bdev_file;
307 const char *devname;307 const char *devname;
308 308
309 devname = kasprintf(GFP_KERNEL, "/dev/disk/by-id/%s%*phN",309 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
311 if (!devname)311 if (!devname)
312 return ERR_PTR(-ENOMEM);312 return ERR_PTR(-ENOMEM);
313 313
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,
315 NULL, NULL);315 NULL, NULL);
316 if (IS_ERR(bdev_handle)) {316 if (IS_ERR(bdev_file)) {
317 pr_warn("pNFS: failed to open device %s (%ld)\n",317 pr_warn("pNFS: failed to open device %s (%ld)\n",
318 devname, PTR_ERR(bdev_handle));318 devname, PTR_ERR(bdev_file));
319 }319 }
320 320
321 kfree(devname);321 kfree(devname);
322 return bdev_handle;322 return bdev_file;
323}323}
324 324
325static int325static int
@@ -327,7 +327,7 @@ bl_parse_scsi(struct nfs_server *server, struct pnfs_block_dev *d, · 1 unmodified line
327 struct pnfs_block_volume *volumes, int idx, gfp_t gfp_mask)327 struct pnfs_block_volume *volumes, int idx, gfp_t gfp_mask)
328{328{
329 struct pnfs_block_volume *v = &volumes[idx];329 struct pnfs_block_volume *v = &volumes[idx];
330 struct bdev_handle *bdev_handle;330 struct file *bdev_file;
331 const struct pr_ops *ops;331 const struct pr_ops *ops;
332 int error;332 int error;
333 333
@@ -340,14 +340,14 @@ bl_parse_scsi(struct nfs_server *server, struct pnfs_block_dev *d, · 6 unmodified lines
340 * On other distributions like Debian, the default SCSI by-id path will340 * On other distributions like Debian, the default SCSI by-id path will
341 * point to the dm-multipath device if one exists.341 * point to the dm-multipath device if one exists.
342 */342 */
343 bdev_handle = bl_open_path(v, "dm-uuid-mpath-0x");343 bdev_file = bl_open_path(v, "dm-uuid-mpath-0x");
344 if (IS_ERR(bdev_handle))344 if (IS_ERR(bdev_file))
345 bdev_handle = bl_open_path(v, "wwn-0x");345 bdev_file = bl_open_path(v, "wwn-0x");
346 if (IS_ERR(bdev_handle))346 if (IS_ERR(bdev_file))
347 return PTR_ERR(bdev_handle);347 return PTR_ERR(bdev_file);
348 d->bdev_handle = bdev_handle;348 d->bdev_file = bdev_file;
349 349
350 d->len = bdev_nr_bytes(d->bdev_handle->bdev);350 d->len = bdev_nr_bytes(file_bdev(d->bdev_file));
351 d->map = bl_map_simple;351 d->map = bl_map_simple;
352 d->pr_key = v->scsi.pr_key;352 d->pr_key = v->scsi.pr_key;
353 353
@@ -355,20 +355,20 @@ bl_parse_scsi(struct nfs_server *server, struct pnfs_block_dev *d, · 1 unmodified line
355 return -ENODEV;355 return -ENODEV;
356 356
357 pr_info("pNFS: using block device %s (reservation key 0x%llx)\n",357 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);
359 359
360 ops = d->bdev_handle->bdev->bd_disk->fops->pr_ops;360 ops = file_bdev(d->bdev_file)->bd_disk->fops->pr_ops;
361 if (!ops) {361 if (!ops) {
362 pr_err("pNFS: block device %s does not support reservations.",362 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);
364 error = -EINVAL;364 error = -EINVAL;
365 goto out_blkdev_put;365 goto out_blkdev_put;
366 }366 }
367 367
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);
369 if (error) {369 if (error) {
370 pr_err("pNFS: failed to register key for block device %s.",370 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);
372 goto out_blkdev_put;372 goto out_blkdev_put;
373 }373 }
374 374
@@ -376,7 +376,7 @@ bl_parse_scsi(struct nfs_server *server, struct pnfs_block_dev *d, · 1 unmodified line
376 return 0;376 return 0;
377 377
378out_blkdev_put:378out_blkdev_put:
379 bdev_release(d->bdev_handle);379 fput(d->bdev_file);
380 return error;380 return error;
381}381}
382 382
fs/ocfs2/cluster/heartbeat.c+16−16
@@ -213,7 +213,7 @@ struct o2hb_region { · 212 unmodified lines
213 unsigned int hr_num_pages;213 unsigned int hr_num_pages;
214 214
215 struct page **hr_slot_data;215 struct page **hr_slot_data;
216 struct bdev_handle *hr_bdev_handle;216 struct file *hr_bdev_file;
217 struct o2hb_disk_slot *hr_slots;217 struct o2hb_disk_slot *hr_slots;
218 218
219 /* live node map of this region */219 /* live node map of this region */
@@ -263,7 +263,7 @@ struct o2hb_region { · 43 unmodified lines
263 263
264static inline struct block_device *reg_bdev(struct o2hb_region *reg)264static inline struct block_device *reg_bdev(struct o2hb_region *reg)
265{265{
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;
267}267}
268 268
269struct o2hb_bio_wait_ctxt {269struct o2hb_bio_wait_ctxt {
@@ -1509,8 +1509,8 @@ static void o2hb_region_release(struct config_item *item) · 1239 unmodified lines
1509 kfree(reg->hr_slot_data);1509 kfree(reg->hr_slot_data);
1510 }1510 }
1511 1511
1512 if (reg->hr_bdev_handle)1512 if (reg->hr_bdev_file)
1513 bdev_release(reg->hr_bdev_handle);1513 fput(reg->hr_bdev_file);
1514 1514
1515 kfree(reg->hr_slots);1515 kfree(reg->hr_slots);
1516 1516
@@ -1569,7 +1569,7 @@ static ssize_t o2hb_region_block_bytes_store(struct config_item *item, · 52 unmodified lines
1569 unsigned long block_bytes;1569 unsigned long block_bytes;
1570 unsigned int block_bits;1570 unsigned int block_bits;
1571 1571
1572 if (reg->hr_bdev_handle)1572 if (reg->hr_bdev_file)
1573 return -EINVAL;1573 return -EINVAL;
1574 1574
1575 status = o2hb_read_block_input(reg, page, &block_bytes,1575 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
1598 char *p = (char *)page;1598 char *p = (char *)page;
1599 ssize_t ret;1599 ssize_t ret;
1600 1600
1601 if (reg->hr_bdev_handle)1601 if (reg->hr_bdev_file)
1602 return -EINVAL;1602 return -EINVAL;
1603 1603
1604 ret = kstrtoull(p, 0, &tmp);1604 ret = kstrtoull(p, 0, &tmp);
@@ -1623,7 +1623,7 @@ static ssize_t o2hb_region_blocks_store(struct config_item *item, · 18 unmodified lines
1623 unsigned long tmp;1623 unsigned long tmp;
1624 char *p = (char *)page;1624 char *p = (char *)page;
1625 1625
1626 if (reg->hr_bdev_handle)1626 if (reg->hr_bdev_file)
1627 return -EINVAL;1627 return -EINVAL;
1628 1628
1629 tmp = simple_strtoul(p, &p, 0);1629 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
1642{1642{
1643 unsigned int ret = 0;1643 unsigned int ret = 0;
1644 1644
1645 if (to_o2hb_region(item)->hr_bdev_handle)1645 if (to_o2hb_region(item)->hr_bdev_file)
1646 ret = sprintf(page, "%pg\n", reg_bdev(to_o2hb_region(item)));1646 ret = sprintf(page, "%pg\n", reg_bdev(to_o2hb_region(item)));
1647 1647
1648 return ret;1648 return ret;
@@ -1753,7 +1753,7 @@ out: · 104 unmodified lines
1753}1753}
1754 1754
1755/*1755/*
1756 * this is acting as commit; we set up all of hr_bdev_handle and hr_task or1756 * this is acting as commit; we set up all of hr_bdev_file and hr_task or
1757 * nothing1757 * nothing
1758 */1758 */
1759static ssize_t o2hb_region_dev_store(struct config_item *item,1759static 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
1769 ssize_t ret = -EINVAL;1769 ssize_t ret = -EINVAL;
1770 int live_threshold;1770 int live_threshold;
1771 1771
1772 if (reg->hr_bdev_handle)1772 if (reg->hr_bdev_file)
1773 goto out;1773 goto out;
1774 1774
1775 /* We can't heartbeat without having had our node number1775 /* 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
1795 if (!S_ISBLK(f.file->f_mapping->host->i_mode))1795 if (!S_ISBLK(f.file->f_mapping->host->i_mode))
1796 goto out2;1796 goto out2;
1797 1797
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,
1799 BLK_OPEN_WRITE | BLK_OPEN_READ, NULL, NULL);1799 BLK_OPEN_WRITE | BLK_OPEN_READ, NULL, NULL);
1800 if (IS_ERR(reg->hr_bdev_handle)) {1800 if (IS_ERR(reg->hr_bdev_file)) {
1801 ret = PTR_ERR(reg->hr_bdev_handle);1801 ret = PTR_ERR(reg->hr_bdev_file);
1802 reg->hr_bdev_handle = NULL;1802 reg->hr_bdev_file = NULL;
1803 goto out2;1803 goto out2;
1804 }1804 }
1805 1805
@@ -1903,8 +1903,8 @@ static ssize_t o2hb_region_dev_store(struct config_item *item, · 97 unmodified lines
1903 1903
1904out3:1904out3:
1905 if (ret < 0) {1905 if (ret < 0) {
1906 bdev_release(reg->hr_bdev_handle);1906 fput(reg->hr_bdev_file);
1907 reg->hr_bdev_handle = NULL;1907 reg->hr_bdev_file = NULL;
1908 }1908 }
1909out2:1909out2:
1910 fdput(f);1910 fdput(f);
fs/reiserfs/journal.c+19−19
@@ -2386,7 +2386,7 @@ static int journal_read(struct super_block *sb) · 2385 unmodified lines
2386 2386
2387 cur_dblock = SB_ONDISK_JOURNAL_1st_BLOCK(sb);2387 cur_dblock = SB_ONDISK_JOURNAL_1st_BLOCK(sb);
2388 reiserfs_info(sb, "checking transaction log (%pg)\n",2388 reiserfs_info(sb, "checking transaction log (%pg)\n",
2389 journal->j_bdev_handle->bdev);2389 file_bdev(journal->j_bdev_file));
2390 start = ktime_get_seconds();2390 start = ktime_get_seconds();
2391 2391
2392 /*2392 /*
@@ -2447,7 +2447,7 @@ static int journal_read(struct super_block *sb) · 54 unmodified lines
2447 * device and journal device to be the same2447 * device and journal device to be the same
2448 */2448 */
2449 d_bh =2449 d_bh =
2450 reiserfs_breada(journal->j_bdev_handle->bdev, cur_dblock,2450 reiserfs_breada(file_bdev(journal->j_bdev_file), cur_dblock,
2451 sb->s_blocksize,2451 sb->s_blocksize,
2452 SB_ONDISK_JOURNAL_1st_BLOCK(sb) +2452 SB_ONDISK_JOURNAL_1st_BLOCK(sb) +
2453 SB_ONDISK_JOURNAL_SIZE(sb));2453 SB_ONDISK_JOURNAL_SIZE(sb));
@@ -2588,9 +2588,9 @@ static void journal_list_init(struct super_block *sb) · 134 unmodified lines
2588 2588
2589static void release_journal_dev(struct reiserfs_journal *journal)2589static void release_journal_dev(struct reiserfs_journal *journal)
2590{2590{
2591 if (journal->j_bdev_handle) {2591 if (journal->j_bdev_file) {
2592 bdev_release(journal->j_bdev_handle);2592 fput(journal->j_bdev_file);
2593 journal->j_bdev_handle = NULL;2593 journal->j_bdev_file = NULL;
2594 }2594 }
2595}2595}
2596 2596
@@ -2605,7 +2605,7 @@ static int journal_init_dev(struct super_block *super, · 8 unmodified lines
2605 2605
2606 result = 0;2606 result = 0;
2607 2607
2608 journal->j_bdev_handle = NULL;2608 journal->j_bdev_file = NULL;
2609 jdev = SB_ONDISK_JOURNAL_DEVICE(super) ?2609 jdev = SB_ONDISK_JOURNAL_DEVICE(super) ?
2610 new_decode_dev(SB_ONDISK_JOURNAL_DEVICE(super)) : super->s_dev;2610 new_decode_dev(SB_ONDISK_JOURNAL_DEVICE(super)) : super->s_dev;
2611 2611
@@ -2616,37 +2616,37 @@ static int journal_init_dev(struct super_block *super, · 4 unmodified lines
2616 if ((!jdev_name || !jdev_name[0])) {2616 if ((!jdev_name || !jdev_name[0])) {
2617 if (jdev == super->s_dev)2617 if (jdev == super->s_dev)
2618 holder = NULL;2618 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,
2620 holder, NULL);2620 holder, NULL);
2621 if (IS_ERR(journal->j_bdev_handle)) {2621 if (IS_ERR(journal->j_bdev_file)) {
2622 result = PTR_ERR(journal->j_bdev_handle);2622 result = PTR_ERR(journal->j_bdev_file);
2623 journal->j_bdev_handle = NULL;2623 journal->j_bdev_file = NULL;
2624 reiserfs_warning(super, "sh-458",2624 reiserfs_warning(super, "sh-458",
2625 "cannot init journal device unknown-block(%u,%u): %i",2625 "cannot init journal device unknown-block(%u,%u): %i",
2626 MAJOR(jdev), MINOR(jdev), result);2626 MAJOR(jdev), MINOR(jdev), result);
2627 return result;2627 return result;
2628 } else if (jdev != super->s_dev)2628 } else if (jdev != super->s_dev)
2629 set_blocksize(journal->j_bdev_handle->bdev,2629 set_blocksize(file_bdev(journal->j_bdev_file),
2630 super->s_blocksize);2630 super->s_blocksize);
2631 2631
2632 return 0;2632 return 0;
2633 }2633 }
2634 2634
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,
2636 holder, NULL);2636 holder, NULL);
2637 if (IS_ERR(journal->j_bdev_handle)) {2637 if (IS_ERR(journal->j_bdev_file)) {
2638 result = PTR_ERR(journal->j_bdev_handle);2638 result = PTR_ERR(journal->j_bdev_file);
2639 journal->j_bdev_handle = NULL;2639 journal->j_bdev_file = NULL;
2640 reiserfs_warning(super, "sh-457",2640 reiserfs_warning(super, "sh-457",
2641 "journal_init_dev: Cannot open '%s': %i",2641 "journal_init_dev: Cannot open '%s': %i",
2642 jdev_name, result);2642 jdev_name, result);
2643 return result;2643 return result;
2644 }2644 }
2645 2645
2646 set_blocksize(journal->j_bdev_handle->bdev, super->s_blocksize);2646 set_blocksize(file_bdev(journal->j_bdev_file), super->s_blocksize);
2647 reiserfs_info(super,2647 reiserfs_info(super,
2648 "journal_init_dev: journal device: %pg\n",2648 "journal_init_dev: journal device: %pg\n",
2649 journal->j_bdev_handle->bdev);2649 file_bdev(journal->j_bdev_file));
2650 return 0;2650 return 0;
2651}2651}
2652 2652
@@ -2804,7 +2804,7 @@ int journal_init(struct super_block *sb, const char *j_dev_name, · 151 unmodified lines
2804 "journal header magic %x (device %pg) does "2804 "journal header magic %x (device %pg) does "
2805 "not match to magic found in super block %x",2805 "not match to magic found in super block %x",
2806 jh->jh_journal.jp_journal_magic,2806 jh->jh_journal.jp_journal_magic,
2807 journal->j_bdev_handle->bdev,2807 file_bdev(journal->j_bdev_file),
2808 sb_jp_journal_magic(rs));2808 sb_jp_journal_magic(rs));
2809 brelse(bhjh);2809 brelse(bhjh);
2810 goto free_and_return;2810 goto free_and_return;
@@ -2828,7 +2828,7 @@ int journal_init(struct super_block *sb, const char *j_dev_name, · 17 unmodified lines
2828 reiserfs_info(sb, "journal params: device %pg, size %u, "2828 reiserfs_info(sb, "journal params: device %pg, size %u, "
2829 "journal first block %u, max trans len %u, max batch %u, "2829 "journal first block %u, max trans len %u, max batch %u, "
2830 "max commit age %u, max trans age %u\n",2830 "max commit age %u, max trans age %u\n",
2831 journal->j_bdev_handle->bdev,2831 file_bdev(journal->j_bdev_file),
2832 SB_ONDISK_JOURNAL_SIZE(sb),2832 SB_ONDISK_JOURNAL_SIZE(sb),
2833 SB_ONDISK_JOURNAL_1st_BLOCK(sb),2833 SB_ONDISK_JOURNAL_1st_BLOCK(sb),
2834 journal->j_trans_max,2834 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
354 "prepare: \t%12lu\n"354 "prepare: \t%12lu\n"
355 "prepare_retry: \t%12lu\n",355 "prepare_retry: \t%12lu\n",
356 DJP(jp_journal_1st_block),356 DJP(jp_journal_1st_block),
357 SB_JOURNAL(sb)->j_bdev_handle->bdev,357 file_bdev(SB_JOURNAL(sb)->j_bdev_file),
358 DJP(jp_journal_dev),358 DJP(jp_journal_dev),
359 DJP(jp_journal_size),359 DJP(jp_journal_size),
360 DJP(jp_journal_trans_max),360 DJP(jp_journal_trans_max),
fs/reiserfs/reiserfs.h+4−4
@@ -299,7 +299,7 @@ struct reiserfs_journal { · 298 unmodified lines
299 /* oldest journal block. start here for traverse */299 /* oldest journal block. start here for traverse */
300 struct reiserfs_journal_cnode *j_first;300 struct reiserfs_journal_cnode *j_first;
301 301
302 struct bdev_handle *j_bdev_handle;302 struct file *j_bdev_file;
303 303
304 /* first block on s_dev of reserved area journal */304 /* first block on s_dev of reserved area journal */
305 int j_1st_reserved_block;305 int j_1st_reserved_block;
@@ -2810,10 +2810,10 @@ struct reiserfs_journal_header { · 2504 unmodified lines
2810 2810
2811/* We need these to make journal.c code more readable */2811/* We need these to make journal.c code more readable */
2812#define journal_find_get_block(s, block) __find_get_block(\2812#define journal_find_get_block(s, block) __find_get_block(\
2813 SB_JOURNAL(s)->j_bdev_handle->bdev, block, s->s_blocksize)2813 file_bdev(SB_JOURNAL(s)->j_bdev_file), block, s->s_blocksize)
2814#define journal_getblk(s, block) __getblk(SB_JOURNAL(s)->j_bdev_handle->bdev,\2814#define journal_getblk(s, block) __getblk(file_bdev(SB_JOURNAL(s)->j_bdev_file),\
2815 block, s->s_blocksize)2815 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),\
2817 block, s->s_blocksize)2817 block, s->s_blocksize)
2818 2818
2819enum reiserfs_bh_state_bits {2819enum 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
594#ifdef CONFIG_ROMFS_ON_BLOCK594#ifdef CONFIG_ROMFS_ON_BLOCK
595 if (sb->s_bdev) {595 if (sb->s_bdev) {
596 sync_blockdev(sb->s_bdev);596 sync_blockdev(sb->s_bdev);
597 bdev_release(sb->s_bdev_handle);597 fput(sb->s_bdev_file);
598 }598 }
599#endif599#endif
600}600}
fs/super.c+9−9
@@ -1527,16 +1527,16 @@ int setup_bdev_super(struct super_block *sb, int sb_flags, · 1526 unmodified lines
1527 struct fs_context *fc)1527 struct fs_context *fc)
1528{1528{
1529 blk_mode_t mode = sb_open_mode(sb_flags);1529 blk_mode_t mode = sb_open_mode(sb_flags);
1530 struct bdev_handle *bdev_handle;1530 struct file *bdev_file;
1531 struct block_device *bdev;1531 struct block_device *bdev;
1532 1532
1533 bdev_handle = bdev_open_by_dev(sb->s_dev, mode, sb, &fs_holder_ops);1533 bdev_file = bdev_file_open_by_dev(sb->s_dev, mode, sb, &fs_holder_ops);
1534 if (IS_ERR(bdev_handle)) {1534 if (IS_ERR(bdev_file)) {
1535 if (fc)1535 if (fc)
1536 errorf(fc, "%s: Can't open blockdev", fc->source);1536 errorf(fc, "%s: Can't open blockdev", fc->source);
1537 return PTR_ERR(bdev_handle);1537 return PTR_ERR(bdev_file);
1538 }1538 }
1539 bdev = bdev_handle->bdev;1539 bdev = file_bdev(bdev_file);
1540 1540
1541 /*1541 /*
1542 * This really should be in blkdev_get_by_dev, but right now can't due1542 * 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
1544 * writable from userspace even for a read-only block device.1544 * writable from userspace even for a read-only block device.
1545 */1545 */
1546 if ((mode & BLK_OPEN_WRITE) && bdev_read_only(bdev)) {1546 if ((mode & BLK_OPEN_WRITE) && bdev_read_only(bdev)) {
1547 bdev_release(bdev_handle);1547 fput(bdev_file);
1548 return -EACCES;1548 return -EACCES;
1549 }1549 }
1550 1550
@@ -1555,11 +1555,11 @@ int setup_bdev_super(struct super_block *sb, int sb_flags, · 4 unmodified lines
1555 if (atomic_read(&bdev->bd_fsfreeze_count) > 0) {1555 if (atomic_read(&bdev->bd_fsfreeze_count) > 0) {
1556 if (fc)1556 if (fc)
1557 warnf(fc, "%pg: Can't mount, blockdev is frozen", bdev);1557 warnf(fc, "%pg: Can't mount, blockdev is frozen", bdev);
1558 bdev_release(bdev_handle);1558 fput(bdev_file);
1559 return -EBUSY;1559 return -EBUSY;
1560 }1560 }
1561 spin_lock(&sb_lock);1561 spin_lock(&sb_lock);
1562 sb->s_bdev_handle = bdev_handle;1562 sb->s_bdev_file = bdev_file;
1563 sb->s_bdev = bdev;1563 sb->s_bdev = bdev;
1564 sb->s_bdi = bdi_get(bdev->bd_disk->bdi);1564 sb->s_bdi = bdi_get(bdev->bd_disk->bdi);
1565 if (bdev_stable_writes(bdev))1565 if (bdev_stable_writes(bdev))
@@ -1675,7 +1675,7 @@ void kill_block_super(struct super_block *sb) · 109 unmodified lines
1675 generic_shutdown_super(sb);1675 generic_shutdown_super(sb);
1676 if (bdev) {1676 if (bdev) {
1677 sync_blockdev(bdev);1677 sync_blockdev(bdev);
1678 bdev_release(sb->s_bdev_handle);1678 fput(sb->s_bdev_file);
1679 }1679 }
1680}1680}
1681 1681
fs/xfs/xfs_buf.c+5−5
@@ -1951,7 +1951,7 @@ xfs_free_buftarg( · 1950 unmodified lines
1951 fs_put_dax(btp->bt_daxdev, btp->bt_mount);1951 fs_put_dax(btp->bt_daxdev, btp->bt_mount);
1952 /* the main block device is closed by kill_block_super */1952 /* the main block device is closed by kill_block_super */
1953 if (btp->bt_bdev != btp->bt_mount->m_super->s_bdev)1953 if (btp->bt_bdev != btp->bt_mount->m_super->s_bdev)
1954 bdev_release(btp->bt_bdev_handle);1954 fput(btp->bt_bdev_file);
1955 1955
1956 kmem_free(btp);1956 kmem_free(btp);
1957}1957}
@@ -1994,7 +1994,7 @@ xfs_setsize_buftarg_early( · 36 unmodified lines
1994struct xfs_buftarg *1994struct xfs_buftarg *
1995xfs_alloc_buftarg(1995xfs_alloc_buftarg(
1996 struct xfs_mount *mp,1996 struct xfs_mount *mp,
1997 struct bdev_handle *bdev_handle)1997 struct file *bdev_file)
1998{1998{
1999 xfs_buftarg_t *btp;1999 xfs_buftarg_t *btp;
2000 const struct dax_holder_operations *ops = NULL;2000 const struct dax_holder_operations *ops = NULL;
@@ -2005,9 +2005,9 @@ xfs_alloc_buftarg( · 4 unmodified lines
2005 btp = kmem_zalloc(sizeof(*btp), KM_NOFS);2005 btp = kmem_zalloc(sizeof(*btp), KM_NOFS);
2006 2006
2007 btp->bt_mount = mp;2007 btp->bt_mount = mp;
2008 btp->bt_bdev_handle = bdev_handle;2008 btp->bt_bdev_file = bdev_file;
2009 btp->bt_dev = bdev_handle->bdev->bd_dev;2009 btp->bt_bdev = file_bdev(bdev_file);
2010 btp->bt_bdev = bdev_handle->bdev;2010 btp->bt_dev = btp->bt_bdev->bd_dev;
2011 btp->bt_daxdev = fs_dax_get_by_bdev(btp->bt_bdev, &btp->bt_dax_part_off,2011 btp->bt_daxdev = fs_dax_get_by_bdev(btp->bt_bdev, &btp->bt_dax_part_off,
2012 mp, ops);2012 mp, ops);
2013 2013
fs/xfs/xfs_buf.h+2−2
@@ -98,7 +98,7 @@ typedef unsigned int xfs_buf_flags_t; · 97 unmodified lines
98 */98 */
99typedef struct xfs_buftarg {99typedef struct xfs_buftarg {
100 dev_t bt_dev;100 dev_t bt_dev;
101 struct bdev_handle *bt_bdev_handle;101 struct file *bt_bdev_file;
102 struct block_device *bt_bdev;102 struct block_device *bt_bdev;
103 struct dax_device *bt_daxdev;103 struct dax_device *bt_daxdev;
104 u64 bt_dax_part_off;104 u64 bt_dax_part_off;
@@ -366,7 +366,7 @@ xfs_buf_update_cksum(struct xfs_buf *bp, unsigned long cksum_offset) · 261 unmodified lines
366 * Handling of buftargs.366 * Handling of buftargs.
367 */367 */
368struct xfs_buftarg *xfs_alloc_buftarg(struct xfs_mount *mp,368struct xfs_buftarg *xfs_alloc_buftarg(struct xfs_mount *mp,
369 struct bdev_handle *bdev_handle);369 struct file *bdev_file);
370extern void xfs_free_buftarg(struct xfs_buftarg *);370extern void xfs_free_buftarg(struct xfs_buftarg *);
371extern void xfs_buftarg_wait(struct xfs_buftarg *);371extern void xfs_buftarg_wait(struct xfs_buftarg *);
372extern void xfs_buftarg_drain(struct xfs_buftarg *);372extern void xfs_buftarg_drain(struct xfs_buftarg *);
fs/xfs/xfs_super.c+22−22
@@ -361,16 +361,16 @@ STATIC int · 360 unmodified lines
361xfs_blkdev_get(361xfs_blkdev_get(
362 xfs_mount_t *mp,362 xfs_mount_t *mp,
363 const char *name,363 const char *name,
364 struct bdev_handle **handlep)364 struct file **bdev_filep)
365{365{
366 int error = 0;366 int error = 0;
367 367
368 *handlep = bdev_open_by_path(name,368 *bdev_filep = bdev_file_open_by_path(name,
369 BLK_OPEN_READ | BLK_OPEN_WRITE | BLK_OPEN_RESTRICT_WRITES,369 BLK_OPEN_READ | BLK_OPEN_WRITE | BLK_OPEN_RESTRICT_WRITES,
370 mp->m_super, &fs_holder_ops);370 mp->m_super, &fs_holder_ops);
371 if (IS_ERR(*handlep)) {371 if (IS_ERR(*bdev_filep)) {
372 error = PTR_ERR(*handlep);372 error = PTR_ERR(*bdev_filep);
373 *handlep = NULL;373 *bdev_filep = NULL;
374 xfs_warn(mp, "Invalid device [%s], error=%d", name, error);374 xfs_warn(mp, "Invalid device [%s], error=%d", name, error);
375 }375 }
376 376
@@ -435,26 +435,26 @@ xfs_open_devices( · 58 unmodified lines
435{435{
436 struct super_block *sb = mp->m_super;436 struct super_block *sb = mp->m_super;
437 struct block_device *ddev = sb->s_bdev;437 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;
439 int error;439 int error;
440 440
441 /*441 /*
442 * Open real time and log devices - order is important.442 * Open real time and log devices - order is important.
443 */443 */
444 if (mp->m_logname) {444 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);
446 if (error)446 if (error)
447 return error;447 return error;
448 }448 }
449 449
450 if (mp->m_rtname) {450 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);
452 if (error)452 if (error)
453 goto out_close_logdev;453 goto out_close_logdev;
454 454
455 if (rtdev_handle->bdev == ddev ||455 if (file_bdev(rtdev_file) == ddev ||
456 (logdev_handle &&456 (logdev_file &&
457 rtdev_handle->bdev == logdev_handle->bdev)) {457 file_bdev(rtdev_file) == file_bdev(logdev_file))) {
458 xfs_warn(mp,458 xfs_warn(mp,
459 "Cannot mount filesystem with identical rtdev and ddev/logdev.");459 "Cannot mount filesystem with identical rtdev and ddev/logdev.");
460 error = -EINVAL;460 error = -EINVAL;
@@ -466,25 +466,25 @@ xfs_open_devices( · 5 unmodified lines
466 * Setup xfs_mount buffer target pointers466 * Setup xfs_mount buffer target pointers
467 */467 */
468 error = -ENOMEM;468 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);
470 if (!mp->m_ddev_targp)470 if (!mp->m_ddev_targp)
471 goto out_close_rtdev;471 goto out_close_rtdev;
472 472
473 if (rtdev_handle) {473 if (rtdev_file) {
474 mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev_handle);474 mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev_file);
475 if (!mp->m_rtdev_targp)475 if (!mp->m_rtdev_targp)
476 goto out_free_ddev_targ;476 goto out_free_ddev_targ;
477 }477 }
478 478
479 if (logdev_handle && logdev_handle->bdev != ddev) {479 if (logdev_file && file_bdev(logdev_file) != ddev) {
480 mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev_handle);480 mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev_file);
481 if (!mp->m_logdev_targp)481 if (!mp->m_logdev_targp)
482 goto out_free_rtdev_targ;482 goto out_free_rtdev_targ;
483 } else {483 } else {
484 mp->m_logdev_targp = mp->m_ddev_targp;484 mp->m_logdev_targp = mp->m_ddev_targp;
485 /* Handle won't be used, drop it */485 /* Handle won't be used, drop it */
486 if (logdev_handle)486 if (logdev_file)
487 bdev_release(logdev_handle);487 fput(logdev_file);
488 }488 }
489 489
490 return 0;490 return 0;
@@ -495,11 +495,11 @@ xfs_open_devices( · 4 unmodified lines
495 out_free_ddev_targ:495 out_free_ddev_targ:
496 xfs_free_buftarg(mp->m_ddev_targp);496 xfs_free_buftarg(mp->m_ddev_targp);
497 out_close_rtdev:497 out_close_rtdev:
498 if (rtdev_handle)498 if (rtdev_file)
499 bdev_release(rtdev_handle);499 fput(rtdev_file);
500 out_close_logdev:500 out_close_logdev:
501 if (logdev_handle)501 if (logdev_file)
502 bdev_release(logdev_handle);502 fput(logdev_file);
503 return error;503 return error;
504}504}
505 505
include/linux/blkdev.h+4−9
@@ -24,6 +24,7 @@ · 23 unmodified lines
24#include <linux/sbitmap.h>24#include <linux/sbitmap.h>
25#include <linux/uuid.h>25#include <linux/uuid.h>
26#include <linux/xarray.h>26#include <linux/xarray.h>
27#include <linux/file.h>
27 28
28struct module;29struct module;
29struct request_queue;30struct request_queue;
@@ -1474,26 +1475,20 @@ extern const struct blk_holder_ops fs_holder_ops; · 1444 unmodified lines
1474 (BLK_OPEN_READ | BLK_OPEN_RESTRICT_WRITES | \1475 (BLK_OPEN_READ | BLK_OPEN_RESTRICT_WRITES | \
1475 (((flags) & SB_RDONLY) ? 0 : BLK_OPEN_WRITE))1476 (((flags) & SB_RDONLY) ? 0 : BLK_OPEN_WRITE))
1476 1477
1477struct bdev_handle {1478struct file *bdev_file_open_by_dev(dev_t dev, blk_mode_t mode, void *holder,
1478 struct block_device *bdev;
1479 void *holder;
1480 blk_mode_t mode;
1481};
1482
1483struct bdev_handle *bdev_open_by_dev(dev_t dev, blk_mode_t mode, void *holder,
1484 const struct blk_holder_ops *hops);1479 const struct blk_holder_ops *hops);
1485struct bdev_handle *bdev_open_by_path(const char *path, blk_mode_t mode,1480struct file *bdev_file_open_by_path(const char *path, blk_mode_t mode,
1486 void *holder, const struct blk_holder_ops *hops);1481 void *holder, const struct blk_holder_ops *hops);
1487int bd_prepare_to_claim(struct block_device *bdev, void *holder,1482int bd_prepare_to_claim(struct block_device *bdev, void *holder,
1488 const struct blk_holder_ops *hops);1483 const struct blk_holder_ops *hops);
1489void bd_abort_claiming(struct block_device *bdev, void *holder);1484void bd_abort_claiming(struct block_device *bdev, void *holder);
1490void bdev_release(struct bdev_handle *handle);
1491 1485
1492/* just for blk-cgroup, don't use elsewhere */1486/* just for blk-cgroup, don't use elsewhere */
1493struct block_device *blkdev_get_no_open(dev_t dev);1487struct block_device *blkdev_get_no_open(dev_t dev);
1494void blkdev_put_no_open(struct block_device *bdev);1488void blkdev_put_no_open(struct block_device *bdev);
1495 1489
1496struct block_device *I_BDEV(struct inode *inode);1490struct block_device *I_BDEV(struct inode *inode);
1491struct block_device *file_bdev(struct file *bdev_file);
1497 1492
1498#ifdef CONFIG_BLOCK1493#ifdef CONFIG_BLOCK
1499void invalidate_bdev(struct block_device *bdev);1494void 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
165 165
166struct dm_dev {166struct dm_dev {
167 struct block_device *bdev;167 struct block_device *bdev;
168 struct bdev_handle *bdev_handle;168 struct file *bdev_file;
169 struct dax_device *dax_dev;169 struct dax_device *dax_dev;
170 blk_mode_t mode;170 blk_mode_t mode;
171 char name[16];171 char name[16];
include/linux/file.h+2−0
@@ -24,6 +24,8 @@ struct inode; · 23 unmodified lines
24struct path;24struct path;
25extern struct file *alloc_file_pseudo(struct inode *, struct vfsmount *,25extern struct file *alloc_file_pseudo(struct inode *, struct vfsmount *,
26 const char *, int flags, const struct file_operations *);26 const char *, int flags, const struct file_operations *);
27extern struct file *alloc_file_pseudo_noaccount(struct inode *, struct vfsmount *,
28 const char *, int flags, const struct file_operations *);
27extern struct file *alloc_file_clone(struct file *, int flags,29extern struct file *alloc_file_clone(struct file *, int flags,
28 const struct file_operations *);30 const struct file_operations *);
29 31
include/linux/fs.h+2−2
@@ -1237,8 +1237,8 @@ struct super_block { · 1236 unmodified lines
1237#endif1237#endif
1238 struct hlist_bl_head s_roots; /* alternate root dentries for NFS */1238 struct hlist_bl_head s_roots; /* alternate root dentries for NFS */
1239 struct list_head s_mounts; /* list of mounts; _not_ for fs use */1239 struct list_head s_mounts; /* list of mounts; _not_ for fs use */
1240 struct block_device *s_bdev;1240 struct block_device *s_bdev; /* can go away once we use an accessor for @s_bdev_file */
1241 struct bdev_handle *s_bdev_handle;1241 struct file *s_bdev_file;
1242 struct backing_dev_info *s_bdi;1242 struct backing_dev_info *s_bdi;
1243 struct mtd_info *s_mtd;1243 struct mtd_info *s_mtd;
1244 struct hlist_node s_instances;1244 struct hlist_node s_instances;
include/linux/pktcdvd.h+2−2
@@ -154,9 +154,9 @@ struct packet_stacked_data · 153 unmodified lines
154 154
155struct pktcdvd_device155struct pktcdvd_device
156{156{
157 struct bdev_handle *bdev_handle; /* dev attached */157 struct file *bdev_file; /* dev attached */
158 /* handle acquired for bdev during pkt_open_dev() */158 /* handle acquired for bdev during pkt_open_dev() */
159 struct bdev_handle *open_bdev_handle;159 struct file *f_open_bdev;
160 dev_t pkt_dev; /* our dev */160 dev_t pkt_dev; /* our dev */
161 struct packet_settings settings;161 struct packet_settings settings;
162 struct packet_stats stats;162 struct packet_stats stats;
include/linux/swap.h+1−1
@@ -298,7 +298,7 @@ struct swap_info_struct { · 297 unmodified lines
298 unsigned int __percpu *cluster_next_cpu; /*percpu index for next allocation */298 unsigned int __percpu *cluster_next_cpu; /*percpu index for next allocation */
299 struct percpu_cluster __percpu *percpu_cluster; /* per cpu's swap location */299 struct percpu_cluster __percpu *percpu_cluster; /* per cpu's swap location */
300 struct rb_root swap_extent_root;/* root of the swap extent rbtree */300 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 */
302 struct block_device *bdev; /* swap device or bdev of swap file */302 struct block_device *bdev; /* swap device or bdev of swap file */
303 struct file *swap_file; /* seldom referenced */303 struct file *swap_file; /* seldom referenced */
304 unsigned int old_block_size; /* seldom referenced */304 unsigned int old_block_size; /* seldom referenced */
init/do_mounts.c+3−0
@@ -208,6 +208,9 @@ retry: · 207 unmodified lines
208 goto out;208 goto out;
209 case -EACCES:209 case -EACCES:
210 case -EINVAL:210 case -EINVAL:
211#ifdef CONFIG_BLOCK
212 init_flush_fput();
213#endif
211 continue;214 continue;
212 }215 }
213 /*216 /*
init/do_mounts.h+9−0
@@ -9,6 +9,8 @@ · 8 unmodified lines
9#include <linux/major.h>9#include <linux/major.h>
10#include <linux/root_dev.h>10#include <linux/root_dev.h>
11#include <linux/init_syscalls.h>11#include <linux/init_syscalls.h>
12#include <linux/task_work.h>
13#include <linux/file.h>
12 14
13void mount_root_generic(char *name, char *pretty_name, int flags);15void mount_root_generic(char *name, char *pretty_name, int flags);
14void mount_root(char *root_device_name);16void mount_root(char *root_device_name);
@@ -41,3 +43,10 @@ static inline bool initrd_load(char *root_device_name) · 26 unmodified lines
41 }43 }
42 44
43#endif45#endif
46
47/* Ensure that async file closing finished to prevent spurious errors. */
48static 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
16#include <linux/mm.h>16#include <linux/mm.h>
17#include <linux/namei.h>17#include <linux/namei.h>
18#include <linux/init_syscalls.h>18#include <linux/init_syscalls.h>
19#include <linux/task_work.h>
20#include <linux/umh.h>19#include <linux/umh.h>
21 20
21#include "do_mounts.h"
22
22static __initdata bool csum_present;23static __initdata bool csum_present;
23static __initdata u32 io_csum;24static __initdata u32 io_csum;
24 25
@@ -734,8 +735,7 @@ done: · 709 unmodified lines
734 initrd_start = 0;735 initrd_start = 0;
735 initrd_end = 0;736 initrd_end = 0;
736 737
737 flush_delayed_fput();738 init_flush_fput();
738 task_work_run();
739}739}
740 740
741static ASYNC_DOMAIN_EXCLUSIVE(initramfs_domain);741static ASYNC_DOMAIN_EXCLUSIVE(initramfs_domain);
kernel/power/swap.c+14−14
@@ -222,7 +222,7 @@ int swsusp_swap_in_use(void) · 221 unmodified lines
222 */222 */
223 223
224static unsigned short root_swap = 0xffff;224static unsigned short root_swap = 0xffff;
225static struct bdev_handle *hib_resume_bdev_handle;225static struct file *hib_resume_bdev_file;
226 226
227struct hib_bio_batch {227struct hib_bio_batch {
228 atomic_t count;228 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
276 struct bio *bio;276 struct bio *bio;
277 int error = 0;277 int error = 0;
278 278
279 bio = bio_alloc(hib_resume_bdev_handle->bdev, 1, opf,279 bio = bio_alloc(file_bdev(hib_resume_bdev_file), 1, opf,
280 GFP_NOIO | __GFP_HIGH);280 GFP_NOIO | __GFP_HIGH);
281 bio->bi_iter.bi_sector = page_off * (PAGE_SIZE >> 9);281 bio->bi_iter.bi_sector = page_off * (PAGE_SIZE >> 9);
282 282
@@ -357,14 +357,14 @@ static int swsusp_swap_check(void) · 74 unmodified lines
357 return res;357 return res;
358 root_swap = res;358 root_swap = res;
359 359
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,
361 BLK_OPEN_WRITE, NULL, NULL);361 BLK_OPEN_WRITE, NULL, NULL);
362 if (IS_ERR(hib_resume_bdev_handle))362 if (IS_ERR(hib_resume_bdev_file))
363 return PTR_ERR(hib_resume_bdev_handle);363 return PTR_ERR(hib_resume_bdev_file);
364 364
365 res = set_blocksize(hib_resume_bdev_handle->bdev, PAGE_SIZE);365 res = set_blocksize(file_bdev(hib_resume_bdev_file), PAGE_SIZE);
366 if (res < 0)366 if (res < 0)
367 bdev_release(hib_resume_bdev_handle);367 fput(hib_resume_bdev_file);
368 368
369 return res;369 return res;
370}370}
@@ -1523,10 +1523,10 @@ int swsusp_check(bool exclusive) · 1152 unmodified lines
1523 void *holder = exclusive ? &swsusp_holder : NULL;1523 void *holder = exclusive ? &swsusp_holder : NULL;
1524 int error;1524 int error;
1525 1525
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,
1527 BLK_OPEN_READ, holder, NULL);1527 BLK_OPEN_READ, holder, NULL);
1528 if (!IS_ERR(hib_resume_bdev_handle)) {1528 if (!IS_ERR(hib_resume_bdev_file)) {
1529 set_blocksize(hib_resume_bdev_handle->bdev, PAGE_SIZE);1529 set_blocksize(file_bdev(hib_resume_bdev_file), PAGE_SIZE);
1530 clear_page(swsusp_header);1530 clear_page(swsusp_header);
1531 error = hib_submit_io(REQ_OP_READ, swsusp_resume_block,1531 error = hib_submit_io(REQ_OP_READ, swsusp_resume_block,
1532 swsusp_header, NULL);1532 swsusp_header, NULL);
@@ -1551,11 +1551,11 @@ int swsusp_check(bool exclusive) · 18 unmodified lines
1551 1551
1552put:1552put:
1553 if (error)1553 if (error)
1554 bdev_release(hib_resume_bdev_handle);1554 fput(hib_resume_bdev_file);
1555 else1555 else
1556 pr_debug("Image signature found, resuming\n");1556 pr_debug("Image signature found, resuming\n");
1557 } else {1557 } else {
1558 error = PTR_ERR(hib_resume_bdev_handle);1558 error = PTR_ERR(hib_resume_bdev_file);
1559 }1559 }
1560 1560
1561 if (error)1561 if (error)
@@ -1570,12 +1570,12 @@ put: · 8 unmodified lines
1570 1570
1571void swsusp_close(void)1571void swsusp_close(void)
1572{1572{
1573 if (IS_ERR(hib_resume_bdev_handle)) {1573 if (IS_ERR(hib_resume_bdev_file)) {
1574 pr_debug("Image device not initialised\n");1574 pr_debug("Image device not initialised\n");
1575 return;1575 return;
1576 }1576 }
1577 1577
1578 bdev_release(hib_resume_bdev_handle);1578 fput(hib_resume_bdev_file);
1579}1579}
1580 1580
1581/**1581/**
mm/swapfile.c+11−11
@@ -2532,10 +2532,10 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile) · 2531 unmodified lines
2532 exit_swap_address_space(p->type);2532 exit_swap_address_space(p->type);
2533 2533
2534 inode = mapping->host;2534 inode = mapping->host;
2535 if (p->bdev_handle) {2535 if (p->bdev_file) {
2536 set_blocksize(p->bdev, old_block_size);2536 set_blocksize(p->bdev, old_block_size);
2537 bdev_release(p->bdev_handle);2537 fput(p->bdev_file);
2538 p->bdev_handle = NULL;2538 p->bdev_file = NULL;
2539 }2539 }
2540 2540
2541 inode_lock(inode);2541 inode_lock(inode);
@@ -2765,14 +2765,14 @@ static int claim_swapfile(struct swap_info_struct *p, struct inode *inode) · 223 unmodified lines
2765 int error;2765 int error;
2766 2766
2767 if (S_ISBLK(inode->i_mode)) {2767 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,
2769 BLK_OPEN_READ | BLK_OPEN_WRITE, p, NULL);2769 BLK_OPEN_READ | BLK_OPEN_WRITE, p, NULL);
2770 if (IS_ERR(p->bdev_handle)) {2770 if (IS_ERR(p->bdev_file)) {
2771 error = PTR_ERR(p->bdev_handle);2771 error = PTR_ERR(p->bdev_file);
2772 p->bdev_handle = NULL;2772 p->bdev_file = NULL;
2773 return error;2773 return error;
2774 }2774 }
2775 p->bdev = p->bdev_handle->bdev;2775 p->bdev = file_bdev(p->bdev_file);
2776 p->old_block_size = block_size(p->bdev);2776 p->old_block_size = block_size(p->bdev);
2777 error = set_blocksize(p->bdev, PAGE_SIZE);2777 error = set_blocksize(p->bdev, PAGE_SIZE);
2778 if (error < 0)2778 if (error < 0)
@@ -3208,10 +3208,10 @@ bad_swap: · 429 unmodified lines
3208 p->percpu_cluster = NULL;3208 p->percpu_cluster = NULL;
3209 free_percpu(p->cluster_next_cpu);3209 free_percpu(p->cluster_next_cpu);
3210 p->cluster_next_cpu = NULL;3210 p->cluster_next_cpu = NULL;
3211 if (p->bdev_handle) {3211 if (p->bdev_file) {
3212 set_blocksize(p->bdev, p->old_block_size);3212 set_blocksize(p->bdev, p->old_block_size);
3213 bdev_release(p->bdev_handle);3213 fput(p->bdev_file);
3214 p->bdev_handle = NULL;3214 p->bdev_file = NULL;
3215 }3215 }
3216 inode = NULL;3216 inode = NULL;
3217 destroy_swap_extents(p);3217 destroy_swap_extents(p);