]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
block: export passthrough stats enabled
authorKeith Busch <kbusch@kernel.org>
Thu, 28 May 2026 01:00:40 +0000 (18:00 -0700)
committerJens Axboe <axboe@kernel.dk>
Thu, 28 May 2026 15:35:38 +0000 (09:35 -0600)
A user can enable io accounting for passthrough requests, so export the
helper that checks if the request should be tracked. This will enable
stacking drivers to to report iostats for passthrough workloads. Since
the stacking request_queue may not be the one providing the request, the
API has to add a parameter for the caller to specify which one to check.

Reviewed-by: Nilay Shroff <nilay@linux.ibm.com>
Reviewed-by: Nitesh Shetty <nj.shetty@samsung.com>
Signed-off-by: Keith Busch <kbusch@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Link: https://patch.msgid.link/20260528010041.1533124-2-kbusch@meta.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk-mq.c
include/linux/blk-mq.h

index ade9d3a89743912ee2cd18e8398f2af3acb97035..629e16003eb7086bf547444092add0e9a6141fc4 100644 (file)
@@ -1088,43 +1088,13 @@ static inline void blk_account_io_done(struct request *req, u64 now)
        }
 }
 
-static inline bool blk_rq_passthrough_stats(struct request *req)
-{
-       struct bio *bio = req->bio;
-
-       if (!blk_queue_passthrough_stat(req->q))
-               return false;
-
-       /* Requests without a bio do not transfer data. */
-       if (!bio)
-               return false;
-
-       /*
-        * Stats are accumulated in the bdev, so must have one attached to a
-        * bio to track stats. Most drivers do not set the bdev for passthrough
-        * requests, but nvme is one that will set it.
-        */
-       if (!bio->bi_bdev)
-               return false;
-
-       /*
-        * We don't know what a passthrough command does, but we know the
-        * payload size and data direction. Ensuring the size is aligned to the
-        * block size filters out most commands with payloads that don't
-        * represent sector access.
-        */
-       if (blk_rq_bytes(req) & (bdev_logical_block_size(bio->bi_bdev) - 1))
-               return false;
-       return true;
-}
-
 static inline void blk_account_io_start(struct request *req)
 {
        trace_block_io_start(req);
 
        if (!blk_queue_io_stat(req->q))
                return;
-       if (blk_rq_is_passthrough(req) && !blk_rq_passthrough_stats(req))
+       if (blk_rq_is_passthrough(req) && !blk_rq_passthrough_stats(req, req->q))
                return;
 
        req->rq_flags |= RQF_IO_STAT;
index 24b4160aeaad332e35de9825134434a9aa59145f..af878597afb8ca77a6ddfc131afca5f18fe3d574 100644 (file)
@@ -1252,4 +1252,44 @@ static inline int blk_rq_map_sg(struct request *rq, struct scatterlist *sglist)
 }
 void blk_dump_rq_flags(struct request *, char *);
 
+/**
+ * blk_rq_passthrough_stats - check if this request should account stats
+ * @rq: request to check
+ * @q: the queue accumulating the stats
+ *
+ * Note, @q does not necessarily need to be the request_queue that provides
+ * @rq.
+ *
+ * Return: true if stats should be accounted.
+ */
+static inline bool blk_rq_passthrough_stats(struct request *rq,
+                                           struct request_queue *q)
+{
+       struct bio *bio = rq->bio;
+
+       if (!blk_queue_passthrough_stat(q))
+               return false;
+
+       /* Requests without a bio do not transfer data. */
+       if (!bio)
+               return false;
+
+       /*
+        * Stats are accumulated in the bdev, so must have one attached to a
+        * bio to track stats. Most drivers do not set the bdev for passthrough
+        * requests, but nvme is one that will set it.
+        */
+       if (!bio->bi_bdev)
+               return false;
+
+       /*
+        * We don't know what a passthrough command does, but we know the
+        * payload size and data direction. Ensuring the size is aligned to the
+        * block size filters out most commands with payloads that don't
+        * represent sector access.
+        */
+       if (blk_rq_bytes(rq) & (bdev_logical_block_size(bio->bi_bdev) - 1))
+               return false;
+       return true;
+}
 #endif /* BLK_MQ_H */