diff mbox series

[4/5] null_blk: create a helper for zoned devices

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

Commit Message

Chaitanya Kulkarni June 29, 2019, 5:04 a.m. UTC
This patch creates a helper function for handling zoned block device
operations.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
 drivers/block/null_blk_main.c | 50 +++++++++++++++++++++--------------
 1 file changed, 30 insertions(+), 20 deletions(-)

Comments

Christoph Hellwig July 1, 2019, 6:30 a.m. UTC | #1
On Fri, Jun 28, 2019 at 10:04:41PM -0700, Chaitanya Kulkarni wrote:
> This patch creates a helper function for handling zoned block device
> operations.
> 
> Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
> ---
>  drivers/block/null_blk_main.c | 50 +++++++++++++++++++++--------------
>  1 file changed, 30 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c
> index e75d187c7393..824392681a28 100644
> --- a/drivers/block/null_blk_main.c
> +++ b/drivers/block/null_blk_main.c
> @@ -1214,6 +1214,34 @@ static inline int nullb_handle_memory_backed(struct nullb_cmd *cmd)
>  	return null_handle_rq(cmd);
>  }
>  
> +static inline void nullb_handle_zoned(struct nullb_cmd *cmd)
> +{
> +	unsigned int nr_sectors;
> +	sector_t sector;
> +	req_opf op;
> +
> +	if (cmd->nq->dev->queue_mode == NULL_Q_BIO) {
> +		op = bio_op(cmd->bio);
> +		sector = cmd->bio->bi_iter.bi_sector;
> +		nr_sectors = cmd->bio->bi_iter.bi_size >> 9;
> +	} else {
> +		op = req_op(cmd->rq);
> +		sector = blk_rq_pos(cmd->rq);
> +		nr_sectors = blk_rq_sectors(cmd->rq);
> +	}

And this checks for the same info as the previous one.
You probably just want to pass sector and nr_sectors as an argument
to null_handle_cmd early in the series.

> +	switch ((op)) {

No need for the double braces.
diff mbox series

Patch

diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c
index e75d187c7393..824392681a28 100644
--- a/drivers/block/null_blk_main.c
+++ b/drivers/block/null_blk_main.c
@@ -1214,6 +1214,34 @@  static inline int nullb_handle_memory_backed(struct nullb_cmd *cmd)
 	return null_handle_rq(cmd);
 }
 
+static inline void nullb_handle_zoned(struct nullb_cmd *cmd)
+{
+	unsigned int nr_sectors;
+	sector_t sector;
+	req_opf op;
+
+	if (cmd->nq->dev->queue_mode == NULL_Q_BIO) {
+		op = bio_op(cmd->bio);
+		sector = cmd->bio->bi_iter.bi_sector;
+		nr_sectors = cmd->bio->bi_iter.bi_size >> 9;
+	} else {
+		op = req_op(cmd->rq);
+		sector = blk_rq_pos(cmd->rq);
+		nr_sectors = blk_rq_sectors(cmd->rq);
+	}
+
+	switch ((op)) {
+	case REQ_OP_WRITE:
+		null_zone_write(cmd, sector, nr_sectors);
+		break;
+	case REQ_OP_ZONE_RESET:
+		null_zone_reset(cmd, sector);
+		break;
+	default:
+		break;
+	}
+}
+
 static blk_status_t null_handle_cmd(struct nullb_cmd *cmd)
 {
 	struct nullb_device *dev = cmd->nq->dev;
@@ -1231,26 +1259,8 @@  static blk_status_t null_handle_cmd(struct nullb_cmd *cmd)
 	err = nullb_handle_memory_backed(cmd);
 	cmd->error = errno_to_blk_status(err);
 
-	if (!cmd->error && dev->zoned) {
-		sector_t sector;
-		unsigned int nr_sectors;
-		enum req_opf op;
-
-		if (dev->queue_mode == NULL_Q_BIO) {
-			op = bio_op(cmd->bio);
-			sector = cmd->bio->bi_iter.bi_sector;
-			nr_sectors = cmd->bio->bi_iter.bi_size >> 9;
-		} else {
-			op = req_op(cmd->rq);
-			sector = blk_rq_pos(cmd->rq);
-			nr_sectors = blk_rq_sectors(cmd->rq);
-		}
-
-		if (op == REQ_OP_WRITE)
-			null_zone_write(cmd, sector, nr_sectors);
-		else if (op == REQ_OP_ZONE_RESET)
-			null_zone_reset(cmd, sector);
-	}
+	if (!cmd->error && dev->zoned)
+		nullb_handle_zoned(cmd);
 out:
 	/* Complete IO by inline, softirq or timer */
 	switch (dev->irqmode) {