clean up is partition checks
Subsystems (16)
Christoph Hellwig
reviewerHi Jens,
this series add a new helepr to check if a struct block_device represents a parition, and removes most direct access to ->bd_contained from drivers.
Diffstat:
Documentation/userspace-api/ioctl/hdio.rst | 24 ++++++++++++------------ block/blk-lib.c | 2 +- block/genhd.c | 2 +- block/ioctl.c | 4 ++-- block/scsi_ioctl.c | 2 +- drivers/block/drbd/drbd_main.c | 2 -- drivers/block/drbd/drbd_receiver.c | 2 +- drivers/block/drbd/drbd_worker.c | 2 +- drivers/ide/ide-ioctls.c | 4 ++-- drivers/md/dm-table.c | 2 +- drivers/md/md.c | 9 ++++----- drivers/md/md.h | 2 +- drivers/mmc/core/block.c | 2 +- drivers/s390/block/dasd_ioctl.c | 8 ++++---- drivers/target/target_core_iblock.c | 5 ++--- fs/nfsd/blocklayout.c | 4 ++-- include/linux/blkdev.h | 9 +++++++-- kernel/trace/blktrace.c | 2 +- lib/vsprintf.c | 4 ++-- 19 files changed, 46 insertions(+), 45 deletions(-)
Christoph Hellwig
reviewerPATCH 1/9 Documentation/hdio: fix up obscure bd_contains references
bd_contains is an implementation detail and should not be mentioned in a userspace API documentation.
--- Documentation/userspace-api/ioctl/hdio.rst | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-)
Documentation/userspace-api/ioctl/hdio.rst +12 -12
@@ -181,7 +181,7 @@ HDIO_SET_UNMASKINTR error return: - - EINVAL (bdev != bdev->bd_contains) (not sure what this means) + - EINVAL Called on a partition instead of the whole disk device - EACCES Access denied: requires CAP_SYS_ADMIN - EINVAL value out of range [0 1] - EBUSY Controller busy
@@ -231,7 +231,7 @@ HDIO_SET_MULTCOUNT error return: - - EINVAL (bdev != bdev->bd_contains) (not sure what this means) + - EINVAL Called on a partition instead of the whole disk device - EACCES Access denied: requires CAP_SYS_ADMIN - EINVAL value out of range supported by disk. - EBUSY Controller busy or blockmode already set.
@@ -295,7 +295,7 @@ HDIO_GET_IDENTITY the ATA specification. error returns: - - EINVAL (bdev != bdev->bd_contains) (not sure what this means) + - EINVAL Called on a partition instead of the whole disk device - ENOMSG IDENTIFY DEVICE information not available notes:
@@ -355,7 +355,7 @@ HDIO_SET_KEEPSETTINGS error return: - - EINVAL (bdev != bdev->bd_contains) (not sure what this means) + - EINVAL Called on a partition instead of the whole disk device - EACCES Access denied: requires CAP_SYS_ADMIN - EINVAL value out of range [0 1] - EBUSY Controller busy
@@ -1055,7 +1055,7 @@ HDIO_SET_32BIT error return: - - EINVAL (bdev != bdev->bd_contains) (not sure what this means) + - EINVAL Called on a partition instead of the whole disk device - EACCES Access denied: requires CAP_SYS_ADMIN - EINVAL value out of range [0 3] - EBUSY Controller busy
@@ -1085,7 +1085,7 @@ HDIO_SET_NOWERR error return: - - EINVAL (bdev != bdev->bd_contains) (not sure what this means) + - EINVAL Called on a partition instead of the whole disk device - EACCES Access denied: requires CAP_SYS_ADMIN - EINVAL value out of range [0 1] - EBUSY Controller busy
@@ -1113,7 +1113,7 @@ HDIO_SET_DMA error return: - - EINVAL (bdev != bdev->bd_contains) (not sure what this means) + - EINVAL Called on a partition instead of the whole disk device - EACCES Access denied: requires CAP_SYS_ADMIN - EINVAL value out of range [0 1] - EBUSY Controller busy
@@ -1141,7 +1141,7 @@ HDIO_SET_PIO_MODE error return: - - EINVAL (bdev != bdev->bd_contains) (not sure what this means) + - EINVAL Called on a partition instead of the whole disk device - EACCES Access denied: requires CAP_SYS_ADMIN - EINVAL value out of range [0 255] - EBUSY Controller busy
@@ -1237,7 +1237,7 @@ HDIO_SET_WCACHE error return: - - EINVAL (bdev != bdev->bd_contains) (not sure what this means) + - EINVAL Called on a partition instead of the whole disk device - EACCES Access denied: requires CAP_SYS_ADMIN - EINVAL value out of range [0 1] - EBUSY Controller busy
@@ -1265,7 +1265,7 @@ HDIO_SET_ACOUSTIC error return: - - EINVAL (bdev != bdev->bd_contains) (not sure what this means) + - EINVAL Called on a partition instead of the whole disk device - EACCES Access denied: requires CAP_SYS_ADMIN - EINVAL value out of range [0 254] - EBUSY Controller busy
@@ -1305,7 +1305,7 @@ HDIO_SET_ADDRESS error return: - - EINVAL (bdev != bdev->bd_contains) (not sure what this means) + - EINVAL Called on a partition instead of the whole disk device - EACCES Access denied: requires CAP_SYS_ADMIN - EINVAL value out of range [0 2] - EBUSY Controller busy
@@ -1331,7 +1331,7 @@ HDIO_SET_IDE_SCSI error return: - - EINVAL (bdev != bdev->bd_contains) (not sure what this means) + - EINVAL Called on a partition instead of the whole disk device - EACCES Access denied: requires CAP_SYS_ADMIN - EINVAL value out of range [0 1] - EBUSY Controller busy
Signature · 1 line
2.28.0
Christoph Hellwig
reviewerPATCH 2/9 block: add a bdev_is_partition helper
In reply to Christoph HellwigAdd a littler helper to make the somewhat arcane bd_contains checks a little more obvious.
--- block/blk-lib.c | 2 +- block/ioctl.c | 4 ++-- block/scsi_ioctl.c | 2 +- drivers/ide/ide-ioctls.c | 4 ++-- drivers/md/dm-table.c | 2 +- drivers/mmc/core/block.c | 2 +- drivers/s390/block/dasd_ioctl.c | 8 ++++---- fs/nfsd/blocklayout.c | 4 ++-- include/linux/blkdev.h | 9 +++++++-- kernel/trace/blktrace.c | 2 +- 10 files changed, 22 insertions(+), 17 deletions(-)
block/blk-lib.c +1 -1
@@ -64,7 +64,7 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,return -EINVAL ;/* In case the discard request is in a partition */ -if (bdev->bd_partno) +if (bdev_is_partition (bdev)) part_offset = bdev->bd_part->start_sect;while (nr_sects) {
block/ioctl.c +2 -2
@@ -23,7 +23,7 @@ static int blkpg_do_ioctl(struct block_device *bdev,return -EACCES ;if (copy_from_user (&p, upart,sizeof (struct blkpg_partition )))return -EFAULT ; -if (bdev != bdev->bd_contains) +if (bdev_is_partition (bdev))return -EINVAL ;if (p.pno <=0 )
@@ -94,7 +94,7 @@ static int blkdev_reread_part(struct block_device *bdev) {int ret; -if (!disk_part_scan_enabled (bdev->bd_disk) || bdev != bdev->bd_contains) +if (!disk_part_scan_enabled (bdev->bd_disk) ||bdev_is_partition (bdev))return -EINVAL ;if (!capable (CAP_SYS_ADMIN ))return -EACCES ;
block/scsi_ioctl.c +1 -1
@@ -854,7 +854,7 @@ EXPORT_SYMBOL(scsi_cmd_ioctl);int scsi_verify_blk_ioctl (struct block_device *bd,unsigned int cmd) { -if (bd && bd == bd->bd_contains) +if (bd && !bdev_is_partition (bd))return 0 ;if (capable (CAP_SYS_RAWIO ))
drivers/ide/ide-ioctls.c +2 -2
@@ -49,7 +49,7 @@ int ide_setting_ioctl(ide_drive_t *drive, struct block_device *bdev,return err >=0 ?put_user_long (err, arg) : err; set_val: -if (bdev != bdev->bd_contains) +if (bdev_is_partition (bdev)) err = -EINVAL ;else {if (!capable (CAP_SYS_ADMIN ))
@@ -257,7 +257,7 @@ int generic_ide_ioctl(ide_drive_t *drive, struct block_device *bdev,switch (cmd) {case HDIO_OBSOLETE_IDENTITY :case HDIO_GET_IDENTITY : -if (bdev != bdev->bd_contains) +if (bdev_is_partition (bdev))return -EINVAL ;return ide_get_identity_ioctl (drive, cmd, argp);case HDIO_GET_NICE :
drivers/md/dm-table.c +1 -1
@@ -903,7 +903,7 @@ static int device_is_rq_stackable(struct dm_target *ti, struct dm_dev *dev,struct request_queue *q =bdev_get_queue (bdev);/* request-based cannot stack on partitions! */ -if (bdev != bdev->bd_contains) +if (bdev_is_partition (bdev))return false;return queue_is_mq (q);
drivers/mmc/core/block.c +1 -1
@@ -723,7 +723,7 @@ static int mmc_blk_check_blkdev(struct block_device *bdev)* whole block device, not on a partition. This prevents overspray * between sibling partitions. */ -if ((!capable (CAP_SYS_RAWIO )) || (bdev != bdev->bd_contains)) +if (!capable (CAP_SYS_RAWIO ) ||bdev_is_partition (bdev))return -EPERM ;return 0 ; }
drivers/s390/block/dasd_ioctl.c +4 -4
@@ -277,7 +277,7 @@ dasd_ioctl_format(struct block_device *bdev, void __user *argp)dasd_put_device (base);return -EFAULT ; } -if (bdev != bdev->bd_contains) { +if (bdev_is_partition (bdev)) {pr_warn ("%s: The specified DASD is a partition and cannot be formatted\n" ,dev_name (&base->cdev->dev));dasd_put_device (base);
@@ -304,7 +304,7 @@ static int dasd_ioctl_check_format(struct block_device *bdev, void __user *argp) base =dasd_device_from_gendisk (bdev->bd_disk);if (!base)return -ENODEV ; -if (bdev != bdev->bd_contains) { +if (bdev_is_partition (bdev)) {pr_warn ("%s: The specified DASD is a partition and cannot be checked\n" ,dev_name (&base->cdev->dev)); rc = -EINVAL ;
@@ -362,7 +362,7 @@ static int dasd_ioctl_release_space(struct block_device *bdev, void __user *argp rc = -EROFS ; goto out_err; } -if (bdev != bdev->bd_contains) { +if (bdev_is_partition (bdev)) {pr_warn ("%s: The specified DASD is a partition and tracks cannot be released\n" ,dev_name (&base->cdev->dev)); rc = -EINVAL ;
@@ -540,7 +540,7 @@ dasd_ioctl_set_ro(struct block_device *bdev, void __user *argp)if (!capable (CAP_SYS_ADMIN ))return -EACCES ; -if (bdev != bdev->bd_contains) +if (bdev_is_partition (bdev))// ro setting is not allowed for partitions return -EINVAL ;if (get_user (intval, (int __user *)argp))
fs/nfsd/blocklayout.c +2 -2
@@ -170,7 +170,7 @@ nfsd4_block_proc_getdeviceinfo(struct super_block *sb,struct nfs4_client *clp, struct nfsd4_getdeviceinfo *gdp) { -if (sb->s_bdev != sb->s_bdev->bd_contains) + if (bdev_is_partition(sb->s_bdev)) return nfserr_inval; return nfserrno(nfsd4_block_get_device_info_simple(sb, gdp)); }
@@ -382,7 +382,7 @@ nfsd4_scsi_proc_getdeviceinfo(struct super_block *sb,struct nfs4_client *clp, struct nfsd4_getdeviceinfo *gdp) { -if (sb->s_bdev != sb->s_bdev->bd_contains) + if (bdev_is_partition(sb->s_bdev)) return nfserr_inval; return nfserrno(nfsd4_block_get_device_info_scsi(sb, clp, gdp)); }
include/linux/blkdev.h +7 -2
@@ -1341,6 +1341,11 @@ static inline int sb_issue_zeroout(struct super_block *sb, sector_t block,extern int blk_verify_command (unsigned char *cmd,fmode_t mode); +static inline bool bdev_is_partition (struct block_device *bdev) +{ +return bdev->bd_partno; +} +enum blk_default_limits {BLK_MAX_SEGMENTS =128 ,BLK_SAFE_MAX_SECTORS =255 ,
@@ -1457,7 +1462,7 @@ static inline int bdev_alignment_offset(struct block_device *bdev)if (q->limits.misaligned)return -1 ; -if (bdev != bdev->bd_contains) +if (bdev_is_partition (bdev))return queue_limit_alignment_offset (&q->limits, bdev->bd_part->start_sect);return q->limits.alignment_offset;
@@ -1498,7 +1503,7 @@ static inline int bdev_discard_alignment(struct block_device *bdev) {struct request_queue *q =bdev_get_queue (bdev); -if (bdev != bdev->bd_contains) +if (bdev_is_partition (bdev))return queue_limit_discard_alignment (&q->limits, bdev->bd_part->start_sect);return q->limits.discard_alignment;
kernel/trace/blktrace.c +1 -1
@@ -527,7 +527,7 @@ static int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,* and scsi-generic block devices we create a temporary new debugfs * directory that will be removed once the trace ends. */ -if (bdev && bdev == bdev->bd_contains) +if (bdev && !bdev_is_partition (bdev)) dir = q->debugfs_dir;else bt->dir = dir =debugfs_create_dir (buts->name, blk_debugfs_root);
Signature · 1 line
2.28.0
Re: [PATCH 2/9] block: add a bdev_is_partition helper
Quoted 5 lines · Christoph Hellwig
Add a littler helper to make the somewhat arcane
bd_containschecks a little more obvious.Signed-off-by Christoph Hellwig <[email protected]>
Not sure why we have both "bd_contains" and "bd_partno", nevertheless, feel free to add:
Kind regards
Uffe
Quoted 221 lines
--- block/blk-lib.c | 2 +- block/ioctl.c | 4 ++-- block/scsi_ioctl.c | 2 +- drivers/ide/ide-ioctls.c | 4 ++-- drivers/md/dm-table.c | 2 +- drivers/mmc/core/block.c | 2 +- drivers/s390/block/dasd_ioctl.c | 8 ++++---- fs/nfsd/blocklayout.c | 4 ++-- include/linux/blkdev.h | 9 +++++++-- kernel/trace/blktrace.c | 2 +- 10 files changed, 22 insertions(+), 17 deletions(-)block/blk-lib.c +1
-1@@ -64,7 +64,7 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,return -EINVAL ;/* In case the discard request is in a partition */ -if (bdev->bd_partno) +if (bdev_is_partition (bdev)) part_offset = bdev->bd_part->start_sect;while (nr_sects) {block/ioctl.c +2
-2@@ -23,7 +23,7 @@ static int blkpg_do_ioctl(struct block_device *bdev,return -EACCES ;if (copy_from_user (&p, upart,sizeof (struct blkpg_partition )))return -EFAULT ; -if (bdev != bdev->bd_contains) +if (bdev_is_partition (bdev))return -EINVAL ;if (p.pno <=0 )@@ -94,7 +94,7 @@ static int blkdev_reread_part(struct block_device *bdev) {int ret; -if (!disk_part_scan_enabled (bdev->bd_disk) || bdev != bdev->bd_contains) +if (!disk_part_scan_enabled (bdev->bd_disk) ||bdev_is_partition (bdev))return -EINVAL ;if (!capable (CAP_SYS_ADMIN ))return -EACCES ;block/scsi_ioctl.c +1
-1@@ -854,7 +854,7 @@ EXPORT_SYMBOL(scsi_cmd_ioctl);int scsi_verify_blk_ioctl (struct block_device *bd,unsigned int cmd) { -if (bd && bd == bd->bd_contains) +if (bd && !bdev_is_partition (bd))return 0 ;if (capable (CAP_SYS_RAWIO ))drivers/ide/ide-ioctls.c +2
-2@@ -49,7 +49,7 @@ int ide_setting_ioctl(ide_drive_t *drive, struct block_device *bdev,return err >=0 ?put_user_long (err, arg) : err; set_val: -if (bdev != bdev->bd_contains) +if (bdev_is_partition (bdev)) err = -EINVAL ;else {if (!capable (CAP_SYS_ADMIN ))@@ -257,7 +257,7 @@ int generic_ide_ioctl(ide_drive_t *drive, struct block_device *bdev,switch (cmd) {case HDIO_OBSOLETE_IDENTITY :case HDIO_GET_IDENTITY : -if (bdev != bdev->bd_contains) +if (bdev_is_partition (bdev))return -EINVAL ;return ide_get_identity_ioctl (drive, cmd, argp);case HDIO_GET_NICE :drivers/md/dm-table.c +1
-1@@ -903,7 +903,7 @@ static int device_is_rq_stackable(struct dm_target *ti, struct dm_dev *dev,struct request_queue *q =bdev_get_queue (bdev);/* request-based cannot stack on partitions! */ -if (bdev != bdev->bd_contains) +if (bdev_is_partition (bdev))return false;return queue_is_mq (q);drivers/mmc/core/block.c +1
-1@@ -723,7 +723,7 @@ static int mmc_blk_check_blkdev(struct block_device *bdev)* whole block device, not on a partition. This prevents overspray * between sibling partitions. */ -if ((!capable (CAP_SYS_RAWIO )) || (bdev != bdev->bd_contains)) +if (!capable (CAP_SYS_RAWIO ) ||bdev_is_partition (bdev))return -EPERM ;return 0 ; }drivers/s390/block/dasd_ioctl.c +4
-4@@ -277,7 +277,7 @@ dasd_ioctl_format(struct block_device *bdev, void __user *argp)dasd_put_device (base);return -EFAULT ; } -if (bdev != bdev->bd_contains) { +if (bdev_is_partition (bdev)) {pr_warn ("%s: The specified DASD is a partition and cannot be formatted\n" ,dev_name (&base->cdev->dev));dasd_put_device (base);@@ -304,7 +304,7 @@ static int dasd_ioctl_check_format(struct block_device *bdev, void __user *argp) base =dasd_device_from_gendisk (bdev->bd_disk);if (!base)return -ENODEV ; -if (bdev != bdev->bd_contains) { +if (bdev_is_partition (bdev)) {pr_warn ("%s: The specified DASD is a partition and cannot be checked\n" ,dev_name (&base->cdev->dev)); rc = -EINVAL ;@@ -362,7 +362,7 @@ static int dasd_ioctl_release_space(struct block_device *bdev, void __user *argp rc = -EROFS ; goto out_err; } -if (bdev != bdev->bd_contains) { +if (bdev_is_partition (bdev)) {pr_warn ("%s: The specified DASD is a partition and tracks cannot be released\n" ,dev_name (&base->cdev->dev)); rc = -EINVAL ;@@ -540,7 +540,7 @@ dasd_ioctl_set_ro(struct block_device *bdev, void __user *argp)if (!capable (CAP_SYS_ADMIN ))return -EACCES ; -if (bdev != bdev->bd_contains) +if (bdev_is_partition (bdev))// ro setting is not allowed for partitions return -EINVAL ;if (get_user (intval, (int __user *)argp))fs/nfsd/blocklayout.c +2
-2@@ -170,7 +170,7 @@ nfsd4_block_proc_getdeviceinfo(struct super_block *sb,struct nfs4_client *clp, struct nfsd4_getdeviceinfo *gdp) { -if (sb->s_bdev != sb->s_bdev->bd_contains) + if (bdev_is_partition(sb->s_bdev)) return nfserr_inval; return nfserrno(nfsd4_block_get_device_info_simple(sb, gdp)); }@@ -382,7 +382,7 @@ nfsd4_scsi_proc_getdeviceinfo(struct super_block *sb,struct nfs4_client *clp, struct nfsd4_getdeviceinfo *gdp) { -if (sb->s_bdev != sb->s_bdev->bd_contains) + if (bdev_is_partition(sb->s_bdev)) return nfserr_inval; return nfserrno(nfsd4_block_get_device_info_scsi(sb, clp, gdp)); }include/linux/blkdev.h +7
-2@@ -1341,6 +1341,11 @@ static inline int sb_issue_zeroout(struct super_block *sb, sector_t block,extern int blk_verify_command (unsigned char *cmd,fmode_t mode); +static inline bool bdev_is_partition (struct block_device *bdev) +{ +return bdev->bd_partno; +} +enum blk_default_limits {BLK_MAX_SEGMENTS =128 ,BLK_SAFE_MAX_SECTORS =255 ,@@ -1457,7 +1462,7 @@ static inline int bdev_alignment_offset(struct block_device *bdev)if (q->limits.misaligned)return -1 ; -if (bdev != bdev->bd_contains) +if (bdev_is_partition (bdev))return queue_limit_alignment_offset (&q->limits, bdev->bd_part->start_sect);return q->limits.alignment_offset;@@ -1498,7 +1503,7 @@ static inline int bdev_discard_alignment(struct block_device *bdev) {struct request_queue *q =bdev_get_queue (bdev); -if (bdev != bdev->bd_contains) +if (bdev_is_partition (bdev))return queue_limit_discard_alignment (&q->limits, bdev->bd_part->start_sect);return q->limits.discard_alignment;kernel/trace/blktrace.c +1
-2@@ -527,7 +527,7 @@ static int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,* and scsi-generic block devices we create a temporary new debugfs * directory that will be removed once the trace ends. */ -if (bdev && bdev == bdev->bd_contains) +if (bdev && !bdev_is_partition (bdev)) dir = q->debugfs_dir;else bt->dir = dir =debugfs_create_dir (buts->name, blk_debugfs_root); --2.28.0
Christoph Hellwig
reviewerRe: [PATCH 2/9] block: add a bdev_is_partition helper
Quoted 9 lines · Ulf Hansson
Quoted 5 lines · Christoph Hellwig
Add a littler helper to make the somewhat arcane
bd_containschecks a little more obvious.Signed-off-by Christoph Hellwig <[email protected]>Not sure why we have both "
bd_contains" and "bd_partno", nevertheless, feel free to add:
Right now both are needed for how blkdev_get/put work. But I plan to eventual kill off bd_contains after some major surgery to that code.
Christoph Hellwig
reviewerPATCH 3/9 md: compare bd_disk instead of bd_contains
In reply to Christoph HellwigTo check for partitions of the same disk bd_contains works as well, but bd_disk is way more obvious.
--- drivers/md/md.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/md/md.c +3 -4
@@ -2322,8 +2322,7 @@ static int match_mddev_units(struct mddev *mddev1, struct mddev *mddev2)test_bit (Journal, &rdev2->flags) || rdev2->raid_disk == -1) continue; -if (rdev->bdev->bd_contains == - rdev2->bdev->bd_contains) { +if (rdev->bdev->bd_disk == rdev2->bdev->bd_disk) {rcu_read_unlock ();return 1 ; }
@@ -5944,8 +5943,8 @@ int md_run(struct mddev *mddev)rdev_for_each (rdev, mddev)rdev_for_each (rdev2, mddev) {if (rdev < rdev2 && - rdev->bdev->bd_contains == - rdev2->bdev->bd_contains) { + rdev->bdev->bd_disk == + rdev2->bdev->bd_disk) { pr_warn("%s: WARNING: %s appears to be on the same physical disk as %s.\n", mdname(mddev), bdevname(rdev->bdev,b),
Signature · 1 line
2.28.0
Re: [PATCH 3/9] md: compare bd_disk instead of bd_contains
Quoted 5 lines · Christoph Hellwig
To check for partitions of the same disk
bd_containsworks as well, butbd_diskis way more obvious.Signed-off-by Christoph Hellwig <[email protected]>
Quoted 32 lines
--- drivers/md/md.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)drivers/md/md.c +3
-5@@ -2322,8 +2322,7 @@ static int match_mddev_units(struct mddev *mddev1, struct mddev *mddev2)test_bit (Journal, &rdev2->flags) || rdev2->raid_disk == -1) continue; -if (rdev->bdev->bd_contains == - rdev2->bdev->bd_contains) { +if (rdev->bdev->bd_disk == rdev2->bdev->bd_disk) {rcu_read_unlock ();return 1 ; }@@ -5944,8 +5943,8 @@ int md_run(struct mddev *mddev)rdev_for_each (rdev, mddev)rdev_for_each (rdev2, mddev) {if (rdev < rdev2 && - rdev->bdev->bd_contains == - rdev2->bdev->bd_contains) { + rdev->bdev->bd_disk == + rdev2->bdev->bd_disk) { pr_warn("%s: WARNING: %s appears to be on the same physical disk as %s.\n", mdname(mddev), bdevname(rdev->bdev,b), --2.28.0
Christoph Hellwig
reviewerPATCH 4/9 md: don't detour through bd_contains for the gendisk
In reply to Christoph Hellwigbd_disk is set on all block devices, including those for partitions.
--- drivers/md/md.c | 2 +- drivers/md/md.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/md/md.c +1 -1
@@ -8444,7 +8444,7 @@ static int is_mddev_idle(struct mddev *mddev, int init) idle =1 ;rcu_read_lock ();rdev_for_each_rcu (rdev, mddev) { -struct gendisk *disk = rdev->bdev->bd_contains->bd_disk; +struct gendisk *disk = rdev->bdev->bd_disk; 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
drivers/md/md.h +1 -1
@@ -551,7 +551,7 @@ extern void mddev_unlock(struct mddev *mddev);static inline void md_sync_acct (struct block_device *bdev,unsigned long nr_sectors) { -atomic_add (nr_sectors, &bdev->bd_contains->bd_disk->sync_io); +atomic_add (nr_sectors, &bdev->bd_disk->sync_io); }static inline void md_sync_acct_bio (struct bio *bio,unsigned long nr_sectors)
Signature · 1 line
2.28.0
Re: [PATCH 4/9] md: don't detour through bd_contains for the gendisk
Quoted 4 lines · Christoph Hellwig
bd_diskis set on all block devices, including those for partitions.Signed-off-by Christoph Hellwig <[email protected]>
Quoted 34 lines
--- drivers/md/md.c | 2 +- drivers/md/md.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)drivers/md/md.c +1
-1@@ -8444,7 +8444,7 @@ static int is_mddev_idle(struct mddev *mddev, int init) idle =1 ;rcu_read_lock ();rdev_for_each_rcu (rdev, mddev) { -struct gendisk *disk = rdev->bdev->bd_contains->bd_disk; +struct gendisk *disk = rdev->bdev->bd_disk; 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 drivers/md/md.h +1
-2@@ -551,7 +551,7 @@ extern void mddev_unlock(struct mddev *mddev);static inline void md_sync_acct (struct block_device *bdev,unsigned long nr_sectors) { -atomic_add (nr_sectors, &bdev->bd_contains->bd_disk->sync_io); +atomic_add (nr_sectors, &bdev->bd_disk->sync_io); }static inline void md_sync_acct_bio (struct bio *bio,unsigned long nr_sectors) --2.28.0
Christoph Hellwig
reviewerPATCH 5/9 drbd: don't detour through bd_contains for the gendisk
In reply to Christoph Hellwigbd_disk is set on all block devices, including those for partitions.
--- drivers/block/drbd/drbd_receiver.c | 2 +- drivers/block/drbd/drbd_worker.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/block/drbd/drbd_receiver.c +1 -1
@@ -2789,7 +2789,7 @@ bool drbd_rs_should_slow_down(struct drbd_device *device, sector_t sector,bool drbd_rs_c_min_rate_throttle (struct drbd_device *device) { -struct gendisk *disk = device->ldev->backing_bdev->bd_contains->bd_disk; +struct gendisk *disk = device->ldev->backing_bdev->bd_disk;unsigned long db, dt, dbdt;unsigned int c_min_rate;int curr_events;
drivers/block/drbd/drbd_worker.c +1 -1
@@ -1672,7 +1672,7 @@ void drbd_resync_after_changed(struct drbd_device *device)void drbd_rs_controller_reset (struct drbd_device *device) { -struct gendisk *disk = device->ldev->backing_bdev->bd_contains->bd_disk; +struct gendisk *disk = device->ldev->backing_bdev->bd_disk;struct fifo_buffer *plan;atomic_set (&device->rs_sect_in,0 );
Signature · 1 line
2.28.0
Christoph Hellwig
reviewerPATCH 6/9 drbd: don't set ->bd_contains
In reply to Christoph HellwigThe ->bd_contains field is set by __blkdev_get and drivers have no business manipulating it.
--- drivers/block/drbd/drbd_main.c | 2 -- 1 file changed, 2 deletions(-)
drivers/block/drbd/drbd_main.c +0 -2
@@ -2766,8 +2766,6 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsig disk->private_data = device; device->this_bdev =bdget (MKDEV (DRBD_MAJOR , minor)); -/* we have no partitions. we contain only ourselves. */ - device->this_bdev->bd_contains = device->this_bdev;blk_queue_write_cache (q, true, true);/* Setting the max_hw_sectors to an odd value of 8kibyte here
Signature · 1 line
2.28.0
Christoph Hellwig
reviewerPATCH 7/9 target/iblock: fix holder printing in iblock_show_configfs_dev_params
In reply to Christoph Hellwigbd_contains is never NULL for an open block device. In addition ibd_bd is always set to a block device that was exclusively opened by the target code, so the holder is guranteed to be ib_dev as well.
--- drivers/target/target_core_iblock.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/target/target_core_iblock.c +2 -3
@@ -611,9 +611,8 @@ static ssize_t iblock_show_configfs_dev_params(struct se_device *dev, char *b) bl +=sprintf (b + bl," " );if (bd) { bl +=sprintf (b + bl,"Major: %d Minor: %d %s\n" , -MAJOR (bd->bd_dev),MINOR (bd->bd_dev), (!bd->bd_contains) ? -"" : (bd->bd_holder == ib_dev) ? -"CLAIMED: IBLOCK" :"CLAIMED: OS" ); +MAJOR (bd->bd_dev),MINOR (bd->bd_dev), +"CLAIMED: IBLOCK" ); }else { bl +=sprintf (b + bl,"Major: 0 Minor: 0\n" ); }
Signature · 1 line
2.28.0
Christoph Hellwig
reviewerPATCH 8/9 block: use bd_partno in bdevname
In reply to Christoph HellwigNo need to go through the hd_struct to find the partition number.
--- block/genhd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/genhd.c +1 -1
@@ -85,7 +85,7 @@ char *disk_name(struct gendisk *hd, int partno, char *buf)const char *bdevname (struct block_device *bdev,char *buf) { -return disk_name (bdev->bd_disk, bdev->bd_part->partno, buf); +return disk_name (bdev->bd_disk, bdev->bd_partno, buf); }EXPORT_SYMBOL (bdevname);
Signature · 1 line
2.28.0
Christoph Hellwig
reviewerPATCH 9/9 vsprintf: use bd_partno in bdev_name
In reply to Christoph HellwigNo need to go through the hd_struct to find the partition number.
--- lib/vsprintf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
lib/vsprintf.c +2 -2
@@ -940,13 +940,13 @@ char *bdev_name(char *buf, char *end, struct block_device *bdev, hd = bdev->bd_disk; buf =string (buf, end, hd->disk_name, spec); -if (bdev->bd_part->partno) { +if (bdev->bd_partno) {if (isdigit (hd->disk_name[strlen (hd->disk_name)-1 ])) {if (buf < end) *buf ='p' ; buf++; } - buf =number (buf, end, bdev->bd_part->partno, spec); + buf =number (buf, end, bdev->bd_partno, spec); }return buf; }
Signature · 1 line
2.28.0
Christoph Hellwig
reviewerJens,
can you pick this series up?
Quoted 5 lines · Christoph Hellwig
Hi Jens,
this series add a new helepr to check if a struct
block_devicerepresents a parition, and removes most direct access to ->bd_contained from drivers.
Applied, thanks.
Signature · 1 line
Jens Axboe