Re: [PATCH v2 2/2] block: add max_active_zones to blk-sysfs

2020-07-03 Thread Greg KH
On Thu, Jul 02, 2020 at 08:19:22PM +0200, Niklas Cassel wrote:
> Add a new max_active zones definition in the sysfs documentation.
> This definition will be common for all devices utilizing the zoned block
> device support in the kernel.
> 
> Export max_active_zones according to this new definition for NVMe Zoned
> Namespace devices, ZAC ATA devices (which are treated as SCSI devices by
> the kernel), and ZBC SCSI devices.
> 
> Add the new max_active_zones member to struct request_queue, rather
> than as a queue limit, since this property cannot be split across stacking
> drivers.
> 
> For SCSI devices, even though max active zones is not part of the ZBC/ZAC
> spec, export max_active_zones as 0, signifying "no limit".
> 
> Signed-off-by: Niklas Cassel 
> Reviewed-by: Javier González 
> ---
>  Documentation/block/queue-sysfs.rst |  7 +++
>  block/blk-sysfs.c   | 14 +-
>  drivers/nvme/host/zns.c |  1 +
>  drivers/scsi/sd_zbc.c   |  1 +
>  include/linux/blkdev.h  | 16 
>  5 files changed, 38 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/block/queue-sysfs.rst 
> b/Documentation/block/queue-sysfs.rst
> index f01cf8530ae4..f261a5c84170 100644
> --- a/Documentation/block/queue-sysfs.rst
> +++ b/Documentation/block/queue-sysfs.rst
> @@ -117,6 +117,13 @@ Maximum number of elements in a DMA scatter/gather list 
> with integrity
>  data that will be submitted by the block layer core to the associated
>  block driver.
>  
> +max_active_zones (RO)
> +-
> +For zoned block devices (zoned attribute indicating "host-managed" or
> +"host-aware"), the sum of zones belonging to any of the zone states:
> +EXPLICIT OPEN, IMPLICIT OPEN or CLOSED, is limited by this value.
> +If this value is 0, there is no limit.

Shouldn't this all be in Documentation/ABI/ to describe the sysfs files?
All other kernel subsystems use that format, why is block special?


> +
>  max_open_zones (RO)
>  ---
>  For zoned block devices (zoned attribute indicating "host-managed" or
> diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
> index fa42961e9678..624bb4d85fc7 100644
> --- a/block/blk-sysfs.c
> +++ b/block/blk-sysfs.c
> @@ -310,6 +310,11 @@ static ssize_t queue_max_open_zones_show(struct 
> request_queue *q, char *page)
>   return queue_var_show(queue_max_open_zones(q), page);
>  }
>  
> +static ssize_t queue_max_active_zones_show(struct request_queue *q, char 
> *page)
> +{
> + return queue_var_show(queue_max_active_zones(q), page);
> +}
> +
>  static ssize_t queue_nomerges_show(struct request_queue *q, char *page)
>  {
>   return queue_var_show((blk_queue_nomerges(q) << 1) |
> @@ -677,6 +682,11 @@ static struct queue_sysfs_entry 
> queue_max_open_zones_entry = {
>   .show = queue_max_open_zones_show,
>  };
>  
> +static struct queue_sysfs_entry queue_max_active_zones_entry = {
> + .attr = {.name = "max_active_zones", .mode = 0444 },
> + .show = queue_max_active_zones_show,
> +};

__ATTR_RO()?

thanks,

greg k-h


Re: [PATCH v2 2/2] block: add max_active_zones to blk-sysfs

2020-07-02 Thread Damien Le Moal
On 2020/07/03 3:20, Niklas Cassel wrote:
> Add a new max_active zones definition in the sysfs documentation.
> This definition will be common for all devices utilizing the zoned block
> device support in the kernel.
> 
> Export max_active_zones according to this new definition for NVMe Zoned
> Namespace devices, ZAC ATA devices (which are treated as SCSI devices by
> the kernel), and ZBC SCSI devices.
> 
> Add the new max_active_zones member to struct request_queue, rather
> than as a queue limit, since this property cannot be split across stacking
> drivers.
> 
> For SCSI devices, even though max active zones is not part of the ZBC/ZAC
> spec, export max_active_zones as 0, signifying "no limit".
> 
> Signed-off-by: Niklas Cassel 
> Reviewed-by: Javier González 
> ---
>  Documentation/block/queue-sysfs.rst |  7 +++
>  block/blk-sysfs.c   | 14 +-
>  drivers/nvme/host/zns.c |  1 +
>  drivers/scsi/sd_zbc.c   |  1 +
>  include/linux/blkdev.h  | 16 
>  5 files changed, 38 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/block/queue-sysfs.rst 
> b/Documentation/block/queue-sysfs.rst
> index f01cf8530ae4..f261a5c84170 100644
> --- a/Documentation/block/queue-sysfs.rst
> +++ b/Documentation/block/queue-sysfs.rst
> @@ -117,6 +117,13 @@ Maximum number of elements in a DMA scatter/gather list 
> with integrity
>  data that will be submitted by the block layer core to the associated
>  block driver.
>  
> +max_active_zones (RO)
> +-
> +For zoned block devices (zoned attribute indicating "host-managed" or
> +"host-aware"), the sum of zones belonging to any of the zone states:
> +EXPLICIT OPEN, IMPLICIT OPEN or CLOSED, is limited by this value.
> +If this value is 0, there is no limit.
> +
>  max_open_zones (RO)
>  ---
>  For zoned block devices (zoned attribute indicating "host-managed" or
> diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
> index fa42961e9678..624bb4d85fc7 100644
> --- a/block/blk-sysfs.c
> +++ b/block/blk-sysfs.c
> @@ -310,6 +310,11 @@ static ssize_t queue_max_open_zones_show(struct 
> request_queue *q, char *page)
>   return queue_var_show(queue_max_open_zones(q), page);
>  }
>  
> +static ssize_t queue_max_active_zones_show(struct request_queue *q, char 
> *page)
> +{
> + return queue_var_show(queue_max_active_zones(q), page);
> +}
> +
>  static ssize_t queue_nomerges_show(struct request_queue *q, char *page)
>  {
>   return queue_var_show((blk_queue_nomerges(q) << 1) |
> @@ -677,6 +682,11 @@ static struct queue_sysfs_entry 
> queue_max_open_zones_entry = {
>   .show = queue_max_open_zones_show,
>  };
>  
> +static struct queue_sysfs_entry queue_max_active_zones_entry = {
> + .attr = {.name = "max_active_zones", .mode = 0444 },
> + .show = queue_max_active_zones_show,
> +};
> +
>  static struct queue_sysfs_entry queue_nomerges_entry = {
>   .attr = {.name = "nomerges", .mode = 0644 },
>   .show = queue_nomerges_show,
> @@ -776,6 +786,7 @@ static struct attribute *queue_attrs[] = {
>   _zoned_entry.attr,
>   _nr_zones_entry.attr,
>   _max_open_zones_entry.attr,
> + _max_active_zones_entry.attr,
>   _nomerges_entry.attr,
>   _rq_affinity_entry.attr,
>   _iostats_entry.attr,
> @@ -803,7 +814,8 @@ static umode_t queue_attr_visible(struct kobject *kobj, 
> struct attribute *attr,
>   (!q->mq_ops || !q->mq_ops->timeout))
>   return 0;
>  
> - if (attr == _max_open_zones_entry.attr &&
> + if ((attr == _max_open_zones_entry.attr ||
> +  attr == _max_active_zones_entry.attr) &&
>   !blk_queue_is_zoned(q))
>   return 0;
>  
> diff --git a/drivers/nvme/host/zns.c b/drivers/nvme/host/zns.c
> index 3d80b9cf6bfc..57cfd78731fb 100644
> --- a/drivers/nvme/host/zns.c
> +++ b/drivers/nvme/host/zns.c
> @@ -97,6 +97,7 @@ int nvme_update_zone_info(struct gendisk *disk, struct 
> nvme_ns *ns,
>   q->limits.zoned = BLK_ZONED_HM;
>   blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, q);
>   blk_queue_max_open_zones(q, le32_to_cpu(id->mor) + 1);
> + blk_queue_max_active_zones(q, le32_to_cpu(id->mar) + 1);
>  free_data:
>   kfree(id);
>   return status;
> diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c
> index aa3564139b40..d8b2c49d645b 100644
> --- a/drivers/scsi/sd_zbc.c
> +++ b/drivers/scsi/sd_zbc.c
> @@ -721,6 +721,7 @@ int sd_zbc_read_zones(struct scsi_disk *sdkp, unsigned 
> char *buf)
>   blk_queue_max_open_zones(q, 0);
>   else
>   blk_queue_max_open_zones(q, sdkp->zones_max_open);
> + blk_queue_max_active_zones(q, 0);
>   nr_zones = round_up(sdkp->capacity, zone_blocks) >> ilog2(zone_blocks);
>  
>   /* READ16/WRITE16 is mandatory for ZBC disks */
> diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
> index fe168abcfdda..bb9e6eb6a7e6 100644
> --- a/include/linux/blkdev.h
> +++ 

[PATCH v2 2/2] block: add max_active_zones to blk-sysfs

2020-07-02 Thread Niklas Cassel
Add a new max_active zones definition in the sysfs documentation.
This definition will be common for all devices utilizing the zoned block
device support in the kernel.

Export max_active_zones according to this new definition for NVMe Zoned
Namespace devices, ZAC ATA devices (which are treated as SCSI devices by
the kernel), and ZBC SCSI devices.

Add the new max_active_zones member to struct request_queue, rather
than as a queue limit, since this property cannot be split across stacking
drivers.

For SCSI devices, even though max active zones is not part of the ZBC/ZAC
spec, export max_active_zones as 0, signifying "no limit".

Signed-off-by: Niklas Cassel 
Reviewed-by: Javier González 
---
 Documentation/block/queue-sysfs.rst |  7 +++
 block/blk-sysfs.c   | 14 +-
 drivers/nvme/host/zns.c |  1 +
 drivers/scsi/sd_zbc.c   |  1 +
 include/linux/blkdev.h  | 16 
 5 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/Documentation/block/queue-sysfs.rst 
b/Documentation/block/queue-sysfs.rst
index f01cf8530ae4..f261a5c84170 100644
--- a/Documentation/block/queue-sysfs.rst
+++ b/Documentation/block/queue-sysfs.rst
@@ -117,6 +117,13 @@ Maximum number of elements in a DMA scatter/gather list 
with integrity
 data that will be submitted by the block layer core to the associated
 block driver.
 
+max_active_zones (RO)
+-
+For zoned block devices (zoned attribute indicating "host-managed" or
+"host-aware"), the sum of zones belonging to any of the zone states:
+EXPLICIT OPEN, IMPLICIT OPEN or CLOSED, is limited by this value.
+If this value is 0, there is no limit.
+
 max_open_zones (RO)
 ---
 For zoned block devices (zoned attribute indicating "host-managed" or
diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index fa42961e9678..624bb4d85fc7 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -310,6 +310,11 @@ static ssize_t queue_max_open_zones_show(struct 
request_queue *q, char *page)
return queue_var_show(queue_max_open_zones(q), page);
 }
 
+static ssize_t queue_max_active_zones_show(struct request_queue *q, char *page)
+{
+   return queue_var_show(queue_max_active_zones(q), page);
+}
+
 static ssize_t queue_nomerges_show(struct request_queue *q, char *page)
 {
return queue_var_show((blk_queue_nomerges(q) << 1) |
@@ -677,6 +682,11 @@ static struct queue_sysfs_entry queue_max_open_zones_entry 
= {
.show = queue_max_open_zones_show,
 };
 
+static struct queue_sysfs_entry queue_max_active_zones_entry = {
+   .attr = {.name = "max_active_zones", .mode = 0444 },
+   .show = queue_max_active_zones_show,
+};
+
 static struct queue_sysfs_entry queue_nomerges_entry = {
.attr = {.name = "nomerges", .mode = 0644 },
.show = queue_nomerges_show,
@@ -776,6 +786,7 @@ static struct attribute *queue_attrs[] = {
_zoned_entry.attr,
_nr_zones_entry.attr,
_max_open_zones_entry.attr,
+   _max_active_zones_entry.attr,
_nomerges_entry.attr,
_rq_affinity_entry.attr,
_iostats_entry.attr,
@@ -803,7 +814,8 @@ static umode_t queue_attr_visible(struct kobject *kobj, 
struct attribute *attr,
(!q->mq_ops || !q->mq_ops->timeout))
return 0;
 
-   if (attr == _max_open_zones_entry.attr &&
+   if ((attr == _max_open_zones_entry.attr ||
+attr == _max_active_zones_entry.attr) &&
!blk_queue_is_zoned(q))
return 0;
 
diff --git a/drivers/nvme/host/zns.c b/drivers/nvme/host/zns.c
index 3d80b9cf6bfc..57cfd78731fb 100644
--- a/drivers/nvme/host/zns.c
+++ b/drivers/nvme/host/zns.c
@@ -97,6 +97,7 @@ int nvme_update_zone_info(struct gendisk *disk, struct 
nvme_ns *ns,
q->limits.zoned = BLK_ZONED_HM;
blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, q);
blk_queue_max_open_zones(q, le32_to_cpu(id->mor) + 1);
+   blk_queue_max_active_zones(q, le32_to_cpu(id->mar) + 1);
 free_data:
kfree(id);
return status;
diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c
index aa3564139b40..d8b2c49d645b 100644
--- a/drivers/scsi/sd_zbc.c
+++ b/drivers/scsi/sd_zbc.c
@@ -721,6 +721,7 @@ int sd_zbc_read_zones(struct scsi_disk *sdkp, unsigned char 
*buf)
blk_queue_max_open_zones(q, 0);
else
blk_queue_max_open_zones(q, sdkp->zones_max_open);
+   blk_queue_max_active_zones(q, 0);
nr_zones = round_up(sdkp->capacity, zone_blocks) >> ilog2(zone_blocks);
 
/* READ16/WRITE16 is mandatory for ZBC disks */
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index fe168abcfdda..bb9e6eb6a7e6 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -521,6 +521,7 @@ struct request_queue {
unsigned long   *conv_zones_bitmap;
unsigned long   *seq_zones_wlock;
unsigned intmax_open_zones;
+