diff mbox series

[2/4] block: lift bio_is_zone_append to bio.h

Message ID 20241101052206.437530-3-hch@lst.de (mailing list archive)
State New
Headers show
Series [1/4] block: fix bio_split_rw_at to take zone_write_granularity into account | expand

Commit Message

Christoph Hellwig Nov. 1, 2024, 5:21 a.m. UTC
Make bio_is_zone_append globally available, because file systems need
to use to check for a zone append bio in their end_io handlers to deal
with the block layer emulation.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 block/blk.h         |  9 ---------
 include/linux/bio.h | 17 +++++++++++++++++
 2 files changed, 17 insertions(+), 9 deletions(-)

Comments

Damien Le Moal Nov. 1, 2024, 5:37 a.m. UTC | #1
On 11/1/24 14:21, Christoph Hellwig wrote:
> Make bio_is_zone_append globally available, because file systems need
> to use to check for a zone append bio in their end_io handlers to deal
> with the block layer emulation.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Looks good (one nit below).

Reviewed-by: Damien Le Moal <dlemoal@kernel.org>

> ---
>  block/blk.h         |  9 ---------
>  include/linux/bio.h | 17 +++++++++++++++++
>  2 files changed, 17 insertions(+), 9 deletions(-)
> 
> diff --git a/block/blk.h b/block/blk.h
> index 63d5df0dc29c..6060e1e180a3 100644
> --- a/block/blk.h
> +++ b/block/blk.h
> @@ -457,11 +457,6 @@ static inline bool bio_zone_write_plugging(struct bio *bio)
>  {
>  	return bio_flagged(bio, BIO_ZONE_WRITE_PLUGGING);
>  }
> -static inline bool bio_is_zone_append(struct bio *bio)
> -{
> -	return bio_op(bio) == REQ_OP_ZONE_APPEND ||
> -		bio_flagged(bio, BIO_EMULATES_ZONE_APPEND);
> -}
>  void blk_zone_write_plug_bio_merged(struct bio *bio);
>  void blk_zone_write_plug_init_request(struct request *rq);
>  static inline void blk_zone_update_request_bio(struct request *rq,
> @@ -510,10 +505,6 @@ static inline bool bio_zone_write_plugging(struct bio *bio)
>  {
>  	return false;
>  }
> -static inline bool bio_is_zone_append(struct bio *bio)
> -{
> -	return false;
> -}
>  static inline void blk_zone_write_plug_bio_merged(struct bio *bio)
>  {
>  }
> diff --git a/include/linux/bio.h b/include/linux/bio.h
> index 4a1bf43ca53d..60830a6a5939 100644
> --- a/include/linux/bio.h
> +++ b/include/linux/bio.h
> @@ -675,6 +675,23 @@ static inline void bio_clear_polled(struct bio *bio)
>  	bio->bi_opf &= ~REQ_POLLED;
>  }
>  
> +/**
> + * bio_is_zone_append - is this a zone append bio?
> + * @bio:	bio to check
> + *
> + * Check if @bio is a zone append operation.  Core block layer code and end_io
> + * handlers must use this instead of an open coded REQ_OP_ZONE_APPEND check
> + * because the block layer can rewrite REQ_OP_ZONE_APPEND to REQ_OP_WRITE if
> + * it is not natively supported.
> + */
> +static inline bool bio_is_zone_append(struct bio *bio)
> +{
> +	if (!IS_ENABLED(CONFIG_BLK_DEV_ZONED))
> +		return false;

Nit: this "if" is probably not needed. But it does not hurt either. Since we
should never be seeing this function being called for the
!IS_ENABLED(CONFIG_BLK_DEV_ZONED) case, should we add a WARN_ON_ONCE() ?

> +	return bio_op(bio) == REQ_OP_ZONE_APPEND ||
> +		bio_flagged(bio, BIO_EMULATES_ZONE_APPEND);
> +}
> +
>  struct bio *blk_next_bio(struct bio *bio, struct block_device *bdev,
>  		unsigned int nr_pages, blk_opf_t opf, gfp_t gfp);
>  struct bio *bio_chain_and_submit(struct bio *prev, struct bio *new);
Christoph Hellwig Nov. 1, 2024, 5:48 a.m. UTC | #2
On Fri, Nov 01, 2024 at 02:37:29PM +0900, Damien Le Moal wrote:
> > +static inline bool bio_is_zone_append(struct bio *bio)
> > +{
> > +	if (!IS_ENABLED(CONFIG_BLK_DEV_ZONED))
> > +		return false;
> 
> Nit: this "if" is probably not needed. But it does not hurt either. Since we
> should never be seeing this function being called for the
> !IS_ENABLED(CONFIG_BLK_DEV_ZONED) case, should we add a WARN_ON_ONCE() ?

The point of the IS_ENALBED is to optimize away the code when it can't
be used.  The WARN_ON_ONCE would generate worse code than just leaving
the check in.
Johannes Thumshirn Nov. 4, 2024, 10:44 a.m. UTC | #3
Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
diff mbox series

Patch

diff --git a/block/blk.h b/block/blk.h
index 63d5df0dc29c..6060e1e180a3 100644
--- a/block/blk.h
+++ b/block/blk.h
@@ -457,11 +457,6 @@  static inline bool bio_zone_write_plugging(struct bio *bio)
 {
 	return bio_flagged(bio, BIO_ZONE_WRITE_PLUGGING);
 }
-static inline bool bio_is_zone_append(struct bio *bio)
-{
-	return bio_op(bio) == REQ_OP_ZONE_APPEND ||
-		bio_flagged(bio, BIO_EMULATES_ZONE_APPEND);
-}
 void blk_zone_write_plug_bio_merged(struct bio *bio);
 void blk_zone_write_plug_init_request(struct request *rq);
 static inline void blk_zone_update_request_bio(struct request *rq,
@@ -510,10 +505,6 @@  static inline bool bio_zone_write_plugging(struct bio *bio)
 {
 	return false;
 }
-static inline bool bio_is_zone_append(struct bio *bio)
-{
-	return false;
-}
 static inline void blk_zone_write_plug_bio_merged(struct bio *bio)
 {
 }
diff --git a/include/linux/bio.h b/include/linux/bio.h
index 4a1bf43ca53d..60830a6a5939 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -675,6 +675,23 @@  static inline void bio_clear_polled(struct bio *bio)
 	bio->bi_opf &= ~REQ_POLLED;
 }
 
+/**
+ * bio_is_zone_append - is this a zone append bio?
+ * @bio:	bio to check
+ *
+ * Check if @bio is a zone append operation.  Core block layer code and end_io
+ * handlers must use this instead of an open coded REQ_OP_ZONE_APPEND check
+ * because the block layer can rewrite REQ_OP_ZONE_APPEND to REQ_OP_WRITE if
+ * it is not natively supported.
+ */
+static inline bool bio_is_zone_append(struct bio *bio)
+{
+	if (!IS_ENABLED(CONFIG_BLK_DEV_ZONED))
+		return false;
+	return bio_op(bio) == REQ_OP_ZONE_APPEND ||
+		bio_flagged(bio, BIO_EMULATES_ZONE_APPEND);
+}
+
 struct bio *blk_next_bio(struct bio *bio, struct block_device *bdev,
 		unsigned int nr_pages, blk_opf_t opf, gfp_t gfp);
 struct bio *bio_chain_and_submit(struct bio *prev, struct bio *new);