diff mbox series

[v2,1/3] block: introduce part_[begin|end]_io_acct

Message ID 20200818222645.952219-2-songliubraving@fb.com (mailing list archive)
State New, archived
Headers show
Series block: improve iostat for md/bcache partitions | expand

Commit Message

Song Liu Aug. 18, 2020, 10:26 p.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       | 39 +++++++++++++++++++++++++++++++++------
 include/linux/blkdev.h |  5 +++++
 2 files changed, 38 insertions(+), 6 deletions(-)

Comments

Christoph Hellwig Aug. 31, 2020, 6:53 a.m. UTC | #1
On Tue, Aug 18, 2020 at 03:26:43PM -0700, Song Liu wrote:
> These functions can be used to enable iostat for partitions on devices
> like md, bcache.
> 
> Signed-off-by: Song Liu <songliubraving@fb.com>

EXPORT_SYMBOL_GPL for new block layer functionality, please.

Otherwise this looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>
Song Liu Aug. 31, 2020, 9:58 p.m. UTC | #2
> On Aug 30, 2020, at 11:53 PM, Christoph Hellwig <hch@infradead.org> wrote:
> 
> On Tue, Aug 18, 2020 at 03:26:43PM -0700, Song Liu wrote:
>> These functions can be used to enable iostat for partitions on devices
>> like md, bcache.
>> 
>> Signed-off-by: Song Liu <songliubraving@fb.com>
> 
> EXPORT_SYMBOL_GPL for new block layer functionality, please.
> 
> Otherwise this looks good:
> 
> Reviewed-by: Christoph Hellwig <hch@lst.de>

Thanks Christoph! Will fix and resend v3.
diff mbox series

Patch

diff --git a/block/blk-core.c b/block/blk-core.c
index 93104c7470e8a..02953e9db3dd0 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 int op)
+static 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,26 @@  unsigned long disk_start_io_acct(struct gendisk *disk, unsigned int sectors,
 
 	return now;
 }
+
+unsigned long part_start_io_acct(struct gendisk *disk, struct hd_struct **part,
+				 struct bio *bio)
+{
+	*part = disk_map_sector_rcu(disk, bio->bi_iter.bi_sector);
+
+	return __part_start_io_acct(*part, bio_sectors(bio), bio_op(bio));
+}
+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,
-		unsigned long start_time)
+static 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 +1500,20 @@  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();
 }
+
+void part_end_io_acct(struct hd_struct *part, struct bio *bio,
+		      unsigned long start_time)
+{
+	__part_end_io_acct(part, bio_op(bio), start_time);
+	hd_struct_put(part);
+}
+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..d2ee868b16a51 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 gendisk *disk, struct hd_struct **part,
+				 struct bio *bio);
+void part_end_io_acct(struct hd_struct *part, struct bio *bio,
+		      unsigned long start_time);
+
 /**
  * bio_start_io_acct - start I/O accounting for bio based drivers
  * @bio:	bio to start account for