misc cleanups
Subsystems (2)
Hi Jens,
this series has a bunch of misc cleanups that didn't fit any other series.
PATCH 1/7 block: remove the alignment_offset field from struct hd_struct
The alignment offset is only used in slow path callers, so just calculate it on the fly.
--- block/partitions/core.c | 7 ++++--- include/linux/blkdev.h | 5 ++--- include/linux/genhd.h | 1 - 3 files changed, 6 insertions(+), 7 deletions(-)
block/partitions/core.c +4 -3
@@ -199,7 +199,10 @@ static ssize_t part_alignment_offset_show(struct device *dev, struct device_attribute *attr, char *buf) { struct hd_struct *p = dev_to_part(dev); -return sprintf (buf,"%llu\n" , (unsigned long long )p->alignment_offset); + +return sprintf (buf,"%u\n" , +queue_limit_alignment_offset (&part_to_disk (p)->queue->limits, + p->start_sect)); } static ssize_t part_discard_alignment_show(struct device *dev,
@@ -397,8 +400,6 @@ static struct hd_struct *add_partition(struct gendisk *disk, int partno, pdev =part_to_dev (p); p->start_sect = start; - p->alignment_offset = -queue_limit_alignment_offset (&disk->queue->limits, start); p->discard_alignment =queue_limit_discard_alignment (&disk->queue->limits, start); p->nr_sects = len;
include/linux/blkdev.h +2 -3
@@ -1456,10 +1456,9 @@ static inline int bdev_alignment_offset(struct block_device *bdev)if (q->limits.misaligned)return -1 ; -if (bdev != bdev->bd_contains) -return bdev->bd_part->alignment_offset; - +return queue_limit_alignment_offset (&q->limits, + bdev->bd_part->start_sect);return q->limits.alignment_offset; }
include/linux/genhd.h +0 -1
@@ -65,7 +65,6 @@ struct hd_struct {struct disk_stats __percpu *dkstats;struct percpu_ref ref; -sector_t alignment_offset;unsigned int discard_alignment;struct device __dev;struct kobject *holder_dir;
Signature · 1 line
2.28.0
PATCH 2/7 block: remove the discard_alignment field from struct hd_struct
In reply to Christoph HellwigThe alignment offset is only used in slow path callers, so just calculate it on the fly.
--- block/partitions/core.c | 7 ++++--- include/linux/blkdev.h | 4 ++-- include/linux/genhd.h | 1 - 3 files changed, 6 insertions(+), 6 deletions(-)
block/partitions/core.c +4 -3
@@ -209,7 +209,10 @@ static ssize_t part_discard_alignment_show(struct device *dev, struct device_attribute *attr, char *buf) { struct hd_struct *p = dev_to_part(dev); -return sprintf (buf,"%u\n" , p->discard_alignment); + +return sprintf (buf,"%u\n" , +queue_limit_discard_alignment (&part_to_disk (p)->queue->limits, + p->start_sect)); } static DEVICE_ATTR(partition, 0444, part_partition_show, NULL);
@@ -400,8 +403,6 @@ static struct hd_struct *add_partition(struct gendisk *disk, int partno, pdev =part_to_dev (p); p->start_sect = start; - p->discard_alignment = -queue_limit_discard_alignment (&disk->queue->limits, start); p->nr_sects = len; p->partno = partno; p->policy =get_disk_ro (disk);
include/linux/blkdev.h +2 -2
@@ -1498,8 +1498,8 @@ static inline int bdev_discard_alignment(struct block_device *bdev)struct request_queue *q =bdev_get_queue (bdev);if (bdev != bdev->bd_contains) -return bdev->bd_part->discard_alignment; - +return queue_limit_discard_alignment (&q->limits, + bdev->bd_part->start_sect);return q->limits.discard_alignment; }
include/linux/genhd.h +0 -1
@@ -65,7 +65,6 @@ struct hd_struct {struct disk_stats __percpu *dkstats;struct percpu_ref ref; -unsigned int discard_alignment;struct device __dev;struct kobject *holder_dir;int policy, partno;
Signature · 1 line
2.28.0
PATCH 3/7 block: remove an outdated comment on the bd_dev field
In reply to Christoph Hellwigkdev_t is long gone, so we don't need to comment a field isn't one..
--- include/linux/blk_types.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/blk_types.h +1 -1
@@ -20,7 +20,7 @@ typedef void (bio_end_io_t) (struct bio *);struct bio_crypt_ctx ;struct block_device { -dev_t bd_dev;/* not a kdev_t - it's a search key */ +dev_t bd_dev;int bd_openers;struct inode * bd_inode;/* will die */ struct super_block * bd_super;
Signature · 1 line
2.28.0
PATCH 4/7 block: move the devcgroup_inode_permission call to blkdev_get
In reply to Christoph Hellwigdevcgroup_inode_permission is never called for the recusive case, so move it out into blkdev_get.
--- fs/block_dev.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-)
fs/block_dev.c +17 -19
@@ -1449,22 +1449,8 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, void *holder,struct gendisk *disk;int ret;int partno; -int perm =0 ;bool first_open = false, unblock_events = true, need_restart; -if (mode &FMODE_READ ) - perm |=MAY_READ ; -if (mode &FMODE_WRITE ) - perm |=MAY_WRITE ; -/* -* hooks: /n/, see "layering violations". -*/ -if (!for_part) { - ret =devcgroup_inode_permission (bdev->bd_inode, perm); -if (ret !=0 ) -return ret; - } - restart: need_restart = false; ret = -ENXIO ;
@@ -1637,12 +1623,24 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, void *holder,*/ int blkdev_get (struct block_device *bdev,fmode_t mode,void *holder) { -int res; +int ret, perm =0 ; - res =__blkdev_get (bdev, mode, holder,0 ); -if (res) -bdput (bdev); -return res; +if (mode &FMODE_READ ) + perm |=MAY_READ ; +if (mode &FMODE_WRITE ) + perm |=MAY_WRITE ; + ret =devcgroup_inode_permission (bdev->bd_inode, perm); +if (ret) + goto bdput; + + ret =__blkdev_get (bdev, mode, holder,0 ); +if (ret) + goto bdput; +return 0 ; + +bdput: +bdput (bdev); +return ret; }EXPORT_SYMBOL (blkdev_get);
Signature · 1 line
2.28.0
PATCH 5/7 block: cleanup __alloc_disk_node
In reply to Christoph HellwigUse early returns and goto-based unwinding to simplify the flow a bit.
--- block/genhd.c | 73 +++++++++++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 35 deletions(-)
block/genhd.c +38 -35
@@ -1729,45 +1729,48 @@ struct gendisk *__alloc_disk_node(int minors, int node_id) } disk =kzalloc_node (sizeof (struct gendisk ),GFP_KERNEL , node_id); -if (disk) { - disk->part0.dkstats = alloc_percpu(struct disk_stats); -if (!disk->part0.dkstats) { -kfree (disk); -return NULL ; - } -init_rwsem (&disk->lookup_sem); - disk->node_id = node_id; -if (disk_expand_part_tbl (disk,0 )) { -free_percpu (disk->part0.dkstats); -kfree (disk); -return NULL ; - } - ptbl =rcu_dereference_protected (disk->part_tbl,1 ); -rcu_assign_pointer (ptbl->part[0 ], &disk->part0); +if (!disk) +return NULL ; -/* -* 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); -kfree (disk); -return NULL ; - } + disk->part0.dkstats = alloc_percpu(struct disk_stats); +if (!disk->part0.dkstats) + goto out_free_disk; - disk->minors = minors; -rand_initialize_disk (disk); -disk_to_dev (disk)->class = &block_class; -disk_to_dev (disk)->type = &disk_type; -device_initialize (disk_to_dev (disk)); +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; } + + 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)) + goto out_free_part0; + + disk->minors = minors; +rand_initialize_disk (disk); +disk_to_dev (disk)->class = &block_class; +disk_to_dev (disk)->type = &disk_type; +device_initialize (disk_to_dev (disk));return disk; + +out_free_part0: +hd_free_part (&disk->part0); +out_free_disk: +kfree (disk); +return NULL ; }EXPORT_SYMBOL (__alloc_disk_node);
Signature · 1 line
2.28.0
PATCH 6/7 block: remove the disk argument to delete_partition
In reply to Christoph HellwigWe can trivially derive the gendisk from the hd_struct.
--- block/blk.h | 2 +- block/genhd.c | 2 +- block/partitions/core.c | 9 +++++---- 3 files changed, 7 insertions(+), 6 deletions(-)
block/blk.h +1 -1
@@ -350,7 +350,7 @@ 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 gendisk *disk,struct hd_struct *part); +void delete_partition (struct hd_struct *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);
block/genhd.c +1 -1
@@ -913,7 +913,7 @@ void del_gendisk(struct gendisk *disk) DISK_PITER_INCL_EMPTY | DISK_PITER_REVERSE);while ((part =disk_part_iter_next (&piter))) {invalidate_partition (disk, part->partno); -delete_partition (disk, part); +delete_partition (part); }disk_part_iter_exit (&piter);
block/partitions/core.c +5 -4
@@ -316,8 +316,9 @@ int hd_ref_init(struct hd_struct *part)* Must be called either with bd_mutex held, before a disk can be opened or * after all disk users are gone. */ -void delete_partition (struct gendisk *disk,struct hd_struct *part) +void delete_partition (struct hd_struct *part) { +struct gendisk *disk =part_to_disk (part);struct disk_part_tbl *ptbl =rcu_dereference_protected (disk->part_tbl,1 );
@@ -325,7 +326,7 @@ void delete_partition(struct gendisk *disk, struct hd_struct *part)* ->part_tbl is referenced in this part's release handler, so * we have to hold the disk device */ -get_device (disk_to_dev (part_to_disk (part))); +get_device (disk_to_dev (disk));rcu_assign_pointer (ptbl->part[part->partno],NULL );kobject_put (part->holder_dir);device_del (part_to_dev (part));
@@ -548,7 +549,7 @@ int bdev_del_partition(struct block_device *bdev, int partno)invalidate_bdev (bdevp);mutex_lock_nested (&bdev->bd_mutex,1 ); -delete_partition (bdev->bd_disk, part); +delete_partition (part);mutex_unlock (&bdev->bd_mutex); ret =0 ;
@@ -629,7 +630,7 @@ int blk_drop_partitions(struct block_device *bdev)disk_part_iter_init (&piter, bdev->bd_disk,DISK_PITER_INCL_EMPTY );while ((part =disk_part_iter_next (&piter))) -delete_partition (bdev->bd_disk, part); +delete_partition (part);disk_part_iter_exit (&piter);return 0 ;
Signature · 1 line
2.28.0
PATCH 7/7 block: remove the unused q argument to part_in_flight and part_in_flight_rw
In reply to Christoph Hellwig--- block/genhd.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
block/genhd.c +5 -7
@@ -110,8 +110,7 @@ static void part_stat_read_all(struct hd_struct *part, struct disk_stats *stat) } } -static unsigned int part_in_flight (struct request_queue *q, -struct hd_struct *part) +static unsigned int part_in_flight (struct hd_struct *part) {unsigned int inflight =0 ;int cpu;
@@ -126,8 +125,7 @@ static unsigned int part_in_flight(struct request_queue *q,return inflight; } -static void part_in_flight_rw (struct request_queue *q,struct hd_struct *part, -unsigned int inflight[2 ]) +static void part_in_flight_rw (struct hd_struct *part,unsigned int inflight[2 ]) {int cpu;
@@ -1301,7 +1299,7 @@ ssize_t part_stat_show(struct device *dev,if (queue_is_mq (q)) inflight =blk_mq_in_flight (q, p);else - inflight =part_in_flight (q, p); + inflight =part_in_flight (p);return sprintf (buf, "%8lu %8lu %8llu %8u "
@@ -1343,7 +1341,7 @@ ssize_t part_inflight_show(struct device *dev, struct device_attribute *attr,if (queue_is_mq (q))blk_mq_in_flight_rw (q, p, inflight);else -part_in_flight_rw (q, p, inflight); +part_in_flight_rw (p, inflight);return sprintf (buf,"%8u %8u\n" , inflight[0 ], inflight[1 ]); }
@@ -1623,7 +1621,7 @@ static int diskstats_show(struct seq_file *seqf, void *v)if (queue_is_mq (gp->queue)) inflight =blk_mq_in_flight (gp->queue, hd);else - inflight =part_in_flight (gp->queue, hd); + inflight =part_in_flight (hd);seq_printf (seqf,"%4d %7d %s " "%lu %lu %lu %u "
Signature · 1 line
2.28.0
Jens Axboe
maintainerQuoted 4 lines · Christoph Hellwig
Hi Jens,
this series has a bunch of misc cleanups that didn't fit any other series.
Looks good to me, applied.
Signature · 1 line
Jens Axboe