diff mbox series

[4/4] null_blk: implement REQ_OP_ZONE_RESET_ALL

Message ID 20190731210102.3472-5-chaitanya.kulkarni@wdc.com (mailing list archive)
State Superseded
Headers show
Series block: introduce REQ_OP_ZONE_RESET_ALL | expand

Commit Message

Chaitanya Kulkarni July 31, 2019, 9:01 p.m. UTC
This patch implements newly introduced zone reset all operation for
null_blk driver.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
 drivers/block/null_blk_main.c  |  3 +++
 drivers/block/null_blk_zoned.c | 28 ++++++++++++++++++++++------
 2 files changed, 25 insertions(+), 6 deletions(-)

Comments

Damien Le Moal Aug. 1, 2019, 1:03 a.m. UTC | #1
On 2019/08/01 6:02, Chaitanya Kulkarni wrote:
> This patch implements newly introduced zone reset all operation for
> null_blk driver.
> 
> Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
> ---
>  drivers/block/null_blk_main.c  |  3 +++
>  drivers/block/null_blk_zoned.c | 28 ++++++++++++++++++++++------
>  2 files changed, 25 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c
> index 99328ded60d1..99c56d72ff78 100644
> --- a/drivers/block/null_blk_main.c
> +++ b/drivers/block/null_blk_main.c
> @@ -1214,6 +1214,8 @@ static blk_status_t null_handle_cmd(struct nullb_cmd *cmd)
>  			null_zone_write(cmd, sector, nr_sectors);
>  		else if (op == REQ_OP_ZONE_RESET)
>  			null_zone_reset(cmd, sector);
> +		else if (op == REQ_OP_ZONE_RESET_ALL)
> +			null_zone_reset(cmd, 0);
>  	}
>  out:
>  	/* Complete IO by inline, softirq or timer */
> @@ -1688,6 +1690,7 @@ static int null_add_dev(struct nullb_device *dev)
>  
>  		blk_queue_chunk_sectors(nullb->q, dev->zone_size_sects);
>  		nullb->q->limits.zoned = BLK_ZONED_HM;
> +		blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, nullb->q);
>  	}
>  
>  	nullb->q->queuedata = nullb;
> diff --git a/drivers/block/null_blk_zoned.c b/drivers/block/null_blk_zoned.c
> index cb28d93f2bd1..8c7f5bf81975 100644
> --- a/drivers/block/null_blk_zoned.c
> +++ b/drivers/block/null_blk_zoned.c
> @@ -125,12 +125,28 @@ void null_zone_reset(struct nullb_cmd *cmd, sector_t sector)
>  	struct nullb_device *dev = cmd->nq->dev;
>  	unsigned int zno = null_zone_no(dev, sector);
>  	struct blk_zone *zone = &dev->zones[zno];
> +	size_t i;
> +
> +	switch (req_op(cmd->rq)) {
> +	case REQ_OP_ZONE_RESET_ALL:
> +		for (i = 0; i < dev->nr_zones; i++) {
> +			if (zone[i].type == BLK_ZONE_TYPE_CONVENTIONAL)
> +				continue;
> +			zone[i].cond = BLK_ZONE_COND_EMPTY;
> +			zone[i].wp = zone[i].start;
> +		}
> +		break;
> +	case REQ_OP_ZONE_RESET:
> +		if (zone->type == BLK_ZONE_TYPE_CONVENTIONAL) {
> +			cmd->error = BLK_STS_IOERR;
> +			return;
> +		}
>  
> -	if (zone->type == BLK_ZONE_TYPE_CONVENTIONAL) {
> -		cmd->error = BLK_STS_IOERR;
> -		return;
> +		zone->cond = BLK_ZONE_COND_EMPTY;
> +		zone->wp = zone->start;
> +		break;
> +	default:
> +		cmd->error = BLK_STS_NOTSUPP;
> +		break;
>  	}
> -
> -	zone->cond = BLK_ZONE_COND_EMPTY;
> -	zone->wp = zone->start;
>  }
> 

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

Patch

diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c
index 99328ded60d1..99c56d72ff78 100644
--- a/drivers/block/null_blk_main.c
+++ b/drivers/block/null_blk_main.c
@@ -1214,6 +1214,8 @@  static blk_status_t null_handle_cmd(struct nullb_cmd *cmd)
 			null_zone_write(cmd, sector, nr_sectors);
 		else if (op == REQ_OP_ZONE_RESET)
 			null_zone_reset(cmd, sector);
+		else if (op == REQ_OP_ZONE_RESET_ALL)
+			null_zone_reset(cmd, 0);
 	}
 out:
 	/* Complete IO by inline, softirq or timer */
@@ -1688,6 +1690,7 @@  static int null_add_dev(struct nullb_device *dev)
 
 		blk_queue_chunk_sectors(nullb->q, dev->zone_size_sects);
 		nullb->q->limits.zoned = BLK_ZONED_HM;
+		blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, nullb->q);
 	}
 
 	nullb->q->queuedata = nullb;
diff --git a/drivers/block/null_blk_zoned.c b/drivers/block/null_blk_zoned.c
index cb28d93f2bd1..8c7f5bf81975 100644
--- a/drivers/block/null_blk_zoned.c
+++ b/drivers/block/null_blk_zoned.c
@@ -125,12 +125,28 @@  void null_zone_reset(struct nullb_cmd *cmd, sector_t sector)
 	struct nullb_device *dev = cmd->nq->dev;
 	unsigned int zno = null_zone_no(dev, sector);
 	struct blk_zone *zone = &dev->zones[zno];
+	size_t i;
+
+	switch (req_op(cmd->rq)) {
+	case REQ_OP_ZONE_RESET_ALL:
+		for (i = 0; i < dev->nr_zones; i++) {
+			if (zone[i].type == BLK_ZONE_TYPE_CONVENTIONAL)
+				continue;
+			zone[i].cond = BLK_ZONE_COND_EMPTY;
+			zone[i].wp = zone[i].start;
+		}
+		break;
+	case REQ_OP_ZONE_RESET:
+		if (zone->type == BLK_ZONE_TYPE_CONVENTIONAL) {
+			cmd->error = BLK_STS_IOERR;
+			return;
+		}
 
-	if (zone->type == BLK_ZONE_TYPE_CONVENTIONAL) {
-		cmd->error = BLK_STS_IOERR;
-		return;
+		zone->cond = BLK_ZONE_COND_EMPTY;
+		zone->wp = zone->start;
+		break;
+	default:
+		cmd->error = BLK_STS_NOTSUPP;
+		break;
 	}
-
-	zone->cond = BLK_ZONE_COND_EMPTY;
-	zone->wp = zone->start;
 }