diff mbox series

[v9,3/8] block: Add bdev atomic write limits helpers

Message ID 20241016100325.3534494-4-john.g.garry@oracle.com (mailing list archive)
State New
Headers show
Series block atomic writes for xfs | expand

Commit Message

John Garry Oct. 16, 2024, 10:03 a.m. UTC
Add helpers to get atomic write limits for a bdev, so that we don't access
request_queue helpers outside the block layer.

We check if the bdev can actually atomic write in these helpers, so we
can avoid users missing using this check.

Suggested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: John Garry <john.g.garry@oracle.com>
---
 include/linux/blkdev.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Comments

Christoph Hellwig Oct. 16, 2024, 12:29 p.m. UTC | #1
On Wed, Oct 16, 2024 at 10:03:20AM +0000, John Garry wrote:
> +static inline unsigned int
> +bdev_atomic_write_unit_min_bytes(struct block_device *bdev)
> +{
> +	if (!bdev_can_atomic_write(bdev))
> +		return 0;

Aren't the limits always zero when the block device doesn't support
atomic writes and we can skip these checks?

Otherwise looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>
John Garry Oct. 16, 2024, 12:36 p.m. UTC | #2
On 16/10/2024 13:29, Christoph Hellwig wrote:
> On Wed, Oct 16, 2024 at 10:03:20AM +0000, John Garry wrote:
>> +static inline unsigned int
>> +bdev_atomic_write_unit_min_bytes(struct block_device *bdev)
>> +{
>> +	if (!bdev_can_atomic_write(bdev))
>> +		return 0;
> 
> Aren't the limits always zero when the block device doesn't support
> atomic writes and we can skip these checks?

Not necessarily. bdev_can_atomic_write() has the partition alignment 
checks also.

> 
> Otherwise looks good:
> 
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> 

thanks, but let me know if you would still like to see any changes.
Christoph Hellwig Oct. 16, 2024, 12:39 p.m. UTC | #3
On Wed, Oct 16, 2024 at 01:36:40PM +0100, John Garry wrote:
> thanks, but let me know if you would still like to see any changes.

Sounds like this is fine.
Darrick J. Wong Oct. 16, 2024, 7:58 p.m. UTC | #4
On Wed, Oct 16, 2024 at 10:03:20AM +0000, John Garry wrote:
> Add helpers to get atomic write limits for a bdev, so that we don't access
> request_queue helpers outside the block layer.
> 
> We check if the bdev can actually atomic write in these helpers, so we
> can avoid users missing using this check.
> 
> Suggested-by: Christoph Hellwig <hch@lst.de>
> Signed-off-by: John Garry <john.g.garry@oracle.com>

Looks good,
Reviewed-by: Darrick J. Wong <djwong@kernel.org>

--D

> ---
>  include/linux/blkdev.h | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
> index 50c3b959da28..c2cc3c146d74 100644
> --- a/include/linux/blkdev.h
> +++ b/include/linux/blkdev.h
> @@ -1674,6 +1674,22 @@ static inline bool bdev_can_atomic_write(struct block_device *bdev)
>  	return true;
>  }
>  
> +static inline unsigned int
> +bdev_atomic_write_unit_min_bytes(struct block_device *bdev)
> +{
> +	if (!bdev_can_atomic_write(bdev))
> +		return 0;
> +	return queue_atomic_write_unit_min_bytes(bdev_get_queue(bdev));
> +}
> +
> +static inline unsigned int
> +bdev_atomic_write_unit_max_bytes(struct block_device *bdev)
> +{
> +	if (!bdev_can_atomic_write(bdev))
> +		return 0;
> +	return queue_atomic_write_unit_max_bytes(bdev_get_queue(bdev));
> +}
> +
>  #define DEFINE_IO_COMP_BATCH(name)	struct io_comp_batch name = { }
>  
>  #endif /* _LINUX_BLKDEV_H */
> -- 
> 2.31.1
> 
>
diff mbox series

Patch

diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 50c3b959da28..c2cc3c146d74 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1674,6 +1674,22 @@  static inline bool bdev_can_atomic_write(struct block_device *bdev)
 	return true;
 }
 
+static inline unsigned int
+bdev_atomic_write_unit_min_bytes(struct block_device *bdev)
+{
+	if (!bdev_can_atomic_write(bdev))
+		return 0;
+	return queue_atomic_write_unit_min_bytes(bdev_get_queue(bdev));
+}
+
+static inline unsigned int
+bdev_atomic_write_unit_max_bytes(struct block_device *bdev)
+{
+	if (!bdev_can_atomic_write(bdev))
+		return 0;
+	return queue_atomic_write_unit_max_bytes(bdev_get_queue(bdev));
+}
+
 #define DEFINE_IO_COMP_BATCH(name)	struct io_comp_batch name = { }
 
 #endif /* _LINUX_BLKDEV_H */