diff mbox series

[2/4] block: introduce part_[begin|end]_io_acct

Message ID 20200818070238.1323126-3-songliubraving@fb.com (mailing list archive)
State New, archived
Headers show
Series [1/4] block: expose disk_map_sector_rcu() and hd_struct_put in genhd.h | expand

Commit Message

Song Liu Aug. 18, 2020, 7:02 a.m. UTC
These functions can be used to enable iostat for partitions on devices
like md, bcache.

Signed-off-by: Song Liu <songliubraving@fb.com>
---
 block/blk-core.c       | 20 ++++++++++++++++----
 include/linux/blkdev.h |  5 +++++
 2 files changed, 21 insertions(+), 4 deletions(-)

Comments

Christoph Hellwig Aug. 18, 2020, 7:48 p.m. UTC | #1
On Tue, Aug 18, 2020 at 12:02:36AM -0700, Song Liu wrote:
> These functions can be used to enable iostat for partitions on devices
> like md, bcache.

Please follow a model like bio_start_io_acct - that is pass a bio
for all the input parameters except for the gendisk.  Given that we
don't have anywhere for the part to store that will need another
output paramater.

The end_io function should drop the hd_struct reference as well for
a well rounded API.
diff mbox series

Patch

diff --git a/block/blk-core.c b/block/blk-core.c
index 93104c7470e8a..6603f56804f41 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -1455,10 +1455,9 @@  void blk_account_io_start(struct request *rq)
 	part_stat_unlock();
 }
 
-unsigned long disk_start_io_acct(struct gendisk *disk, unsigned int sectors,
+unsigned long part_start_io_acct(struct hd_struct *part, unsigned int sectors,
 		unsigned int op)
 {
-	struct hd_struct *part = &disk->part0;
 	const int sgrp = op_stat_group(op);
 	unsigned long now = READ_ONCE(jiffies);
 
@@ -1471,12 +1470,18 @@  unsigned long disk_start_io_acct(struct gendisk *disk, unsigned int sectors,
 
 	return now;
 }
+EXPORT_SYMBOL(part_start_io_acct);
+
+unsigned long disk_start_io_acct(struct gendisk *disk, unsigned int sectors,
+		unsigned int op)
+{
+	return part_start_io_acct(&disk->part0, sectors, op);
+}
 EXPORT_SYMBOL(disk_start_io_acct);
 
-void disk_end_io_acct(struct gendisk *disk, unsigned int op,
+void part_end_io_acct(struct hd_struct *part, unsigned int op,
 		unsigned long start_time)
 {
-	struct hd_struct *part = &disk->part0;
 	const int sgrp = op_stat_group(op);
 	unsigned long now = READ_ONCE(jiffies);
 	unsigned long duration = now - start_time;
@@ -1487,6 +1492,13 @@  void disk_end_io_acct(struct gendisk *disk, unsigned int op,
 	part_stat_local_dec(part, in_flight[op_is_write(op)]);
 	part_stat_unlock();
 }
+EXPORT_SYMBOL(part_end_io_acct);
+
+void disk_end_io_acct(struct gendisk *disk, unsigned int op,
+		unsigned long start_time)
+{
+	part_end_io_acct(&disk->part0, op, start_time);
+}
 EXPORT_SYMBOL(disk_end_io_acct);
 
 /*
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 285b59cfc0646..894e55c91e1d8 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1931,6 +1931,11 @@  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 hd_struct *part, unsigned int sectors,
+		unsigned int op);
+void part_end_io_acct(struct hd_struct *part, unsigned int op,
+		unsigned long start_time);
+
 /**
  * bio_start_io_acct - start I/O accounting for bio based drivers
  * @bio:	bio to start account for