diff mbox series

[V3,5/6] null_blk: create a helper for zoned devices

Message ID 20190821061314.3262-6-chaitanya.kulkarni@wdc.com (mailing list archive)
State New, archived
Headers show
Series null_blk: simplify null_handle_cmd() | expand

Commit Message

Chaitanya Kulkarni Aug. 21, 2019, 6:13 a.m. UTC
This patch creates a helper function for handling zoned block device
operations.

This patch also restructured the code for null_blk_zoned.c and uses the
pattern to return blk_status_t and catch the error in the function
null_handle_cmd() into cmd->error variable instead of setting it up in
the deeper layer just like the way it is done for flush, badblocks and
memory backed case in the null_handle_cmd().

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
 drivers/block/null_blk.h       | 19 +++++++++++++------
 drivers/block/null_blk_main.c  | 31 +++++++++++++++++++++++--------
 drivers/block/null_blk_zoned.c | 23 ++++++++++-------------
 3 files changed, 46 insertions(+), 27 deletions(-)

Comments

Christoph Hellwig Aug. 22, 2019, 12:58 a.m. UTC | #1
> +static inline blk_status_t null_handle_zoned(struct nullb_cmd *cmd,
> +					     enum req_opf op, sector_t sector,
> +					     sector_t nr_sectors)
> +{

Shouldn't this go into null_blk_zoned.c?  Also the indentation for the
here seems odd.

> +	blk_status_t sts = BLK_STS_OK;
> +
> +	switch (op) {
> +	case REQ_OP_WRITE:
> +		sts = null_zone_write(cmd, sector, nr_sectors);
> +		break;
> +	case REQ_OP_ZONE_RESET:
> +		sts = null_zone_reset(cmd, sector);
> +		break;
> +	default:
> +		break;
> +	}
> +
> +	return sts;

Why not:

	switch (op) {
	case REQ_OP_WRITE:
		return null_zone_write(cmd, sector, nr_sectors);
	case REQ_OP_ZONE_RESET:
		return null_zone_reset(cmd, sector);
	default:
		return BLK_STS_OK;
}
Chaitanya Kulkarni Aug. 22, 2019, 2:23 a.m. UTC | #2
Okay, will send the new version..

On 8/21/19 5:58 PM, Christoph Hellwig wrote:
>> +static inline blk_status_t null_handle_zoned(struct nullb_cmd *cmd,
>> +					     enum req_opf op, sector_t sector,
>> +					     sector_t nr_sectors)
>> +{
> Shouldn't this go into null_blk_zoned.c?  Also the indentation for the
> here seems odd.
>
>> +	blk_status_t sts = BLK_STS_OK;
>> +
>> +	switch (op) {
>> +	case REQ_OP_WRITE:
>> +		sts = null_zone_write(cmd, sector, nr_sectors);
>> +		break;
>> +	case REQ_OP_ZONE_RESET:
>> +		sts = null_zone_reset(cmd, sector);
>> +		break;
>> +	default:
>> +		break;
>> +	}
>> +
>> +	return sts;
> Why not:
>
> 	switch (op) {
> 	case REQ_OP_WRITE:
> 		return null_zone_write(cmd, sector, nr_sectors);
> 	case REQ_OP_ZONE_RESET:
> 		return null_zone_reset(cmd, sector);
> 	default:
> 		return BLK_STS_OK;
> }
diff mbox series

Patch

diff --git a/drivers/block/null_blk.h b/drivers/block/null_blk.h
index a1b9929bd911..1a8d5a12461f 100644
--- a/drivers/block/null_blk.h
+++ b/drivers/block/null_blk.h
@@ -90,9 +90,9 @@  int null_zone_init(struct nullb_device *dev);
 void null_zone_exit(struct nullb_device *dev);
 int null_zone_report(struct gendisk *disk, sector_t sector,
 		     struct blk_zone *zones, unsigned int *nr_zones);
-void null_zone_write(struct nullb_cmd *cmd, sector_t sector,
-			unsigned int nr_sectors);
-void null_zone_reset(struct nullb_cmd *cmd, sector_t sector);
+blk_status_t null_zone_write(struct nullb_cmd *cmd, sector_t sector,
+			     unsigned int nr_sectors);
+blk_status_t null_zone_reset(struct nullb_cmd *cmd, sector_t sector);
 #else
 static inline int null_zone_init(struct nullb_device *dev)
 {
@@ -106,10 +106,17 @@  static inline int null_zone_report(struct gendisk *disk, sector_t sector,
 {
 	return -EOPNOTSUPP;
 }
-static inline void null_zone_write(struct nullb_cmd *cmd, sector_t sector,
-				   unsigned int nr_sectors)
+static inline blk_status_t null_zone_write(struct nullb_cmd *cmd,
+					   sector_t sector,
+					   unsigned int nr_sectors)
 {
+	return BLK_STS_NOTSUPP;
+}
+
+static inline blk_status_t null_zone_reset(struct nullb_cmd *cmd,
+					   sector_t sector)
+{
+	return BLK_STS_NOTSUPP;
 }
-static inline void null_zone_reset(struct nullb_cmd *cmd, sector_t sector) {}
 #endif /* CONFIG_BLK_DEV_ZONED */
 #endif /* __NULL_BLK_H */
diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c
index 4299274cccfb..501af79bffb2 100644
--- a/drivers/block/null_blk_main.c
+++ b/drivers/block/null_blk_main.c
@@ -1182,6 +1182,26 @@  static inline blk_status_t null_handle_memory_backed(struct nullb_cmd *cmd,
 	return errno_to_blk_status(err);
 }
 
+static inline blk_status_t null_handle_zoned(struct nullb_cmd *cmd,
+					     enum req_opf op, sector_t sector,
+					     sector_t nr_sectors)
+{
+	blk_status_t sts = BLK_STS_OK;
+
+	switch (op) {
+	case REQ_OP_WRITE:
+		sts = null_zone_write(cmd, sector, nr_sectors);
+		break;
+	case REQ_OP_ZONE_RESET:
+		sts = null_zone_reset(cmd, sector);
+		break;
+	default:
+		break;
+	}
+
+	return sts;
+}
+
 static blk_status_t null_handle_cmd(struct nullb_cmd *cmd, sector_t sector,
 				    sector_t nr_sectors, enum req_opf op)
 {
@@ -1209,14 +1229,9 @@  static blk_status_t null_handle_cmd(struct nullb_cmd *cmd, sector_t sector,
 	if (dev->memory_backed)
 		cmd->error = null_handle_memory_backed(cmd, op);
 
-	if (!cmd->error && dev->zoned) {
-		if (op == REQ_OP_WRITE)
-			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);
-	}
+	if (!cmd->error && dev->zoned)
+		cmd->error = null_handle_zoned(cmd, op, sector, nr_sectors);
+
 out:
 	/* Complete IO by inline, softirq or timer */
 	switch (dev->irqmode) {
diff --git a/drivers/block/null_blk_zoned.c b/drivers/block/null_blk_zoned.c
index 8c7f5bf81975..4e48b4e088ae 100644
--- a/drivers/block/null_blk_zoned.c
+++ b/drivers/block/null_blk_zoned.c
@@ -84,7 +84,7 @@  int null_zone_report(struct gendisk *disk, sector_t sector,
 	return 0;
 }
 
-void null_zone_write(struct nullb_cmd *cmd, sector_t sector,
+blk_status_t null_zone_write(struct nullb_cmd *cmd, sector_t sector,
 		     unsigned int nr_sectors)
 {
 	struct nullb_device *dev = cmd->nq->dev;
@@ -95,14 +95,12 @@  void null_zone_write(struct nullb_cmd *cmd, sector_t sector,
 	case BLK_ZONE_COND_FULL:
 		/* Cannot write to a full zone */
 		cmd->error = BLK_STS_IOERR;
-		break;
+		return BLK_STS_IOERR;
 	case BLK_ZONE_COND_EMPTY:
 	case BLK_ZONE_COND_IMP_OPEN:
 		/* Writes must be at the write pointer position */
-		if (sector != zone->wp) {
-			cmd->error = BLK_STS_IOERR;
-			break;
-		}
+		if (sector != zone->wp)
+			return BLK_STS_IOERR;
 
 		if (zone->cond == BLK_ZONE_COND_EMPTY)
 			zone->cond = BLK_ZONE_COND_IMP_OPEN;
@@ -115,12 +113,12 @@  void null_zone_write(struct nullb_cmd *cmd, sector_t sector,
 		break;
 	default:
 		/* Invalid zone condition */
-		cmd->error = BLK_STS_IOERR;
-		break;
+		return BLK_STS_IOERR;
 	}
+	return BLK_STS_OK;
 }
 
-void null_zone_reset(struct nullb_cmd *cmd, sector_t sector)
+blk_status_t 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);
@@ -137,10 +135,8 @@  void null_zone_reset(struct nullb_cmd *cmd, sector_t sector)
 		}
 		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)
+			return BLK_STS_IOERR;
 
 		zone->cond = BLK_ZONE_COND_EMPTY;
 		zone->wp = zone->start;
@@ -149,4 +145,5 @@  void null_zone_reset(struct nullb_cmd *cmd, sector_t sector)
 		cmd->error = BLK_STS_NOTSUPP;
 		break;
 	}
+	return BLK_STS_OK;
 }