diff mbox series

[1/6] block: factor out a chunk_size_left helper

Message ID 20220614090934.570632-2-hch@lst.de (mailing list archive)
State New, archived
Headers show
Series [1/6] block: factor out a chunk_size_left helper | expand

Commit Message

Christoph Hellwig June 14, 2022, 9:09 a.m. UTC
Factor out a helper from blk_max_size_offset so that it can be reused
independently.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 include/linux/blkdev.h | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

Comments

Bart Van Assche June 14, 2022, 4:39 p.m. UTC | #1
On 6/14/22 02:09, Christoph Hellwig wrote:
> Factor out a helper from blk_max_size_offset so that it can be reused
> independently. 
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Pankaj Raghav June 15, 2022, 10:32 a.m. UTC | #2
On Tue, Jun 14, 2022 at 11:09:29AM +0200, Christoph Hellwig wrote:
> Factor out a helper from blk_max_size_offset so that it can be reused
> independently.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  include/linux/blkdev.h | 19 +++++++++++++------
>  1 file changed, 13 insertions(+), 6 deletions(-)
> 

Looks good,
Reviewed-by: Pankaj Raghav <p.raghav@samsung.com>
Mike Snitzer June 16, 2022, 11:05 p.m. UTC | #3
On Tue, Jun 14 2022 at  5:09P -0400,
Christoph Hellwig <hch@lst.de> wrote:

> Factor out a helper from blk_max_size_offset so that it can be reused
> independently.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  include/linux/blkdev.h | 19 +++++++++++++------
>  1 file changed, 13 insertions(+), 6 deletions(-)
> 
> diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
> index 914c613d81da7..e66ad451274ec 100644
> --- a/include/linux/blkdev.h
> +++ b/include/linux/blkdev.h
> @@ -933,6 +933,17 @@ static inline unsigned int blk_queue_get_max_sectors(struct request_queue *q,
>  	return q->limits.max_sectors;
>  }
>  
> +/*
> + * Return how much of the chunk is left to be used for I/O at a given offset.
> + */
> +static inline unsigned int blk_chunk_sectors_left(sector_t offset,
> +		unsigned int chunk_sectors)
> +{
> +	if (unlikely(!is_power_of_2(chunk_sectors)))
> +		return chunk_sectors - sector_div(offset, chunk_sectors);
> +	return chunk_sectors - (offset & (chunk_sectors - 1));
> +}
> +
>  /*
>   * Return maximum size of a request at given offset. Only valid for
>   * file system requests.
> @@ -948,12 +959,8 @@ static inline unsigned int blk_max_size_offset(struct request_queue *q,
>  			return q->limits.max_sectors;
>  	}
>  
> -	if (likely(is_power_of_2(chunk_sectors)))
> -		chunk_sectors -= offset & (chunk_sectors - 1);
> -	else
> -		chunk_sectors -= sector_div(offset, chunk_sectors);
> -
> -	return min(q->limits.max_sectors, chunk_sectors);
> +	return min(q->limits.max_sectors,
> +			blk_chunk_sectors_left(offset, chunk_sectors));
>  }

While you're at it, any reason not to use queue_max_sectors() here?
Christoph Hellwig June 17, 2022, 6:22 a.m. UTC | #4
On Thu, Jun 16, 2022 at 07:05:48PM -0400, Mike Snitzer wrote:
> > +	return min(q->limits.max_sectors,
> > +			blk_chunk_sectors_left(offset, chunk_sectors));
> >  }
> 
> While you're at it, any reason not to use queue_max_sectors() here?

I'm not sure if it is a good reason, but this code sniplet goes
away later in the series, and all replacemens do use queue_max_sectors.
diff mbox series

Patch

diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 914c613d81da7..e66ad451274ec 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -933,6 +933,17 @@  static inline unsigned int blk_queue_get_max_sectors(struct request_queue *q,
 	return q->limits.max_sectors;
 }
 
+/*
+ * Return how much of the chunk is left to be used for I/O at a given offset.
+ */
+static inline unsigned int blk_chunk_sectors_left(sector_t offset,
+		unsigned int chunk_sectors)
+{
+	if (unlikely(!is_power_of_2(chunk_sectors)))
+		return chunk_sectors - sector_div(offset, chunk_sectors);
+	return chunk_sectors - (offset & (chunk_sectors - 1));
+}
+
 /*
  * Return maximum size of a request at given offset. Only valid for
  * file system requests.
@@ -948,12 +959,8 @@  static inline unsigned int blk_max_size_offset(struct request_queue *q,
 			return q->limits.max_sectors;
 	}
 
-	if (likely(is_power_of_2(chunk_sectors)))
-		chunk_sectors -= offset & (chunk_sectors - 1);
-	else
-		chunk_sectors -= sector_div(offset, chunk_sectors);
-
-	return min(q->limits.max_sectors, chunk_sectors);
+	return min(q->limits.max_sectors,
+			blk_chunk_sectors_left(offset, chunk_sectors));
 }
 
 /*