* [PATCH 1/7] block: remove the alignment_offset field from struct hd_struct
2020-08-31 18:02 misc cleanups Christoph Hellwig
@ 2020-08-31 18:02 ` Christoph Hellwig
2020-08-31 18:02 ` [PATCH 2/7] block: remove the discard_alignment " Christoph Hellwig
` (6 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Christoph Hellwig @ 2020-08-31 18:02 UTC (permalink / raw)
To: axboe; +Cc: linux-block
The alignment offset is only used in slow path callers, so just calculate
it on the fly.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/partitions/core.c | 7 ++++---
include/linux/blkdev.h | 5 ++---
include/linux/genhd.h | 1 -
3 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/block/partitions/core.c b/block/partitions/core.c
index 328a2cb7875ba1..4baa065eef7864 100644
--- a/block/partitions/core.c
+++ b/block/partitions/core.c
@@ -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;
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 0a1730b30ad210..ba1f5f5e11c647 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -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;
}
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index 39025dc0397c04..bfa411c80dbbf8 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -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;
--
2.28.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 2/7] block: remove the discard_alignment field from struct hd_struct
2020-08-31 18:02 misc cleanups Christoph Hellwig
2020-08-31 18:02 ` [PATCH 1/7] block: remove the alignment_offset field from struct hd_struct Christoph Hellwig
@ 2020-08-31 18:02 ` Christoph Hellwig
2020-08-31 18:02 ` [PATCH 3/7] block: remove an outdated comment on the bd_dev field Christoph Hellwig
` (5 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Christoph Hellwig @ 2020-08-31 18:02 UTC (permalink / raw)
To: axboe; +Cc: linux-block
The alignment offset is only used in slow path callers, so just calculate
it on the fly.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/partitions/core.c | 7 ++++---
include/linux/blkdev.h | 4 ++--
include/linux/genhd.h | 1 -
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/block/partitions/core.c b/block/partitions/core.c
index 4baa065eef7864..1150474caca0cf 100644
--- a/block/partitions/core.c
+++ b/block/partitions/core.c
@@ -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);
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index ba1f5f5e11c647..d0d61bc81615b2 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -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;
}
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index bfa411c80dbbf8..9ea2ca31c278ea 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -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;
--
2.28.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 3/7] block: remove an outdated comment on the bd_dev field
2020-08-31 18:02 misc cleanups Christoph Hellwig
2020-08-31 18:02 ` [PATCH 1/7] block: remove the alignment_offset field from struct hd_struct Christoph Hellwig
2020-08-31 18:02 ` [PATCH 2/7] block: remove the discard_alignment " Christoph Hellwig
@ 2020-08-31 18:02 ` Christoph Hellwig
2020-08-31 18:02 ` [PATCH 4/7] block: move the devcgroup_inode_permission call to blkdev_get Christoph Hellwig
` (4 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Christoph Hellwig @ 2020-08-31 18:02 UTC (permalink / raw)
To: axboe; +Cc: linux-block
kdev_t is long gone, so we don't need to comment a field isn't one..
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
include/linux/blk_types.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
index 63a39e47fc6047..59d9150165c490 100644
--- a/include/linux/blk_types.h
+++ b/include/linux/blk_types.h
@@ -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;
--
2.28.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 4/7] block: move the devcgroup_inode_permission call to blkdev_get
2020-08-31 18:02 misc cleanups Christoph Hellwig
` (2 preceding siblings ...)
2020-08-31 18:02 ` [PATCH 3/7] block: remove an outdated comment on the bd_dev field Christoph Hellwig
@ 2020-08-31 18:02 ` Christoph Hellwig
2020-08-31 18:02 ` [PATCH 5/7] block: cleanup __alloc_disk_node Christoph Hellwig
` (3 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Christoph Hellwig @ 2020-08-31 18:02 UTC (permalink / raw)
To: axboe; +Cc: linux-block
devcgroup_inode_permission is never called for the recusive case, so
move it out into blkdev_get.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/block_dev.c | 36 +++++++++++++++++-------------------
1 file changed, 17 insertions(+), 19 deletions(-)
diff --git a/fs/block_dev.c b/fs/block_dev.c
index 08158bb2e76c85..990e97bcbeaf0d 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -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);
--
2.28.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 5/7] block: cleanup __alloc_disk_node
2020-08-31 18:02 misc cleanups Christoph Hellwig
` (3 preceding siblings ...)
2020-08-31 18:02 ` [PATCH 4/7] block: move the devcgroup_inode_permission call to blkdev_get Christoph Hellwig
@ 2020-08-31 18:02 ` Christoph Hellwig
2020-08-31 18:02 ` [PATCH 6/7] block: remove the disk argument to delete_partition Christoph Hellwig
` (2 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Christoph Hellwig @ 2020-08-31 18:02 UTC (permalink / raw)
To: axboe; +Cc: linux-block
Use early returns and goto-based unwinding to simplify the flow a bit.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/genhd.c | 73 +++++++++++++++++++++++++++------------------------
1 file changed, 38 insertions(+), 35 deletions(-)
diff --git a/block/genhd.c b/block/genhd.c
index 99c64641c3148c..055ce9cf18358a 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -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);
--
2.28.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 6/7] block: remove the disk argument to delete_partition
2020-08-31 18:02 misc cleanups Christoph Hellwig
` (4 preceding siblings ...)
2020-08-31 18:02 ` [PATCH 5/7] block: cleanup __alloc_disk_node Christoph Hellwig
@ 2020-08-31 18:02 ` Christoph Hellwig
2020-08-31 18:02 ` [PATCH 7/7] block: remove the unused q argument to part_in_flight and part_in_flight_rw Christoph Hellwig
2020-09-01 15:12 ` misc cleanups Jens Axboe
7 siblings, 0 replies; 12+ messages in thread
From: Christoph Hellwig @ 2020-08-31 18:02 UTC (permalink / raw)
To: axboe; +Cc: linux-block
We can trivially derive the gendisk from the hd_struct.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/blk.h | 2 +-
block/genhd.c | 2 +-
block/partitions/core.c | 9 +++++----
3 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/block/blk.h b/block/blk.h
index 49e2928a163299..3e60ffd3f500e5 100644
--- a/block/blk.h
+++ b/block/blk.h
@@ -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);
diff --git a/block/genhd.c b/block/genhd.c
index 055ce9cf18358a..2055b5bf637a80 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -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);
diff --git a/block/partitions/core.c b/block/partitions/core.c
index 1150474caca0cf..7af3f8796f0a2c 100644
--- a/block/partitions/core.c
+++ b/block/partitions/core.c
@@ -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;
--
2.28.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 7/7] block: remove the unused q argument to part_in_flight and part_in_flight_rw
2020-08-31 18:02 misc cleanups Christoph Hellwig
` (5 preceding siblings ...)
2020-08-31 18:02 ` [PATCH 6/7] block: remove the disk argument to delete_partition Christoph Hellwig
@ 2020-08-31 18:02 ` Christoph Hellwig
2020-09-01 15:12 ` misc cleanups Jens Axboe
7 siblings, 0 replies; 12+ messages in thread
From: Christoph Hellwig @ 2020-08-31 18:02 UTC (permalink / raw)
To: axboe; +Cc: linux-block
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/genhd.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/block/genhd.c b/block/genhd.c
index 2055b5bf637a80..5fc6d82e6c68c4 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -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 "
--
2.28.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: misc cleanups
2020-08-31 18:02 misc cleanups Christoph Hellwig
` (6 preceding siblings ...)
2020-08-31 18:02 ` [PATCH 7/7] block: remove the unused q argument to part_in_flight and part_in_flight_rw Christoph Hellwig
@ 2020-09-01 15:12 ` Jens Axboe
7 siblings, 0 replies; 12+ messages in thread
From: Jens Axboe @ 2020-09-01 15:12 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: linux-block
On 8/31/20 12:02 PM, Christoph Hellwig wrote:
> Hi Jens,
>
> this series has a bunch of misc cleanups that didn't fit any other
> series.
Looks good to me, applied.
--
Jens Axboe
^ permalink raw reply [flat|nested] 12+ messages in thread