All of lore.kernel.org
 help / color / mirror / Atom feed
From: Caleb Sander Mateos <csander@purestorage.com>
To: Ming Lei <tom.leiming@gmail.com>, Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
	Caleb Sander Mateos <csander@purestorage.com>
Subject: [PATCH 7.2 1/2] blk-mq: introduce blk_rq_has_data()
Date: Wed, 13 May 2026 15:18:45 -0600	[thread overview]
Message-ID: <20260513211846.1956810-2-csander@purestorage.com> (raw)
In-Reply-To: <20260513211846.1956810-1-csander@purestorage.com>

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>
---
 include/linux/blk-mq.h | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h
index 18a2388ba581..4349aefdbc87 100644
--- a/include/linux/blk-mq.h
+++ b/include/linux/blk-mq.h
@@ -1102,10 +1102,11 @@ struct req_iterator {
 		 bio_iter_last(bvec, _iter.iter))
 
 /*
  * 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
  * blk_rq_stats_sectors()	: sectors of the entire request used for stats
  */
@@ -1117,10 +1118,18 @@ static inline sector_t blk_rq_pos(const struct request *rq)
 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)
 		return 0;
 	if (!bio_has_data(rq->bio))	/* dataless requests such as discard */
-- 
2.54.0


  reply	other threads:[~2026-05-13 21:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-13 21:18 [PATCH 7.2 0/2] ublk: optimize ublk_rq_has_data() Caleb Sander Mateos
2026-05-13 21:18 ` Caleb Sander Mateos [this message]
2026-05-14  9:35   ` [PATCH 7.2 1/2] blk-mq: introduce blk_rq_has_data() Ming Lei
2026-05-13 21:18 ` [PATCH 7.2 2/2] ublk: optimize ublk_rq_has_data() Caleb Sander Mateos
2026-05-14  9:36   ` Ming Lei

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260513211846.1956810-2-csander@purestorage.com \
    --to=csander@purestorage.com \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tom.leiming@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.