block: introduce part_[begin|end]_io_acct

These functions can be used to enable iostat for partitions on devices
like md, bcache.

Signed-off-by: Song Liu <songliubraving@fb.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
Song Liu 2020-08-31 15:27:23 -07:00 committed by Jens Axboe
parent 285008501c
commit 7b26410b05
2 changed files with 38 additions and 6 deletions

View file

@ -1324,10 +1324,9 @@ void blk_account_io_start(struct request *rq)
part_stat_unlock(); part_stat_unlock();
} }
unsigned long disk_start_io_acct(struct gendisk *disk, unsigned int sectors, static unsigned long __part_start_io_acct(struct hd_struct *part,
unsigned int op) unsigned int sectors, unsigned int op)
{ {
struct hd_struct *part = &disk->part0;
const int sgrp = op_stat_group(op); const int sgrp = op_stat_group(op);
unsigned long now = READ_ONCE(jiffies); unsigned long now = READ_ONCE(jiffies);
@ -1340,12 +1339,26 @@ unsigned long disk_start_io_acct(struct gendisk *disk, unsigned int sectors,
return now; 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_GPL(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); EXPORT_SYMBOL(disk_start_io_acct);
void disk_end_io_acct(struct gendisk *disk, unsigned int op, static void __part_end_io_acct(struct hd_struct *part, unsigned int op,
unsigned long start_time) unsigned long start_time)
{ {
struct hd_struct *part = &disk->part0;
const int sgrp = op_stat_group(op); const int sgrp = op_stat_group(op);
unsigned long now = READ_ONCE(jiffies); unsigned long now = READ_ONCE(jiffies);
unsigned long duration = now - start_time; unsigned long duration = now - start_time;
@ -1356,6 +1369,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_local_dec(part, in_flight[op_is_write(op)]);
part_stat_unlock(); 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_GPL(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); EXPORT_SYMBOL(disk_end_io_acct);
/* /*

View file

@ -1933,6 +1933,11 @@ unsigned long disk_start_io_acct(struct gendisk *disk, unsigned int sectors,
void disk_end_io_acct(struct gendisk *disk, unsigned int op, void disk_end_io_acct(struct gendisk *disk, unsigned int op,
unsigned long start_time); 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_start_io_acct - start I/O accounting for bio based drivers
* @bio: bio to start account for * @bio: bio to start account for