From: John Garry Currently diskstats for partitions are never updated: $ ./fio_read nvme1n1p1 # run traffic on /dev/nvme1n1p1 ... $ more /proc/diskstats | grep nvme1 259 2 nvme1c1n1 49857 0 400344 768565 0 0 0 0 0 2334 768565 0 0 0 0 0 0 259 3 nvme1n1 99710 0 800680 1599285 0 0 0 0 0 2346 1599285 0 0 0 0 0 0 259 5 nvme1n1p1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 259 4 nvme1c2n1 49853 0 400336 831472 0 0 0 0 0 2315 831472 0 0 0 0 0 0 This is because we only ever update the diskstats for the multipath disk in nvme_mpath_end_request(), and we never take into account that the original bi_bdev may been a partition of this disk. Functions bdev_start_io_acct() and bdev_start_io_acct() do handle updating diskstats for a partition, in that they also update the whole disk also (if a partition), so use the partition (if applicable) when calling those functions. Change any functionality which used to lookup the gendisk part0 to now lookup the specific gendisk partition. Signed-off-by: John Garry --- drivers/nvme/host/multipath.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c index 75dbb58286a32..5c95a2ab7755f 100644 --- a/drivers/nvme/host/multipath.c +++ b/drivers/nvme/host/multipath.c @@ -144,6 +144,19 @@ void nvme_mpath_start_freeze(struct nvme_subsystem *subsys) blk_freeze_queue_start(h->disk->queue); } +static struct block_device *nvme_to_disk_part(struct gendisk *disk, u8 partno) +{ + struct block_device *bdev; + + /* Quick lookup for whole disk */ + if (!partno) + return disk->part0; + rcu_read_lock(); + bdev = xa_load(&disk->part_tbl, partno); + rcu_read_unlock(); + return bdev; +} + void nvme_failover_req(struct request *req) { struct nvme_ns *ns = req->q->queuedata; @@ -165,8 +178,10 @@ void nvme_failover_req(struct request *req) } spin_lock_irqsave(&ns->head->requeue_lock, flags); - for (bio = req->bio; bio; bio = bio->bi_next) - bio_set_dev(bio, ns->head->disk->part0); + for (bio = req->bio; bio; bio = bio->bi_next) { + bio_set_dev(bio, nvme_to_disk_part(ns->head->disk, + bdev_partno(bio->bi_bdev))); + } blk_steal_bios(&ns->head->requeue_list, req); spin_unlock_irqrestore(&ns->head->requeue_lock, flags); @@ -194,8 +209,9 @@ void nvme_mpath_start_request(struct request *rq) return; nvme_req(rq)->flags |= NVME_MPATH_IO_STATS; - nvme_req(rq)->start_time = bdev_start_io_acct(disk->part0, req_op(rq), - jiffies); + nvme_req(rq)->start_time = bdev_start_io_acct( + nvme_to_disk_part(disk, bdev_partno(rq->part)), + req_op(rq), jiffies); } EXPORT_SYMBOL_GPL(nvme_mpath_start_request); @@ -208,7 +224,8 @@ void nvme_mpath_end_request(struct request *rq) if (!(nvme_req(rq)->flags & NVME_MPATH_IO_STATS)) return; - bdev_end_io_acct(ns->head->disk->part0, req_op(rq), + bdev_end_io_acct(nvme_to_disk_part(ns->head->disk, + bdev_partno(rq->part)), req_op(rq), blk_rq_bytes(rq) >> SECTOR_SHIFT, nvme_req(rq)->start_time); } @@ -549,7 +566,9 @@ static void nvme_ns_head_submit_bio(struct bio *bio) srcu_idx = srcu_read_lock(&head->srcu); ns = nvme_find_path(head); if (likely(ns)) { - bio_set_dev(bio, ns->disk->part0); + bio_set_dev(bio, nvme_to_disk_part(ns->disk, + bdev_partno(bio->bi_bdev))); + /* * Use BIO_REMAPPED to skip bio_check_eod() when this bio * enters submit_bio_noacct() for the per-path device. The EOD -- 2.43.7