Skip to contentSkip to conversation

virtio_blk: corrent types for status handling

PATCH In review Michael S. Tsirkin 5 participants 5 messages Oct 25, 2021 – Oct 26, 2021

Subsystems (3)
lore
Share & tools
lore

Michael S. Tsirkin

author maintainer
#0 lore raw

PATCH 1/1 virtio_blk: corrent types for status handling

virtblk_setup_cmd returns blk_status_t in an int, callers then assign it back to a blk_status_t variable. blk_status_t is either u32 or (more typically) u8 so it works, but is inelegant and causes sparse warnings.

Pass the status in blk_status_t in a consistent way.

Fixes b2c5221fd074 ("virtio-blk: avoid preallocating big SGL for data")
Cc Max Gurtovoy <[email protected]>
---
 drivers/block/virtio_blk.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/block/virtio_blk.c +8 -6
index c336d9bb9105..c7d05ff24084 100644
@@ -208,8 +208,9 @@ static void virtblk_cleanup_cmd(struct request *req)
 		kfree(bvec_virt(&req->special_vec));
 }
 
-static int virtblk_setup_cmd(struct virtio_device *vdev, struct request *req,
-		struct virtblk_req *vbr)
+static blk_status_t virtblk_setup_cmd(struct virtio_device *vdev,
+				      struct request *req,
+				      struct virtblk_req *vbr)
 {
 	bool unmap = false;
 	u32 type;
@@ -317,14 +318,15 @@ static blk_status_t virtio_queue_rq(struct blk_mq_hw_ctx *hctx,
 	unsigned long flags;
 	unsigned int num;
 	int qid = hctx->queue_num;
-	int err;
 	bool notify = false;
+	blk_status_t status;
+	int err;
 
 	BUG_ON(req->nr_phys_segments + 2 > vblk->sg_elems);
 
-	err = virtblk_setup_cmd(vblk->vdev, req, vbr);
-	if (unlikely(err))
-		return err;
+	status = virtblk_setup_cmd(vblk->vdev, req, vbr);
+	if (unlikely(status))
+		return status;
 
 	blk_mq_start_request(req);
 
Signature · 1 line
MST
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Michael S. Tsirkin

virtblk_setup_cmd returns blk_status_t in an int, callers then assign it back to a blk_status_t variable. blk_status_t is either u32 or (more typically) u8 so it works, but is inelegant and causes sparse warnings.

Pass the status in blk_status_t in a consistent way.

Quoted 7 lines
Fixes b2c5221fd074 ("virtio-blk: avoid preallocating big SGL for data")
Cc Max Gurtovoy <[email protected]>
---
 drivers/block/virtio_blk.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
Reviewed-by on v1 1/1
#2 lore raw
In reply to Michael S. Tsirkin
Quoted 38 lines · Michael S. Tsirkin

virtblk_setup_cmd returns blk_status_t in an int, callers then assign it back to a blk_status_t variable. blk_status_t is either u32 or (more typically) u8 so it works, but is inelegant and causes sparse warnings.

Pass the status in blk_status_t in a consistent way.

Fixes b2c5221fd074 ("virtio-blk: avoid preallocating big SGL for data")
Cc Max Gurtovoy <[email protected]>
---
  drivers/block/virtio_blk.c | 14 ++++++++------
  1 file changed, 8 insertions(+), 6 deletions(-)
drivers/block/virtio_blk.c +5 -3
index c336d9bb9105..c7d05ff24084 100644
@@ -208,8 +208,9 @@ static void virtblk_cleanup_cmd(struct request *req)
  		kfree(bvec_virt(&req->special_vec));
  }
 
-static int virtblk_setup_cmd(struct virtio_device *vdev, struct request *req,
-		struct virtblk_req *vbr)
+static blk_status_t virtblk_setup_cmd(struct virtio_device *vdev,
+				      struct request *req,
+				      struct virtblk_req *vbr)
  {
  	bool unmap = false;
  	u32 type;
@@ -317,14 +318,15 @@ static blk_status_t virtio_queue_rq(struct blk_mq_hw_ctx *hctx,
  	unsigned long flags;
  	unsigned int num;
  	int qid = hctx->queue_num;
-	int err;
  	bool notify = false;
+	blk_status_t status;
+	int err;

drivers/block/virtio_blk.c static blk_status_t virtio_queue_rq(struct blk_mq_hw_ctx *hctx, · line 330

Quoted 10 lines
drivers/block/virtio_blk.c +3 -3
 
  	BUG_ON(req->nr_phys_segments + 2 > vblk->sg_elems);
 
-	err = virtblk_setup_cmd(vblk->vdev, req, vbr);
-	if (unlikely(err))
-		return err;
+	status = virtblk_setup_cmd(vblk->vdev, req, vbr);
+	if (unlikely(status))
+		return status;
 

Maybe we can compare the returned status to BLK_STS_OK. But I see we don't do it also in NVMe subsystem so I guess we can assume BLK_STS_OK == 0 forever.

Jens/Christoph, any thoughts on that ?

Anyway Looks good.

Thanks for the fix,

Quoted 2 lines
drivers/block/virtio_blk.c +0 -0
  	blk_mq_start_request(req);
 
#3 lore raw
Quoted 3 lines · Max Gurtovoy

Maybe we can compare the returned status to BLK_STS_OK. But I see we don't do it also in NVMe subsystem so I guess we can assume BLK_STS_OK == 0 forever.

Jes, BLK_STS_OK == 0 is an intentional allowed short cut. It is not just a block layer design, but part of how the sparse __bitwise__ annotations work.

Acked-by on v1 1/1
#4 lore raw
In reply to Michael S. Tsirkin
Quoted 11 lines · Michael S. Tsirkin

virtblk_setup_cmd returns blk_status_t in an int, callers then assign it back to a blk_status_t variable. blk_status_t is either u32 or (more typically) u8 so it works, but is inelegant and causes sparse warnings.

Pass the status in blk_status_t in a consistent way.

Fixes b2c5221fd074 ("virtio-blk: avoid preallocating big SGL for data")
Cc Max Gurtovoy <[email protected]>
Quoted 43 lines
---
 drivers/block/virtio_blk.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/block/virtio_blk.c +8 -7
index c336d9bb9105..c7d05ff24084 100644
@@ -208,8 +208,9 @@ static void virtblk_cleanup_cmd(struct request *req)
                kfree(bvec_virt(&req->special_vec));
 }
 
-static int virtblk_setup_cmd(struct virtio_device *vdev, struct request *req,
-               struct virtblk_req *vbr)
+static blk_status_t virtblk_setup_cmd(struct virtio_device *vdev,
+                                     struct request *req,
+                                     struct virtblk_req *vbr)
 {
        bool unmap = false;
        u32 type;
@@ -317,14 +318,15 @@ static blk_status_t virtio_queue_rq(struct blk_mq_hw_ctx *hctx,
        unsigned long flags;
        unsigned int num;
        int qid = hctx->queue_num;
-       int err;
        bool notify = false;
+       blk_status_t status;
+       int err;
 
        BUG_ON(req->nr_phys_segments + 2 > vblk->sg_elems);
 
-       err = virtblk_setup_cmd(vblk->vdev, req, vbr);
-       if (unlikely(err))
-               return err;
+       status = virtblk_setup_cmd(vblk->vdev, req, vbr);
+       if (unlikely(status))
+               return status;
 
        blk_mq_start_request(req);
 
--

MST