diff mbox series

[v5,1/2] virtio-blk: use a helper to handle request queuing errors

Message ID 20221108040718.2785649-2-dmitry.fomichev@wdc.com (mailing list archive)
State New, archived
Headers show
Series virtio-blk: support zoned block devices | expand

Commit Message

Dmitry Fomichev Nov. 8, 2022, 4:07 a.m. UTC
Define a new helper function, virtblk_fail_to_queue(), to
clean up the error handling code in virtio_queue_rq().

Signed-off-by: Dmitry Fomichev <dmitry.fomichev@wdc.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 drivers/block/virtio_blk.c | 29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)

Comments

Damien Le Moal Nov. 8, 2022, 6:53 a.m. UTC | #1
On 11/8/22 13:07, Dmitry Fomichev wrote:
> Define a new helper function, virtblk_fail_to_queue(), to
> clean up the error handling code in virtio_queue_rq().
> 
> Signed-off-by: Dmitry Fomichev <dmitry.fomichev@wdc.com>
> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

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

> ---
>  drivers/block/virtio_blk.c | 29 ++++++++++++++++-------------
>  1 file changed, 16 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
> index 19da5defd734..3efe3da5f8c2 100644
> --- a/drivers/block/virtio_blk.c
> +++ b/drivers/block/virtio_blk.c
> @@ -315,6 +315,19 @@ static void virtio_commit_rqs(struct blk_mq_hw_ctx *hctx)
>  		virtqueue_notify(vq->vq);
>  }
>  
> +static blk_status_t virtblk_fail_to_queue(struct request *req, int rc)
> +{
> +	virtblk_cleanup_cmd(req);
> +	switch (rc) {
> +	case -ENOSPC:
> +		return BLK_STS_DEV_RESOURCE;
> +	case -ENOMEM:
> +		return BLK_STS_RESOURCE;
> +	default:
> +		return BLK_STS_IOERR;
> +	}
> +}
> +
>  static blk_status_t virtblk_prep_rq(struct blk_mq_hw_ctx *hctx,
>  					struct virtio_blk *vblk,
>  					struct request *req,
> @@ -327,10 +340,8 @@ static blk_status_t virtblk_prep_rq(struct blk_mq_hw_ctx *hctx,
>  		return status;
>  
>  	vbr->sg_table.nents = virtblk_map_data(hctx, req, vbr);
> -	if (unlikely(vbr->sg_table.nents < 0)) {
> -		virtblk_cleanup_cmd(req);
> -		return BLK_STS_RESOURCE;
> -	}
> +	if (unlikely(vbr->sg_table.nents < 0))
> +		return virtblk_fail_to_queue(req, -ENOMEM);
>  
>  	blk_mq_start_request(req);
>  
> @@ -364,15 +375,7 @@ static blk_status_t virtio_queue_rq(struct blk_mq_hw_ctx *hctx,
>  			blk_mq_stop_hw_queue(hctx);
>  		spin_unlock_irqrestore(&vblk->vqs[qid].lock, flags);
>  		virtblk_unmap_data(req, vbr);
> -		virtblk_cleanup_cmd(req);
> -		switch (err) {
> -		case -ENOSPC:
> -			return BLK_STS_DEV_RESOURCE;
> -		case -ENOMEM:
> -			return BLK_STS_RESOURCE;
> -		default:
> -			return BLK_STS_IOERR;
> -		}
> +		return virtblk_fail_to_queue(req, err);
>  	}
>  
>  	if (bd->last && virtqueue_kick_prepare(vblk->vqs[qid].vq))
Johannes Thumshirn Nov. 8, 2022, 7:47 a.m. UTC | #2
Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Chaitanya Kulkarni Nov. 8, 2022, 11:07 p.m. UTC | #3
On 11/7/22 20:07, Dmitry Fomichev wrote:
> Define a new helper function, virtblk_fail_to_queue(), to
> clean up the error handling code in virtio_queue_rq().
> 
> Signed-off-by: Dmitry Fomichev <dmitry.fomichev@wdc.com>
> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>   drivers/block/virtio_blk.c | 29 ++++++++++++++++-------------
>   1 file changed, 16 insertions(+), 13 deletions(-)
> 

Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>

-ck
diff mbox series

Patch

diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 19da5defd734..3efe3da5f8c2 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -315,6 +315,19 @@  static void virtio_commit_rqs(struct blk_mq_hw_ctx *hctx)
 		virtqueue_notify(vq->vq);
 }
 
+static blk_status_t virtblk_fail_to_queue(struct request *req, int rc)
+{
+	virtblk_cleanup_cmd(req);
+	switch (rc) {
+	case -ENOSPC:
+		return BLK_STS_DEV_RESOURCE;
+	case -ENOMEM:
+		return BLK_STS_RESOURCE;
+	default:
+		return BLK_STS_IOERR;
+	}
+}
+
 static blk_status_t virtblk_prep_rq(struct blk_mq_hw_ctx *hctx,
 					struct virtio_blk *vblk,
 					struct request *req,
@@ -327,10 +340,8 @@  static blk_status_t virtblk_prep_rq(struct blk_mq_hw_ctx *hctx,
 		return status;
 
 	vbr->sg_table.nents = virtblk_map_data(hctx, req, vbr);
-	if (unlikely(vbr->sg_table.nents < 0)) {
-		virtblk_cleanup_cmd(req);
-		return BLK_STS_RESOURCE;
-	}
+	if (unlikely(vbr->sg_table.nents < 0))
+		return virtblk_fail_to_queue(req, -ENOMEM);
 
 	blk_mq_start_request(req);
 
@@ -364,15 +375,7 @@  static blk_status_t virtio_queue_rq(struct blk_mq_hw_ctx *hctx,
 			blk_mq_stop_hw_queue(hctx);
 		spin_unlock_irqrestore(&vblk->vqs[qid].lock, flags);
 		virtblk_unmap_data(req, vbr);
-		virtblk_cleanup_cmd(req);
-		switch (err) {
-		case -ENOSPC:
-			return BLK_STS_DEV_RESOURCE;
-		case -ENOMEM:
-			return BLK_STS_RESOURCE;
-		default:
-			return BLK_STS_IOERR;
-		}
+		return virtblk_fail_to_queue(req, err);
 	}
 
 	if (bd->last && virtqueue_kick_prepare(vblk->vqs[qid].vq))