[08/10] block: nvme: use blk_is_valid_logical_block_size
diff mbox series

Message ID 20200721105239.8270-9-mlevitsk@redhat.com
State New
Headers show
Series
  • RFC: move logical block size checking to the block core
Related show

Commit Message

Maxim Levitsky July 21, 2020, 10:52 a.m. UTC
This replaces manual checking in the driver

Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
---
 drivers/nvme/host/core.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

Comments

Damien Le Moal July 21, 2020, 11:23 a.m. UTC | #1
On 2020/07/21 19:55, Maxim Levitsky wrote:
> This replaces manual checking in the driver
> 
> Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
> ---
>  drivers/nvme/host/core.c | 17 ++++++++---------
>  1 file changed, 8 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index add040168e67e..8014b3046992a 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -1849,10 +1849,16 @@ static void nvme_update_disk_info(struct gendisk *disk,
>  	unsigned short bs = 1 << ns->lba_shift;
>  	u32 atomic_bs, phys_bs, io_opt = 0;
>  
> -	if (ns->lba_shift > PAGE_SHIFT) {
> -		/* unsupported block size, set capacity to 0 later */
> +	/*
> +	 * The block layer can't support LBA sizes larger than the page size
> +	 * yet, so catch this early and don't allow block I/O.
> +	 */
> +

No need for the blank line here.

> +	if (!blk_is_valid_logical_block_size(bs)) {
>  		bs = (1 << 9);
> +		capacity = 0;>  	}
> +
>  	blk_mq_freeze_queue(disk->queue);
>  	blk_integrity_unregister(disk);
>  
> @@ -1887,13 +1893,6 @@ static void nvme_update_disk_info(struct gendisk *disk,
>  	blk_queue_io_min(disk->queue, phys_bs);
>  	blk_queue_io_opt(disk->queue, io_opt);
>  
> -	/*
> -	 * The block layer can't support LBA sizes larger than the page size
> -	 * yet, so catch this early and don't allow block I/O.
> -	 */
> -	if (ns->lba_shift > PAGE_SHIFT)
> -		capacity = 0;
> -
>  	/*
>  	 * Register a metadata profile for PI, or the plain non-integrity NVMe
>  	 * metadata masquerading as Type 0 if supported, otherwise reject block
> 

Apart from the nit above, this looks OK to me.

Reviewed-by: Damien Le Moal <damien.lemoal@wdc.com>

Patch
diff mbox series

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index add040168e67e..8014b3046992a 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1849,10 +1849,16 @@  static void nvme_update_disk_info(struct gendisk *disk,
 	unsigned short bs = 1 << ns->lba_shift;
 	u32 atomic_bs, phys_bs, io_opt = 0;
 
-	if (ns->lba_shift > PAGE_SHIFT) {
-		/* unsupported block size, set capacity to 0 later */
+	/*
+	 * The block layer can't support LBA sizes larger than the page size
+	 * yet, so catch this early and don't allow block I/O.
+	 */
+
+	if (!blk_is_valid_logical_block_size(bs)) {
 		bs = (1 << 9);
+		capacity = 0;
 	}
+
 	blk_mq_freeze_queue(disk->queue);
 	blk_integrity_unregister(disk);
 
@@ -1887,13 +1893,6 @@  static void nvme_update_disk_info(struct gendisk *disk,
 	blk_queue_io_min(disk->queue, phys_bs);
 	blk_queue_io_opt(disk->queue, io_opt);
 
-	/*
-	 * The block layer can't support LBA sizes larger than the page size
-	 * yet, so catch this early and don't allow block I/O.
-	 */
-	if (ns->lba_shift > PAGE_SHIFT)
-		capacity = 0;
-
 	/*
 	 * Register a metadata profile for PI, or the plain non-integrity NVMe
 	 * metadata masquerading as Type 0 if supported, otherwise reject block