Linux-Block Archive on lore.kernel.org
 help / color / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>,
	Stefan Haberland <sth@linux.ibm.com>,
	Jan Hoeppner <hoeppner@linux.ibm.com>
Cc: Tejun Heo <tj@kernel.org>,
	linux-block@vger.kernel.org, linux-s390@vger.kernel.org
Subject: [PATCH 10/11] block: simplify diskstats_show
Date: Tue,  6 Apr 2021 08:23:01 +0200
Message-ID: <20210406062303.811835-11-hch@lst.de> (raw)
In-Reply-To: <20210406062303.811835-1-hch@lst.de>

Just use xa_for_each to iterate over the partitions as there is no need
to grab a reference to each partition.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 block/genhd.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/block/genhd.c b/block/genhd.c
index 5726714ef82fcf..cbfe1ff19360b3 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -1236,11 +1236,11 @@ const struct device_type disk_type = {
 static int diskstats_show(struct seq_file *seqf, void *v)
 {
 	struct gendisk *gp = v;
-	struct disk_part_iter piter;
 	struct block_device *hd;
 	char buf[BDEVNAME_SIZE];
 	unsigned int inflight;
 	struct disk_stats stat;
+	unsigned long idx;
 
 	/*
 	if (&disk_to_dev(gp)->kobj.entry == block_class.devices.next)
@@ -1250,8 +1250,10 @@ static int diskstats_show(struct seq_file *seqf, void *v)
 				"\n\n");
 	*/
 
-	disk_part_iter_init(&piter, gp, DISK_PITER_INCL_EMPTY_PART0);
-	while ((hd = disk_part_iter_next(&piter))) {
+	rcu_read_lock();
+	xa_for_each(&gp->part_tbl, idx, hd) {
+		if (bdev_is_partition(hd) && !bdev_nr_sectors(hd))
+			continue;
 		part_stat_read_all(hd, &stat);
 		if (queue_is_mq(gp->queue))
 			inflight = blk_mq_in_flight(gp->queue, hd);
@@ -1294,7 +1296,7 @@ static int diskstats_show(struct seq_file *seqf, void *v)
 						 NSEC_PER_MSEC)
 			);
 	}
-	disk_part_iter_exit(&piter);
+	rcu_read_unlock();
 
 	return 0;
 }
-- 
2.30.1


  parent reply index

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-06  6:22 partition iteration simplifications Christoph Hellwig
2021-04-06  6:22 ` [PATCH 01/11] dasd: use bdev_disk_changed instead of blk_drop_partitions Christoph Hellwig
2021-04-08 14:31   ` Stefan Haberland
2021-04-06  6:22 ` [PATCH 02/11] block: remove invalidate_partition Christoph Hellwig
2021-04-06  6:22 ` [PATCH 03/11] block: move more syncing and invalidation to delete_partition Christoph Hellwig
2021-04-06  6:22 ` [PATCH 04/11] block: refactor blk_drop_partitions Christoph Hellwig
2021-04-06  6:22 ` [PATCH 05/11] block: take bd_mutex around delete_partitions in del_gendisk Christoph Hellwig
2021-04-06  6:22 ` [PATCH 06/11] block: simplify partition removal Christoph Hellwig
2021-04-06  6:22 ` [PATCH 07/11] block: simplify partition_overlaps Christoph Hellwig
2021-04-06  6:22 ` [PATCH 08/11] block: simplify printk_all_partitions Christoph Hellwig
2021-04-06  6:23 ` [PATCH 09/11] block: simplify show_partition Christoph Hellwig
2021-04-06  6:23 ` Christoph Hellwig [this message]
2021-04-06  6:23 ` [PATCH 11/11] block: remove disk_part_iter Christoph Hellwig
2021-04-08 16:24 ` partition iteration simplifications Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210406062303.811835-11-hch@lst.de \
    --to=hch@lst.de \
    --cc=axboe@kernel.dk \
    --cc=hoeppner@linux.ibm.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=sth@linux.ibm.com \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux-Block Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-block/0 linux-block/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-block linux-block/ https://lore.kernel.org/linux-block \
		linux-block@vger.kernel.org
	public-inbox-index linux-block

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-block


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git