merge struct block_device and struct hd_struct
Subsystems (26)
Christoph Hellwig
maintainerHi Jens,
this series cleans up our main per-device node data structure by merging the block_device and hd_struct data structures that have the same scope, but different life times. The main effect (besides removing lots of code) is that instead of having two device sizes that need complex synchronization there is just one now.
Note that it depends on the previous "misc cleanups" series.
A git tree is available here:
git://git.infradead.org/users/hch/block.git bdev-lookup
Gitweb:
http://git.infradead.org/users/hch/block.git/shortlog/refs/heads/bdev-lookup
Diffstat:
block/bio.c | 6 block/blk-cgroup.c | 50 +- block/blk-core.c | 85 +-- block/blk-flush.c | 2 block/blk-iocost.c | 36 - block/blk-lib.c | 2 block/blk-merge.c | 6 block/blk-mq.c | 11 block/blk-mq.h | 5 block/blk.h | 92 ---- block/genhd.c | 444 +++++--------------- block/ioctl.c | 7 block/partitions/core.c | 238 +++-------- drivers/block/drbd/drbd_receiver.c | 2 drivers/block/drbd/drbd_worker.c | 2 drivers/block/loop.c | 21 drivers/block/nbd.c | 6 drivers/block/xen-blkback/common.h | 4 drivers/block/xen-blkfront.c | 20 drivers/block/zram/zram_drv.c | 20 drivers/md/bcache/request.c | 4 drivers/md/bcache/super.c | 53 -- drivers/md/dm-table.c | 9 drivers/md/dm.c | 16 drivers/md/md.c | 8 drivers/mtd/mtdsuper.c | 17 drivers/nvme/target/admin-cmd.c | 20 drivers/s390/block/dasd.c | 8 drivers/s390/block/dasd_ioctl.c | 9 drivers/scsi/scsicam.c | 2 drivers/target/target_core_file.c | 6 drivers/target/target_core_pscsi.c | 7 drivers/usb/gadget/function/storage_common.c | 8 fs/block_dev.c | 578 ++++++++------------------- fs/btrfs/sysfs.c | 15 fs/btrfs/volumes.c | 13 fs/ext4/super.c | 18 fs/ext4/sysfs.c | 10 fs/f2fs/checkpoint.c | 5 fs/f2fs/f2fs.h | 2 fs/f2fs/super.c | 8 fs/f2fs/sysfs.c | 9 fs/inode.c | 3 fs/internal.h | 7 fs/io_uring.c | 10 fs/pipe.c | 5 fs/pstore/blk.c | 2 fs/quota/quota.c | 40 + fs/statfs.c | 2 fs/super.c | 86 ---- include/linux/blk-cgroup.h | 4 include/linux/blk_types.h | 26 + include/linux/blkdev.h | 24 - include/linux/fs.h | 5 include/linux/genhd.h | 104 ---- include/linux/part_stat.h | 17 init/do_mounts.c | 271 +++++------- kernel/trace/blktrace.c | 54 -- mm/filemap.c | 9 59 files changed, 837 insertions(+), 1716 deletions(-)
Christoph Hellwig
maintainerPATCH 1/20 blk-cgroup: fix a hd_struct leak in blkcg_fill_root_iostats
disk_get_part needs to be paired with a disk_put_part.
--- block/blk-cgroup.c | 1 + 1 file changed, 1 insertion(+)
block/blk-cgroup.c +1 -0
@@ -849,6 +849,7 @@ static void blkcg_fill_root_iostats(void)blkg_iostat_set (&blkg->iostat.cur, &tmp);u64_stats_update_end (&blkg->iostat.sync); } +disk_put_part (part); } }
Signature · 1 line
2.29.2
Re: [PATCH 01/20] blk-cgroup: fix a hd_struct leak in blkcg_fill_root_iostats
Quoted 4 lines · Christoph Hellwig
disk_get_partneeds to be paired with adisk_put_part.Fixes ef45fe470e1 ("blk-cgroup: show global disk stats in root cgroup io.stat")Signed-off-by Christoph Hellwig <[email protected]>
Looks good to me. You can add:
Honza
Quoted 19 lines
--- block/blk-cgroup.c | 1 + 1 file changed, 1 insertion(+)block/blk-cgroup.c +1
-0@@ -849,6 +849,7 @@ static void blkcg_fill_root_iostats(void)blkg_iostat_set (&blkg->iostat.cur, &tmp);u64_stats_update_end (&blkg->iostat.sync); } +disk_put_part (part); } }Signature · 1 line
2.29.2
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH 01/20] blk-cgroup: fix a hd_struct leak in blkcg_fill_root_iostats
In reply to Christoph HellwigLooks good,
Re: [PATCH 01/20] blk-cgroup: fix a hd_struct leak in blkcg_fill_root_iostats
In reply to Christoph HellwigQuoted 4 lines · Christoph Hellwig
disk_get_partneeds to be paired with adisk_put_part.Fixes ef45fe470e1 ("blk-cgroup: show global disk stats in root cgroup io.stat")Signed-off-by Christoph Hellwig <[email protected]>
Thanks.
Signature · 1 line
tejun
Christoph Hellwig
maintainerPATCH 2/20 block: remove a duplicate __disk_get_part prototype
In reply to Christoph Hellwig--- include/linux/genhd.h | 1 - 1 file changed, 1 deletion(-)
include/linux/genhd.h +0 -1
@@ -250,7 +250,6 @@ static inline dev_t part_devt(struct hd_struct *part)return part_to_dev (part)->devt; } -extern struct hd_struct *__disk_get_part (struct gendisk *disk,int partno);extern struct hd_struct *disk_get_part (struct gendisk *disk,int partno);static inline void disk_put_part (struct hd_struct *part)
Signature · 1 line
2.29.2
Re: [PATCH 02/20] block: remove a duplicate __disk_get_part prototype
Quoted 1 line · Christoph Hellwig
Signed-off-by Christoph Hellwig <[email protected]>
Looks good. You can add:
Honza
Quoted 19 lines
--- include/linux/genhd.h | 1 - 1 file changed, 1 deletion(-)include/linux/genhd.h +0
-1@@ -250,7 +250,6 @@ static inline dev_t part_devt(struct hd_struct *part)return part_to_dev (part)->devt; } -extern struct hd_struct *__disk_get_part (struct gendisk *disk,int partno);extern struct hd_struct *disk_get_part (struct gendisk *disk,int partno);static inline void disk_put_part (struct hd_struct *part)Signature · 1 line
2.29.2
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH 02/20] block: remove a duplicate __disk_get_part prototype
In reply to Christoph HellwigLooks good,
Christoph Hellwig
maintainerPATCH 3/20 block: add a bdev_kobj helper
In reply to Christoph HellwigAdd a little helper to find the kobject for a struct block_device.
--- drivers/md/bcache/super.c | 7 ++----- drivers/md/md.c | 4 +--- fs/btrfs/sysfs.c | 15 +++------------ include/linux/blk_types.h | 3 +++ 4 files changed, 9 insertions(+), 20 deletions(-)
drivers/md/bcache/super.c +2 -5
@@ -1447,8 +1447,7 @@ static int register_bdev(struct cache_sb *sb, struct cache_sb_disk *sb_disk, goto err; err ="error creating kobject" ; -if (kobject_add (&dc->disk.kobj, &part_to_dev (bdev->bd_part)->kobj, -"bcache" )) +if (kobject_add (&dc->disk.kobj,bdev_kobj (bdev),"bcache" )) goto err;if (bch_cache_accounting_add_kobjs (&dc->accounting, &dc->disk.kobj)) goto err;
@@ -2342,9 +2341,7 @@ static int register_cache(struct cache_sb *sb, struct cache_sb_disk *sb_disk, goto err; } -if (kobject_add (&ca->kobj, - &part_to_dev (bdev->bd_part)->kobj, -"bcache" )) { +if (kobject_add (&ca->kobj,bdev_kobj (bdev),"bcache" )) { err ="error calling kobject_add" ; ret = -ENOMEM ; goto out;
drivers/md/md.c +1 -3
@@ -2414,7 +2414,6 @@ EXPORT_SYMBOL(md_integrity_add_rdev);static int bind_rdev_to_array (struct md_rdev *rdev,struct mddev *mddev) {char b[BDEVNAME_SIZE ]; -struct kobject *ko;int err;/* prevent duplicates */
@@ -2477,9 +2476,8 @@ static int bind_rdev_to_array(struct md_rdev *rdev, struct mddev *mddev)if ((err =kobject_add (&rdev->kobj, &mddev->kobj,"dev-%s" , b))) goto fail; - ko = &part_to_dev (rdev->bdev->bd_part)->kobj;/* failure here is OK */ - err =sysfs_create_link (&rdev->kobj, ko,"block" ); + err =sysfs_create_link (&rdev->kobj,bdev_kobj (rdev->bdev),"block" ); rdev->sysfs_state =sysfs_get_dirent_safe (rdev->kobj.sd,"state" ); rdev->sysfs_unack_badblocks =sysfs_get_dirent_safe (rdev->kobj.sd,"unacknowledged_bad_blocks" );
fs/btrfs/sysfs.c +3 -12
@@ -1232,8 +1232,6 @@ int btrfs_sysfs_add_space_info_type(struct btrfs_fs_info *fs_info,void btrfs_sysfs_remove_device (struct btrfs_device *device) { -struct hd_struct *disk; -struct kobject *disk_kobj;struct kobject *devices_kobj;/*
@@ -1243,11 +1241,8 @@ void btrfs_sysfs_remove_device(struct btrfs_device *device) devices_kobj = device->fs_info->fs_devices->devices_kobj;ASSERT (devices_kobj); -if (device->bdev) { - disk = device->bdev->bd_part; - disk_kobj = &part_to_dev (disk)->kobj; -sysfs_remove_link (devices_kobj, disk_kobj->name); - } +if (device->bdev) +sysfs_remove_link (devices_kobj,bdev_kobj (device->bdev)->name);if (device->devid_kobj.state_initialized) {kobject_del (&device->devid_kobj);
@@ -1353,11 +1348,7 @@ int btrfs_sysfs_add_device(struct btrfs_device *device) nofs_flag =memalloc_nofs_save ();if (device->bdev) { -struct hd_struct *disk; -struct kobject *disk_kobj; - - disk = device->bdev->bd_part; - disk_kobj = &part_to_dev (disk)->kobj; +struct kobject *disk_kobj =bdev_kobj (device->bdev); ret =sysfs_create_link (devices_kobj, disk_kobj, disk_kobj->name);if (ret) {
include/linux/blk_types.h +3 -0
@@ -48,6 +48,9 @@ struct block_device {struct mutex bd_fsfreeze_mutex; } __randomize_layout; +#define bdev_kobj (_bdev) \ + (&part_to_dev((_bdev)->bd_part)->kobj) +/* * Block error status values. See block/blk-core:blk_errors for the details. * Alpha cannot write a byte atomically, so we need to use 32-bit value.
Signature · 1 line
2.29.2
Re: [PATCH 03/20] block: add a bdev_kobj helper
Quoted 3 lines · Christoph Hellwig
Add a little helper to find the kobject for a struct
block_device.Signed-off-by Christoph Hellwig <[email protected]>
Looks good. You can add:
Honza
Quoted 112 lines
--- drivers/md/bcache/super.c | 7 ++----- drivers/md/md.c | 4 +--- fs/btrfs/sysfs.c | 15 +++------------ include/linux/blk_types.h | 3 +++ 4 files changed, 9 insertions(+), 20 deletions(-)drivers/md/bcache/super.c +2
-5@@ -1447,8 +1447,7 @@ static int register_bdev(struct cache_sb *sb, struct cache_sb_disk *sb_disk, goto err; err ="error creating kobject" ; -if (kobject_add (&dc->disk.kobj, &part_to_dev (bdev->bd_part)->kobj, -"bcache" )) +if (kobject_add (&dc->disk.kobj,bdev_kobj (bdev),"bcache" )) goto err;if (bch_cache_accounting_add_kobjs (&dc->accounting, &dc->disk.kobj)) goto err;@@ -2342,9 +2341,7 @@ static int register_cache(struct cache_sb *sb, struct cache_sb_disk *sb_disk, goto err; } -if (kobject_add (&ca->kobj, - &part_to_dev (bdev->bd_part)->kobj, -"bcache" )) { +if (kobject_add (&ca->kobj,bdev_kobj (bdev),"bcache" )) { err ="error calling kobject_add" ; ret = -ENOMEM ; goto out;drivers/md/md.c +1
-3@@ -2414,7 +2414,6 @@ EXPORT_SYMBOL(md_integrity_add_rdev);static int bind_rdev_to_array (struct md_rdev *rdev,struct mddev *mddev) {char b[BDEVNAME_SIZE ]; -struct kobject *ko;int err;/* prevent duplicates */ @@ -2477,9 +2476,8 @@ static int bind_rdev_to_array(struct md_rdev *rdev, struct mddev *mddev)if ((err =kobject_add (&rdev->kobj, &mddev->kobj,"dev-%s" , b))) goto fail; - ko = &part_to_dev (rdev->bdev->bd_part)->kobj;/* failure here is OK */ - err =sysfs_create_link (&rdev->kobj, ko,"block" ); + err =sysfs_create_link (&rdev->kobj,bdev_kobj (rdev->bdev),"block" ); rdev->sysfs_state =sysfs_get_dirent_safe (rdev->kobj.sd,"state" ); rdev->sysfs_unack_badblocks =sysfs_get_dirent_safe (rdev->kobj.sd,"unacknowledged_bad_blocks" );fs/btrfs/sysfs.c +3
-12@@ -1232,8 +1232,6 @@ int btrfs_sysfs_add_space_info_type(struct btrfs_fs_info *fs_info,void btrfs_sysfs_remove_device (struct btrfs_device *device) { -struct hd_struct *disk; -struct kobject *disk_kobj;struct kobject *devices_kobj;/* @@ -1243,11 +1241,8 @@ void btrfs_sysfs_remove_device(struct btrfs_device *device) devices_kobj = device->fs_info->fs_devices->devices_kobj;ASSERT (devices_kobj); -if (device->bdev) { - disk = device->bdev->bd_part; - disk_kobj = &part_to_dev (disk)->kobj; -sysfs_remove_link (devices_kobj, disk_kobj->name); - } +if (device->bdev) +sysfs_remove_link (devices_kobj,bdev_kobj (device->bdev)->name);if (device->devid_kobj.state_initialized) {kobject_del (&device->devid_kobj);@@ -1353,11 +1348,7 @@ int btrfs_sysfs_add_device(struct btrfs_device *device) nofs_flag =memalloc_nofs_save ();if (device->bdev) { -struct hd_struct *disk; -struct kobject *disk_kobj; - - disk = device->bdev->bd_part; - disk_kobj = &part_to_dev (disk)->kobj; +struct kobject *disk_kobj =bdev_kobj (device->bdev); ret =sysfs_create_link (devices_kobj, disk_kobj, disk_kobj->name);if (ret) {include/linux/blk_types.h +3
-0@@ -48,6 +48,9 @@ struct block_device {struct mutex bd_fsfreeze_mutex; } __randomize_layout; +#define bdev_kobj (_bdev) \ + (&part_to_dev((_bdev)->bd_part)->kobj) +/* * Block error status values. See block/blk-core:blk_errors for the details. * Alpha cannot write a byte atomically, so we need to use 32-bit value. Signature · 1 line
2.29.2
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH 03/20] block: add a bdev_kobj helper
In reply to Christoph HellwigLooks good,
Christoph Hellwig
maintainerPATCH 4/20 block: use disk_part_iter_exit in disk_part_iter_next
In reply to Christoph HellwigCall disk_part_iter_exit in disk_part_iter_next instead of duplicating the functionality.
--- block/genhd.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
block/genhd.c +1 -2
@@ -227,8 +227,7 @@ struct hd_struct *disk_part_iter_next(struct disk_part_iter *piter)int inc, end;/* put the last partition */ -disk_put_part (piter->part); - piter->part =NULL ; +disk_part_iter_exit (piter);/* get part_tbl */ rcu_read_lock ();
Signature · 1 line
2.29.2
Re: [PATCH 04/20] block: use disk_part_iter_exit in disk_part_iter_next
Quoted 4 lines · Christoph Hellwig
Call
disk_part_iter_exitindisk_part_iter_nextinstead of duplicating the functionality.Signed-off-by Christoph Hellwig <[email protected]>
OK. You can add:
Honza
Quoted 21 lines
--- block/genhd.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)block/genhd.c +1
-2@@ -227,8 +227,7 @@ struct hd_struct *disk_part_iter_next(struct disk_part_iter *piter)int inc, end;/* put the last partition */ -disk_put_part (piter->part); - piter->part =NULL ; +disk_part_iter_exit (piter);/* get part_tbl */ rcu_read_lock ();Signature · 1 line
2.29.2
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH 04/20] block: use disk_part_iter_exit in disk_part_iter_next
In reply to Christoph HellwigLooks good,
Christoph Hellwig
maintainerPATCH 5/20 block: use put_device in put_disk
In reply to Christoph HellwigUse put_device to put the device instead of poking into the internals and using kobject_put.
--- block/genhd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/genhd.c +1 -1
@@ -1803,7 +1803,7 @@ EXPORT_SYMBOL(__alloc_disk_node);void put_disk (struct gendisk *disk) {if (disk) -kobject_put (&disk_to_dev (disk)->kobj); +put_device (disk_to_dev (disk)); }EXPORT_SYMBOL (put_disk);
Signature · 1 line
2.29.2
Re: [PATCH 05/20] block: use put_device in put_disk
Quoted 4 lines · Christoph Hellwig
Use
put_deviceto put the device instead of poking into the internals and usingkobject_put.Signed-off-by Christoph Hellwig <[email protected]>
Looks good. You can add:
Honza
Quoted 20 lines
--- block/genhd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)block/genhd.c +1
-1@@ -1803,7 +1803,7 @@ EXPORT_SYMBOL(__alloc_disk_node);void put_disk (struct gendisk *disk) {if (disk) -kobject_put (&disk_to_dev (disk)->kobj); +put_device (disk_to_dev (disk)); }EXPORT_SYMBOL (put_disk);Signature · 1 line
2.29.2
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH 05/20] block: use put_device in put_disk
In reply to Christoph HellwigLooks good,
Christoph Hellwig
maintainerPATCH 6/20 block: change the hash used for looking up block devices
In reply to Christoph HellwigAdding the minor to the major creates tons of pointless conflicts. Just use the dev_t itself, which is 32-bits and thus is guaranteed to fit into ino_t.
--- fs/block_dev.c | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-)
fs/block_dev.c +2 -24
@@ -870,35 +870,12 @@ void __init bdev_cache_init(void) blockdev_superblock = bd_mnt->mnt_sb;/* For writeback */ } -/* -* Most likely _very_ bad one - but then it's hardly critical for small -* /dev and can be fixed when somebody will need really large one. -* Keep in mind that it will be fed through icache hash function too. -*/ -static inline unsigned long hash (dev_t dev) -{ -return MAJOR (dev)+MINOR (dev); -} - -static int bdev_test (struct inode *inode,void *data) -{ -return BDEV_I (inode)->bdev.bd_dev == *(dev_t *)data; -} - -static int bdev_set (struct inode *inode,void *data) -{ -BDEV_I (inode)->bdev.bd_dev = *(dev_t *)data; -return 0 ; -} -static struct block_device *bdget (dev_t dev) {struct block_device *bdev;struct inode *inode; - inode =iget5_locked (blockdev_superblock,hash (dev), - bdev_test, bdev_set, &dev); - + inode =iget_locked (blockdev_superblock, dev);if (!inode)return NULL ;
@@ -910,6 +887,7 @@ static struct block_device *bdget(dev_t dev) bdev->bd_super =NULL ; bdev->bd_inode = inode; bdev->bd_part_count =0 ; + bdev->bd_dev = dev; inode->i_mode =S_IFBLK ; inode->i_rdev = dev; inode->i_bdev = bdev;
Signature · 1 line
2.29.2
Re: [PATCH 06/20] block: change the hash used for looking up block devices
Quoted 5 lines · Christoph Hellwig
Adding the minor to the major creates tons of pointless conflicts. Just use the
dev_titself, which is 32-bits and thus is guaranteed to fit intoino_t.Signed-off-by Christoph Hellwig <[email protected]>
Fair enough. You can add:
Honza
Quoted 56 lines
--- fs/block_dev.c | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-)fs/block_dev.c +2
-24@@ -870,35 +870,12 @@ void __init bdev_cache_init(void) blockdev_superblock = bd_mnt->mnt_sb;/* For writeback */ } -/* -* Most likely _very_ bad one - but then it's hardly critical for small -* /dev and can be fixed when somebody will need really large one. -* Keep in mind that it will be fed through icache hash function too. -*/ -static inline unsigned long hash (dev_t dev) -{ -return MAJOR (dev)+MINOR (dev); -} - -static int bdev_test (struct inode *inode,void *data) -{ -return BDEV_I (inode)->bdev.bd_dev == *(dev_t *)data; -} - -static int bdev_set (struct inode *inode,void *data) -{ -BDEV_I (inode)->bdev.bd_dev = *(dev_t *)data; -return 0 ; -} -static struct block_device *bdget (dev_t dev) {struct block_device *bdev;struct inode *inode; - inode =iget5_locked (blockdev_superblock,hash (dev), - bdev_test, bdev_set, &dev); - + inode =iget_locked (blockdev_superblock, dev);if (!inode)return NULL ;@@ -910,6 +887,7 @@ static struct block_device *bdget(dev_t dev) bdev->bd_super =NULL ; bdev->bd_inode = inode; bdev->bd_part_count =0 ; + bdev->bd_dev = dev; inode->i_mode =S_IFBLK ; inode->i_rdev = dev; inode->i_bdev = bdev;Signature · 1 line
2.29.2
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Christoph Hellwig
maintainerPATCH 7/20 init: refactor name_to_dev_t
In reply to Christoph HellwigSplit each case into a self-contained helper.
--- include/linux/genhd.h | 7 +- init/do_mounts.c | 183 +++++++++++++++++++++--------------------- 2 files changed, 91 insertions(+), 99 deletions(-)
include/linux/genhd.h +1 -6
@@ -388,18 +388,13 @@ static inline void bd_unlink_disk_holder(struct block_device *bdev, }#endif /* CONFIG_SYSFS */ +dev_t blk_lookup_devt (const char *name,int partno);#ifdef CONFIG_BLOCK void printk_all_partitions (void ); -dev_t blk_lookup_devt (const char *name,int partno);#else /* CONFIG_BLOCK */ static inline void printk_all_partitions (void ) { } -static inline dev_t blk_lookup_devt (const char *name,int partno) -{ -dev_t devt =MKDEV (0 ,0 ); -return devt; -}#endif /* CONFIG_BLOCK */ #endif /* _LINUX_GENHD_H */
init/do_mounts.c +90 -93
205 lines not on this page · raw message
Signature · 1 line
2.29.2
Jan Kara
maintainerRe: [PATCH 07/20] init: refactor name_to_dev_t
Quoted 20 lines · Christoph Hellwig
Split each case into a self-contained helper.
Signed-off-by Christoph Hellwig <[email protected]>--- include/linux/genhd.h | 7 +- init/do_mounts.c | 183 +++++++++++++++++++++--------------------- 2 files changed, 91 insertions(+), 99 deletions(-)include/linux/genhd.h +1
-1@@ -388,18 +388,13 @@ static inline void bd_unlink_disk_holder(struct block_device *bdev, }#endif /* CONFIG_SYSFS */ +dev_t blk_lookup_devt (const char *name,int partno);#ifdef CONFIG_BLOCK void printk_all_partitions (void ); -dev_t blk_lookup_devt (const char *name,int partno);
include/linux/genhd.h static inline void bd_unlink_disk_holder(struct block_device *bdev, · line 398
Quoted 10 lines
include/linux/genhd.h +0
-5#else /* CONFIG_BLOCK */ static inline void printk_all_partitions (void ) { } -static inline dev_t blk_lookup_devt (const char *name,int partno) -{ -dev_t devt =MKDEV (0 ,0 ); -return devt; -}#endif /* CONFIG_BLOCK */
This hunk looks unrelated to the change? Also why you move the declaration outside the CONFIG_BLOCK ifdef? AFAICS blk_lookup_devt() still exists only when CONFIG_BLOCK is defined? Otherwise the patch looks good to me.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Christoph Hellwig
maintainerRe: [PATCH 07/20] init: refactor name_to_dev_t
Quoted 10 lines · Jan Kara
include/linux/genhd.h static inline void bd_unlink_disk_holder(struct block_device *bdev, · line 398
Quoted 6 lines
include/linux/genhd.h +0
-5-static inline dev_t blk_lookup_devt (const char *name,int partno) -{ -dev_t devt =MKDEV (0 ,0 ); -return devt; -}#endif /* CONFIG_BLOCK */ This hunk looks unrelated to the change? Also why you move the declaration outside the
CONFIG_BLOCKifdef? AFAICSblk_lookup_devt()still exists only whenCONFIG_BLOCKis defined? Otherwise the patch looks good to me.
blk_lookup_devt is a hack only for name_to_dev_t only referenced from code under CONFIG_BLOCK now, as it didn't do anything before when blk_lookup_devt returned 0. I guess I'll need to update the commit log a little to mention this.
Re: [PATCH 07/20] init: refactor name_to_dev_t
Quoted 12 lines · Christoph Hellwig
Quoted 10 lines · Jan Kara
include/linux/genhd.h static inline void bd_unlink_disk_holder(struct block_device *bdev, · line 398
Quoted 6 lines
include/linux/genhd.h +0
-5-static inline dev_t blk_lookup_devt (const char *name,int partno) -{ -dev_t devt =MKDEV (0 ,0 ); -return devt; -}#endif /* CONFIG_BLOCK */ This hunk looks unrelated to the change? Also why you move the declaration outside the
CONFIG_BLOCKifdef? AFAICSblk_lookup_devt()still exists only whenCONFIG_BLOCKis defined? Otherwise the patch looks good to me.
Quoted 4 lines
blk_lookup_devtis a hack only forname_to_dev_tonly referenced from code underCONFIG_BLOCKnow, as it didn't do anything before whenblk_lookup_devtreturned 0. I guess I'll need to update the commit log a little to mention this.
OK, understood. Still it would seem more logical to leave blk_lookup_devt() declaration inside #ifdef CONFIG_BLOCK and just delete the !CONFIG_BLOCK definition (to make it clear we ever expect only users compiled when CONFIG_BLOCK is defined). But whatever... Feel free to add:
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Christoph Hellwig
maintainerRe: [PATCH 07/20] init: refactor name_to_dev_t
Quoted 4 lines · Jan Kara
OK, understood. Still it would seem more logical to leave
blk_lookup_devt()declaration inside #ifdefCONFIG_BLOCKand just delete the !CONFIG_BLOCK definition (to make it clear we ever expect only users compiled whenCONFIG_BLOCKis defined). But whatever... Feel free to add:
Not having the ifdef would allow using IS_ENABLED() around it. Which is what I did in one of the earlier variants before settlings on this one.
Re: [PATCH 07/20] init: refactor name_to_dev_t
In reply to Christoph HellwigLooks good,
Christoph Hellwig
maintainerPATCH 8/20 init: refactor devt_from_partuuid
In reply to Christoph HellwigThe code in devt_from_partuuid is very convoluted. Refactor a bit by sanitizing the goto and variable name usage.
--- init/do_mounts.c | 68 ++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 37 deletions(-)
init/do_mounts.c +31 -37
@@ -105,13 +105,10 @@ static int match_dev_by_uuid(struct device *dev, const void *data)*/ static dev_t devt_from_partuuid (const char *uuid_str) { -dev_t res =0 ;struct uuidcmp cmp;struct device *dev =NULL ; -struct gendisk *disk; -struct hd_struct *part; +dev_t devt =0 ;int offset =0 ; -bool clear_root_wait = false;char *slash; cmp.uuid = uuid_str;
@@ -120,52 +117,49 @@ static dev_t devt_from_partuuid(const char *uuid_str)/* Check for optional partition number offset attributes. */ if (slash) {char c =0 ; +/* Explicitly fail on poor PARTUUID syntax. */ -if (sscanf (slash +1 , -"PARTNROFF=%d%c" , &offset, &c) !=1 ) { - clear_root_wait = true; - goto done; - } +if (sscanf (slash +1 ,"PARTNROFF=%d%c" , &offset, &c) !=1 ) + goto clear_root_wait; cmp.len = slash - uuid_str; }else { cmp.len =strlen (uuid_str); } -if (!cmp.len) { - clear_root_wait = true; - goto done; - } +if (!cmp.len) + goto clear_root_wait; - dev =class_find_device (&block_class,NULL , &cmp, - &match_dev_by_uuid); + dev =class_find_device (&block_class,NULL , &cmp, &match_dev_by_uuid);if (!dev) - goto done; - - res = dev->devt; +return 0 ; -/* Attempt to find the partition by offset. */ -if (!offset) - goto no_offset; +if (offset) { +/* +* Attempt to find the requested partition by adding an offset +* to the partition number found by UUID. +*/ +struct hd_struct *part; - res =0 ; - disk =part_to_disk (dev_to_part (dev)); - part =disk_get_part (disk,dev_to_part (dev)->partno + offset); -if (part) { - res =part_devt (part); -put_device (part_to_dev (part)); + part =disk_get_part (dev_to_disk (dev), +dev_to_part (dev)->partno + offset); +if (part) { + devt =part_devt (part); +put_device (part_to_dev (part)); + } + }else { + devt = dev->devt; } -no_offset:put_device (dev); -done: -if (clear_root_wait) { -pr_err ("VFS: PARTUUID= is invalid.\n" -"Expected PARTUUID=<valid-uuid-id>[/PARTNROFF=%%d]\n" ); -if (root_wait) -pr_err ("Disabling rootwait; root= is invalid.\n" ); - root_wait =0 ; - } -return res; +return devt; + +clear_root_wait: +pr_err ("VFS: PARTUUID= is invalid.\n" +"Expected PARTUUID=<valid-uuid-id>[/PARTNROFF=%%d]\n" ); +if (root_wait) +pr_err ("Disabling rootwait; root= is invalid.\n" ); + root_wait =0 ; +return 0 ; }/**
Signature · 1 line
2.29.2
Re: [PATCH 08/20] init: refactor devt_from_partuuid
Quoted 4 lines · Christoph Hellwig
The code in
devt_from_partuuidis very convoluted. Refactor a bit by sanitizing the goto and variable name usage.Signed-off-by Christoph Hellwig <[email protected]>
The patch looks good to me. You can add:
Honza
Quoted 109 lines
--- init/do_mounts.c | 68 ++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 37 deletions(-)init/do_mounts.c +31
-37@@ -105,13 +105,10 @@ static int match_dev_by_uuid(struct device *dev, const void *data)*/ static dev_t devt_from_partuuid (const char *uuid_str) { -dev_t res =0 ;struct uuidcmp cmp;struct device *dev =NULL ; -struct gendisk *disk; -struct hd_struct *part; +dev_t devt =0 ;int offset =0 ; -bool clear_root_wait = false;char *slash; cmp.uuid = uuid_str;@@ -120,52 +117,49 @@ static dev_t devt_from_partuuid(const char *uuid_str)/* Check for optional partition number offset attributes. */ if (slash) {char c =0 ; +/* Explicitly fail on poor PARTUUID syntax. */ -if (sscanf (slash +1 , -"PARTNROFF=%d%c" , &offset, &c) !=1 ) { - clear_root_wait = true; - goto done; - } +if (sscanf (slash +1 ,"PARTNROFF=%d%c" , &offset, &c) !=1 ) + goto clear_root_wait; cmp.len = slash - uuid_str; }else { cmp.len =strlen (uuid_str); } -if (!cmp.len) { - clear_root_wait = true; - goto done; - } +if (!cmp.len) + goto clear_root_wait; - dev =class_find_device (&block_class,NULL , &cmp, - &match_dev_by_uuid); + dev =class_find_device (&block_class,NULL , &cmp, &match_dev_by_uuid);if (!dev) - goto done; - - res = dev->devt; +return 0 ; -/* Attempt to find the partition by offset. */ -if (!offset) - goto no_offset; +if (offset) { +/* +* Attempt to find the requested partition by adding an offset +* to the partition number found by UUID. +*/ +struct hd_struct *part; - res =0 ; - disk =part_to_disk (dev_to_part (dev)); - part =disk_get_part (disk,dev_to_part (dev)->partno + offset); -if (part) { - res =part_devt (part); -put_device (part_to_dev (part)); + part =disk_get_part (dev_to_disk (dev), +dev_to_part (dev)->partno + offset); +if (part) { + devt =part_devt (part); +put_device (part_to_dev (part)); + } + }else { + devt = dev->devt; } -no_offset:put_device (dev); -done: -if (clear_root_wait) { -pr_err ("VFS: PARTUUID= is invalid.\n" -"Expected PARTUUID=<valid-uuid-id>[/PARTNROFF=%%d]\n" ); -if (root_wait) -pr_err ("Disabling rootwait; root= is invalid.\n" ); - root_wait =0 ; - } -return res; +return devt; + +clear_root_wait: +pr_err ("VFS: PARTUUID= is invalid.\n" +"Expected PARTUUID=<valid-uuid-id>[/PARTNROFF=%%d]\n" ); +if (root_wait) +pr_err ("Disabling rootwait; root= is invalid.\n" ); + root_wait =0 ; +return 0 ; }/** Signature · 1 line
2.29.2
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Christoph Hellwig
maintainerPATCH 9/20 init: cleanup match_dev_by_uuid and match_dev_by_label
In reply to Christoph HellwigAvoid a totally pointless goto label, and use the same style of comparism for both helpers.
--- init/do_mounts.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
init/do_mounts.c +6 -12
@@ -79,15 +79,10 @@ static int match_dev_by_uuid(struct device *dev, const void *data)const struct uuidcmp *cmp = data;struct hd_struct *part =dev_to_part (dev); -if (!part->info) - goto no_match; - -if (strncasecmp (cmp->uuid, part->info->uuid, cmp->len)) - goto no_match; - +if (!part->info || +strncasecmp (cmp->uuid, part->info->uuid, cmp->len)) +return 0 ;return 1 ; -no_match: -return 0 ; }/**
@@ -174,10 +169,9 @@ static int match_dev_by_label(struct device *dev, const void *data)const char *label = data;struct hd_struct *part =dev_to_part (dev); -if (part->info && !strcmp (label, part->info->volname)) -return 1 ; - -return 0 ; +if (!part->info ||strcmp (label, part->info->volname)) +return 0 ; +return 1 ; }static dev_t devt_from_partlabel (const char *label)
Signature · 1 line
2.29.2
Re: [PATCH 09/20] init: cleanup match_dev_by_uuid and match_dev_by_label
Quoted 4 lines · Christoph Hellwig
Avoid a totally pointless goto label, and use the same style of comparism for both helpers.
Signed-off-by Christoph Hellwig <[email protected]>
OK. You can add:
Honza
Quoted 44 lines
--- init/do_mounts.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)init/do_mounts.c +6
-12@@ -79,15 +79,10 @@ static int match_dev_by_uuid(struct device *dev, const void *data)const struct uuidcmp *cmp = data;struct hd_struct *part =dev_to_part (dev); -if (!part->info) - goto no_match; - -if (strncasecmp (cmp->uuid, part->info->uuid, cmp->len)) - goto no_match; - +if (!part->info || +strncasecmp (cmp->uuid, part->info->uuid, cmp->len)) +return 0 ;return 1 ; -no_match: -return 0 ; }/** @@ -174,10 +169,9 @@ static int match_dev_by_label(struct device *dev, const void *data)const char *label = data;struct hd_struct *part =dev_to_part (dev); -if (part->info && !strcmp (label, part->info->volname)) -return 1 ; - -return 0 ; +if (!part->info ||strcmp (label, part->info->volname)) +return 0 ; +return 1 ; }static dev_t devt_from_partlabel (const char *label)Signature · 1 line
2.29.2
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH 09/20] init: cleanup match_dev_by_uuid and match_dev_by_label
In reply to Christoph HellwigLooks good,
Christoph Hellwig
maintainerPATCH 10/20 block: refactor __blkdev_put
In reply to Christoph HellwigReorder the code to have one big section for the last close, and to use bdev_is_partition.
--- fs/block_dev.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
fs/block_dev.c +7 -7
@@ -1745,22 +1745,22 @@ static void __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part)WARN_ON_ONCE (bdev->bd_holders);sync_blockdev (bdev);kill_bdev (bdev); -bdev_write_inode (bdev); - } -if (bdev->bd_contains == bdev) { -if (disk->fops->release) + +if (!bdev_is_partition (bdev) && disk->fops->release) disk->fops->release (disk, mode); - } -if (!bdev->bd_openers) { +disk_put_part (bdev->bd_part); bdev->bd_part =NULL ; bdev->bd_disk =NULL ; -if (bdev != bdev->bd_contains) +if (bdev_is_partition (bdev)) victim = bdev->bd_contains; bdev->bd_contains =NULL ;put_disk_and_module (disk); + }else { +if (!bdev_is_partition (bdev) && disk->fops->release) + disk->fops->release (disk, mode); }mutex_unlock (&bdev->bd_mutex);bdput (bdev);
Signature · 1 line
2.29.2
Re: [PATCH 10/20] block: refactor __blkdev_put
Quoted 4 lines · Christoph Hellwig
Reorder the code to have one big section for the last close, and to use
bdev_is_partition.Signed-off-by Christoph Hellwig <[email protected]>
Looks good. You can add:
Honza
Quoted 41 lines
--- fs/block_dev.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)fs/block_dev.c +7
-7@@ -1745,22 +1745,22 @@ static void __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part)WARN_ON_ONCE (bdev->bd_holders);sync_blockdev (bdev);kill_bdev (bdev); -bdev_write_inode (bdev); - } -if (bdev->bd_contains == bdev) { -if (disk->fops->release) + +if (!bdev_is_partition (bdev) && disk->fops->release) disk->fops->release (disk, mode); - } -if (!bdev->bd_openers) { +disk_put_part (bdev->bd_part); bdev->bd_part =NULL ; bdev->bd_disk =NULL ; -if (bdev != bdev->bd_contains) +if (bdev_is_partition (bdev)) victim = bdev->bd_contains; bdev->bd_contains =NULL ;put_disk_and_module (disk); + }else { +if (!bdev_is_partition (bdev) && disk->fops->release) + disk->fops->release (disk, mode); }mutex_unlock (&bdev->bd_mutex);bdput (bdev);Signature · 1 line
2.29.2
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Christoph Hellwig
maintainerPATCH 11/20 block: reference struct block_device from struct hd_struct
In reply to Christoph HellwigTo simplify block device lookup and a few other upcomdin areas, make sure that we always have a struct block_device available for each disk and each partition. The only downside of this is that each device and partition uses a little more memories. The upside will be that a lot of code can be simplified.
With that all we need to look up the block device is to lookup the inode and do a few sanity checks on the gendisk, instead of the separate lookup for the gendisk.
As part of the change switch bdget() to only find existing block devices, given that we know that the block_device structure must be allocated at probe / partition scan time.
blk-cgroup needed a bit of a special treatment as the only place that wanted to lookup a gendisk outside of the normal blkdev_get path. It is switched to lookup using the block device hash now that this is the primary lookup path.
--- block/blk-cgroup.c | 42 ++++---- block/blk-iocost.c | 36 +++---- block/blk.h | 2 +- block/genhd.c | 204 ++++--------------------------------- block/partitions/core.c | 28 ++--- fs/block_dev.c | 123 ++++++++++++---------- include/linux/blk-cgroup.h | 4 +- include/linux/blkdev.h | 3 + include/linux/genhd.h | 4 +- 9 files changed, 156 insertions(+), 290 deletions(-)
block/blk-cgroup.c +21 -21
@@ -556,22 +556,22 @@ static struct blkcg_gq *blkg_lookup_check(struct blkcg *blkcg, }/** -* blkg_conf_prep - parse and prepare for per-blkg config update +* blkcg_conf_get_bdev - parse and open bdev for per-blkg config update * @inputp: input string pointer * * Parse the device node prefix part, MAJ:MIN, of per-blkg config update -* from @input and get and return the matching gendisk. *@inputp is +* from @input and get and return the matching bdev. *@inputp is * updated to point past the device node prefix. Returns an ERR_PTR() * value on error. * * Use this function iff blkg_conf_prep() can't be used for some reason. */ -struct gendisk *blkcg_conf_get_disk (char **inputp) +struct block_device *blkcg_conf_get_bdev (char **inputp) {char *input = *inputp;unsigned int major, minor; -struct gendisk *disk; -int key_len, part; +struct block_device *bdev; +int key_len;if (sscanf (input,"%u:%u%n" , &major, &minor, &key_len) !=2 )return ERR_PTR (-EINVAL );
@@ -581,16 +581,16 @@ struct gendisk *blkcg_conf_get_disk(char **inputp)return ERR_PTR (-EINVAL ); input =skip_spaces (input); - disk =get_gendisk (MKDEV (major, minor), &part); -if (!disk) + bdev =bdget (MKDEV (major, minor)); +if (!bdev)return ERR_PTR (-ENODEV ); -if (part) { -put_disk_and_module (disk); +if (bdev_is_partition (bdev)) { +bdput (bdev);return ERR_PTR (-ENODEV ); } *inputp = input; -return disk; +return bdev; }/**
@@ -607,18 +607,18 @@ struct gendisk *blkcg_conf_get_disk(char **inputp)*/ int blkg_conf_prep (struct blkcg *blkcg,const struct blkcg_policy *pol,char *input,struct blkg_conf_ctx *ctx) - __acquires(rcu) __acquires(&disk->queue->queue_lock) + __acquires(rcu) __acquires(&bdev->bd_disk->queue->queue_lock) { -struct gendisk *disk; +struct block_device *bdev;struct request_queue *q;struct blkcg_gq *blkg;int ret; - disk =blkcg_conf_get_disk (&input); -if (IS_ERR (disk)) -return PTR_ERR (disk); + bdev =blkcg_conf_get_bdev (&input); +if (IS_ERR (bdev)) +return PTR_ERR (bdev); - q = disk->queue; + q = bdev->bd_disk->queue;rcu_read_lock ();spin_lock_irq (&q->queue_lock);
@@ -689,7 +689,7 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol, goto success; } success: - ctx->disk = disk; + ctx->bdev = bdev; ctx->blkg = blkg; ctx->body = input;return 0 ;
@@ -700,7 +700,7 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol,spin_unlock_irq (&q->queue_lock);rcu_read_unlock (); fail: -put_disk_and_module (disk); +bdput (bdev);/* * If queue was bypassing, we should retry. Do so after a * short msleep(). It isn't strictly necessary but queue
@@ -723,11 +723,11 @@ EXPORT_SYMBOL_GPL(blkg_conf_prep);* with blkg_conf_prep(). */ void blkg_conf_finish (struct blkg_conf_ctx *ctx) - __releases(&ctx->disk->queue->queue_lock) __releases(rcu) + __releases(&ctx->bdev->bd_disk->queue->queue_lock) __releases(rcu) { -spin_unlock_irq (&ctx->disk->queue->queue_lock); +spin_unlock_irq (&ctx->bdev->bd_disk->queue->queue_lock);rcu_read_unlock (); -put_disk_and_module (ctx->disk); +bdput (ctx->bdev); }EXPORT_SYMBOL_GPL (blkg_conf_finish);
block/blk-iocost.c +18 -18
@@ -3120,23 +3120,23 @@ static const match_table_t qos_tokens = {static ssize_t ioc_qos_write (struct kernfs_open_file *of,char *input,size_t nbytes,loff_t off) { -struct gendisk *disk; +struct block_device *bdev;struct ioc *ioc;u32 qos[NR_QOS_PARAMS ];bool enable, user;char *p;int ret; - disk =blkcg_conf_get_disk (&input); -if (IS_ERR (disk)) -return PTR_ERR (disk); + bdev =blkcg_conf_get_bdev (&input); +if (IS_ERR (bdev)) +return PTR_ERR (bdev); - ioc =q_to_ioc (disk->queue); + ioc =q_to_ioc (bdev->bd_disk->queue);if (!ioc) { - ret =blk_iocost_init (disk->queue); + ret =blk_iocost_init (bdev->bd_disk->queue);if (ret) goto err; - ioc =q_to_ioc (disk->queue); + ioc =q_to_ioc (bdev->bd_disk->queue); }spin_lock_irq (&ioc->lock);
@@ -3231,12 +3231,12 @@ static ssize_t ioc_qos_write(struct kernfs_open_file *of, char *input,ioc_refresh_params (ioc, true);spin_unlock_irq (&ioc->lock); -put_disk_and_module (disk); +bdput (bdev);return nbytes; einval: ret = -EINVAL ; err: -put_disk_and_module (disk); +bdput (bdev);return ret; }
@@ -3287,23 +3287,23 @@ static const match_table_t i_lcoef_tokens = {static ssize_t ioc_cost_model_write (struct kernfs_open_file *of,char *input,size_t nbytes,loff_t off) { -struct gendisk *disk; +struct block_device *bdev;struct ioc *ioc;u64 u[NR_I_LCOEFS ];bool user;char *p;int ret; - disk =blkcg_conf_get_disk (&input); -if (IS_ERR (disk)) -return PTR_ERR (disk); + bdev =blkcg_conf_get_bdev (&input); +if (IS_ERR (bdev)) +return PTR_ERR (bdev); - ioc =q_to_ioc (disk->queue); + ioc =q_to_ioc (bdev->bd_disk->queue);if (!ioc) { - ret =blk_iocost_init (disk->queue); + ret =blk_iocost_init (bdev->bd_disk->queue);if (ret) goto err; - ioc =q_to_ioc (disk->queue); + ioc =q_to_ioc (bdev->bd_disk->queue); }spin_lock_irq (&ioc->lock);
@@ -3356,13 +3356,13 @@ static ssize_t ioc_cost_model_write(struct kernfs_open_file *of, char *input,ioc_refresh_params (ioc, true);spin_unlock_irq (&ioc->lock); -put_disk_and_module (disk); +bdput (bdev);return nbytes; einval: ret = -EINVAL ; err: -put_disk_and_module (disk); +bdput (bdev);return ret; }
block/blk.h +1 -1
@@ -352,7 +352,6 @@ struct hd_struct *disk_map_sector_rcu(struct gendisk *disk, sector_t sector);int blk_alloc_devt (struct hd_struct *part,dev_t *devt);void blk_free_devt (dev_t devt); -void blk_invalidate_devt (dev_t devt);char *disk_name (struct gendisk *hd,int partno,char *buf);#define ADDPART_FLAG_NONE 0#define ADDPART_FLAG_RAID 1
@@ -384,6 +383,7 @@ static inline void hd_free_part(struct hd_struct *part) {free_percpu (part->dkstats);kfree (part->info); +bdput (part->bdev);percpu_ref_exit (&part->ref); }
block/genhd.c +21 -183
289 lines not on this page · raw message
block/partitions/core.c +16 -12
@@ -340,12 +340,11 @@ void delete_partition(struct hd_struct *part)device_del (part_to_dev (part));/* -* Remove gendisk pointer from idr so that it cannot be looked up -* while RCU period before freeing gendisk is running to prevent -* use-after-free issues. Note that the device number stays -* "in-use" until we really free the gendisk. +* Remove the block device from the inode hash, so that it cannot be +* looked up while waiting for the RCU grace period. */ -blk_invalidate_devt (part_devt (part)); +remove_inode_hash (part->bdev->bd_inode); +percpu_ref_kill (&part->ref); }
@@ -402,11 +401,14 @@ static struct hd_struct *add_partition(struct gendisk *disk, int partno,if (!p)return ERR_PTR (-EBUSY ); + err = -ENOMEM ; p->dkstats = alloc_percpu(struct disk_stats); -if (!p->dkstats) { - err = -ENOMEM ; +if (!p->dkstats) goto out_free; - } + + p->bdev =bdev_alloc (disk, partno); +if (!p->bdev) + goto out_free_stats;hd_sects_seq_init (p); pdev =part_to_dev (p);
@@ -420,10 +422,8 @@ static struct hd_struct *add_partition(struct gendisk *disk, int partno,struct partition_meta_info *pinfo; pinfo =kzalloc_node (sizeof (*pinfo),GFP_KERNEL , disk->node_id); -if (!pinfo) { - err = -ENOMEM ; - goto out_free_stats; - } +if (!pinfo) + goto out_bdput;memcpy (pinfo, info,sizeof (*info)); p->info = pinfo; }
@@ -470,6 +470,7 @@ static struct hd_struct *add_partition(struct gendisk *disk, int partno, }/* everything is up and running, commence */ +bdev_add (p->bdev, devt);rcu_assign_pointer (ptbl->part[partno], p);/* suppress uevent if the disk suppresses it */
@@ -479,11 +480,14 @@ static struct hd_struct *add_partition(struct gendisk *disk, int partno, out_free_info:kfree (p->info); +out_bdput: +bdput (p->bdev); out_free_stats:free_percpu (p->dkstats); out_free:kfree (p);return ERR_PTR (err); + out_remove_file:device_remove_file (pdev, &dev_attr_whole_disk); out_del:
fs/block_dev.c +72 -51
198 lines not on this page · raw message
include/linux/blk-cgroup.h +2 -2
@@ -197,12 +197,12 @@ void blkcg_print_blkgs(struct seq_file *sf, struct blkcg *blkcg,u64 __blkg_prfill_u64 (struct seq_file *sf,struct blkg_policy_data *pd,u64 v);struct blkg_conf_ctx { -struct gendisk *disk; +struct block_device *bdev;struct blkcg_gq *blkg;char *body; }; -struct gendisk *blkcg_conf_get_disk (char **inputp); +struct block_device *blkcg_conf_get_bdev (char **inputp);int blkg_conf_prep (struct blkcg *blkcg,const struct blkcg_policy *pol,char *input,struct blkg_conf_ctx *ctx);void blkg_conf_finish (struct blkg_conf_ctx *ctx);
include/linux/blkdev.h +3 -0
@@ -1994,6 +1994,9 @@ void bd_abort_claiming(struct block_device *bdev, struct block_device *whole, void *holder);void blkdev_put (struct block_device *bdev,fmode_t mode); +struct block_device *bdev_alloc (struct gendisk *disk,u8 partno); +void bdev_add (struct block_device *bdev,dev_t dev); +struct block_device *bdget (dev_t dev);struct block_device *I_BDEV (struct inode *inode);struct block_device *bdget_part (struct hd_struct *part);struct block_device *bdgrab (struct block_device *bdev);
include/linux/genhd.h +2 -2
@@ -65,6 +65,7 @@ struct hd_struct {struct disk_stats __percpu *dkstats;struct percpu_ref ref; +struct block_device *bdev;struct device __dev;struct kobject *holder_dir;int policy, partno;
@@ -300,7 +301,6 @@ static inline void add_disk_no_queue_reg(struct gendisk *disk) }extern void del_gendisk (struct gendisk *gp); -extern struct gendisk *get_gendisk (dev_t dev,int *partno);extern struct block_device *bdget_disk (struct gendisk *disk,int partno);extern void set_disk_ro (struct gendisk *disk,int flag);
@@ -338,7 +338,6 @@ int blk_drop_partitions(struct block_device *bdev);extern struct gendisk *__alloc_disk_node (int minors,int node_id);extern void put_disk (struct gendisk *disk); -extern void put_disk_and_module (struct gendisk *disk);#define alloc_disk_node (minors, node_id) \ ({ \
@@ -389,6 +388,7 @@ static inline void bd_unlink_disk_holder(struct block_device *bdev,#endif /* CONFIG_SYSFS */ dev_t blk_lookup_devt (const char *name,int partno); +void blk_request_module (dev_t devt);#ifdef CONFIG_BLOCK void printk_all_partitions (void );#else /* CONFIG_BLOCK */
Signature · 1 line
2.29.2
Jan Kara
maintainerRe: [PATCH 11/20] block: reference struct block_device from struct hd_struct
Quoted 4 lines · Christoph Hellwig
To simplify block device lookup and a few other upcomdin areas, make sure that we always have a struct
block_deviceavailable for each disk and each partition. The only downside of this is that each device and partition uses a little more memories. The upside will be that a lot of
^^^ memory
Quoted 10 lines
code can be simplified.
With that all we need to look up the block device is to lookup the inode and do a few sanity checks on the gendisk, instead of the separate lookup for the gendisk.
As part of the change switch
bdget()to only find existing block devices, given that we know that theblock_devicestructure must be allocated at probe / partition scan time.
Quoted 6 lines
blk-cgroup needed a bit of a special treatment as the only place that wanted to lookup a gendisk outside of the normal
blkdev_getpath. It is switched to lookup using the block device hash now that this is the primary lookup path.Signed-off-by Christoph Hellwig <[email protected]>
The patch looks good to me and I like the simplifications! I've found just one small issue below.
Quoted 25 lines
block/genhd.c +7
-5@@ -1748,16 +1600,18 @@ struct gendisk *__alloc_disk_node(int minors, int node_id)if (!disk)return NULL ; + disk->part0.bdev =bdev_alloc (disk,0 ); +if (!disk->part0.bdev) + goto out_free_disk; + disk->part0.dkstats = alloc_percpu(struct disk_stats);if (!disk->part0.dkstats) - goto out_free_disk; + goto out_bdput;init_rwsem (&disk->lookup_sem); disk->node_id = node_id; -if (disk_expand_part_tbl (disk,0 )) { -free_percpu (disk->part0.dkstats); - goto out_free_disk; - } +if (disk_expand_part_tbl (disk,0 )) + goto out_free_bdstats; ptbl =rcu_dereference_protected (disk->part_tbl,1 );rcu_assign_pointer (ptbl->part[0 ], &disk->part0);
block/genhd.c struct gendisk *__alloc_disk_node(int minors, int node_id) · line 1630
Quoted 7 lines
block/genhd.c +2
-2@@ -1772,8 +1626,10 @@ struct gendisk *__alloc_disk_node(int minors, int node_id)* converted to make use of bd_mutex and sequence counters. */ hd_sects_seq_init (&disk->part0); -if (hd_ref_init (&disk->part0)) - goto out_free_part0; +if (hd_ref_init (&disk->part0)) { +hd_free_part (&disk->part0);
Aren't you missing kfree(disk) here?
block/genhd.c struct gendisk *__alloc_disk_node(int minors, int node_id) · line 1635
Quoted 5 lines
block/genhd.c +2
-0+return NULL ; + } disk->minors = minors;rand_initialize_disk (disk);
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Christoph Hellwig
maintainerRe: [PATCH 11/20] block: reference struct block_device from struct hd_struct
Quoted 11 lines · Jan Kara
block/genhd.c struct gendisk *__alloc_disk_node(int minors, int node_id) · line 1630
Quoted 9 lines
block/genhd.c +2
-2rcu_assign_pointer (ptbl->part[0 ], &disk->part0);@@ -1772,8 +1626,10 @@ struct gendisk *__alloc_disk_node(int minors, int node_id)* converted to make use of bd_mutex and sequence counters. */ hd_sects_seq_init (&disk->part0); -if (hd_ref_init (&disk->part0)) - goto out_free_part0; +if (hd_ref_init (&disk->part0)) { +hd_free_part (&disk->part0);Aren't you missing kfree(disk) here?
This should actually jump to out_free_bdstats, I've fixed it up.
Tejun Heo
maintainerRe: [PATCH 11/20] block: reference struct block_device from struct hd_struct
In reply to Christoph HellwigHello,
This is great. So much simpler & better. Some nits below.
Quoted 7 lines
block/partitions/core.c +0
-0@@ -340,12 +340,11 @@ void delete_partition(struct hd_struct *part)device_del (part_to_dev (part));
block/partitions/core.c void delete_partition(struct hd_struct *part) · line 346
Quoted 10 lines
block/partitions/core.c +3
-5/* -* Remove gendisk pointer from idr so that it cannot be looked up -* while RCU period before freeing gendisk is running to prevent -* use-after-free issues. Note that the device number stays -* "in-use" until we really free the gendisk. +* Remove the block device from the inode hash, so that it cannot be +* looked up while waiting for the RCU grace period. */ -blk_invalidate_devt (part_devt (part)); +remove_inode_hash (part->bdev->bd_inode);
I don't think this is necessary now that the bdev and inode lifetimes are one. Before, punching out the association early was necessary because we could be in a situation where we can successfully look up a part from idr and then try to pin the associated disk which may already be freed. With the new code, the lookup is through the inode whose lifetime is one and the same with gendisk, so use-after-free isn't possible and __blkdev_get() will reliably reject such open attempts.
...
Quoted 23 lines
fs/block_dev.c +5
-3@@ -870,34 +870,50 @@ void __init bdev_cache_init(void) blockdev_superblock = bd_mnt->mnt_sb;/* For writeback */ } -static struct block_device *bdget (dev_t dev) +struct block_device *bdev_alloc (struct gendisk *disk,u8 partno) {struct block_device *bdev;struct inode *inode; - inode =iget_locked (blockdev_superblock, dev); + inode =new_inode (blockdev_superblock);if (!inode)return NULL ; - bdev = &BDEV_I (inode)->bdev; + bdev =I_BDEV (inode); +spin_lock_init (&bdev->bd_size_lock); + bdev->bd_disk = disk;
fs/block_dev.c void __init bdev_cache_init(void) · line 894
Quoted 10 lines
fs/block_dev.c +10
-0+ bdev->bd_partno = partno; + bdev->bd_contains =NULL ; + bdev->bd_super =NULL ; + bdev->bd_inode = inode; + bdev->bd_part_count =0 ; + + inode->i_mode =S_IFBLK ; + inode->i_rdev =0 ; + inode->i_bdev = bdev; + inode->i_data.a_ops = &def_blk_aops;
Missing the call to mapping_set_gfp_mask().
Quoted 17 lines
fs/block_dev.c +0
-14-if (inode->i_state &I_NEW ) { -spin_lock_init (&bdev->bd_size_lock); - bdev->bd_contains =NULL ; - bdev->bd_super =NULL ; - bdev->bd_inode = inode; - bdev->bd_part_count =0 ; - bdev->bd_dev = dev; - inode->i_mode =S_IFBLK ; - inode->i_rdev = dev; - inode->i_bdev = bdev; - inode->i_data.a_ops = &def_blk_aops; -mapping_set_gfp_mask (&inode->i_data,GFP_USER ); -unlock_new_inode (inode); - }return bdev; }
...
fs/block_dev.c static struct block_device *bd_acquire(struct inode *inode) · line 979
Quoted 11 lines
/**
* bdgrab -- Grab a reference to an already referenced block device
* @bdev: Block device to grab a reference to.fs/block_dev.c +4
-0@@ -957,6 +973,10 @@ static struct block_device *bd_acquire(struct inode *inode)bd_forget (inode); bdev =bdget (inode->i_rdev); +if (!bdev) { +blk_request_module (inode->i_rdev); + bdev =bdget (inode->i_rdev); + }
One side effect here is that, before, a device which uses the traditional consecutive devt range would reserve all minors for the partitions whether they exist or not and fail open requests without requesting the matching module. After the change, trying to open an non-existent partition would trigger module probe. I don't think the behavior change is consequential in any sane not-crazily-arcane setup but it might be worth mentioning in the commit log.
Thank you.
Signature · 1 line
tejun
Jan Kara
maintainerRe: [PATCH 11/20] block: reference struct block_device from struct hd_struct
Hello!
Quoted 18 lines · Tejun Heo
Quoted 7 lines
block/partitions/core.c +0
-0@@ -340,12 +340,11 @@ void delete_partition(struct hd_struct *part)device_del (part_to_dev (part));block/partitions/core.c void delete_partition(struct hd_struct *part) · line 346
Quoted 10 lines
block/partitions/core.c +3
-5/* -* Remove gendisk pointer from idr so that it cannot be looked up -* while RCU period before freeing gendisk is running to prevent -* use-after-free issues. Note that the device number stays -* "in-use" until we really free the gendisk. +* Remove the block device from the inode hash, so that it cannot be +* looked up while waiting for the RCU grace period. */ -blk_invalidate_devt (part_devt (part)); +remove_inode_hash (part->bdev->bd_inode);
Quoted 7 lines
I don't think this is necessary now that the bdev and inode lifetimes are one. Before, punching out the association early was necessary because we could be in a situation where we can successfully look up a part from idr and then try to pin the associated disk which may already be freed. With the new code, the lookup is through the inode whose lifetime is one and the same with gendisk, so use-after-free isn't possible and
__blkdev_get()will reliably reject such open attempts.
I think the remove_inode_hash() call is actually still needed. Consider a situation when the disk is unplugged, gendisk gets destroyed, bdev still lives on (e.g. because it is still open). Device gets re-plugged, gendisk for the same device number gets created. But we really need new bdev for this because from higher level POV this is completely new device. And the old bdev needs to live on as long as it is open. So IMO we still need to just unhash the inode and leave it lingering in the background.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Tejun Heo
maintainerRe: [PATCH 11/20] block: reference struct block_device from struct hd_struct
Hey, Jan,
Quoted 8 lines · Jan Kara
Quoted 7 lines
I don't think this is necessary now that the bdev and inode lifetimes are one. Before, punching out the association early was necessary because we could be in a situation where we can successfully look up a part from idr and then try to pin the associated disk which may already be freed. With the new code, the lookup is through the inode whose lifetime is one and the same with gendisk, so use-after-free isn't possible and
__blkdev_get()will reliably reject such open attempts.
Quoted 7 lines
I think the
remove_inode_hash()call is actually still needed. Consider a situation when the disk is unplugged, gendisk gets destroyed, bdev still lives on (e.g. because it is still open). Device gets re-plugged, gendisk for the same device number gets created. But we really need new bdev for this because from higher level POV this is completely new device. And the old bdev needs to live on as long as it is open. So IMO we still need to just unhash the inode and leave it lingering in the background.
You're absolutely right. I was only thinking about the lifetime problem described in the comment. So, it just needs an updated comment there, I think.
Thanks.
Signature · 1 line
tejun
Christoph Hellwig
maintainerPATCH 12/20 block: simplify the block device claiming interface
In reply to Christoph HellwigStop passing the whole device as a separate argument given that it can be trivially deducted.
--- drivers/block/loop.c | 12 +++----- fs/block_dev.c | 69 +++++++++++++++++++----------------------- include/linux/blkdev.h | 6 ++-- 3 files changed, 38 insertions(+), 49 deletions(-)
drivers/block/loop.c +5 -7
@@ -1071,7 +1071,6 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,struct file *file;struct inode *inode;struct address_space *mapping; -struct block_device *claimed_bdev =NULL ;int error;loff_t size;bool partscan;
@@ -1090,8 +1089,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,* here to avoid changing device under exclusive owner. */ if (!(mode &FMODE_EXCL )) { - claimed_bdev = bdev->bd_contains; - error =bd_prepare_to_claim (bdev, claimed_bdev, loop_configure); + error =bd_prepare_to_claim (bdev, loop_configure);if (error) goto out_putf; }
@@ -1178,15 +1176,15 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,mutex_unlock (&loop_ctl_mutex);if (partscan)loop_reread_partitions (lo, bdev); -if (claimed_bdev) -bd_abort_claiming (bdev, claimed_bdev, loop_configure); +if (!(mode &FMODE_EXCL )) +bd_abort_claiming (bdev, loop_configure);return 0 ; out_unlock:mutex_unlock (&loop_ctl_mutex); out_bdev: -if (claimed_bdev) -bd_abort_claiming (bdev, claimed_bdev, loop_configure); +if (!(mode &FMODE_EXCL )) +bd_abort_claiming (bdev, loop_configure); out_putf:fput (file); out:
fs/block_dev.c +31 -38
144 lines not on this page · raw message
include/linux/blkdev.h +2 -4
@@ -1988,10 +1988,8 @@ void blkdev_show(struct seq_file *seqf, off_t offset);struct block_device *blkdev_get_by_path (const char *path,fmode_t mode,void *holder);struct block_device *blkdev_get_by_dev (dev_t dev,fmode_t mode,void *holder); -int bd_prepare_to_claim (struct block_device *bdev,struct block_device *whole, -void *holder); -void bd_abort_claiming (struct block_device *bdev,struct block_device *whole, -void *holder); +int bd_prepare_to_claim (struct block_device *bdev,void *holder); +void bd_abort_claiming (struct block_device *bdev,void *holder);void blkdev_put (struct block_device *bdev,fmode_t mode);struct block_device *bdev_alloc (struct gendisk *disk,u8 partno);
Signature · 1 line
2.29.2
Re: [PATCH 12/20] block: simplify the block device claiming interface
Quoted 4 lines · Christoph Hellwig
Stop passing the whole device as a separate argument given that it can be trivially deducted.
Signed-off-by Christoph Hellwig <[email protected]>
The patch looks good to me. You can add:
Honza
Quoted 225 lines
--- drivers/block/loop.c | 12 +++----- fs/block_dev.c | 69 +++++++++++++++++++----------------------- include/linux/blkdev.h | 6 ++-- 3 files changed, 38 insertions(+), 49 deletions(-)drivers/block/loop.c +5
-7@@ -1071,7 +1071,6 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,struct file *file;struct inode *inode;struct address_space *mapping; -struct block_device *claimed_bdev =NULL ;int error;loff_t size;bool partscan;@@ -1090,8 +1089,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,* here to avoid changing device under exclusive owner. */ if (!(mode &FMODE_EXCL )) { - claimed_bdev = bdev->bd_contains; - error =bd_prepare_to_claim (bdev, claimed_bdev, loop_configure); + error =bd_prepare_to_claim (bdev, loop_configure);if (error) goto out_putf; }@@ -1178,15 +1176,15 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,mutex_unlock (&loop_ctl_mutex);if (partscan)loop_reread_partitions (lo, bdev); -if (claimed_bdev) -bd_abort_claiming (bdev, claimed_bdev, loop_configure); +if (!(mode &FMODE_EXCL )) +bd_abort_claiming (bdev, loop_configure);return 0 ; out_unlock:mutex_unlock (&loop_ctl_mutex); out_bdev: -if (claimed_bdev) -bd_abort_claiming (bdev, claimed_bdev, loop_configure); +if (!(mode &FMODE_EXCL )) +bd_abort_claiming (bdev, loop_configure); out_putf:fput (file); out:fs/block_dev.c +31
-38@@ -110,24 +110,20 @@ EXPORT_SYMBOL(invalidate_bdev);int truncate_bdev_range (struct block_device *bdev,fmode_t mode,loff_t lstart,loff_t lend) { -struct block_device *claimed_bdev =NULL ; -int err; -/* * If we don't hold exclusive handle for the device, upgrade to it * while we discard the buffer cache to avoid discarding buffers * under live filesystem. */ if (!(mode &FMODE_EXCL )) { - claimed_bdev = bdev->bd_contains; - err =bd_prepare_to_claim (bdev, claimed_bdev, - truncate_bdev_range); +int err =bd_prepare_to_claim (bdev, truncate_bdev_range);if (err)return err; } +truncate_inode_pages_range (bdev->bd_inode->i_mapping, lstart, lend); -if (claimed_bdev) -bd_abort_claiming (bdev, claimed_bdev, truncate_bdev_range); +if (!(mode &FMODE_EXCL )) +bd_abort_claiming (bdev, truncate_bdev_range);return 0 ; }EXPORT_SYMBOL (truncate_bdev_range);@@ -1047,7 +1043,6 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,/** * bd_prepare_to_claim - claim a block device * @bdev: block device of interest -* @whole: the whole device containing @bdev, may equal @bdev * @holder: holder trying to claim @bdev * * Claim @bdev. This function fails if @bdev is already claimed by another @@ -1057,9 +1052,10 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,* RETURNS: * 0 if @bdev can be claimed, -EBUSY otherwise. */ -int bd_prepare_to_claim (struct block_device *bdev,struct block_device *whole, -void *holder) +int bd_prepare_to_claim (struct block_device *bdev,void *holder) { +struct block_device *whole = bdev->bd_contains; + retry:spin_lock (&bdev_lock);/* if someone else claimed, fail */ @@ -1099,15 +1095,15 @@ static void bd_clear_claiming(struct block_device *whole, void *holder)/** * bd_finish_claiming - finish claiming of a block device * @bdev: block device of interest -* @whole: whole block device * @holder: holder that has claimed @bdev * * Finish exclusive open of a block device. Mark the device as exlusively * open by the holder and wake up all waiters for exclusive open to finish. */ -static void bd_finish_claiming (struct block_device *bdev, -struct block_device *whole,void *holder) +static void bd_finish_claiming (struct block_device *bdev,void *holder) { +struct block_device *whole = bdev->bd_contains; +spin_lock (&bdev_lock);BUG_ON (!bd_may_claim (bdev, whole, holder));/* @@ -1132,11 +1128,10 @@ static void bd_finish_claiming(struct block_device *bdev,* also used when exclusive open is not actually desired and we just needed * to block other exclusive openers for a while. */ -void bd_abort_claiming (struct block_device *bdev,struct block_device *whole, -void *holder) +void bd_abort_claiming (struct block_device *bdev,void *holder) {spin_lock (&bdev_lock); -bd_clear_claiming (whole, holder); +bd_clear_claiming (bdev->bd_contains, holder);spin_unlock (&bdev_lock); }EXPORT_SYMBOL (bd_abort_claiming);@@ -1434,7 +1429,7 @@ static void put_disk_and_module(struct gendisk *disk)static int __blkdev_get (struct block_device *bdev,fmode_t mode,void *holder,int for_part) { -struct block_device *whole =NULL , *claiming =NULL ; +struct block_device *whole =NULL ;struct gendisk *disk = bdev->bd_disk;int ret;bool first_open = false, unblock_events = true, need_restart;@@ -1462,11 +1457,7 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, void *holder,if (!for_part && (mode &FMODE_EXCL )) {WARN_ON_ONCE (!holder); -if (whole) - claiming = whole; -else - claiming = bdev; - ret =bd_prepare_to_claim (bdev, claiming, holder); + ret =bd_prepare_to_claim (bdev, holder);if (ret) goto out_put_whole; }@@ -1543,21 +1534,23 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, void *holder, } } bdev->bd_openers++; -if (for_part) +if (for_part) { bdev->bd_part_count++; -if (claiming) -bd_finish_claiming (bdev, claiming, holder); + }else if (mode &FMODE_EXCL ) { +bd_finish_claiming (bdev, holder); -/* -* Block event polling for write claims if requested. Any write holder -* makes the write_holder state stick until all are released. This is -* good enough and tracking individual writeable reference is too -* fragile given the way @mode is used in blkdev_get/put(). -*/ -if (claiming && (mode &FMODE_WRITE ) && !bdev->bd_write_holder && - (disk->flags &GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE )) { - bdev->bd_write_holder = true; - unblock_events = false; +/* +* Block event polling for write claims if requested. Any write +* holder makes the write_holder state stick until all are +* released. This is good enough and tracking individual +* writeable reference is too fragile given the way @mode is +* used in blkdev_get/put(). +*/ +if ((mode &FMODE_WRITE ) && !bdev->bd_write_holder && + (disk->flags &GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE )) { + bdev->bd_write_holder = true; + unblock_events = false; + } }mutex_unlock (&bdev->bd_mutex);@@ -1578,8 +1571,8 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, void *holder,__blkdev_put (bdev->bd_contains, mode,1 ); bdev->bd_contains =NULL ; out_unlock_bdev: -if (claiming) -bd_abort_claiming (bdev, claiming, holder); +if (!for_part && (mode &FMODE_EXCL )) +bd_abort_claiming (bdev, holder);mutex_unlock (&bdev->bd_mutex);disk_unblock_events (disk); out_put_whole:include/linux/blkdev.h +2
-4@@ -1988,10 +1988,8 @@ void blkdev_show(struct seq_file *seqf, off_t offset);struct block_device *blkdev_get_by_path (const char *path,fmode_t mode,void *holder);struct block_device *blkdev_get_by_dev (dev_t dev,fmode_t mode,void *holder); -int bd_prepare_to_claim (struct block_device *bdev,struct block_device *whole, -void *holder); -void bd_abort_claiming (struct block_device *bdev,struct block_device *whole, -void *holder); +int bd_prepare_to_claim (struct block_device *bdev,void *holder); +void bd_abort_claiming (struct block_device *bdev,void *holder);void blkdev_put (struct block_device *bdev,fmode_t mode);struct block_device *bdev_alloc (struct gendisk *disk,u8 partno);Signature · 1 line
2.29.2
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Christoph Hellwig
maintainerPATCH 13/20 block: remove ->bd_contains
In reply to Christoph HellwigNow that each hd_struct has a reference to the corresponding block_device, there is no need for the bd_contains pointer. Add a bdev_whole() helper to look up the whole device block_device struture instead.
--- drivers/scsi/scsicam.c | 2 +- fs/block_dev.c | 46 ++++++++++++--------------------------- include/linux/blk_types.h | 4 +++- 3 files changed, 18 insertions(+), 34 deletions(-)
drivers/scsi/scsicam.c +1 -1
@@ -32,7 +32,7 @@*/ unsigned char *scsi_bios_ptable (struct block_device *dev) { -struct address_space *mapping = dev->bd_contains->bd_inode->i_mapping; +struct address_space *mapping =bdev_whole (dev)->bd_inode->i_mapping;unsigned char *res =NULL ;struct page *page;
fs/block_dev.c +14 -32
143 lines not on this page · raw message
include/linux/blk_types.h +3 -1
@@ -32,7 +32,6 @@ struct block_device {#ifdef CONFIG_SYSFS struct list_head bd_holder_disks;#endif -struct block_device * bd_contains;u8 bd_partno;struct hd_struct * bd_part;/* number of times partitions within this device have been opened. */
@@ -48,6 +47,9 @@ struct block_device {struct mutex bd_fsfreeze_mutex; } __randomize_layout; +#define bdev_whole (_bdev) \ + ((_bdev)->bd_disk->part0.bdev) +#define bdev_kobj (_bdev) \ (&part_to_dev((_bdev)->bd_part)->kobj)
Signature · 1 line
2.29.2
Re: [PATCH 13/20] block: remove ->bd_contains
Quoted 6 lines · Christoph Hellwig
Now that each
hd_structhas a reference to the correspondingblock_device, there is no need for thebd_containspointer. Add abdev_whole()helper to look up the whole deviceblock_devicestruture instead.Signed-off-by Christoph Hellwig <[email protected]>
Just two nits below. Otherwise feel free to add:
fs/block_dev.c static int __blkdev_get(struct block_device *bdev, fmode_t mode, void *holder, · line 1513
Quoted 6 lines
fs/block_dev.c +1
-1@@ -1521,7 +1510,7 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, void *holder,if (bdev->bd_bdi == &noop_backing_dev_info) bdev->bd_bdi =bdi_get (disk->queue->backing_dev_info); }else { -if (bdev->bd_contains == bdev) { +if (!bdev->bd_partno) {
This should be !bdev_is_partition(bdev) for consistency, right?
Quoted 3 lines
fs/block_dev.c +0
-0ret =0 ;if (bdev->bd_disk->fops->open) ret = bdev->bd_disk->fops->open (bdev, mode);
...
Quoted 13 lines
include/linux/blk_types.h +0
-1@@ -32,7 +32,6 @@ struct block_device {#ifdef CONFIG_SYSFS struct list_head bd_holder_disks;#endif -struct block_device * bd_contains;u8 bd_partno;struct hd_struct * bd_part;/* number of times partitions within this device have been opened. */
include/linux/blk_types.h struct block_device { · line 54
Quoted 8 lines
include/linux/blk_types.h +3
-0@@ -48,6 +47,9 @@ struct block_device {struct mutex bd_fsfreeze_mutex; } __randomize_layout; +#define bdev_whole (_bdev) \ + ((_bdev)->bd_disk->part0.bdev) +#define bdev_kobj (_bdev) \ (&part_to_dev((_bdev)->bd_part)->kobj)
I'd somewhat prefer if these helpers could actually be inline functions and not macros. I guess they are macros because hd_struct isn't in blk_types.h. But if we moved helpers to blkdev.h, we'd have all definitions we need... Is that a problem for some users?
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Christoph Hellwig
maintainerRe: [PATCH 13/20] block: remove ->bd_contains
Quoted 8 lines · Jan Kara
fs/block_dev.c static int __blkdev_get(struct block_device *bdev, fmode_t mode, void *holder, · line 1513
Quoted 6 lines
fs/block_dev.c +1
-1@@ -1521,7 +1510,7 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, void *holder,if (bdev->bd_bdi == &noop_backing_dev_info) bdev->bd_bdi =bdi_get (disk->queue->backing_dev_info); }else { -if (bdev->bd_contains == bdev) { +if (!bdev->bd_partno) {This should be !bdev_is_partition(bdev) for consistency, right?
Yes. Same for the same check further up for the !bdev->bd_openers case.
Quoted 10 lines
include/linux/blk_types.h struct block_device { · line 54
Quoted 5 lines
include/linux/blk_types.h +3
-0+#define bdev_whole (_bdev) \ + ((_bdev)->bd_disk->part0.bdev) +#define bdev_kobj (_bdev) \ (&part_to_dev((_bdev)->bd_part)->kobj)I'd somewhat prefer if these helpers could actually be inline functions and not macros. I guess they are macros because
hd_structisn't inblk_types.h. But if we moved helpers toblkdev.h, we'd have all definitions we need... Is that a problem for some users?
As you pointed out the reason these are macros is that the obvious placement doesn't work. My plan was to look into cleaning up the block headers, which are a complete mess between blk_types.h, bio.h, blkdev.h and genhd.h after I'm done making sense of the data structures, so for now I didn't want to move too much around. Hopefully we'll be able to convert these helpers to inlines once I'm done.
Christoph Hellwig
maintainerPATCH 14/20 block: remove the nr_sects field in struct hd_struct
In reply to Christoph HellwigNow that the hd_struct always has a block device attached to it, there is no need for having two size field that just get out of sync.
Additional the field in hd_struct did not use proper serializiation, possibly allowing for torn writes. By only using the block_device field this problem also gets fixed.
--- block/bio.c | 2 +- block/blk-core.c | 2 +- block/blk.h | 53 ---------------------- block/genhd.c | 34 +++++++------- block/partitions/core.c | 17 ++++--- drivers/block/loop.c | 1 - drivers/block/nbd.c | 2 +- drivers/block/xen-blkback/common.h | 4 +- drivers/md/bcache/super.c | 2 +- drivers/s390/block/dasd_ioctl.c | 4 +- drivers/target/target_core_pscsi.c | 7 +-- fs/block_dev.c | 73 +----------------------------- fs/f2fs/super.c | 2 +- fs/pstore/blk.c | 2 +- include/linux/genhd.h | 29 +++--------- kernel/trace/blktrace.c | 2 +- 16 files changed, 47 insertions(+), 189 deletions(-)
block/bio.c +1 -1
@@ -613,7 +613,7 @@ void guard_bio_eod(struct bio *bio)rcu_read_lock (); part =__disk_get_part (bio->bi_disk, bio->bi_partno);if (part) - maxsector =part_nr_sects_read (part); + maxsector =bdev_nr_sectors (part->bdev);else maxsector =get_capacity (bio->bi_disk);rcu_read_unlock ();
block/blk-core.c +1 -1
@@ -755,7 +755,7 @@ static inline int blk_partition_remap(struct bio *bio) goto out;if (bio_sectors (bio)) { -if (bio_check_eod (bio,part_nr_sects_read (p))) +if (bio_check_eod (bio,bdev_nr_sectors (p->bdev))) goto out; bio->bi_iter.bi_sector += p->start_sect; trace_block_bio_remap(bio->bi_disk->queue, bio, part_devt(p),
block/blk.h +0 -53
59 lines not on this page · raw message
block/genhd.c +17 -17
@@ -38,6 +38,16 @@ static void disk_add_events(struct gendisk *disk);static void disk_del_events (struct gendisk *disk);static void disk_release_events (struct gendisk *disk); +void set_capacity (struct gendisk *disk,sector_t sectors) +{ +struct block_device *bdev = disk->part0.bdev; + +spin_lock (&bdev->bd_size_lock); +i_size_write (bdev->bd_inode, (loff_t )sectors <<SECTOR_SHIFT ); +spin_unlock (&bdev->bd_size_lock); +} +EXPORT_SYMBOL (set_capacity); +/* * Set disk capacity and notify if the size is not currently zero and will not * be set to zero. Returns true if a uevent was sent, otherwise false.
@@ -47,11 +57,12 @@ bool set_capacity_and_notify(struct gendisk *disk, sector_t size)sector_t capacity =get_capacity (disk);set_capacity (disk, size); -revalidate_disk_size (disk, true);if (capacity != size && capacity !=0 && size !=0 ) {char *envp[] = {"RESIZE=1" ,NULL }; +pr_info ("%s: detected capacity change from %lld to %lld\n" , + disk->disk_name, size, capacity);kobject_uevent_env (&disk_to_dev (disk)->kobj,KOBJ_CHANGE , envp);return true; }
@@ -245,7 +256,7 @@ struct hd_struct *disk_part_iter_next(struct disk_part_iter *piter) part =rcu_dereference (ptbl->part[piter->idx]);if (!part)continue ; -if (!part_nr_sects_read (part) && +if (!bdev_nr_sectors (part->bdev) && !(piter->flags &DISK_PITER_INCL_EMPTY ) && !(piter->flags &DISK_PITER_INCL_EMPTY_PART0 && piter->idx ==0 ))
@@ -282,7 +293,7 @@ EXPORT_SYMBOL_GPL(disk_part_iter_exit);static inline int sector_in_part (struct hd_struct *part,sector_t sector) {return part->start_sect <= sector && - sector < part->start_sect +part_nr_sects_read (part); + sector < part->start_sect +bdev_nr_sectors (part->bdev); }/**
@@ -983,7 +994,7 @@ void __init printk_all_partitions(void)printk ("%s%s %10llu %s %s" , is_part0 ?"" :" " ,bdevt_str (part_devt (part), devt_buf), - (unsigned long long )part_nr_sects_read (part) >>1 +bdev_nr_sectors (part->bdev) >>1 ,disk_name (disk, part->partno, name_buf), part->info ? part->info->uuid :"" );if (is_part0) {
@@ -1076,7 +1087,7 @@ static int show_partition(struct seq_file *seqf, void *v)while ((part =disk_part_iter_next (&piter)))seq_printf (seqf,"%4d %7d %10llu %s\n" ,MAJOR (part_devt (part)),MINOR (part_devt (part)), - (unsigned long long )part_nr_sects_read (part) >>1 , +bdev_nr_sectors (part->bdev) >>1 ,disk_name (sgp, part->partno, buf));disk_part_iter_exit (&piter);
@@ -1158,8 +1169,7 @@ ssize_t part_size_show(struct device *dev, {struct hd_struct *p =dev_to_part (dev); -return sprintf (buf,"%llu\n" , - (unsigned long long )part_nr_sects_read (p)); +return sprintf (buf,"%llu\n" ,bdev_nr_sectors (p->bdev)); } ssize_t part_stat_show(struct device *dev,
@@ -1616,16 +1626,6 @@ struct gendisk *__alloc_disk_node(int minors, int node_id) ptbl =rcu_dereference_protected (disk->part_tbl,1 );rcu_assign_pointer (ptbl->part[0 ], &disk->part0); -/* -* set_capacity() and get_capacity() currently don't use -* seqcounter to read/update the part0->nr_sects. Still init -* the counter as we can read the sectors in IO submission -* patch using seqence counters. -* -* TODO: Ideally set_capacity() and get_capacity() should be -* converted to make use of bd_mutex and sequence counters. -*/ -hd_sects_seq_init (&disk->part0);if (hd_ref_init (&disk->part0)) {hd_free_part (&disk->part0);return NULL ;
block/partitions/core.c +11 -6
@@ -85,6 +85,13 @@ static int (*check_part[])(struct parsed_partitions *) = { NULL }; +static void bdev_set_nr_sectors (struct block_device *bdev,sector_t sectors) +{ +spin_lock (&bdev->bd_size_lock); +i_size_write (bdev->bd_inode, (loff_t )sectors <<SECTOR_SHIFT ); +spin_unlock (&bdev->bd_size_lock); +} +static struct parsed_partitions *allocate_partitions (struct gendisk *hd) {struct parsed_partitions *state;
@@ -295,7 +302,7 @@ static void hd_struct_free_work(struct work_struct *work)put_device (disk_to_dev (disk)); part->start_sect =0 ; - part->nr_sects =0 ; +bdev_set_nr_sectors (part->bdev,0 );part_stat_set_all (part,0 );put_device (part_to_dev (part)); }
@@ -410,11 +417,10 @@ static struct hd_struct *add_partition(struct gendisk *disk, int partno,if (!p->bdev) goto out_free_stats; -hd_sects_seq_init (p); pdev =part_to_dev (p); p->start_sect = start; - p->nr_sects = len; +bdev_set_nr_sectors (p->bdev, len); p->partno = partno; p->policy =get_disk_ro (disk);
@@ -508,7 +514,7 @@ static bool partition_overlaps(struct gendisk *disk, sector_t start,disk_part_iter_init (&piter, disk,DISK_PITER_INCL_EMPTY );while ((part =disk_part_iter_next (&piter))) {if (part->partno == skip_partno || - start >= part->start_sect + part->nr_sects || + start >= part->start_sect +bdev_nr_sectors (part->bdev) || start + length <= part->start_sect)continue ; overlap = true;
@@ -599,8 +605,7 @@ int bdev_resize_partition(struct block_device *bdev, int partno,if (partition_overlaps (bdev->bd_disk, start, length, partno)) goto out_unlock; -part_nr_sects_write (part, length); -bd_set_nr_sectors (bdevp, length); +bdev_set_nr_sectors (bdevp, length); ret =0 ; out_unlock:
drivers/block/loop.c +0 -1
@@ -1243,7 +1243,6 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)set_capacity (lo->lo_disk,0 );loop_sysfs_exit (lo);if (bdev) { -bd_set_nr_sectors (bdev,0 );/* let user-space know about this change */ kobject_uevent (&disk_to_dev (bdev->bd_disk)->kobj,KOBJ_CHANGE ); }
drivers/block/nbd.c +1 -1
@@ -1132,7 +1132,7 @@ static void nbd_bdev_reset(struct block_device *bdev) {if (bdev->bd_openers >1 )return ; -bd_set_nr_sectors (bdev,0 ); +set_capacity (bdev->bd_disk,0 ); }static void nbd_parse_flags (struct nbd_device *nbd)
drivers/block/xen-blkback/common.h +1 -3
@@ -358,9 +358,7 @@ struct pending_req { }; -#define vbd_sz (_v) ((_v)->bdev->bd_part ? \ - (_v)->bdev->bd_part->nr_sects : \ - get_capacity((_v)->bdev->bd_disk)) +#define vbd_sz (_v) bdev_nr_sectors((_v)->bdev)#define xen_blkif_get (_b) (atomic_inc(&(_b)->refcnt))#define xen_blkif_put (_b) \
drivers/md/bcache/super.c +1 -1
@@ -1408,7 +1408,7 @@ static int cached_dev_init(struct cached_dev *dc, unsigned int block_size) q->limits.raid_partial_stripes_expensive; ret =bcache_device_init (&dc->disk, block_size, - dc->bdev->bd_part->nr_sects - dc->sb.data_offset, +bdev_nr_sectors (dc->bdev) - dc->sb.data_offset, dc->bdev, &bcache_cached_ops);if (ret)return ret;
drivers/s390/block/dasd_ioctl.c +1 -3
@@ -54,8 +54,6 @@ dasd_ioctl_enable(struct block_device *bdev)return -ENODEV ;dasd_enable_device (base); -/* Formatting the dasd device can change the capacity. */ -bd_set_nr_sectors (bdev,get_capacity (base->block->gdp));dasd_put_device (base);return 0 ; }
@@ -88,7 +86,7 @@ dasd_ioctl_disable(struct block_device *bdev)* Set i_size to zero, since read, write, etc. check against this * value. */ -bd_set_nr_sectors (bdev,0 ); +set_capacity (bdev->bd_disk,0 );dasd_put_device (base);return 0 ; }
drivers/target/target_core_pscsi.c +1 -6
@@ -1027,12 +1027,7 @@ static u32 pscsi_get_device_type(struct se_device *dev)static sector_t pscsi_get_blocks (struct se_device *dev) { -struct pscsi_dev_virt *pdv =PSCSI_DEV (dev); - -if (pdv->pdv_bd && pdv->pdv_bd->bd_part) -return pdv->pdv_bd->bd_part->nr_sects; - -return 0 ; +return bdev_nr_sectors (PSCSI_DEV (dev)->pdv_bd); }static void pscsi_req_done (struct request *req,blk_status_t status)
fs/block_dev.c +2 -71
101 lines not on this page · raw message
fs/f2fs/super.c +1 -1
@@ -3151,7 +3151,7 @@ static int f2fs_report_zone_cb(struct blk_zone *zone, unsigned int idx,static int init_blkz_info (struct f2fs_sb_info *sbi,int devi) {struct block_device *bdev =FDEV (devi).bdev; -sector_t nr_sectors = bdev->bd_part->nr_sects; +sector_t nr_sectors =bdev_nr_sectors (bdev);struct f2fs_report_zones_args rep_zone_arg;int ret;
fs/pstore/blk.c +1 -1
@@ -245,7 +245,7 @@ static struct block_device *psblk_get_bdev(void *holder,return bdev; } - nr_sects =part_nr_sects_read (bdev->bd_part); + nr_sects =bdev_nr_sectors (bdev);if (!nr_sects) {pr_err ("not enough space for '%s'\n" , blkdev);blkdev_put (bdev, mode);
include/linux/genhd.h +7 -22
@@ -52,15 +52,6 @@ struct partition_meta_info {struct hd_struct {sector_t start_sect; -/* -* nr_sects is protected by sequence counter. One might extend a -* partition while IO is happening to it and update of nr_sects -* can be non-atomic on 32bit machines with 64bit sector_t. -*/ -sector_t nr_sects; -#if BITS_PER_LONG ==32 && defined(CONFIG_SMP ) -seqcount_t nr_sects_seq; -#endif unsigned long stamp;struct disk_stats __percpu *dkstats;struct percpu_ref ref;
@@ -259,13 +250,6 @@ static inline void disk_put_part(struct hd_struct *part)put_device (part_to_dev (part)); } -static inline void hd_sects_seq_init (struct hd_struct *p) -{ -#if BITS_PER_LONG ==32 && defined(CONFIG_SMP ) -seqcount_init (&p->nr_sects_seq); -#endif -} -/* * Smarter partition iterator without context limits. */
@@ -323,13 +307,15 @@ static inline sector_t get_start_sect(struct block_device *bdev) {return bdev->bd_part->start_sect; } -static inline sector_t get_capacity (struct gendisk *disk) + +static inline sector_t bdev_nr_sectors (struct block_device *bdev) { -return disk->part0.nr_sects; +return i_size_read (bdev->bd_inode) >>9 ; } -static inline void set_capacity (struct gendisk *disk,sector_t size) + +static inline sector_t get_capacity (struct gendisk *disk) { - disk->part0.nr_sects = size; +return bdev_nr_sectors (disk->part0.bdev); }int bdev_disk_changed (struct block_device *bdev,bool invalidate);
@@ -363,10 +349,9 @@ int __register_blkdev(unsigned int major, const char *name, __register_blkdev(major, name, NULL)void unregister_blkdev (unsigned int major,const char *name); -void revalidate_disk_size (struct gendisk *disk,bool verbose);bool bdev_check_media_change (struct block_device *bdev);int __invalidate_device (struct block_device *bdev,bool kill_dirty); -void bd_set_nr_sectors (struct block_device *bdev,sector_t sectors); +void set_capacity (struct gendisk *disk,sector_t size);/* for drivers/char/raw.c: */ int blkdev_ioctl (struct block_device *,fmode_t ,unsigned ,unsigned long );
kernel/trace/blktrace.c +1 -1
@@ -465,7 +465,7 @@ static void blk_trace_setup_lba(struct blk_trace *bt,if (part) { bt->start_lba = part->start_sect; - bt->end_lba = part->start_sect + part->nr_sects; + bt->end_lba = part->start_sect +bdev_nr_sectors (bdev); }else { bt->start_lba =0 ; bt->end_lba =-1ULL ;
Signature · 1 line
2.29.2
Jan Kara
maintainerRe: [PATCH 14/20] block: remove the nr_sects field in struct hd_struct
Quoted 8 lines · Christoph Hellwig
Now that the
hd_structalways has a block device attached to it, there is no need for having two size field that just get out of sync.Additional the field in
hd_structdid not use proper serializiation, possibly allowing for torn writes. By only using theblock_devicefield this problem also gets fixed.Signed-off-by Christoph Hellwig <[email protected]>
Overall the patch looks good but I have a couple of comments below.
block/bio.c void guard_bio_eod(struct bio *bio) · line 618
Quoted 12 lines
block/bio.c +1
-1@@ -613,7 +613,7 @@ void guard_bio_eod(struct bio *bio)rcu_read_lock (); part =__disk_get_part (bio->bi_disk, bio->bi_partno);if (part) - maxsector =part_nr_sects_read (part); + maxsector =bdev_nr_sectors (part->bdev);else maxsector =get_capacity (bio->bi_disk);
I have to say that after these changes I find it a bit confusing that we have get/set_capacity() and bdev_nr_sectors() / bdev_set_nr_sectors() and they are all the same thing (i_size of the bdev). Is there a reason for the distinction?
Quoted 5 lines
block/genhd.c +0
-0
block/genhd.c static void disk_add_events(struct gendisk *disk); · line 47
Quoted 10 lines
block/genhd.c +7
-0@@ -38,6 +38,16 @@ static void disk_add_events(struct gendisk *disk);static void disk_del_events (struct gendisk *disk);static void disk_release_events (struct gendisk *disk); +void set_capacity (struct gendisk *disk,sector_t sectors) +{ +struct block_device *bdev = disk->part0.bdev; + +spin_lock (&bdev->bd_size_lock); +i_size_write (bdev->bd_inode, (loff_t )sectors <<SECTOR_SHIFT ); +spin_unlock (&bdev->bd_size_lock);
AFAICT bd_size_lock is pointless after these changes so we can just remove it?
Quoted 7 lines
block/genhd.c +3
-0+} +EXPORT_SYMBOL (set_capacity); +/* * Set disk capacity and notify if the size is not currently zero and will not * be set to zero. Returns true if a uevent was sent, otherwise false.
block/genhd.c bool set_capacity_and_notify(struct gendisk *disk, sector_t size) · line 65
Quoted 10 lines
block/genhd.c +2
-1@@ -47,11 +57,12 @@ bool set_capacity_and_notify(struct gendisk *disk, sector_t size)sector_t capacity =get_capacity (disk);set_capacity (disk, size); -revalidate_disk_size (disk, true);if (capacity != size && capacity !=0 && size !=0 ) {char *envp[] = {"RESIZE=1" ,NULL }; +pr_info ("%s: detected capacity change from %lld to %lld\n" , + disk->disk_name, size, capacity);
So we are now missing above message for transitions from / to 0 capacity? Is there any other notification in the kernel log when e.g. media is inserted into a CD-ROM drive? I remember using these messages for detecting that...
Also what about GENHD_FL_HIDDEN devices? Are we sure we never set capacity for them?
Quoted 3 lines
block/genhd.c +0
-0kobject_uevent_env (&disk_to_dev (disk)->kobj,KOBJ_CHANGE , envp);return true; }
...
Quoted 19 lines
block/genhd.c +2
-2@@ -983,7 +994,7 @@ void __init printk_all_partitions(void)printk ("%s%s %10llu %s %s" , is_part0 ?"" :" " ,bdevt_str (part_devt (part), devt_buf), - (unsigned long long )part_nr_sects_read (part) >>1 +bdev_nr_sectors (part->bdev) >>1 ,disk_name (disk, part->partno, name_buf), part->info ? part->info->uuid :"" );if (is_part0) {@@ -1076,7 +1087,7 @@ static int show_partition(struct seq_file *seqf, void *v)while ((part =disk_part_iter_next (&piter)))seq_printf (seqf,"%4d %7d %10llu %s\n" ,MAJOR (part_devt (part)),MINOR (part_devt (part)), - (unsigned long long )part_nr_sects_read (part) >>1 , +bdev_nr_sectors (part->bdev) >>1 ,disk_name (sgp, part->partno, buf));disk_part_iter_exit (&piter);
block/genhd.c ssize_t part_size_show(struct device *dev, · line 1172
Quoted 6 lines
block/genhd.c +1
-2@@ -1158,8 +1169,7 @@ ssize_t part_size_show(struct device *dev, {struct hd_struct *p =dev_to_part (dev); -return sprintf (buf,"%llu\n" , - (unsigned long long )part_nr_sects_read (p)); +return sprintf (buf,"%llu\n" ,bdev_nr_sectors (p->bdev));
Is sector_t really guaranteed to be unsigned long long?
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Christoph Hellwig
maintainerRe: [PATCH 14/20] block: remove the nr_sects field in struct hd_struct
Quoted 5 lines · Jan Kara
Quoted 5 lines
block/bio.c +0
-1@@ -613,7 +613,7 @@ void guard_bio_eod(struct bio *bio)rcu_read_lock (); part =__disk_get_part (bio->bi_disk, bio->bi_partno);if (part) - maxsector =part_nr_sects_read (part);
Quoted 8 lines
block/bio.c void guard_bio_eod(struct bio *bio) · line 618
Quoted 3 lines
block/bio.c +1
-0+ maxsector =bdev_nr_sectors (part->bdev); else maxsector =get_capacity (bio->bi_disk);I have to say that after these changes I find it a bit confusing that we have get/set_capacity() and
bdev_nr_sectors()/bdev_set_nr_sectors()and they are all the same thing (i_sizeof the bdev). Is there a reason for the distinction?
get_capacity/set_capacity are the existing unchanged interfaces that work on struct gendisk, and unchanged from what we had before. They also have lots of users which makes them kinda awkward to touch.
bdev_nr_sectors is the public interface to query the size for any kind of struct block device, to be used by consumers of the block device interface.
bdev_set_nr_sectors is a private helper for the partitions core that avoids duplicating a bit of code, and works on partitions.
Quoted 4 lines
Quoted 4 lines
block/genhd.c +0
-0@@ -38,6 +38,16 @@ static void disk_add_events(struct gendisk *disk);static void disk_del_events (struct gendisk *disk);static void disk_release_events (struct gendisk *disk);
Quoted 10 lines
block/genhd.c static void disk_add_events(struct gendisk *disk); · line 47
Quoted 7 lines
block/genhd.c +7
-0+void set_capacity (struct gendisk *disk,sector_t sectors) +{ +struct block_device *bdev = disk->part0.bdev; + +spin_lock (&bdev->bd_size_lock); +i_size_write (bdev->bd_inode, (loff_t )sectors <<SECTOR_SHIFT ); +spin_unlock (&bdev->bd_size_lock);AFAICT
bd_size_lockis pointless after these changes so we can just remove it?
I don't think it is, as reuqiring bd_mutex for size updates leads to rather awkward lock ordering problems.
Quoted 10 lines
block/genhd.c bool set_capacity_and_notify(struct gendisk *disk, sector_t size) · line 65
Quoted 5 lines
block/genhd.c +2
-0if (capacity != size && capacity !=0 && size !=0 ) {char *envp[] = {"RESIZE=1" ,NULL }; +pr_info ("%s: detected capacity change from %lld to %lld\n" , + disk->disk_name, size, capacity);So we are now missing above message for transitions from / to 0 capacity? Is there any other notification in the kernel log when e.g. media is inserted into a CD-ROM drive? I remember using these messages for detecting that...
True, I guess we should keep the messages for that case at least under some circumstances. Let me take a closer look at what could make sense.
Quoted 2 lines
Also what about
GENHD_FL_HIDDENdevices? Are we sure we never set capacity for them?
We absolutely set the capacity for them, as we have to. And even use this interface. But yes, I think we should skip sending the uevent for them.
Quoted 9 lines
block/genhd.c ssize_t part_size_show(struct device *dev, · line 1172
Quoted 7 lines
block/genhd.c +1
-2@@ -1158,8 +1169,7 @@ ssize_t part_size_show(struct device *dev, {struct hd_struct *p =dev_to_part (dev); -return sprintf (buf,"%llu\n" , - (unsigned long long )part_nr_sects_read (p)); +return sprintf (buf,"%llu\n" ,bdev_nr_sectors (p->bdev));Is
sector_treally guaranteed to be unsigned long long?
Yes, it is these days, ever since I removed the option to have a 32-bit one on 32-bit platforms a while ago.
Jan Kara
maintainerRe: [PATCH 14/20] block: remove the nr_sects field in struct hd_struct
Quoted 19 lines · Christoph Hellwig
Quoted 5 lines · Jan Kara
Quoted 5 lines
block/bio.c +0
-1@@ -613,7 +613,7 @@ void guard_bio_eod(struct bio *bio)rcu_read_lock (); part =__disk_get_part (bio->bi_disk, bio->bi_partno);if (part) - maxsector =part_nr_sects_read (part);Quoted 8 lines
block/bio.c void guard_bio_eod(struct bio *bio) · line 618
Quoted 3 lines
block/bio.c +1
-0+ maxsector =bdev_nr_sectors (part->bdev); else maxsector =get_capacity (bio->bi_disk);I have to say that after these changes I find it a bit confusing that we have get/set_capacity() and
bdev_nr_sectors()/bdev_set_nr_sectors()and they are all the same thing (i_sizeof the bdev). Is there a reason for the distinction?get_capacity/set_capacity are the existing unchanged interfaces that work on struct gendisk, and unchanged from what we had before. They also have lots of users which makes them kinda awkward to touch.
Quoted 6 lines
bdev_nr_sectorsis the public interface to query the size for any kind of struct block device, to be used by consumers of the block device interface.
bdev_set_nr_sectorsis a private helper for the partitions core that avoids duplicating a bit of code, and works on partitions.
OK, I guess I'll get used to this...
Quoted 15 lines
Quoted 4 lines
Quoted 4 lines
block/genhd.c +0
-0@@ -38,6 +38,16 @@ static void disk_add_events(struct gendisk *disk);static void disk_del_events (struct gendisk *disk);static void disk_release_events (struct gendisk *disk);Quoted 10 lines
block/genhd.c static void disk_add_events(struct gendisk *disk); · line 47
Quoted 7 lines
block/genhd.c +7
-0+void set_capacity (struct gendisk *disk,sector_t sectors) +{ +struct block_device *bdev = disk->part0.bdev; + +spin_lock (&bdev->bd_size_lock); +i_size_write (bdev->bd_inode, (loff_t )sectors <<SECTOR_SHIFT ); +spin_unlock (&bdev->bd_size_lock);AFAICT
bd_size_lockis pointless after these changes so we can just remove it?
Quoted 2 lines
I don't think it is, as reuqiring
bd_mutexfor size updates leads to rather awkward lock ordering problems.
OK, let me ask differently: What is bd_size_lock protecting now? Ah, I see, on 32-bit it is needed to prevent torn writes to i_size, right?
Quoted 14 lines
Quoted 10 lines
block/genhd.c bool set_capacity_and_notify(struct gendisk *disk, sector_t size) · line 65
Quoted 5 lines
block/genhd.c +2
-0if (capacity != size && capacity !=0 && size !=0 ) {char *envp[] = {"RESIZE=1" ,NULL }; +pr_info ("%s: detected capacity change from %lld to %lld\n" , + disk->disk_name, size, capacity);So we are now missing above message for transitions from / to 0 capacity? Is there any other notification in the kernel log when e.g. media is inserted into a CD-ROM drive? I remember using these messages for detecting that...
True, I guess we should keep the messages for that case at least under some circumstances. Let me take a closer look at what could make sense.
Quoted 6 lines
Quoted 2 lines
Also what about
GENHD_FL_HIDDENdevices? Are we sure we never set capacity for them?We absolutely set the capacity for them, as we have to. And even use this interface. But yes, I think we should skip sending the uevent for them.
Also previously we were not printing any messages for hidden devices and now we do. I'm not sure whether that's intended or not.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Christoph Hellwig
maintainerRe: [PATCH 14/20] block: remove the nr_sects field in struct hd_struct
Quoted 8 lines · Jan Kara
Quoted 5 lines
Quoted 2 lines
AFAICT
bd_size_lockis pointless after these changes so we can just remove it?I don't think it is, as reuqiring
bd_mutexfor size updates leads to rather awkward lock ordering problems.OK, let me ask differently: What is
bd_size_lockprotecting now? Ah, I see, on 32-bit it is needed to prevent torn writes toi_size, right?
Exactly. In theory we could skip it for 64-bit, but as updating the size isn't a fast path, and struct block_device isn't super size critical I'd rather keep the same code for 32 vs 64-bit builds.
Matthew Wilcox
maintainerRe: [PATCH 14/20] block: remove the nr_sects field in struct hd_struct
Quoted 7 lines · Christoph Hellwig
Quoted 6 lines · Jan Kara
Quoted 5 lines
Quoted 2 lines
AFAICT
bd_size_lockis pointless after these changes so we can just remove it?I don't think it is, as reuqiring
bd_mutexfor size updates leads to rather awkward lock ordering problems.
Quoted 6 lines
Quoted 2 lines
OK, let me ask differently: What is
bd_size_lockprotecting now? Ah, I see, on 32-bit it is needed to prevent torn writes toi_size, right?Exactly. In theory we could skip it for 64-bit, but as updating the size isn't a fast path, and struct
block_deviceisn't super size critical I'd rather keep the same code for 32 vs 64-bit builds.
Is it better to switch to i_size_write() / i_size_read()?
Christoph Hellwig
maintainerRe: [PATCH 14/20] block: remove the nr_sects field in struct hd_struct
Quoted 5 lines · Matthew Wilcox
Quoted 3 lines
Exactly. In theory we could skip it for 64-bit, but as updating the size isn't a fast path, and struct
block_deviceisn't super size critical I'd rather keep the same code for 32 vs 64-bit builds.Is it better to switch to
i_size_write()/i_size_read()?
I think we've stopped updating the size from contexts that can't block, so it is worth pursuing. I'd rather do it after this series is done and merged, though.
Jan Kara
maintainerRe: [PATCH 14/20] block: remove the nr_sects field in struct hd_struct
In reply to Matthew WilcoxQuoted 8 lines · Matthew Wilcox
Quoted 7 lines · Christoph Hellwig
Quoted 6 lines · Jan Kara
Quoted 5 lines
Quoted 2 lines
AFAICT
bd_size_lockis pointless after these changes so we can just remove it?I don't think it is, as reuqiring
bd_mutexfor size updates leads to rather awkward lock ordering problems.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
OK, let me ask differently: What is
bd_size_lockprotecting now? Ah, I see, on 32-bit it is needed to prevent torn writes toi_size, right?Exactly. In theory we could skip it for 64-bit, but as updating the size isn't a fast path, and struct
block_deviceisn't super size critical I'd rather keep the same code for 32 vs 64-bit builds.Is it better to switch to
i_size_write()/i_size_read()?
The code is already switched to it AFAICT (the lock is really only used in the two places that write i_size). But the problem is that in theory two i_size_write() calls can race in a way that the resulting stored i_size is a mix of two stored sizes. Now I have hard time imagining how this could happen for a block device and if two reconfigurations of a block device could race like that we'd have a large problems anyway...
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Christoph Hellwig
maintainerRe: [PATCH 14/20] block: remove the nr_sects field in struct hd_struct
Quoted 6 lines · Jan Kara
The code is already switched to it AFAICT (the lock is really only used in the two places that write
i_size). But the problem is that in theory twoi_size_write()calls can race in a way that the resulting storedi_sizeis a mix of two stored sizes. Now I have hard time imagining how this could happen for a block device and if two reconfigurations of a block device could race like that we'd have a large problems anyway...
Now that you mention it, yes - i_size_write needs to be under i_rwsem or an equivalent lock. We could look into using i_rwsem also for block device, but for now the spinlock seems to be doing fine. Note that in current mainline we only have such a lock protecting i_size of the block_device inode, but none for the size in hd_struct.
Christoph Hellwig
maintainerPATCH 15/20 block: merge struct block_device and struct hd_struct
In reply to Christoph HellwigInstead of having two structures that represent each block device with different lift time rules merged them into a single one. This also greatly simplifies the reference counting rules, as we can use the inode reference count as the main reference count for the new struct block_device, with the device model reference front ending it for device model interaction. The percpu refcount in struct hd_struct is entirely gone given that struct block_device must be opened and thus valid for the duration of the I/O.
--- block/bio.c | 6 +- block/blk-cgroup.c | 9 +- block/blk-core.c | 85 +++++----- block/blk-flush.c | 2 +- block/blk-lib.c | 2 +- block/blk-merge.c | 6 +- block/blk-mq.c | 11 +- block/blk-mq.h | 5 +- block/blk.h | 39 ++--- block/genhd.c | 240 +++++++++++------------------ block/ioctl.c | 4 +- block/partitions/core.c | 221 ++++++++------------------ drivers/block/drbd/drbd_receiver.c | 2 +- drivers/block/drbd/drbd_worker.c | 2 +- drivers/block/zram/zram_drv.c | 2 +- drivers/md/bcache/request.c | 4 +- drivers/md/dm.c | 8 +- drivers/md/md.c | 4 +- drivers/nvme/target/admin-cmd.c | 20 +-- drivers/s390/block/dasd.c | 8 +- fs/block_dev.c | 77 ++++----- fs/ext4/super.c | 18 +-- fs/ext4/sysfs.c | 10 +- fs/f2fs/checkpoint.c | 5 +- fs/f2fs/f2fs.h | 2 +- fs/f2fs/super.c | 6 +- fs/f2fs/sysfs.c | 9 -- include/linux/blk_types.h | 23 ++- include/linux/blkdev.h | 13 +- include/linux/genhd.h | 67 ++------ include/linux/part_stat.h | 17 +- init/do_mounts.c | 20 +-- kernel/trace/blktrace.c | 54 ++----- 33 files changed, 362 insertions(+), 639 deletions(-)
block/bio.c +3 -3
@@ -608,12 +608,12 @@ void bio_truncate(struct bio *bio, unsigned new_size)void guard_bio_eod (struct bio *bio) {sector_t maxsector; -struct hd_struct *part; +struct block_device *part;rcu_read_lock (); - part =__disk_get_part (bio->bi_disk, bio->bi_partno); + part =__bdget_disk (bio->bi_disk, bio->bi_partno);if (part) - maxsector =bdev_nr_sectors (part->bdev); + maxsector =bdev_nr_sectors (part);else maxsector =get_capacity (bio->bi_disk);rcu_read_unlock ();
block/blk-cgroup.c +4 -5
@@ -820,9 +820,9 @@ static void blkcg_fill_root_iostats(void)class_dev_iter_init (&iter, &block_class,NULL , &disk_type);while ((dev =class_dev_iter_next (&iter))) { -struct gendisk *disk =dev_to_disk (dev); -struct hd_struct *part =disk_get_part (disk,0 ); -struct blkcg_gq *blkg =blk_queue_root_blkg (disk->queue); +struct block_device *bdev =dev_to_bdev (dev); +struct blkcg_gq *blkg = +blk_queue_root_blkg (bdev->bd_disk->queue);struct blkg_iostat tmp;int cpu;
@@ -830,7 +830,7 @@ static void blkcg_fill_root_iostats(void)for_each_possible_cpu (cpu) {struct disk_stats *cpu_dkstats; - cpu_dkstats =per_cpu_ptr (part->dkstats, cpu); + cpu_dkstats =per_cpu_ptr (bdev->bd_stats, cpu); tmp.ios[BLKG_IOSTAT_READ ] += cpu_dkstats->ios[STAT_READ ]; tmp.ios[BLKG_IOSTAT_WRITE] +=
@@ -849,7 +849,6 @@ static void blkcg_fill_root_iostats(void)blkg_iostat_set (&blkg->iostat.cur, &tmp);u64_stats_update_end (&blkg->iostat.sync); } -disk_put_part (part); } }
block/blk-core.c +39 -46
226 lines not on this page · raw message
block/blk-flush.c +1 -1
@@ -139,7 +139,7 @@ static void blk_flush_queue_rq(struct request *rq, bool add_front)static void blk_account_io_flush (struct request *rq) { -struct hd_struct *part = &rq->rq_disk->part0; +struct block_device *part = rq->rq_disk->part0;part_stat_lock ();part_stat_inc (part, ios[STAT_FLUSH ]);
block/blk-lib.c +1 -1
@@ -65,7 +65,7 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,/* In case the discard request is in a partition */ if (bdev_is_partition (bdev)) - part_offset = bdev->bd_part->start_sect; + part_offset = bdev->bd_start_sect;while (nr_sects) {sector_t granularity_aligned_lba, req_sects;
block/blk-merge.c +2 -4
@@ -681,10 +681,8 @@ static void blk_account_io_merge_request(struct request *req) {if (blk_do_io_stat (req)) {part_stat_lock (); -part_stat_inc (req->part, merges[op_stat_group (req_op (req))]); +part_stat_inc (req->bdev, merges[op_stat_group (req_op (req))]);part_stat_unlock (); - -hd_struct_put (req->part); } }
@@ -906,7 +904,7 @@ static void blk_account_io_merge_bio(struct request *req)return ;part_stat_lock (); -part_stat_inc (req->part, merges[op_stat_group (req_op (req))]); +part_stat_inc (req->bdev, merges[op_stat_group (req_op (req))]);part_stat_unlock (); }
block/blk-mq.c +6 -5
@@ -95,7 +95,7 @@ static void blk_mq_hctx_clear_pending(struct blk_mq_hw_ctx *hctx, }struct mq_inflight { -struct hd_struct *part; +struct block_device *part;unsigned int inflight[2 ]; };
@@ -105,13 +105,14 @@ static bool blk_mq_check_inflight(struct blk_mq_hw_ctx *hctx, {struct mq_inflight *mi = priv; -if (rq->part == mi->part &&blk_mq_rq_state (rq) ==MQ_RQ_IN_FLIGHT ) +if (rq->bdev == mi->part &&blk_mq_rq_state (rq) ==MQ_RQ_IN_FLIGHT ) mi->inflight[rq_data_dir (rq)]++;return true; } -unsigned int blk_mq_in_flight (struct request_queue *q,struct hd_struct *part) +unsigned int blk_mq_in_flight (struct request_queue *q, +struct block_device *part) {struct mq_inflight mi = { .part = part };
@@ -120,7 +121,7 @@ unsigned int blk_mq_in_flight(struct request_queue *q, struct hd_struct *part)return mi.inflight[0 ] + mi.inflight[1 ]; } -void blk_mq_in_flight_rw (struct request_queue *q,struct hd_struct *part, +void blk_mq_in_flight_rw (struct request_queue *q,struct block_device *part,unsigned int inflight[2 ]) {struct mq_inflight mi = { .part = part };
@@ -300,7 +301,7 @@ static struct request *blk_mq_rq_ctx_init(struct blk_mq_alloc_data *data,INIT_HLIST_NODE (&rq->hash);RB_CLEAR_NODE (&rq->rb_node); rq->rq_disk =NULL ; - rq->part =NULL ; + rq->bdev =NULL ;#ifdef CONFIG_BLK_RQ_ALLOC_TIME rq->alloc_time_ns = alloc_time_ns;#endif
block/blk-mq.h +3 -2
@@ -182,8 +182,9 @@ static inline bool blk_mq_hw_queue_mapped(struct blk_mq_hw_ctx *hctx)return hctx->nr_ctx && hctx->tags; } -unsigned int blk_mq_in_flight (struct request_queue *q,struct hd_struct *part); -void blk_mq_in_flight_rw (struct request_queue *q,struct hd_struct *part, +unsigned int blk_mq_in_flight (struct request_queue *q, +struct block_device *bdev); +void blk_mq_in_flight_rw (struct request_queue *q,struct block_device *bdev,unsigned int inflight[2 ]);static inline void blk_mq_put_dispatch_budget (struct request_queue *q)
block/blk.h +12 -27
@@ -215,7 +215,15 @@ static inline void elevator_exit(struct request_queue *q,__elevator_exit (q, e); } -struct hd_struct *__disk_get_part (struct gendisk *disk,int partno); +static inline struct block_device *__bdget_disk (struct gendisk *disk, +int partno) +{ +struct disk_part_tbl *ptbl =rcu_dereference (disk->part_tbl); + +if (unlikely (partno <0 || partno >= ptbl->len)) +return NULL ; +return rcu_dereference (ptbl->part[partno]); +}ssize_t part_size_show (struct device *dev,struct device_attribute *attr,char *buf);
@@ -348,44 +356,21 @@ void blk_queue_free_zone_bitmaps(struct request_queue *q);static inline void blk_queue_free_zone_bitmaps (struct request_queue *q) {}#endif -struct hd_struct *disk_map_sector_rcu (struct gendisk *disk,sector_t sector); +struct block_device *disk_map_sector_rcu (struct gendisk *disk,sector_t sector); -int blk_alloc_devt (struct hd_struct *part,dev_t *devt); +int blk_alloc_devt (struct block_device *bdev,dev_t *devt);void blk_free_devt (dev_t devt);char *disk_name (struct gendisk *hd,int partno,char *buf);#define ADDPART_FLAG_NONE 0#define ADDPART_FLAG_RAID 1#define ADDPART_FLAG_WHOLEDISK 2 -void delete_partition (struct hd_struct *part); +void delete_partition (struct block_device *part);int bdev_add_partition (struct block_device *bdev,int partno,sector_t start,sector_t length);int bdev_del_partition (struct block_device *bdev,int partno);int bdev_resize_partition (struct block_device *bdev,int partno,sector_t start,sector_t length);int disk_expand_part_tbl (struct gendisk *disk,int target); -int hd_ref_init (struct hd_struct *part); - -/* no need to get/put refcount of part0 */ -static inline int hd_struct_try_get (struct hd_struct *part) -{ -if (part->partno) -return percpu_ref_tryget_live (&part->ref); -return 1 ; -} - -static inline void hd_struct_put (struct hd_struct *part) -{ -if (part->partno) -percpu_ref_put (&part->ref); -} - -static inline void hd_free_part (struct hd_struct *part) -{ -free_percpu (part->dkstats); -kfree (part->info); -bdput (part->bdev); -percpu_ref_exit (&part->ref); -} int bio_add_hw_page(struct request_queue *q, struct bio *bio, struct page *page, unsigned int len, unsigned int offset,
block/genhd.c +88 -152
558 lines not on this page · raw message
block/ioctl.c +2 -2
@@ -35,7 +35,7 @@ static int blkpg_do_ioctl(struct block_device *bdev, start = p.start >>SECTOR_SHIFT ; length = p.length >>SECTOR_SHIFT ; -/* check for fit in a hd_struct */ +/* check for fit in a sector_t */ if (sizeof (sector_t) <sizeof (long long )) {long pstart = start, plength = length;
@@ -354,7 +354,7 @@ static int blkdev_roset(struct block_device *bdev, fmode_t mode,if (ret)return ret; } - bdev->bd_part->policy = n; + bdev->bd_policy = n;return 0 ; }
block/partitions/core.c +64 -157
406 lines not on this page · raw message
drivers/block/drbd/drbd_receiver.c +1 -1
@@ -2802,7 +2802,7 @@ bool drbd_rs_c_min_rate_throttle(struct drbd_device *device)if (c_min_rate ==0 )return false; - curr_events = (int )part_stat_read_accum (&disk->part0, sectors) - + curr_events = (int )part_stat_read_accum (disk->part0, sectors) -atomic_read (&device->rs_sect_ev); if (atomic_read(&device->ap_actlog_cnt)
drivers/block/drbd/drbd_worker.c +1 -1
@@ -1678,7 +1678,7 @@ void drbd_rs_controller_reset(struct drbd_device *device)atomic_set (&device->rs_sect_in,0 );atomic_set (&device->rs_sect_ev,0 ); device->rs_in_flight =0 ; - device->rs_last_events = (int )part_stat_read_accum (&disk->part0, sectors); + device->rs_last_events =part_stat_read_accum (disk->part0, sectors);/* Updating the RCU protected object in place is necessary since this function gets called from atomic context.
drivers/block/zram/zram_drv.c +1 -1
@@ -1687,7 +1687,7 @@ static void zram_reset_device(struct zram *zram) zram->disksize =0 ;set_capacity_and_notify (zram->disk,0 ); -part_stat_set_all (&zram->disk->part0,0 ); +part_stat_set_all (zram->disk->part0,0 );up_write (&zram->init_lock);/* I/O operation under all of CPU are done so let's free */
drivers/md/bcache/request.c +2 -2
@@ -475,7 +475,7 @@ struct search { unsigned int read_dirty_data:1; unsigned int cache_missed:1; -struct hd_struct *part; +struct block_device *part;unsigned long start_time;struct btree_op op;
@@ -1073,7 +1073,7 @@ struct detached_dev_io_private {unsigned long start_time;bio_end_io_t *bi_end_io;void *bi_private; -struct hd_struct *part; +struct block_device *part; };static void detached_dev_end_io (struct bio *bio)
drivers/md/dm.c +4 -4
@@ -1607,7 +1607,7 @@ static blk_qc_t __split_and_process_bio(struct mapped_device *md,* (by eliminating DM's splitting and just using bio_split) */ part_stat_lock (); -__dm_part_stat_sub (&dm_disk (md)->part0, +__dm_part_stat_sub (dm_disk (md)->part0, sectors[op_stat_group (bio_op (bio))], ci.sector_count);part_stat_unlock ();
@@ -2242,12 +2242,12 @@ EXPORT_SYMBOL_GPL(dm_put);static bool md_in_flight_bios (struct mapped_device *md) {int cpu; -struct hd_struct *part = &dm_disk (md)->part0; +struct block_device *bdev =dm_disk (md)->part0;long sum =0 ;for_each_possible_cpu (cpu) { - sum +=part_stat_local_read_cpu (part, in_flight[0 ], cpu); - sum +=part_stat_local_read_cpu (part, in_flight[1 ], cpu); + sum +=part_stat_local_read_cpu (bdev, in_flight[0 ], cpu); + sum +=part_stat_local_read_cpu (bdev, in_flight[1 ], cpu); }return sum !=0 ;
drivers/md/md.c +2 -2
@@ -464,7 +464,7 @@ struct md_io {bio_end_io_t *orig_bi_end_io;void *orig_bi_private;unsigned long start_time; -struct hd_struct *part; +struct block_device *part; };static void md_end_io (struct bio *bio)
@@ -8441,7 +8441,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)rcu_read_lock ();rdev_for_each_rcu (rdev, mddev) {struct gendisk *disk = rdev->bdev->bd_disk; - curr_events = (int )part_stat_read_accum (&disk->part0, sectors) - + curr_events = (int )part_stat_read_accum (disk->part0, sectors) -atomic_read (&disk->sync_io);/* sync IO will cause sync_io to increase before the disk_stats * as sync_io is counted when a request starts, and
drivers/nvme/target/admin-cmd.c +10 -10
@@ -89,12 +89,12 @@ static u16 nvmet_get_smart_log_nsid(struct nvmet_req *req,if (!ns->bdev) goto out; - host_reads =part_stat_read (ns->bdev->bd_part, ios[READ ]); - data_units_read =DIV_ROUND_UP (part_stat_read (ns->bdev->bd_part, - sectors[READ ]),1000 ); - host_writes =part_stat_read (ns->bdev->bd_part, ios[WRITE ]); - data_units_written =DIV_ROUND_UP (part_stat_read (ns->bdev->bd_part, - sectors[WRITE ]),1000 ); + host_reads =part_stat_read (ns->bdev, ios[READ ]); + data_units_read = +DIV_ROUND_UP (part_stat_read (ns->bdev, sectors[READ ]),1000 ); + host_writes =part_stat_read (ns->bdev, ios[WRITE ]); + data_units_written = +DIV_ROUND_UP (part_stat_read (ns->bdev, sectors[WRITE ]),1000 );put_unaligned_le64 (host_reads, &slog->host_reads[0 ]);put_unaligned_le64 (data_units_read, &slog->data_units_read[0 ]);
@@ -120,12 +120,12 @@ static u16 nvmet_get_smart_log_all(struct nvmet_req *req,/* we don't have the right data for file backed ns */ if (!ns->bdev)continue ; - host_reads +=part_stat_read (ns->bdev->bd_part, ios[READ ]); + host_reads +=part_stat_read (ns->bdev, ios[READ ]); data_units_read +=DIV_ROUND_UP ( -part_stat_read (ns->bdev->bd_part, sectors[READ ]),1000 ); - host_writes +=part_stat_read (ns->bdev->bd_part, ios[WRITE ]); +part_stat_read (ns->bdev, sectors[READ ]),1000 ); + host_writes +=part_stat_read (ns->bdev, ios[WRITE ]); data_units_written +=DIV_ROUND_UP ( -part_stat_read (ns->bdev->bd_part, sectors[WRITE ]),1000 ); +part_stat_read (ns->bdev, sectors[WRITE ]),1000 ); }put_unaligned_le64 (host_reads, &slog->host_reads[0 ]);
drivers/s390/block/dasd.c +4 -4
@@ -432,7 +432,7 @@ dasd_state_ready_to_online(struct dasd_device * device) {struct gendisk *disk;struct disk_part_iter piter; -struct hd_struct *part; +struct block_device *part; device->state =DASD_STATE_ONLINE ;if (device->block) {
@@ -445,7 +445,7 @@ dasd_state_ready_to_online(struct dasd_device * device) disk = device->block->bdev->bd_disk;disk_part_iter_init (&piter, disk,DISK_PITER_INCL_PART0 );while ((part =disk_part_iter_next (&piter))) -kobject_uevent (&part_to_dev (part)->kobj,KOBJ_CHANGE ); +kobject_uevent (bdev_kobj (part),KOBJ_CHANGE );disk_part_iter_exit (&piter); }return 0 ;
@@ -459,7 +459,7 @@ static int dasd_state_online_to_ready(struct dasd_device *device)int rc;struct gendisk *disk;struct disk_part_iter piter; -struct hd_struct *part; +struct block_device *part;if (device->discipline->online_to_ready) { rc = device->discipline->online_to_ready (device);
@@ -472,7 +472,7 @@ static int dasd_state_online_to_ready(struct dasd_device *device) disk = device->block->bdev->bd_disk;disk_part_iter_init (&piter, disk,DISK_PITER_INCL_PART0 );while ((part =disk_part_iter_next (&piter))) -kobject_uevent (&part_to_dev (part)->kobj,KOBJ_CHANGE ); +kobject_uevent (bdev_kobj (part),KOBJ_CHANGE );disk_part_iter_exit (&piter); }return 0 ;
fs/block_dev.c +33 -44
181 lines not on this page · raw message
fs/ext4/super.c +6 -12
@@ -4048,9 +4048,8 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) sbi->s_sb = sb; sbi->s_inode_readahead_blks =EXT4_DEF_INODE_READAHEAD_BLKS ; sbi->s_sb_block = sb_block; -if (sb->s_bdev->bd_part) - sbi->s_sectors_written_start = -part_stat_read (sb->s_bdev->bd_part, sectors[STAT_WRITE ]); + sbi->s_sectors_written_start = +part_stat_read (sb->s_bdev, sectors[STAT_WRITE ]);/* Cleanup superblock name */ strreplace (sb->s_id,'/' ,'!' );
@@ -5509,15 +5508,10 @@ static int ext4_commit_super(struct super_block *sb, int sync)*/ if (!(sb->s_flags &SB_RDONLY ))ext4_update_tstamp (es, s_wtime); -if (sb->s_bdev->bd_part) - es->s_kbytes_written = -cpu_to_le64 (EXT4_SB (sb)->s_kbytes_written + - ((part_stat_read (sb->s_bdev->bd_part, - sectors[STAT_WRITE ]) - -EXT4_SB (sb)->s_sectors_written_start) >>1 )); -else - es->s_kbytes_written = -cpu_to_le64 (EXT4_SB (sb)->s_kbytes_written); + es->s_kbytes_written = +cpu_to_le64 (EXT4_SB (sb)->s_kbytes_written + + ((part_stat_read (sb->s_bdev, sectors[STAT_WRITE ]) - +EXT4_SB (sb)->s_sectors_written_start) >>1 ));if (percpu_counter_initialized (&EXT4_SB (sb)->s_freeclusters_counter)) ext4_free_blocks_count_set(es, EXT4_C2B(EXT4_SB(sb), percpu_counter_sum_positive(
fs/ext4/sysfs.c +2 -8
@@ -62,11 +62,8 @@ static ssize_t session_write_kbytes_show(struct ext4_sb_info *sbi, char *buf) {struct super_block *sb = sbi->s_buddy_cache->i_sb; -if (!sb->s_bdev->bd_part) -return snprintf (buf,PAGE_SIZE ,"0\n" );return snprintf (buf,PAGE_SIZE ,"%lu\n" , - (part_stat_read (sb->s_bdev->bd_part, - sectors[STAT_WRITE ]) - + (part_stat_read (sb->s_bdev, sectors[STAT_WRITE ]) - sbi->s_sectors_written_start) >>1 ); }
@@ -74,12 +71,9 @@ static ssize_t lifetime_write_kbytes_show(struct ext4_sb_info *sbi, char *buf) {struct super_block *sb = sbi->s_buddy_cache->i_sb; -if (!sb->s_bdev->bd_part) -return snprintf (buf,PAGE_SIZE ,"0\n" );return snprintf (buf,PAGE_SIZE ,"%llu\n" , (unsigned long long )(sbi->s_kbytes_written + - ((part_stat_read (sb->s_bdev->bd_part, - sectors[STAT_WRITE ]) - + ((part_stat_read (sb->s_bdev, sectors[STAT_WRITE ]) -EXT4_SB (sb)->s_sectors_written_start) >>1 ))); }
fs/f2fs/checkpoint.c +1 -4
@@ -1395,7 +1395,6 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)__u32 crc32 =0 ;int i;int cp_payload_blks =__cp_payload (sbi); -struct super_block *sb = sbi->sb;struct curseg_info *seg_i =CURSEG_I (sbi,CURSEG_HOT_NODE );u64 kbytes_written;int err;
@@ -1489,9 +1488,7 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc) start_blk += data_sum_blocks;/* Record write statistics in the hot node summary */ - kbytes_written = sbi->kbytes_written; -if (sb->s_bdev->bd_part) - kbytes_written +=BD_PART_WRITTEN (sbi); + kbytes_written = sbi->kbytes_written +BD_PART_WRITTEN (sbi); seg_i->journal->info.kbytes_written =cpu_to_le64 (kbytes_written);
fs/f2fs/f2fs.h +1 -1
@@ -1675,7 +1675,7 @@ static inline bool f2fs_is_multi_device(struct f2fs_sb_info *sbi)* and the return value is in kbytes. s is of struct f2fs_sb_info. */ #define BD_PART_WRITTEN (s) \ -(((u64)part_stat_read((s)->sb->s_bdev->bd_part, sectors[STAT_WRITE]) - \ +(((u64)part_stat_read((s)->sb->s_bdev, sectors[STAT_WRITE]) - \ (s)->sectors_written_start) >> 1)static inline void f2fs_update_time (struct f2fs_sb_info *sbi,int type)
fs/f2fs/super.c +2 -4
@@ -3700,10 +3700,8 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) }/* For write statistics */ -if (sb->s_bdev->bd_part) - sbi->sectors_written_start = - (u64 )part_stat_read (sb->s_bdev->bd_part, - sectors[STAT_WRITE ]); + sbi->sectors_written_start = +part_stat_read (sb->s_bdev, sectors[STAT_WRITE ]);/* Read accumulated write IO statistics if exists */ seg_i =CURSEG_I (sbi,CURSEG_HOT_NODE );
fs/f2fs/sysfs.c +0 -9
@@ -90,11 +90,6 @@ static ssize_t free_segments_show(struct f2fs_attr *a,static ssize_t lifetime_write_kbytes_show (struct f2fs_attr *a,struct f2fs_sb_info *sbi,char *buf) { -struct super_block *sb = sbi->sb; - -if (!sb->s_bdev->bd_part) -return sprintf (buf,"0\n" ); -return sprintf (buf,"%llu\n" , (unsigned long long )(sbi->kbytes_written +BD_PART_WRITTEN (sbi)));
@@ -103,12 +98,8 @@ static ssize_t lifetime_write_kbytes_show(struct f2fs_attr *a,static ssize_t features_show (struct f2fs_attr *a,struct f2fs_sb_info *sbi,char *buf) { -struct super_block *sb = sbi->sb;int len =0 ; -if (!sb->s_bdev->bd_part) -return sprintf (buf,"0\n" ); -if (f2fs_sb_has_encrypt (sbi)) len +=scnprintf (buf,PAGE_SIZE - len,"%s" ,"encryption" );
include/linux/blk_types.h +19 -4
@@ -8,6 +8,7 @@#include <linux/types.h> #include <linux/bvec.h> +#include <linux/device.h> #include <linux/ktime.h> struct bio_set ;
@@ -20,7 +21,13 @@ typedef void (bio_end_io_t) (struct bio *);struct bio_crypt_ctx ;struct block_device { +sector_t bd_start_sect; +unsigned long bd_stamp; +struct disk_stats __percpu *bd_stats; +u8 bd_partno; +int bd_policy;dev_t bd_dev; +struct device bd_device;int bd_openers;struct inode * bd_inode;/* will die */ struct super_block * bd_super;
@@ -32,8 +39,7 @@ struct block_device {#ifdef CONFIG_SYSFS struct list_head bd_holder_disks;#endif -u8 bd_partno; -struct hd_struct * bd_part; +struct kobject *bd_holder_dir;/* number of times partitions within this device have been opened. */ unsigned bd_part_count;
@@ -45,13 +51,22 @@ struct block_device {int bd_fsfreeze_count;/* Mutex for freeze */ struct mutex bd_fsfreeze_mutex; + +struct partition_meta_info *bd_meta_info; +#ifdef CONFIG_FAIL_MAKE_REQUEST +int bd_make_it_fail; +#endif } __randomize_layout;#define bdev_whole (_bdev) \ - ((_bdev)->bd_disk->part0.bdev) + ((_bdev)->bd_disk->part0) + +#define dev_to_bdev (device) \ + container_of((device), struct block_device, bd_device) +#define part_to_dev (part) (&((part)->bd_device))#define bdev_kobj (_bdev) \ - (&part_to_dev((_bdev)->bd_part)->kobj) + (&part_to_dev((_bdev))->kobj)/* * Block error status values. See block/blk-core:blk_errors for the details.
include/linux/blkdev.h +6 -7
@@ -191,7 +191,7 @@ struct request { };struct gendisk *rq_disk; -struct hd_struct *part; +struct block_device *bdev;#ifdef CONFIG_BLK_RQ_ALLOC_TIME /* Time that the first bio started allocating this request. */ u64 alloc_time_ns;
@@ -1488,7 +1488,7 @@ static inline int bdev_alignment_offset(struct block_device *bdev)return -1 ;if (bdev_is_partition (bdev))return queue_limit_alignment_offset (&q->limits, - bdev->bd_part->start_sect); + bdev->bd_start_sect);return q->limits.alignment_offset; }
@@ -1529,7 +1529,7 @@ static inline int bdev_discard_alignment(struct block_device *bdev)if (bdev_is_partition (bdev))return queue_limit_discard_alignment (&q->limits, - bdev->bd_part->start_sect); + bdev->bd_start_sect);return q->limits.discard_alignment; }
@@ -1943,9 +1943,9 @@ unsigned long disk_start_io_acct(struct gendisk *disk, unsigned int sectors,void disk_end_io_acct (struct gendisk *disk,unsigned int op,unsigned long start_time); -unsigned long part_start_io_acct (struct gendisk *disk,struct hd_struct **part, -struct bio *bio); -void part_end_io_acct (struct hd_struct *part,struct bio *bio, +unsigned long part_start_io_acct (struct gendisk *disk, +struct block_device **part,struct bio *bio); +void part_end_io_acct (struct block_device *part,struct bio *bio,unsigned long start_time);/**
@@ -1996,7 +1996,6 @@ struct block_device *bdev_alloc(struct gendisk *disk, u8 partno);void bdev_add (struct block_device *bdev,dev_t dev);struct block_device *bdget (dev_t dev);struct block_device *I_BDEV (struct inode *inode); -struct block_device *bdget_part (struct hd_struct *part);struct block_device *bdgrab (struct block_device *bdev);void bdput (struct block_device *);
include/linux/genhd.h +13 -54
139 lines not on this page · raw message
include/linux/part_stat.h +8 -9
@@ -25,26 +25,26 @@ struct disk_stats {#define part_stat_unlock () preempt_enable()#define part_stat_get_cpu (part, field, cpu) \ - (per_cpu_ptr((part)->dkstats, (cpu))->field) + (per_cpu_ptr((part)->bd_stats, (cpu))->field)#define part_stat_get (part, field) \ part_stat_get_cpu(part, field, smp_processor_id())#define part_stat_read (part, field) \ ({ \ - typeof((part)->dkstats->field) res = 0; \ + typeof((part)->bd_stats->field) res = 0; \ unsigned int _cpu; \ for_each_possible_cpu(_cpu) \ - res += per_cpu_ptr((part)->dkstats, _cpu)->field; \ + res += per_cpu_ptr((part)->bd_stats, _cpu)->field; \ res; \ }) -static inline void part_stat_set_all (struct hd_struct *part,int value) +static inline void part_stat_set_all (struct block_device *bdev,int value) {int i;for_each_possible_cpu (i) -memset (per_cpu_ptr (part->dkstats, i), value, +memset (per_cpu_ptr (bdev->bd_stats, i), value,sizeof (struct disk_stats )); }
@@ -54,13 +54,12 @@ static inline void part_stat_set_all(struct hd_struct *part, int value) part_stat_read(part, field[STAT_DISCARD]))#define __part_stat_add (part, field, addnd) \ - __this_cpu_add((part)->dkstats->field, addnd) + __this_cpu_add((part)->bd_stats->field, addnd)#define part_stat_add (part, field, addnd) do { \ __part_stat_add((part), field, addnd); \ - if ((part)->partno) \ - __part_stat_add(&part_to_disk((part))->part0, \ - field, addnd); \ + if ((part)->bd_partno) \ + __part_stat_add((part)->bd_disk->part0, field, addnd); \ } while (0)#define part_stat_dec (gendiskp, field) \
init/do_mounts.c +10 -10
@@ -76,11 +76,11 @@ struct uuidcmp {*/ static int match_dev_by_uuid (struct device *dev,const void *data) { +struct block_device *bdev =dev_to_bdev (dev);const struct uuidcmp *cmp = data; -struct hd_struct *part =dev_to_part (dev); -if (!part->info || -strncasecmp (cmp->uuid, part->info->uuid, cmp->len)) +if (!bdev->bd_meta_info || +strncasecmp (cmp->uuid, bdev->bd_meta_info->uuid, cmp->len))return 0 ;return 1 ; }
@@ -133,13 +133,13 @@ static dev_t devt_from_partuuid(const char *uuid_str)* Attempt to find the requested partition by adding an offset * to the partition number found by UUID. */ -struct hd_struct *part; +struct block_device *part; - part =disk_get_part (dev_to_disk (dev), -dev_to_part (dev)->partno + offset); + part =bdget_disk (dev_to_disk (dev), +dev_to_bdev (dev)->bd_partno + offset);if (part) { - devt =part_devt (part); -put_device (part_to_dev (part)); + devt = part->bd_dev; +bdput (part); } }else { devt = dev->devt;
@@ -166,10 +166,10 @@ static dev_t devt_from_partuuid(const char *uuid_str)*/ static int match_dev_by_label (struct device *dev,const void *data) { +struct block_device *bdev =dev_to_bdev (dev);const char *label = data; -struct hd_struct *part =dev_to_part (dev); -if (!part->info ||strcmp (label, part->info->volname)) +if (!bdev->bd_meta_info ||strcmp (label, bdev->bd_meta_info->volname))return 0 ;return 1 ; }
kernel/trace/blktrace.c +11 -43
97 lines not on this page · raw message
Signature · 1 line
2.29.2
Jan Kara
maintainerRe: [PATCH 15/20] block: merge struct block_device and struct hd_struct
Quoted 2 lines · Christoph Hellwig
Instead of having two structures that represent each block device with different lift time rules merged them into a single one. This also
^^^ :) life ^^^^ merge
Quoted 8 lines
greatly simplifies the reference counting rules, as we can use the inode reference count as the main reference count for the new struct
block_device, with the device model reference front ending it for device model interaction. The percpu refcount in structhd_structis entirely gone given that structblock_devicemust be opened and thus valid for the duration of the I/O.Signed-off-by Christoph Hellwig <[email protected]>
This patch is kind of difficult to review due to the size of mostly mechanical changes mixed with not completely mechanical changes. Can we perhaps split out the mechanical bits? E.g. the rq->part => rq->bdev renaming is mechanical and notable part of the patch. Similarly the part->foo => part->bd_foo bits...
Also I'm kind of wondering: AFAIU the new lifetime rules, gendisk holds bdev reference and bdev is created on gendisk allocation so bdev lifetime is strictly larger than gendisk lifetime. But what now keeps bdev->bd_disk reference safe in presence device hot unplug? In most cases we are still protected by gendisk reference taken in __blkdev_get() but how about disk->lookup_sem and disk->flags dereferences before we actually grab the reference?
Also I find it rather non-obvious (although elegant ;) that bdev->bd_device rules the lifetime of gendisk. Can you perhaps explain this in the changelog and probably also add somewhere to source a documentation about the new lifetime rules?
Quoted 8 lines
block/blk.h +0
-0@@ -215,7 +215,15 @@ static inline void elevator_exit(struct request_queue *q,__elevator_exit (q, e); }
block/blk.h static inline void elevator_exit(struct request_queue *q, · line 226
Quoted 10 lines
block/blk.h +9
-1-struct hd_struct *__disk_get_part (struct gendisk *disk,int partno); +static inline struct block_device *__bdget_disk (struct gendisk *disk, +int partno) +{ +struct disk_part_tbl *ptbl =rcu_dereference (disk->part_tbl); + +if (unlikely (partno <0 || partno >= ptbl->len)) +return NULL ; +return rcu_dereference (ptbl->part[partno]); +}
I understand this is lower-level counterpart of bdget_disk() but it is confusing to me that this has 'bdget' in the name and returns no bdev reference. Can we call it like __bdev_from_disk() or something like that?
block/blk.h static inline void elevator_exit(struct request_queue *q, · line 229
Quoted 3 lines
block/blk.h +0
-0ssize_t part_size_show (struct device *dev,struct device_attribute *attr,char *buf);
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Christoph Hellwig
maintainerRe: [PATCH 15/20] block: merge struct block_device and struct hd_struct
Quoted 5 lines · Jan Kara
This patch is kind of difficult to review due to the size of mostly mechanical changes mixed with not completely mechanical changes. Can we perhaps split out the mechanical bits? E.g. the
rq->part=>rq->bdevrenaming is mechanical and notable part of the patch. Similarly thepart->foo=>part->bd_foobits...
We'd end with really weird patches that way. Never mind that I'm not even sure how we could mechnically do the renaming.
Quoted 8 lines
Also I'm kind of wondering: AFAIU the new lifetime rules, gendisk holds bdev reference and bdev is created on gendisk allocation so bdev lifetime is strictly larger than gendisk lifetime. But what now keeps
bdev->bd_diskreference safe in presence device hot unplug? In most cases we are still protected by gendisk reference taken in__blkdev_get()but how aboutdisk->lookup_semanddisk->flagsdereferences before we actually grab the reference?
Good question. I'll need to think about this a bit more.
Quoted 4 lines
Also I find it rather non-obvious (although elegant ;) that
bdev->bd_devicerules the lifetime of gendisk. Can you perhaps explain this in the changelog and probably also add somewhere to source a documentation about the new lifetime rules?
Yes.
Quoted 6 lines
Quoted 6 lines
block/blk.h +5
-1-struct hd_struct *__disk_get_part (struct gendisk *disk,int partno); +static inline struct block_device *__bdget_disk (struct gendisk *disk, +int partno) +{ +struct disk_part_tbl *ptbl =rcu_dereference (disk->part_tbl); +
Quoted 8 lines
block/blk.h static inline void elevator_exit(struct request_queue *q, · line 226
Quoted 4 lines
block/blk.h +4
-0+if (unlikely (partno <0 || partno >= ptbl->len)) +return NULL ; +return rcu_dereference (ptbl->part[partno]); +}I understand this is lower-level counterpart of
bdget_disk()but it is confusing to me that this has 'bdget' in the name and returns no bdev reference. Can we call it like__bdev_from_disk()or something like that?
Sure.
Jan Kara
maintainerRe: [PATCH 15/20] block: merge struct block_device and struct hd_struct
Quoted 9 lines · Christoph Hellwig
Quoted 5 lines · Jan Kara
This patch is kind of difficult to review due to the size of mostly mechanical changes mixed with not completely mechanical changes. Can we perhaps split out the mechanical bits? E.g. the
rq->part=>rq->bdevrenaming is mechanical and notable part of the patch. Similarly thepart->foo=>part->bd_foobits...We'd end with really weird patches that way. Never mind that I'm not even sure how we could mechnically do the renaming.
Well, I believe coccinelle should be able to do the renaming automatically.
Quoted 9 lines
Quoted 7 lines
Also I'm kind of wondering: AFAIU the new lifetime rules, gendisk holds bdev reference and bdev is created on gendisk allocation so bdev lifetime is strictly larger than gendisk lifetime. But what now keeps
bdev->bd_diskreference safe in presence device hot unplug? In most cases we are still protected by gendisk reference taken in__blkdev_get()but how aboutdisk->lookup_semanddisk->flagsdereferences before we actually grab the reference?Good question. I'll need to think about this a bit more.
My thinking was that you could use
kobject_get_unless_zero(bdev->bd_device->kobj)
and after you hold this reference, you can do everything else safely. In this case it is really useful that device is embedded in block_dev and not in gendisk itself...
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Christoph Hellwig
maintainerPATCH 16/20 block: stop using bdget_disk for partition 0
In reply to Christoph HellwigWe can just dereference the point in struct gendisk instead. Also remove the now unused export.
--- block/genhd.c | 1 - drivers/block/nbd.c | 4 +--- drivers/block/xen-blkfront.c | 20 +++++--------------- drivers/block/zram/zram_drv.c | 18 +++--------------- drivers/md/dm.c | 8 +------- drivers/s390/block/dasd_ioctl.c | 5 ++--- 6 files changed, 12 insertions(+), 44 deletions(-)
block/genhd.c +0 -1
@@ -907,7 +907,6 @@ struct block_device *bdget_disk(struct gendisk *disk, int partno)return bdev; } -EXPORT_SYMBOL (bdget_disk);/* * print a full list of all partitions - intended for places where the root
drivers/block/nbd.c +1 -3
@@ -1488,12 +1488,10 @@ static int nbd_open(struct block_device *bdev, fmode_t mode)static void nbd_release (struct gendisk *disk,fmode_t mode) {struct nbd_device *nbd = disk->private_data; -struct block_device *bdev =bdget_disk (disk,0 );if (test_bit (NBD_RT_DISCONNECT_ON_CLOSE , &nbd->config->runtime_flags) && - bdev->bd_openers ==0 ) + disk->part0->bd_openers ==0 )nbd_disconnect_and_put (nbd); -bdput (bdev);nbd_config_put (nbd);nbd_put (nbd);
drivers/block/xen-blkfront.c +5 -15
@@ -2153,7 +2153,7 @@ static void blkfront_closing(struct blkfront_info *info) }if (info->gd) - bdev =bdget_disk (info->gd,0 ); + bdev =bdgrab (info->gd->part0);mutex_unlock (&info->mutex);
@@ -2518,7 +2518,7 @@ static int blkfront_remove(struct xenbus_device *xbdev) disk = info->gd;if (disk) - bdev =bdget_disk (disk,0 ); + bdev =bdgrab (disk->part0); info->xbdev =NULL ;mutex_unlock (&info->mutex);
@@ -2595,19 +2595,11 @@ static int blkif_open(struct block_device *bdev, fmode_t mode)static void blkif_release (struct gendisk *disk,fmode_t mode) {struct blkfront_info *info = disk->private_data; -struct block_device *bdev;struct xenbus_device *xbdev;mutex_lock (&blkfront_mutex); - - bdev =bdget_disk (disk,0 ); - -if (!bdev) { -WARN (1 ,"Block device %s yanked out from us!\n" , disk->disk_name); +if (disk->part0->bd_openers) goto out_mutex; - } -if (bdev->bd_openers) - goto out;/* * Check if we have been instructed to close. We will have
@@ -2619,7 +2611,7 @@ static void blkif_release(struct gendisk *disk, fmode_t mode)if (xbdev && xbdev->state == XenbusStateClosing) {/* pending switch to state closed */ -dev_info (disk_to_dev (bdev->bd_disk),"releasing disk\n" ); +dev_info (disk_to_dev (disk),"releasing disk\n" );xlvbd_release_gendisk (info);xenbus_frontend_closed (info->xbdev); }
@@ -2628,14 +2620,12 @@ static void blkif_release(struct gendisk *disk, fmode_t mode)if (!xbdev) {/* sudden device removal */ -dev_info (disk_to_dev (bdev->bd_disk),"releasing disk\n" ); +dev_info (disk_to_dev (disk),"releasing disk\n" );xlvbd_release_gendisk (info); disk->private_data =NULL ;free_info (info); } -out: -bdput (bdev); out_mutex:mutex_unlock (&blkfront_mutex); }
drivers/block/zram/zram_drv.c +3 -15
@@ -1748,7 +1748,7 @@ static ssize_t reset_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) { struct zram *zram = dev_to_zram(dev); -struct block_device *bdev; +struct block_device *bdev = zram->disk->part0;unsigned short do_reset;int ret =0 ;
@@ -1758,17 +1758,12 @@ static ssize_t reset_store(struct device *dev,if (!do_reset)return -EINVAL ; - bdev =bdget_disk (zram->disk,0 ); -if (!bdev) -return -ENOMEM ; -mutex_lock (&bdev->bd_mutex);if (bdev->bd_openers) ret = -EBUSY ;else zram_reset_device (zram);mutex_unlock (&bdev->bd_mutex); -bdput (bdev);return ret ? ret : len; }
@@ -1933,15 +1928,8 @@ static int zram_add(void)static int zram_remove (struct zram *zram) { -struct block_device *bdev =bdget_disk (zram->disk,0 ); - -if (bdev) { -if (bdev->bd_openers) { -bdput (bdev); -return -EBUSY ; - } -bdput (bdev); - } +if (zram->disk->part0->bd_openers) +return -EBUSY ;del_gendisk (zram->disk);zram_debugfs_unregister (zram);
drivers/md/dm.c +1 -7
@@ -2375,17 +2375,12 @@ struct dm_table *dm_swap_table(struct mapped_device *md, struct dm_table *table)*/ static int lock_fs (struct mapped_device *md) { -struct block_device *bdev;int r;WARN_ON (md->frozen_sb); - bdev =bdget_disk (md->disk,0 ); -if (!bdev) -return -ENOMEM ; - md->frozen_sb =freeze_bdev (bdev); + md->frozen_sb =freeze_bdev (md->disk->part0);if (IS_ERR (md->frozen_sb)) { -bdput (bdev); r =PTR_ERR (md->frozen_sb); md->frozen_sb =NULL ;return r;
@@ -2402,7 +2397,6 @@ static void unlock_fs(struct mapped_device *md)return ;thaw_bdev (md->frozen_sb->s_bdev, md->frozen_sb); -bdput (md->frozen_sb->s_bdev); md->frozen_sb =NULL ;clear_bit (DMF_FROZEN , &md->flags); }
drivers/s390/block/dasd_ioctl.c +2 -3
@@ -220,9 +220,8 @@ dasd_format(struct dasd_block *block, struct format_data_t *fdata)* enabling the device later. */ if (fdata->start_unit ==0 ) { -struct block_device *bdev =bdget_disk (block->gdp,0 ); - bdev->bd_inode->i_blkbits =blksize_bits (fdata->blksize); -bdput (bdev); + block->gdp->part0->bd_inode->i_blkbits = +blksize_bits (fdata->blksize); } rc = base->discipline->format_device (base, fdata,1 );
Signature · 1 line
2.29.2
Re: [PATCH 16/20] block: stop using bdget_disk for partition 0
Quoted 4 lines · Christoph Hellwig
We can just dereference the point in struct gendisk instead. Also remove the now unused export.
Signed-off-by Christoph Hellwig <[email protected]>
Looks good to me. You can add:
Honza
Quoted 206 lines
--- block/genhd.c | 1 - drivers/block/nbd.c | 4 +--- drivers/block/xen-blkfront.c | 20 +++++--------------- drivers/block/zram/zram_drv.c | 18 +++--------------- drivers/md/dm.c | 8 +------- drivers/s390/block/dasd_ioctl.c | 5 ++--- 6 files changed, 12 insertions(+), 44 deletions(-)block/genhd.c +0
-1@@ -907,7 +907,6 @@ struct block_device *bdget_disk(struct gendisk *disk, int partno)return bdev; } -EXPORT_SYMBOL (bdget_disk);/* * print a full list of all partitions - intended for places where the root drivers/block/nbd.c +1
-3@@ -1488,12 +1488,10 @@ static int nbd_open(struct block_device *bdev, fmode_t mode)static void nbd_release (struct gendisk *disk,fmode_t mode) {struct nbd_device *nbd = disk->private_data; -struct block_device *bdev =bdget_disk (disk,0 );if (test_bit (NBD_RT_DISCONNECT_ON_CLOSE , &nbd->config->runtime_flags) && - bdev->bd_openers ==0 ) + disk->part0->bd_openers ==0 )nbd_disconnect_and_put (nbd); -bdput (bdev);nbd_config_put (nbd);nbd_put (nbd);drivers/block/xen-blkfront.c +5
-15@@ -2153,7 +2153,7 @@ static void blkfront_closing(struct blkfront_info *info) }if (info->gd) - bdev =bdget_disk (info->gd,0 ); + bdev =bdgrab (info->gd->part0);mutex_unlock (&info->mutex);@@ -2518,7 +2518,7 @@ static int blkfront_remove(struct xenbus_device *xbdev) disk = info->gd;if (disk) - bdev =bdget_disk (disk,0 ); + bdev =bdgrab (disk->part0); info->xbdev =NULL ;mutex_unlock (&info->mutex);@@ -2595,19 +2595,11 @@ static int blkif_open(struct block_device *bdev, fmode_t mode)static void blkif_release (struct gendisk *disk,fmode_t mode) {struct blkfront_info *info = disk->private_data; -struct block_device *bdev;struct xenbus_device *xbdev;mutex_lock (&blkfront_mutex); - - bdev =bdget_disk (disk,0 ); - -if (!bdev) { -WARN (1 ,"Block device %s yanked out from us!\n" , disk->disk_name); +if (disk->part0->bd_openers) goto out_mutex; - } -if (bdev->bd_openers) - goto out;/* * Check if we have been instructed to close. We will have @@ -2619,7 +2611,7 @@ static void blkif_release(struct gendisk *disk, fmode_t mode)if (xbdev && xbdev->state == XenbusStateClosing) {/* pending switch to state closed */ -dev_info (disk_to_dev (bdev->bd_disk),"releasing disk\n" ); +dev_info (disk_to_dev (disk),"releasing disk\n" );xlvbd_release_gendisk (info);xenbus_frontend_closed (info->xbdev); }@@ -2628,14 +2620,12 @@ static void blkif_release(struct gendisk *disk, fmode_t mode)if (!xbdev) {/* sudden device removal */ -dev_info (disk_to_dev (bdev->bd_disk),"releasing disk\n" ); +dev_info (disk_to_dev (disk),"releasing disk\n" );xlvbd_release_gendisk (info); disk->private_data =NULL ;free_info (info); } -out: -bdput (bdev); out_mutex:mutex_unlock (&blkfront_mutex); }drivers/block/zram/zram_drv.c +3
-15@@ -1748,7 +1748,7 @@ static ssize_t reset_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) { struct zram *zram = dev_to_zram(dev); -struct block_device *bdev; +struct block_device *bdev = zram->disk->part0;unsigned short do_reset;int ret =0 ;@@ -1758,17 +1758,12 @@ static ssize_t reset_store(struct device *dev,if (!do_reset)return -EINVAL ; - bdev =bdget_disk (zram->disk,0 ); -if (!bdev) -return -ENOMEM ; -mutex_lock (&bdev->bd_mutex);if (bdev->bd_openers) ret = -EBUSY ;else zram_reset_device (zram);mutex_unlock (&bdev->bd_mutex); -bdput (bdev);return ret ? ret : len; }@@ -1933,15 +1928,8 @@ static int zram_add(void)static int zram_remove (struct zram *zram) { -struct block_device *bdev =bdget_disk (zram->disk,0 ); - -if (bdev) { -if (bdev->bd_openers) { -bdput (bdev); -return -EBUSY ; - } -bdput (bdev); - } +if (zram->disk->part0->bd_openers) +return -EBUSY ;del_gendisk (zram->disk);zram_debugfs_unregister (zram);drivers/md/dm.c +1
-7@@ -2375,17 +2375,12 @@ struct dm_table *dm_swap_table(struct mapped_device *md, struct dm_table *table)*/ static int lock_fs (struct mapped_device *md) { -struct block_device *bdev;int r;WARN_ON (md->frozen_sb); - bdev =bdget_disk (md->disk,0 ); -if (!bdev) -return -ENOMEM ; - md->frozen_sb =freeze_bdev (bdev); + md->frozen_sb =freeze_bdev (md->disk->part0);if (IS_ERR (md->frozen_sb)) { -bdput (bdev); r =PTR_ERR (md->frozen_sb); md->frozen_sb =NULL ;return r;@@ -2402,7 +2397,6 @@ static void unlock_fs(struct mapped_device *md)return ;thaw_bdev (md->frozen_sb->s_bdev, md->frozen_sb); -bdput (md->frozen_sb->s_bdev); md->frozen_sb =NULL ;clear_bit (DMF_FROZEN , &md->flags); }drivers/s390/block/dasd_ioctl.c +2
-3@@ -220,9 +220,8 @@ dasd_format(struct dasd_block *block, struct format_data_t *fdata)* enabling the device later. */ if (fdata->start_unit ==0 ) { -struct block_device *bdev =bdget_disk (block->gdp,0 ); - bdev->bd_inode->i_blkbits =blksize_bits (fdata->blksize); -bdput (bdev); + block->gdp->part0->bd_inode->i_blkbits = +blksize_bits (fdata->blksize); } rc = base->discipline->format_device (base, fdata,1 );Signature · 1 line
2.29.2
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Christoph Hellwig
maintainerPATCH 17/20 filemap: consistently use ->f_mapping over ->i_mapping
In reply to Christoph HellwigUse file->f_mapping in all remaining places that have a struct file available to properly handle the case where inode->i_mapping != file_inode(file)->i_mapping.
--- mm/filemap.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
mm/filemap.c +4 -5
@@ -2887,13 +2887,13 @@ EXPORT_SYMBOL(filemap_map_pages);vm_fault_t filemap_page_mkwrite (struct vm_fault *vmf) {struct page *page = vmf->page; -struct inode *inode =file_inode (vmf->vma->vm_file); +struct inode *inode = vmf->vma->vm_file->f_mapping->host;vm_fault_t ret =VM_FAULT_LOCKED ;sb_start_pagefault (inode->i_sb);file_update_time (vmf->vma->vm_file);lock_page (page); -if (page->mapping != inode->i_mapping) { +if (page->mapping != vmf->vma->vm_file->f_mapping) {unlock_page (page); ret =VM_FAULT_NOPAGE ; goto out;
@@ -3149,10 +3149,9 @@ void dio_warn_stale_pagecache(struct file *filp) { static DEFINE_RATELIMIT_STATE(_rs, 86400 * HZ, DEFAULT_RATELIMIT_BURST);char pathname[128 ]; -struct inode *inode =file_inode (filp);char *path; -errseq_set (&inode->i_mapping->wb_err, -EIO ); +errseq_set (&filp->f_mapping->wb_err, -EIO );if (__ratelimit (&_rs)) { path =file_path (filp, pathname,sizeof (pathname));if (IS_ERR (path))
@@ -3179,7 +3178,7 @@ generic_file_direct_write(struct kiocb *iocb, struct iov_iter *from)if (iocb->ki_flags &IOCB_NOWAIT ) {/* If there are pages to writeback, return */ -if (filemap_range_has_page (inode->i_mapping, pos, +if (filemap_range_has_page (file->f_mapping, pos, pos + write_len -1 ))return -EAGAIN ; }else {
Signature · 1 line
2.29.2
Re: [PATCH 17/20] filemap: consistently use ->f_mapping over ->i_mapping
Quoted 5 lines · Christoph Hellwig
Use
file->f_mappingin all remaining places that have a struct file available to properly handle the case whereinode->i_mapping!= file_inode(file)->i_mapping.Signed-off-by Christoph Hellwig <[email protected]>
Looks good. You can add:
Honza
Quoted 48 lines
--- mm/filemap.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)mm/filemap.c +4
-5@@ -2887,13 +2887,13 @@ EXPORT_SYMBOL(filemap_map_pages);vm_fault_t filemap_page_mkwrite (struct vm_fault *vmf) {struct page *page = vmf->page; -struct inode *inode =file_inode (vmf->vma->vm_file); +struct inode *inode = vmf->vma->vm_file->f_mapping->host;vm_fault_t ret =VM_FAULT_LOCKED ;sb_start_pagefault (inode->i_sb);file_update_time (vmf->vma->vm_file);lock_page (page); -if (page->mapping != inode->i_mapping) { +if (page->mapping != vmf->vma->vm_file->f_mapping) {unlock_page (page); ret =VM_FAULT_NOPAGE ; goto out;@@ -3149,10 +3149,9 @@ void dio_warn_stale_pagecache(struct file *filp) { static DEFINE_RATELIMIT_STATE(_rs, 86400 * HZ, DEFAULT_RATELIMIT_BURST);char pathname[128 ]; -struct inode *inode =file_inode (filp);char *path; -errseq_set (&inode->i_mapping->wb_err, -EIO ); +errseq_set (&filp->f_mapping->wb_err, -EIO );if (__ratelimit (&_rs)) { path =file_path (filp, pathname,sizeof (pathname));if (IS_ERR (path))@@ -3179,7 +3178,7 @@ generic_file_direct_write(struct kiocb *iocb, struct iov_iter *from)if (iocb->ki_flags &IOCB_NOWAIT ) {/* If there are pages to writeback, return */ -if (filemap_range_has_page (inode->i_mapping, pos, +if (filemap_range_has_page (file->f_mapping, pos, pos + write_len -1 ))return -EAGAIN ; }else {Signature · 1 line
2.29.2
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Matthew Wilcox
maintainerRe: [PATCH 17/20] filemap: consistently use ->f_mapping over ->i_mapping
In reply to Christoph Hellwigmm/filemap.c EXPORT_SYMBOL(filemap_map_pages); · line 2896
Quoted 13 lines · Christoph Hellwig
mm/filemap.c +2
-2@@ -2887,13 +2887,13 @@ EXPORT_SYMBOL(filemap_map_pages);vm_fault_t filemap_page_mkwrite (struct vm_fault *vmf) {struct page *page = vmf->page; -struct inode *inode =file_inode (vmf->vma->vm_file); +struct inode *inode = vmf->vma->vm_file->f_mapping->host;vm_fault_t ret =VM_FAULT_LOCKED ;sb_start_pagefault (inode->i_sb);file_update_time (vmf->vma->vm_file);lock_page (page); -if (page->mapping != inode->i_mapping) { +if (page->mapping != vmf->vma->vm_file->f_mapping) {
Bit messy. I'd do:
struct address_space *mapping = vmf->vma->vm_file->f_mapping; sb_start_pagefault(mapping->host->i_sb); if (page->mapping != mapping) sb_end_pagefault(mapping->host->i_sb);
--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
Christoph Hellwig
maintainerRe: [PATCH 17/20] filemap: consistently use ->f_mapping over ->i_mapping
Quoted 17 lines · Matthew Wilcox
mm/filemap.c EXPORT_SYMBOL(filemap_map_pages); · line 2896
Quoted 13 lines · Christoph Hellwig
mm/filemap.c +2
-2@@ -2887,13 +2887,13 @@ EXPORT_SYMBOL(filemap_map_pages);vm_fault_t filemap_page_mkwrite (struct vm_fault *vmf) {struct page *page = vmf->page; -struct inode *inode =file_inode (vmf->vma->vm_file); +struct inode *inode = vmf->vma->vm_file->f_mapping->host;vm_fault_t ret =VM_FAULT_LOCKED ;sb_start_pagefault (inode->i_sb);file_update_time (vmf->vma->vm_file);lock_page (page); -if (page->mapping != inode->i_mapping) { +if (page->mapping != vmf->vma->vm_file->f_mapping) {Bit messy. I'd do:
Quoted 7 lines
struct address_space *mapping = vmf->vma->vm_file->f_mapping; sb_start_pagefault(mapping->host->i_sb); if (page->mapping != mapping) sb_end_pagefault(mapping->host->i_sb);
Fine with me.
Christoph Hellwig
maintainerPATCH 18/20 fs: remove get_super_thawed and get_super_exclusive_thawed
In reply to Christoph HellwigJust open code the wait in the only caller of both functions.
--- fs/internal.h | 2 ++ fs/quota/quota.c | 31 +++++++++++++++++++++------- fs/super.c | 51 ++-------------------------------------------- include/linux/fs.h | 4 +--- 4 files changed, 29 insertions(+), 59 deletions(-)
fs/internal.h +2 -0
@@ -114,7 +114,9 @@ extern struct file *alloc_empty_file_noaccount(int, const struct cred *);*/ extern int reconfigure_super (struct fs_context *);extern bool trylock_super (struct super_block *sb); +struct super_block *__get_super (struct block_device *bdev,bool excl);extern struct super_block *user_get_super (dev_t ); +void put_super (struct super_block *sb);extern bool mount_capable (struct fs_context *);/*
fs/quota/quota.c +24 -7
@@ -20,6 +20,7 @@#include <linux/writeback.h> #include <linux/nospec.h> #include "compat.h" +#include "../internal.h" static int check_quotactl_permission (struct super_block *sb,int type,int cmd,qid_t id)
@@ -868,6 +869,7 @@ static struct super_block *quotactl_block(const char __user *special, int cmd)struct block_device *bdev;struct super_block *sb;struct filename *tmp =getname (special); +bool excl = false, thawed = false;if (IS_ERR (tmp))return ERR_CAST (tmp);
@@ -875,17 +877,32 @@ static struct super_block *quotactl_block(const char __user *special, int cmd)putname (tmp);if (IS_ERR (bdev))return ERR_CAST (bdev); -if (quotactl_cmd_onoff (cmd)) - sb =get_super_exclusive_thawed (bdev); -else if (quotactl_cmd_write (cmd)) - sb =get_super_thawed (bdev); -else - sb =get_super (bdev); + +if (quotactl_cmd_onoff (cmd)) { + excl = true; + thawed = true; + }else if (quotactl_cmd_write (cmd)) { + thawed = true; + } + +retry: + sb =__get_super (bdev, excl); +if (thawed && sb && sb->s_writers.frozen !=SB_UNFROZEN ) { +if (excl) +up_write (&sb->s_umount); +else +up_read (&sb->s_umount); +wait_event (sb->s_writers.wait_unfrozen, + sb->s_writers.frozen ==SB_UNFROZEN ); +put_super (sb); + goto retry; + } +bdput (bdev);if (!sb)return ERR_PTR (-ENODEV ); -return sb; +#else return ERR_PTR (-ENODEV );#endif
fs/super.c +2 -49
69 lines not on this page · raw message
include/linux/fs.h +1 -3
@@ -1409,7 +1409,7 @@ enum {struct sb_writers {int frozen;/* Is sb frozen? */ -wait_queue_head_t wait_unfrozen;/* for get_super_thawed() */ +wait_queue_head_t wait_unfrozen;/* wait for thaw */ struct percpu_rw_semaphore rw_sem[SB_FREEZE_LEVELS ]; };
@@ -3132,8 +3132,6 @@ extern struct file_system_type *get_filesystem(struct file_system_type *fs);extern void put_filesystem (struct file_system_type *fs);extern struct file_system_type *get_fs_type (const char *name);extern struct super_block *get_super (struct block_device *); -extern struct super_block *get_super_thawed (struct block_device *); -extern struct super_block *get_super_exclusive_thawed (struct block_device *bdev);extern struct super_block *get_active_super (struct block_device *bdev);extern void drop_super (struct super_block *sb);extern void drop_super_exclusive (struct super_block *sb);
Signature · 1 line
2.29.2
Jan Kara
maintainerRe: [PATCH 18/20] fs: remove get_super_thawed and get_super_exclusive_thawed
Quoted 3 lines · Christoph Hellwig
Just open code the wait in the only caller of both functions.
Signed-off-by Christoph Hellwig <[email protected]>
As far as I remember, Al (added to CC) generally objected against exporting bits from fs/super.c (like put_super(), __get_super()) in the past. FWIW I also find a dedicated function in fs/super.c somewhat cleaner than opencoding in quota code but I can live with both...
Honza
Quoted 182 lines
--- fs/internal.h | 2 ++ fs/quota/quota.c | 31 +++++++++++++++++++++------- fs/super.c | 51 ++-------------------------------------------- include/linux/fs.h | 4 +--- 4 files changed, 29 insertions(+), 59 deletions(-)fs/internal.h +2
-0@@ -114,7 +114,9 @@ extern struct file *alloc_empty_file_noaccount(int, const struct cred *);*/ extern int reconfigure_super (struct fs_context *);extern bool trylock_super (struct super_block *sb); +struct super_block *__get_super (struct block_device *bdev,bool excl);extern struct super_block *user_get_super (dev_t ); +void put_super (struct super_block *sb);extern bool mount_capable (struct fs_context *);/* fs/quota/quota.c +24
-7@@ -20,6 +20,7 @@#include <linux/writeback.h> #include <linux/nospec.h> #include "compat.h" +#include "../internal.h" static int check_quotactl_permission (struct super_block *sb,int type,int cmd,qid_t id)@@ -868,6 +869,7 @@ static struct super_block *quotactl_block(const char __user *special, int cmd)struct block_device *bdev;struct super_block *sb;struct filename *tmp =getname (special); +bool excl = false, thawed = false;if (IS_ERR (tmp))return ERR_CAST (tmp);@@ -875,17 +877,32 @@ static struct super_block *quotactl_block(const char __user *special, int cmd)putname (tmp);if (IS_ERR (bdev))return ERR_CAST (bdev); -if (quotactl_cmd_onoff (cmd)) - sb =get_super_exclusive_thawed (bdev); -else if (quotactl_cmd_write (cmd)) - sb =get_super_thawed (bdev); -else - sb =get_super (bdev); + +if (quotactl_cmd_onoff (cmd)) { + excl = true; + thawed = true; + }else if (quotactl_cmd_write (cmd)) { + thawed = true; + } + +retry: + sb =__get_super (bdev, excl); +if (thawed && sb && sb->s_writers.frozen !=SB_UNFROZEN ) { +if (excl) +up_write (&sb->s_umount); +else +up_read (&sb->s_umount); +wait_event (sb->s_writers.wait_unfrozen, + sb->s_writers.frozen ==SB_UNFROZEN ); +put_super (sb); + goto retry; + } +bdput (bdev);if (!sb)return ERR_PTR (-ENODEV ); -return sb; +#else return ERR_PTR (-ENODEV );#endif fs/super.c +2
-49@@ -307,7 +307,7 @@ static void __put_super(struct super_block *s)* Drops a temporary reference, frees superblock if there's no * references left. */ -static void put_super (struct super_block *sb) +void put_super (struct super_block *sb) {spin_lock (&sb_lock);__put_super (sb);@@ -740,7 +740,7 @@ void iterate_supers_type(struct file_system_type *type,EXPORT_SYMBOL (iterate_supers_type); -static struct super_block *__get_super (struct block_device *bdev,bool excl) +struct super_block *__get_super (struct block_device *bdev,bool excl) {struct super_block *sb;@@ -789,53 +789,6 @@ struct super_block *get_super(struct block_device *bdev) }EXPORT_SYMBOL (get_super); -static struct super_block *__get_super_thawed (struct block_device *bdev, -bool excl) -{ -while (1 ) { -struct super_block *s =__get_super (bdev, excl); -if (!s || s->s_writers.frozen ==SB_UNFROZEN ) -return s; -if (!excl) -up_read (&s->s_umount); -else -up_write (&s->s_umount); -wait_event (s->s_writers.wait_unfrozen, - s->s_writers.frozen ==SB_UNFROZEN ); -put_super (s); - } -} - -/** -* get_super_thawed - get thawed superblock of a device -* @bdev: device to get the superblock for -* -* Scans the superblock list and finds the superblock of the file system -* mounted on the device. The superblock is returned once it is thawed -* (or immediately if it was not frozen). %NULL is returned if no match -* is found. -*/ -struct super_block *get_super_thawed (struct block_device *bdev) -{ -return __get_super_thawed (bdev, false); -} -EXPORT_SYMBOL (get_super_thawed); - -/** -* get_super_exclusive_thawed - get thawed superblock of a device -* @bdev: device to get the superblock for -* -* Scans the superblock list and finds the superblock of the file system -* mounted on the device. The superblock is returned once it is thawed -* (or immediately if it was not frozen) and s_umount semaphore is held -* in exclusive mode. %NULL is returned if no match is found. -*/ -struct super_block *get_super_exclusive_thawed (struct block_device *bdev) -{ -return __get_super_thawed (bdev, true); -} -EXPORT_SYMBOL (get_super_exclusive_thawed); -/** * get_active_super - get an active reference to the superblock of a device * @bdev: device to get the superblock for include/linux/fs.h +1
-3@@ -1409,7 +1409,7 @@ enum {struct sb_writers {int frozen;/* Is sb frozen? */ -wait_queue_head_t wait_unfrozen;/* for get_super_thawed() */ +wait_queue_head_t wait_unfrozen;/* wait for thaw */ struct percpu_rw_semaphore rw_sem[SB_FREEZE_LEVELS ]; };@@ -3132,8 +3132,6 @@ extern struct file_system_type *get_filesystem(struct file_system_type *fs);extern void put_filesystem (struct file_system_type *fs);extern struct file_system_type *get_fs_type (const char *name);extern struct super_block *get_super (struct block_device *); -extern struct super_block *get_super_thawed (struct block_device *); -extern struct super_block *get_super_exclusive_thawed (struct block_device *bdev);extern struct super_block *get_active_super (struct block_device *bdev);extern void drop_super (struct super_block *sb);extern void drop_super_exclusive (struct super_block *sb);Signature · 1 line
2.29.2
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Christoph Hellwig
maintainerPATCH 19/20 bcache: remove a superflous lookup_bdev all
In reply to Christoph HellwigDon't bother to call lookup_bdev for just a slightly different error message without any functional change.
--- drivers/md/bcache/super.c | 44 +-------------------------------------- 1 file changed, 1 insertion(+), 43 deletions(-)
drivers/md/bcache/super.c +1 -43
@@ -2380,40 +2380,6 @@ kobj_attribute_write(register, register_bcache);kobj_attribute_write (register_quiet, register_bcache);kobj_attribute_write (pendings_cleanup, bch_pending_bdevs_cleanup); -static bool bch_is_open_backing (struct block_device *bdev) -{ -struct cache_set *c, *tc; -struct cached_dev *dc, *t; - -list_for_each_entry_safe (c, tc, &bch_cache_sets, list) -list_for_each_entry_safe (dc, t, &c->cached_devs, list) -if (dc->bdev == bdev) -return true; -list_for_each_entry_safe (dc, t, &uncached_devices, list) -if (dc->bdev == bdev) -return true; -return false; -} - -static bool bch_is_open_cache (struct block_device *bdev) -{ -struct cache_set *c, *tc; - -list_for_each_entry_safe (c, tc, &bch_cache_sets, list) { -struct cache *ca = c->cache; - -if (ca->bdev == bdev) -return true; - } - -return false; -} - -static bool bch_is_open (struct block_device *bdev) -{ -return bch_is_open_cache (bdev) ||bch_is_open_backing (bdev); -} -struct async_reg_args {struct delayed_work reg_work;char *path;
@@ -2535,15 +2501,7 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr, sb);if (IS_ERR (bdev)) {if (bdev ==ERR_PTR (-EBUSY )) { - bdev =lookup_bdev (strim (path)); -mutex_lock (&bch_register_lock); -if (!IS_ERR (bdev) &&bch_is_open (bdev)) - err ="device already registered" ; -else - err ="device busy" ; -mutex_unlock (&bch_register_lock); -if (!IS_ERR (bdev)) -bdput (bdev); + err ="device busy" ;if (attr == &ksysfs_register_quiet) goto done; }
Signature · 1 line
2.29.2
Re: [PATCH 19/20] bcache: remove a superflous lookup_bdev all
Quoted 4 lines · Christoph Hellwig
Don't bother to call
lookup_bdevfor just a slightly different error message without any functional change.Signed-off-by Christoph Hellwig <[email protected]>ist
Hi Christoph,
NACK. This removing error message is frequently triggered and observed, and distinct a busy device and an already registered device is important (the first one is critical error and second one is not).
Remove such error message will be a functional regression.
Coly Li
Quoted 67 lines
--- drivers/md/bcache/super.c | 44 +-------------------------------------- 1 file changed, 1 insertion(+), 43 deletions(-)drivers/md/bcache/super.c +1
-43@@ -2380,40 +2380,6 @@ kobj_attribute_write(register, register_bcache);kobj_attribute_write (register_quiet, register_bcache);kobj_attribute_write (pendings_cleanup, bch_pending_bdevs_cleanup); -static bool bch_is_open_backing (struct block_device *bdev) -{ -struct cache_set *c, *tc; -struct cached_dev *dc, *t; - -list_for_each_entry_safe (c, tc, &bch_cache_sets, list) -list_for_each_entry_safe (dc, t, &c->cached_devs, list) -if (dc->bdev == bdev) -return true; -list_for_each_entry_safe (dc, t, &uncached_devices, list) -if (dc->bdev == bdev) -return true; -return false; -} - -static bool bch_is_open_cache (struct block_device *bdev) -{ -struct cache_set *c, *tc; - -list_for_each_entry_safe (c, tc, &bch_cache_sets, list) { -struct cache *ca = c->cache; - -if (ca->bdev == bdev) -return true; - } - -return false; -} - -static bool bch_is_open (struct block_device *bdev) -{ -return bch_is_open_cache (bdev) ||bch_is_open_backing (bdev); -} -struct async_reg_args {struct delayed_work reg_work;char *path;@@ -2535,15 +2501,7 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr, sb);if (IS_ERR (bdev)) {if (bdev ==ERR_PTR (-EBUSY )) { - bdev =lookup_bdev (strim (path)); -mutex_lock (&bch_register_lock); -if (!IS_ERR (bdev) &&bch_is_open (bdev)) - err ="device already registered" ; -else - err ="device busy" ; -mutex_unlock (&bch_register_lock); -if (!IS_ERR (bdev)) -bdput (bdev); + err ="device busy" ;if (attr == &ksysfs_register_quiet) goto done; }
Greg KH
maintainerRe: [PATCH 19/20] bcache: remove a superflous lookup_bdev all
Quoted 6 lines · Coly Li
Quoted 4 lines · Christoph Hellwig
Don't bother to call
lookup_bdevfor just a slightly different error message without any functional change.Signed-off-by Christoph Hellwig <[email protected]>ist
Quoted 7 lines
Hi Christoph,
NACK. This removing error message is frequently triggered and observed, and distinct a busy device and an already registered device is important (the first one is critical error and second one is not).
Remove such error message will be a functional regression.
What normal operation causes this error message to be emitted? And what can a user do with it?
thanks,
greg k-h
Re: [PATCH 19/20] bcache: remove a superflous lookup_bdev all
Quoted 9 lines · Greg KH
Quoted 8 lines · Coly Li
Quoted 4 lines · Christoph Hellwig
Don't bother to call
lookup_bdevfor just a slightly different error message without any functional change.Signed-off-by Christoph Hellwig <[email protected]>istHi Christoph,
Quoted 8 lines
Quoted 5 lines
NACK. This removing error message is frequently triggered and observed, and distinct a busy device and an already registered device is important (the first one is critical error and second one is not).
Remove such error message will be a functional regression.
What normal operation causes this error message to be emitted? And what can a user do with it?
When there was bug and the caching or backing device was not unregistered successfully, people could see "device busy"; and if it was because the device registered again, it could be "already registered". Without the different message, people may think the device is always busy but indeed it isn't.
he motivation of the patch is OK to me, but we need to make the logical consistent, otherwise we will have similar bug report for bogus warning dmesg from bcache users in soon future.
Coly Li
Christoph Hellwig
maintainerRe: [PATCH 19/20] bcache: remove a superflous lookup_bdev all
In reply to Coly LiQuoted 6 lines · Coly Li
Quoted 4 lines · Christoph Hellwig
Don't bother to call
lookup_bdevfor just a slightly different error message without any functional change.Signed-off-by Christoph Hellwig <[email protected]>ist
Quoted 7 lines
Hi Christoph,
NACK. This removing error message is frequently triggered and observed, and distinct a busy device and an already registered device is important (the first one is critical error and second one is not).
Remove such error message will be a functional regression.
I can probably keep it, the amount of code to prettiefy an error message seems excessive, though.
Christoph Hellwig
maintainerPATCH 20/20 block: remove i_bdev
In reply to Christoph HellwigSwitch the block device lookup interfaces to directly work with a dev_t so that struct block_device references are only acquired by the blkdev_get variants (and the blk-cgroup special case). This means that we not don't need an extra reference in the inode and can generally simplify handling of struct block_device to keep the lookups contained in the core block layer code.
--- block/ioctl.c | 3 +- drivers/block/loop.c | 8 +- drivers/md/dm-table.c | 9 +- drivers/mtd/mtdsuper.c | 17 +- drivers/target/target_core_file.c | 6 +- drivers/usb/gadget/function/storage_common.c | 8 +- fs/block_dev.c | 198 +++++-------------- fs/btrfs/volumes.c | 13 +- fs/inode.c | 3 - fs/internal.h | 7 +- fs/io_uring.c | 10 +- fs/pipe.c | 5 +- fs/quota/quota.c | 19 +- fs/statfs.c | 2 +- fs/super.c | 37 ++-- include/linux/blkdev.h | 2 +- include/linux/fs.h | 1 - 17 files changed, 104 insertions(+), 244 deletions(-)
block/ioctl.c +1 -2
@@ -599,8 +599,7 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg) {int ret;void __user *argp =compat_ptr (arg); -struct inode *inode = file->f_mapping->host; -struct block_device *bdev = inode->i_bdev; +struct block_device *bdev =I_BDEV (file->f_mapping->host);struct gendisk *disk = bdev->bd_disk;fmode_t mode = file->f_mode;loff_t size;
drivers/block/loop.c +3 -5
@@ -675,10 +675,10 @@ static int loop_validate_file(struct file *file, struct block_device *bdev)while (is_loop_device (f)) {struct loop_device *l; -if (f->f_mapping->host->i_bdev == bdev) +if (f->f_mapping->host->i_rdev == bdev->bd_dev)return -EBADF ; - l = f->f_mapping->host->i_bdev->bd_disk->private_data; + l =I_BDEV (f->f_mapping->host)->bd_disk->private_data;if (l->lo_state != Lo_bound) {return -EINVAL ; }
@@ -885,9 +885,7 @@ static void loop_config_discard(struct loop_device *lo)* file-backed loop devices: discarded regions read back as zero. */ if (S_ISBLK (inode->i_mode) && !lo->lo_encrypt_key_size) { -struct request_queue *backingq; - - backingq =bdev_get_queue (inode->i_bdev); +struct request_queue *backingq =bdev_get_queue (I_BDEV (inode)); max_discard_sectors = backingq->limits.max_write_zeroes_sectors; granularity = backingq->limits.discard_granularity ?:
drivers/md/dm-table.c +1 -8
@@ -348,16 +348,9 @@ static int upgrade_mode(struct dm_dev_internal *dd, fmode_t new_mode,dev_t dm_get_dev_t (const char *path) {dev_t dev; -struct block_device *bdev; - bdev =lookup_bdev (path); -if (IS_ERR (bdev)) +if (lookup_bdev (path, &dev)) dev =name_to_dev_t (path); -else { - dev = bdev->bd_dev; -bdput (bdev); - } -return dev; }EXPORT_SYMBOL_GPL (dm_get_dev_t);
drivers/mtd/mtdsuper.c +6 -11
@@ -120,8 +120,8 @@ int get_tree_mtd(struct fs_context *fc, struct fs_context *fc)) {#ifdef CONFIG_BLOCK -struct block_device *bdev; -int ret, major; +dev_t dev; +int ret;#endif int mtdnr;
@@ -169,20 +169,15 @@ int get_tree_mtd(struct fs_context *fc,/* try the old way - the hack where we allowed users to mount * /dev/mtdblock$(n) but didn't actually _use_ the blockdev */ - bdev =lookup_bdev (fc->source); -if (IS_ERR (bdev)) { - ret =PTR_ERR (bdev); + ret =lookup_bdev (fc->source, &dev); +if (ret) {errorf (fc,"MTD: Couldn't look up '%s': %d" , fc->source, ret);return ret; }pr_debug ("MTDSB: lookup_bdev() returned 0\n" ); - major =MAJOR (bdev->bd_dev); - mtdnr =MINOR (bdev->bd_dev); -bdput (bdev); - -if (major ==MTD_BLOCK_MAJOR ) -return mtd_get_sb_by_nr (fc, mtdnr, fill_super); +if (MAJOR (dev) ==MTD_BLOCK_MAJOR ) +return mtd_get_sb_by_nr (fc,MINOR (dev), fill_super);#endif /* CONFIG_BLOCK */
drivers/target/target_core_file.c +3 -3
@@ -133,10 +133,10 @@ static int fd_configure_device(struct se_device *dev)*/ inode = file->f_mapping->host;if (S_ISBLK (inode->i_mode)) { -struct request_queue *q =bdev_get_queue (inode->i_bdev); +struct request_queue *q =bdev_get_queue (I_BDEV (inode));unsigned long long dev_size; - fd_dev->fd_block_size =bdev_logical_block_size (inode->i_bdev); + fd_dev->fd_block_size =bdev_logical_block_size (I_BDEV (inode));/* * Determine the number of bytes from i_size_read() minus * one (1) logical sector from underlying struct block_device
@@ -559,7 +559,7 @@ fd_execute_unmap(struct se_cmd *cmd, sector_t lba, sector_t nolb)if (S_ISBLK (inode->i_mode)) {/* The backend is block device, use discard */ -struct block_device *bdev = inode->i_bdev; +struct block_device *bdev =I_BDEV (inode);struct se_device *dev = cmd->se_dev; ret = blkdev_issue_discard(bdev,
drivers/usb/gadget/function/storage_common.c +4 -4
@@ -204,7 +204,7 @@ int fsg_lun_open(struct fsg_lun *curlun, const char *filename)if (!(filp->f_mode &FMODE_WRITE )) ro =1 ; - inode =file_inode (filp); + inode = filp->f_mapping->host;if ((!S_ISREG (inode->i_mode) && !S_ISBLK (inode->i_mode))) {LINFO (curlun,"invalid file type: %s\n" , filename); goto out;
@@ -221,7 +221,7 @@ int fsg_lun_open(struct fsg_lun *curlun, const char *filename)if (!(filp->f_mode &FMODE_CAN_WRITE )) ro =1 ; - size =i_size_read (inode->i_mapping->host); + size =i_size_read (inode);if (size <0 ) {LINFO (curlun,"unable to find file size: %s\n" , filename); rc = (int ) size;
@@ -231,8 +231,8 @@ int fsg_lun_open(struct fsg_lun *curlun, const char *filename)if (curlun->cdrom) { blksize =2048 ; blkbits =11 ; - }else if (inode->i_bdev) { - blksize =bdev_logical_block_size (inode->i_bdev); + }else if (S_ISBLK (inode->i_mode)) { + blksize =bdev_logical_block_size (I_BDEV (inode)); blkbits =blksize_bits (blksize); }else { blksize =512 ;
fs/block_dev.c +50 -148
300 lines not on this page · raw message
fs/btrfs/volumes.c +6 -7
@@ -929,16 +929,16 @@ static noinline struct btrfs_device *device_list_add(const char *path,* make sure it's the same device if the device is mounted */ if (device->bdev) { -struct block_device *path_bdev; +int error; +dev_t path_dev; - path_bdev =lookup_bdev (path); -if (IS_ERR (path_bdev)) { + error =lookup_bdev (path, &path_dev); +if (error) {mutex_unlock (&fs_devices->device_list_mutex); -return ERR_CAST (path_bdev); +return ERR_PTR (error); } -if (device->bdev != path_bdev) { -bdput (path_bdev); +if (device->bdev->bd_dev != path_dev) {mutex_unlock (&fs_devices->device_list_mutex); btrfs_warn_in_rcu(device->fs_info, "duplicate device %s devid %llu generation %llu scanned by %s (%d)",
@@ -947,7 +947,6 @@ static noinline struct btrfs_device *device_list_add(const char *path, task_pid_nr(current));return ERR_PTR (-EEXIST ); } -bdput (path_bdev); btrfs_info_in_rcu(device->fs_info, "devid %llu device path %s changed to %s scanned by %s (%d)", devid, rcu_str_deref(device->name),
fs/inode.c +0 -3
@@ -155,7 +155,6 @@ int inode_init_always(struct super_block *sb, struct inode *inode) inode->i_bytes =0 ; inode->i_generation =0 ; inode->i_pipe =NULL ; - inode->i_bdev =NULL ; inode->i_cdev =NULL ; inode->i_link =NULL ; inode->i_dir_seq =0 ;
@@ -580,8 +579,6 @@ static void evict(struct inode *inode)truncate_inode_pages_final (&inode->i_data);clear_inode (inode); } -if (S_ISBLK (inode->i_mode) && inode->i_bdev) -bd_forget (inode);if (S_ISCHR (inode->i_mode) && inode->i_cdev)cd_forget (inode);
fs/internal.h +1 -6
@@ -25,7 +25,6 @@ extern void __init bdev_cache_init(void);extern int __sync_blockdev (struct block_device *bdev,int wait);void iterate_bdevs (void (*)(struct block_device *,void *),void *);void emergency_thaw_bdev (struct super_block *sb); -void bd_forget (struct inode *inode);#else static inline void bdev_cache_init (void ) {
@@ -43,9 +42,6 @@ static inline int emergency_thaw_bdev(struct super_block *sb) {return 0 ; } -static inline void bd_forget (struct inode *inode) -{ -}#endif /* CONFIG_BLOCK */ /*
@@ -114,8 +110,7 @@ extern struct file *alloc_empty_file_noaccount(int, const struct cred *);*/ extern int reconfigure_super (struct fs_context *);extern bool trylock_super (struct super_block *sb); -struct super_block *__get_super (struct block_device *bdev,bool excl); -extern struct super_block *user_get_super (dev_t ); +struct super_block *user_get_super (dev_t ,bool excl);void put_super (struct super_block *sb);extern bool mount_capable (struct fs_context *);
fs/io_uring.c +4 -6
@@ -2716,11 +2716,7 @@ static struct file *__io_file_get(struct io_submit_state *state, int fd)static bool io_bdev_nowait (struct block_device *bdev) { -#ifdef CONFIG_BLOCK return !bdev ||blk_queue_nowait (bdev_get_queue (bdev)); -#else -return true; -#endif }/*
@@ -2733,14 +2729,16 @@ static bool io_file_supports_async(struct file *file, int rw)umode_t mode =file_inode (file)->i_mode;if (S_ISBLK (mode)) { -if (io_bdev_nowait (file->f_inode->i_bdev)) +if (IS_ENABLED (CONFIG_BLOCK ) && +io_bdev_nowait (I_BDEV (file->f_mapping->host)))return true;return false; }if (S_ISCHR (mode) ||S_ISSOCK (mode))return true;if (S_ISREG (mode)) { -if (io_bdev_nowait (file->f_inode->i_sb->s_bdev) && +if (IS_ENABLED (CONFIG_BLOCK ) && +io_bdev_nowait (file->f_inode->i_sb->s_bdev) && file->f_op != &io_uring_fops)return true;return false;
fs/pipe.c +2 -3
@@ -1342,9 +1342,8 @@ static long pipe_set_size(struct pipe_inode_info *pipe, unsigned long arg) }/* -* After the inode slimming patch, i_pipe/i_bdev/i_cdev share the same -* location, so checking ->i_pipe is not enough to verify that this is a -* pipe. +* Note that i_pipe and i_cdev share the same location, so checking ->i_pipe is +* not enough to verify that this is a pipe. */ struct pipe_inode_info *get_pipe_info (struct file *file,bool for_splice) {
fs/quota/quota.c +9 -10
@@ -866,17 +866,18 @@ static bool quotactl_cmd_onoff(int cmd)static struct super_block *quotactl_block (const char __user *special,int cmd) {#ifdef CONFIG_BLOCK -struct block_device *bdev;struct super_block *sb;struct filename *tmp =getname (special);bool excl = false, thawed = false; +int error; +dev_t dev;if (IS_ERR (tmp))return ERR_CAST (tmp); - bdev =lookup_bdev (tmp->name); + error =lookup_bdev (tmp->name, &dev);putname (tmp); -if (IS_ERR (bdev)) -return ERR_CAST (bdev); +if (error) +return ERR_PTR (error);if (quotactl_cmd_onoff (cmd)) { excl = true;
@@ -886,8 +887,10 @@ static struct super_block *quotactl_block(const char __user *special, int cmd) } retry: - sb =__get_super (bdev, excl); -if (thawed && sb && sb->s_writers.frozen !=SB_UNFROZEN ) { + sb =user_get_super (dev, excl); +if (!sb) +return ERR_PTR (-ENODEV ); +if (thawed && sb->s_writers.frozen !=SB_UNFROZEN ) {if (excl)up_write (&sb->s_umount);else
@@ -897,10 +900,6 @@ static struct super_block *quotactl_block(const char __user *special, int cmd)put_super (sb); goto retry; } - -bdput (bdev); -if (!sb) -return ERR_PTR (-ENODEV );return sb;#else
fs/statfs.c +1 -1
@@ -235,7 +235,7 @@ SYSCALL_DEFINE3(fstatfs64, unsigned int, fd, size_t, sz, struct statfs64 __userstatic int vfs_ustat (dev_t dev,struct kstatfs *sbuf) { -struct super_block *s =user_get_super (dev); +struct super_block *s =user_get_super (dev, false);int err;if (!s)return -EINVAL ;
fs/super.c +12 -25
@@ -740,7 +740,7 @@ void iterate_supers_type(struct file_system_type *type,EXPORT_SYMBOL (iterate_supers_type); -struct super_block *__get_super (struct block_device *bdev,bool excl) +struct super_block *get_super (struct block_device *bdev) {struct super_block *sb;
@@ -755,17 +755,11 @@ struct super_block *__get_super(struct block_device *bdev, bool excl)if (sb->s_bdev == bdev) { sb->s_count++;spin_unlock (&sb_lock); -if (!excl) -down_read (&sb->s_umount); -else -down_write (&sb->s_umount); +down_read (&sb->s_umount);/* still alive? */ if (sb->s_root && (sb->s_flags &SB_BORN ))return sb; -if (!excl) -up_read (&sb->s_umount); -else -up_write (&sb->s_umount); +up_read (&sb->s_umount);/* nope, got unmounted */ spin_lock (&sb_lock);__put_super (sb);
@@ -776,19 +770,6 @@ struct super_block *__get_super(struct block_device *bdev, bool excl)return NULL ; } -/** -* get_super - get the superblock of a device -* @bdev: device to get the superblock for -* -* Scans the superblock list and finds the superblock of the file system -* mounted on the device given. %NULL is returned if no match is found. -*/ -struct super_block *get_super (struct block_device *bdev) -{ -return __get_super (bdev, false); -} -EXPORT_SYMBOL (get_super); -/** * get_active_super - get an active reference to the superblock of a device * @bdev: device to get the superblock for
@@ -820,7 +801,7 @@ struct super_block *get_active_super(struct block_device *bdev)return NULL ; } -struct super_block *user_get_super (dev_t dev) +struct super_block *user_get_super (dev_t dev,bool excl) {struct super_block *sb;
@@ -832,11 +813,17 @@ struct super_block *user_get_super(dev_t dev)if (sb->s_dev == dev) { sb->s_count++;spin_unlock (&sb_lock); -down_read (&sb->s_umount); +if (excl) +down_write (&sb->s_umount); +else +down_read (&sb->s_umount);/* still alive? */ if (sb->s_root && (sb->s_flags &SB_BORN ))return sb; -up_read (&sb->s_umount); +if (excl) +up_write (&sb->s_umount); +else +up_read (&sb->s_umount);/* nope, got unmounted */ spin_lock (&sb_lock);__put_super (sb);
include/linux/blkdev.h +1 -1
@@ -1973,7 +1973,7 @@ int bdev_read_only(struct block_device *bdev);int set_blocksize (struct block_device *bdev,int size);const char *bdevname (struct block_device *bdev,char *buffer); -struct block_device *lookup_bdev (const char *); +int lookup_bdev (const char *pathname,dev_t *dev);void blkdev_show (struct seq_file *seqf,off_t offset);
include/linux/fs.h +0 -1
@@ -696,7 +696,6 @@ struct inode {struct list_head i_devices;union {struct pipe_inode_info *i_pipe; -struct block_device *i_bdev;struct cdev *i_cdev;char *i_link;unsigned i_dir_seq;
Signature · 1 line
2.29.2
Christoph,
Quoted 53 lines · Christoph Hellwig
Diffstat:
block/bio.c | 6 block/blk-cgroup.c | 50 +- block/blk-core.c | 85 +-- block/blk-flush.c | 2 block/blk-iocost.c | 36 - block/blk-lib.c | 2 block/blk-merge.c | 6 block/blk-mq.c | 11 block/blk-mq.h | 5 block/blk.h | 92 ---- block/genhd.c | 444 +++++--------------- block/ioctl.c | 7 block/partitions/core.c | 238 +++-------- drivers/block/drbd/drbd_receiver.c | 2 drivers/block/drbd/drbd_worker.c | 2 drivers/block/loop.c | 21 drivers/block/nbd.c | 6 drivers/block/xen-blkback/common.h | 4 drivers/block/xen-blkfront.c | 20 drivers/block/zram/zram_drv.c | 20 drivers/md/bcache/request.c | 4 drivers/md/bcache/super.c | 53 -- drivers/md/dm-table.c | 9 drivers/md/dm.c | 16 drivers/md/md.c | 8 drivers/mtd/mtdsuper.c | 17 drivers/nvme/target/admin-cmd.c | 20 drivers/s390/block/dasd.c | 8 drivers/s390/block/dasd_ioctl.c | 9 drivers/scsi/scsicam.c | 2 drivers/target/target_core_file.c | 6 drivers/target/target_core_pscsi.c | 7 drivers/usb/gadget/function/storage_common.c | 8 fs/block_dev.c | 578 ++++++++------------------- fs/btrfs/sysfs.c | 15 fs/btrfs/volumes.c | 13 fs/ext4/super.c | 18 fs/ext4/sysfs.c | 10 fs/f2fs/checkpoint.c | 5 fs/f2fs/f2fs.h | 2 fs/f2fs/super.c | 8 fs/f2fs/sysfs.c | 9 fs/inode.c | 3 fs/internal.h | 7 fs/io_uring.c | 10 fs/pipe.c | 5 fs/pstore/blk.c | 2 fs/quota/quota.c | 40 + fs/statfs.c | 2 fs/super.c | 86 ---- include/linux/blk-cgroup.h | 4 include/linux/blk_types.h | 26 +
Quoted 8 lines
include/linux/blkdev.h | 24 - include/linux/fs.h | 5 include/linux/genhd.h | 104 ---- include/linux/part_stat.h | 17 init/do_mounts.c | 271 +++++------- kernel/trace/blktrace.c | 54 -- mm/filemap.c | 9 59 files changed, 837 insertions(+), 1716 deletions(-)
since this isn't the first series from you recently spamming xen-devel, may I ask that you don't Cc entire series to lists which are involved with perhaps just one out of the many patches? IMO Cc lists should be compiled on a per-patch basis; the cover letter may of course be sent to the union of all of them.
Thanks much,
Jan
Christoph Hellwig
maintainerQuoted 5 lines · Jan Beulich
since this isn't the first series from you recently spamming xen-devel, may I ask that you don't Cc entire series to lists which are involved with perhaps just one out of the many patches? IMO Cc lists should be compiled on a per-patch basis; the cover letter may of course be sent to the union of all of them.
No way. Individual CCs are completely broken as they don't provide the reviewer a context. If you don't want xen-blkfront patches to go to xen-devel remove it from MAINTAINERS.
Quoted 9 lines · Christoph Hellwig
Quoted 5 lines · Jan Beulich
since this isn't the first series from you recently spamming xen-devel, may I ask that you don't Cc entire series to lists which are involved with perhaps just one out of the many patches? IMO Cc lists should be compiled on a per-patch basis; the cover letter may of course be sent to the union of all of them.
No way. Individual CCs are completely broken as they don't provide the reviewer a context.
That's the view of some people, but not all. Context can be easily established by those who care going to one of the many archives on which the entire series lands. Getting spammed, however, can't be avoided by the dozens or hundreds of list subscribers.
Quoted 2 lines
If you don't want xen-blkfront patches to
go to xen-devel remove it fromMAINTAINERS.
Patches to Xen drivers very much ought to go to xen-devel imo, so no - removal is not an option.
Jan
Christoph Hellwig
maintainerQuoted 4 lines · Jan Beulich
That's the view of some people, but not all. Context can be easily established by those who care going to one of the many archives on which the entire series lands. Getting spammed, however, can't be avoided by the dozens or hundreds of list subscribers.
No, that is simply a completely broken model. Mails a are trivial to ignore, finding them OTOH is everything but. Learn how to ignore a few mails, it isn't hard at all.
Greg KH
maintainerQuoted 8 lines · Jan Beulich
Quoted 7 lines · Christoph Hellwig
Quoted 5 lines · Jan Beulich
since this isn't the first series from you recently spamming xen-devel, may I ask that you don't Cc entire series to lists which are involved with perhaps just one out of the many patches? IMO Cc lists should be compiled on a per-patch basis; the cover letter may of course be sent to the union of all of them.
Quoted 7 lines
Quoted 2 lines
No way. Individual CCs are completely broken as they don't provide the reviewer a context.
That's the view of some people, but not all. Context can be easily established by those who care going to one of the many archives on which the entire series lands. Getting spammed, however, can't be avoided by the dozens or hundreds of list subscribers.
kernel patches are never "spam", sorry, but for developers to try to determine which lists/maintainers want to see the whole series and which do not is impossible.
Patches in a series are easily deleted from sane mail clients with a single click/keystroke all at once, they aren't a problem that needs to be reduced in volume.
thanks,
greg k-h
Quoted 17 lines · Greg KH
Quoted 8 lines · Jan Beulich
Quoted 7 lines · Christoph Hellwig
Quoted 5 lines · Jan Beulich
since this isn't the first series from you recently spamming xen-devel, may I ask that you don't Cc entire series to lists which are involved with perhaps just one out of the many patches? IMO Cc lists should be compiled on a per-patch basis; the cover letter may of course be sent to the union of all of them.
Quoted 7 lines
Quoted 2 lines
No way. Individual CCs are completely broken as they don't provide the reviewer a context.
That's the view of some people, but not all. Context can be easily established by those who care going to one of the many archives on which the entire series lands. Getting spammed, however, can't be avoided by the dozens or hundreds of list subscribers.
Quoted 7 lines
kernel patches are never "spam", sorry, but for developers to try to determine which lists/maintainers want to see the whole series and which do not is impossible.
Patches in a series are easily deleted from sane mail clients with a single click/keystroke all at once, they aren't a problem that needs to be reduced in volume.
This doesn't scale, neither in the dimension of recipients nor in the dimension of possible sources of such series.
While it may seem small, it's also a waste of resources to have mails sent to hundreds of even thousands of people. So while from a technical content perspective I surely agree with you saying 'kernel patches are never "spam"', they still are from the perspective of what "spam mail" originally means: Mail the recipients did not want to receive.
Jan
Greg KH
maintainerQuoted 22 lines · Jan Beulich
Quoted 21 lines · Greg KH
Quoted 8 lines · Jan Beulich
Quoted 7 lines · Christoph Hellwig
Quoted 5 lines · Jan Beulich
since this isn't the first series from you recently spamming xen-devel, may I ask that you don't Cc entire series to lists which are involved with perhaps just one out of the many patches? IMO Cc lists should be compiled on a per-patch basis; the cover letter may of course be sent to the union of all of them.
Quoted 7 lines
Quoted 2 lines
No way. Individual CCs are completely broken as they don't provide the reviewer a context.
That's the view of some people, but not all. Context can be easily established by those who care going to one of the many archives on which the entire series lands. Getting spammed, however, can't be avoided by the dozens or hundreds of list subscribers.
kernel patches are never "spam", sorry, but for developers to try to determine which lists/maintainers want to see the whole series and which do not is impossible.
Quoted 6 lines
Quoted 3 lines
Patches in a series are easily deleted from sane mail clients with a single click/keystroke all at once, they aren't a problem that needs to be reduced in volume.
This doesn't scale, neither in the dimension of recipients nor in the dimension of possible sources of such series.
Again, trying to figure out what subsystem does, and does not, want stuff like this does not scale either. Remember, we had 4000 developers last year, how are you going to tell all of them what the special rules are for your subsystem and how they differ from any other subsystem?
And why does it matter? We are all working on the same project, why wouldn't you want to see core block device handling patches? What hurts with that, someone might notice something in one of them that a different developer did not.
Quoted 6 lines
While it may seem small, it's also a waste of resources to have mails sent to hundreds of even thousands of people. So while from a technical content perspective I surely agree with you saying 'kernel patches are never "spam"', they still are from the perspective of what "spam mail" originally means: Mail the recipients did not want to receive.
Anyone on a kernel subsystem mailing list should expect to see kernel patches, that's part of the process, and always has been.
Kernel subsystems are not silos, people on them should be aware of what else is going on in order to stay informed. And again, if it's a huge problem, one click/keystroke and they are gone, no waste.
thanks,
greg k-h
Matthew Wilcox
maintainerQuoted 29 lines · Jan Beulich
Quoted 17 lines · Greg KH
Quoted 8 lines · Jan Beulich
Quoted 7 lines · Christoph Hellwig
Quoted 5 lines · Jan Beulich
since this isn't the first series from you recently spamming xen-devel, may I ask that you don't Cc entire series to lists which are involved with perhaps just one out of the many patches? IMO Cc lists should be compiled on a per-patch basis; the cover letter may of course be sent to the union of all of them.
Quoted 7 lines
Quoted 2 lines
No way. Individual CCs are completely broken as they don't provide the reviewer a context.
That's the view of some people, but not all. Context can be easily established by those who care going to one of the many archives on which the entire series lands. Getting spammed, however, can't be avoided by the dozens or hundreds of list subscribers.
Quoted 7 lines
kernel patches are never "spam", sorry, but for developers to try to determine which lists/maintainers want to see the whole series and which do not is impossible.
Patches in a series are easily deleted from sane mail clients with a single click/keystroke all at once, they aren't a problem that needs to be reduced in volume.
This doesn't scale, neither in the dimension of recipients nor in the dimension of possible sources of such series.
Quoted 6 lines
While it may seem small, it's also a waste of resources to have mails sent to hundreds of even thousands of people. So while from a technical content perspective I surely agree with you saying 'kernel patches are never "spam"', they still are from the perspective of what "spam mail" originally means: Mail the recipients did not want to receive.
What doesn't scale is developers who only care about their tiny sliver of Linux and don't stick their heads up from time to time and look around. This is an opportunity for people to become more involved in the development of Linux as a whole, instead of just worrying about their bit. You're not "a Xen developer". You're a Linux developer whose current focus is on Xen.
Greg KH
Reviewed-by Greg Kroah-HartmanQuoted 10 lines · Christoph Hellwig
Hi Jens,
this series cleans up our main per-device node data structure by merging the
block_deviceandhd_structdata structures that have the same scope, but different life times. The main effect (besides removing lots of code) is that instead of having two device sizes that need complex synchronization there is just one now.Note that it depends on the previous "misc cleanups" series.
Quoted 7 lines
A git tree is available here:
git://git.infradead.org/users/hch/block.gitbdev-lookupGitweb:
http://git.infradead.org/users/hch/block.git/shortlog/refs/heads/bdev-lookup
Nice cleanups, thanks for doing this.
Series is: