diff mbox series

[02/11] block: introduce bio zone helpers

Message ID 20210519025529.707897-3-damien.lemoal@wdc.com (mailing list archive)
State New, archived
Headers show
Series dm: Improve zoned block device support | expand

Commit Message

Damien Le Moal May 19, 2021, 2:55 a.m. UTC
Introduce the helper functions bio_zone_no() and bio_zone_is_seq().
Both are the BIO counterparts of the request helpers blk_rq_zone_no()
and blk_rq_zone_is_seq(), respectively returning the number of the
target zone of a bio and true if the BIO target zone is sequential.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
 include/linux/blkdev.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

Johannes Thumshirn May 19, 2021, 7:17 a.m. UTC | #1
On 19/05/2021 04:56, Damien Le Moal wrote:
> +static inline unsigned int bio_zone_no(struct request_queue *q,
> +				       struct bio *bio)
> +{
> +	return blk_queue_zone_no(q, bio->bi_iter.bi_sector);
> +}
> +
> +static inline unsigned int bio_zone_is_seq(struct request_queue *q,
> +					   struct bio *bio)
> +{
> +	return blk_queue_zone_is_seq(q, bio->bi_iter.bi_sector);
> +}
> +

Can't we derive the queue from the bio via bio->bi_bdev->bd_disk->queue
or would this be too much pointer chasing for a small helper like this?
Chaitanya Kulkarni May 19, 2021, 7:42 a.m. UTC | #2
Sent from my iPhone

> On May 19, 2021, at 12:17 AM, Johannes Thumshirn <Johannes.Thumshirn@wdc.com> wrote:
> 
> On 19/05/2021 04:56, Damien Le Moal wrote:
>> +static inline unsigned int bio_zone_no(struct request_queue *q,
>> +                       struct bio *bio)
>> +{
>> +    return blk_queue_zone_no(q, bio->bi_iter.bi_sector);
>> +}
>> +
>> +static inline unsigned int bio_zone_is_seq(struct request_queue *q,
>> +                       struct bio *bio)
>> +{
>> +    return blk_queue_zone_is_seq(q, bio->bi_iter.bi_sector);
>> +}
>> +
> 
> Can't we derive the queue from the bio via bio->bi_bdev->bd_disk->queue
> or would this be too much pointer chasing for a small helper like this?

We have made such code changes to get rid of separate argument q and derive it from bio for block trace cleanup. Unless there is a strong reason (such as q is not available in this call which I have not looked into), we should avoid passing q as separate argument.
Damien Le Moal May 19, 2021, 8:27 a.m. UTC | #3
On 2021/05/19 16:42, Chaitanya Kulkarni wrote:
>> On May 19, 2021, at 12:17 AM, Johannes Thumshirn <Johannes.Thumshirn@wdc.com> wrote:
>>
>> On 19/05/2021 04:56, Damien Le Moal wrote:
>>> +static inline unsigned int bio_zone_no(struct request_queue *q,
>>> +                       struct bio *bio)
>>> +{
>>> +    return blk_queue_zone_no(q, bio->bi_iter.bi_sector);
>>> +}
>>> +
>>> +static inline unsigned int bio_zone_is_seq(struct request_queue *q,
>>> +                       struct bio *bio)
>>> +{
>>> +    return blk_queue_zone_is_seq(q, bio->bi_iter.bi_sector);
>>> +}
>>> +
>>
>> Can't we derive the queue from the bio via bio->bi_bdev->bd_disk->queue
>> or would this be too much pointer chasing for a small helper like this?
> 
> We have made such code changes to get rid of separate argument q and derive it from bio for block trace cleanup. Unless there is a strong reason (such as q is not available in this call which I have not looked into), we should avoid passing q as separate argument. 

Will fix that in v2.
Christoph Hellwig May 19, 2021, 9:38 a.m. UTC | #4
On Wed, May 19, 2021 at 07:17:04AM +0000, Johannes Thumshirn wrote:
> Can't we derive the queue from the bio via bio->bi_bdev->bd_disk->queue
> or would this be too much pointer chasing for a small helper like this?

Yes, we can should do away with the pointless q argument.
diff mbox series

Patch

diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index f69c75bd6d27..e74ad1252e78 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1008,6 +1008,18 @@  static inline unsigned int blk_rq_stats_sectors(const struct request *rq)
 /* Helper to convert BLK_ZONE_ZONE_XXX to its string format XXX */
 const char *blk_zone_cond_str(enum blk_zone_cond zone_cond);
 
+static inline unsigned int bio_zone_no(struct request_queue *q,
+				       struct bio *bio)
+{
+	return blk_queue_zone_no(q, bio->bi_iter.bi_sector);
+}
+
+static inline unsigned int bio_zone_is_seq(struct request_queue *q,
+					   struct bio *bio)
+{
+	return blk_queue_zone_is_seq(q, bio->bi_iter.bi_sector);
+}
+
 static inline unsigned int blk_rq_zone_no(struct request *rq)
 {
 	return blk_queue_zone_no(rq->q, blk_rq_pos(rq));