]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
blk-mq: introduce blk_rq_has_data()
authorCaleb Sander Mateos <csander@purestorage.com>
Wed, 13 May 2026 21:18:45 +0000 (15:18 -0600)
committerJens Axboe <axboe@kernel.dk>
Fri, 22 May 2026 14:05:33 +0000 (08:05 -0600)
Add blk_rq_has_data(), an analogue of bio_has_data() for struct request.
This skips one dereference relative to bio_has_data(rq->bio).

Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
Reviewed-by: Ming Lei <tom.leiming@gmail.com>
Link: https://patch.msgid.link/20260513211846.1956810-2-csander@purestorage.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
include/linux/blk-mq.h

index 18a2388ba581d060f514d3b130ad01e6b5d2ea20..4349aefdbc87e5fe5a07f6d5af84738a77e73e74 100644 (file)
@@ -1104,6 +1104,7 @@ struct req_iterator {
 /*
  * blk_rq_pos()                        : the current sector
  * blk_rq_bytes()              : bytes left in the entire request
+ * blk_rq_has_data()           : whether the request carries data
  * blk_rq_cur_bytes()          : bytes left in the current segment
  * blk_rq_sectors()            : sectors left in the entire request
  * blk_rq_cur_sectors()                : sectors left in the current segment
@@ -1119,6 +1120,14 @@ static inline unsigned int blk_rq_bytes(const struct request *rq)
        return rq->__data_len;
 }
 
+static inline bool blk_rq_has_data(const struct request *rq)
+{
+       return blk_rq_bytes(rq) &&
+              req_op(rq) != REQ_OP_DISCARD &&
+              req_op(rq) != REQ_OP_SECURE_ERASE &&
+              req_op(rq) != REQ_OP_WRITE_ZEROES;
+}
+
 static inline int blk_rq_cur_bytes(const struct request *rq)
 {
        if (!rq->bio)