Skip to contentSkip to conversation

virtio-scsi: clean up virtio_scsi_parse_cdb

PATCH In review Paolo Bonzini 2 participants 2 messages Sep 18, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio-scsi: clean up virtio_scsi_parse_cdb

The command direction according to the guest-passed buffers is already stored in the VirtIOSCSIReq. We can use it instead of computing it again from req->elem.

---
 hw/scsi/virtio-scsi.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
hw/scsi/virtio-scsi.c +1 -7
index f0d21a3..6953cbe 100644
@@ -430,13 +430,7 @@ static int virtio_scsi_parse_cdb(SCSIDevice *dev, SCSICommand *cmd,
      * host device passthrough.
      */
     cmd->xfer = req->qsgl.size;
-    if (cmd->xfer == 0) {
-        cmd->mode = SCSI_XFER_NONE;
-    } else if (iov_size(req->elem.in_sg, req->elem.in_num) > req->resp_size) {
-        cmd->mode = SCSI_XFER_FROM_DEV;
-    } else {
-        cmd->mode = SCSI_XFER_TO_DEV;
-    }
+    cmd->mode = req->mode;
     return 0;
 }
 
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 20 lines · Paolo Bonzini

The command direction according to the guest-passed buffers is already stored in the VirtIOSCSIReq. We can use it instead of computing it again from req->elem.

---
 hw/scsi/virtio-scsi.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
hw/scsi/virtio-scsi.c +0 -1
index f0d21a3..6953cbe 100644
@@ -430,13 +430,7 @@ static int virtio_scsi_parse_cdb(SCSIDevice *dev, SCSICommand *cmd,
      * host device passthrough.
      */
     cmd->xfer = req->qsgl.size;
-    if (cmd->xfer == 0) {

hw/scsi/virtio-scsi.c static int virtio_scsi_parse_cdb(SCSIDevice *dev, SCSICommand *cmd, · line 436

Quoted 10 lines
hw/scsi/virtio-scsi.c +1 -6
-        cmd->mode = SCSI_XFER_NONE;
-    } else if (iov_size(req->elem.in_sg, req->elem.in_num) > req->resp_size) {
-        cmd->mode = SCSI_XFER_FROM_DEV;
-    } else {
-        cmd->mode = SCSI_XFER_TO_DEV;
-    }
+    cmd->mode = req->mode;
     return 0;
 }
 

virtio_scsi_handle_cmd() [hw/scsi/virtio-scsi.c]
virtio_scsi_parse_req() [hw/scsi/virtio-scsi.c]

    /* sets req->mode */

scsi_req_new() [hw/scsi/scsi-bus.c]
scsi_block_parse_cdb() | scsi_generic_parse_cdb() [hw/scsi/scsi-disk.c | hw/scsi/scsi-generic.c]
scsi_bus_parse_cdb() [hw/scsi/scsi-bus.c]
virtio_scsi_parse_cdb() [hw/scsi/virtio-scsi.c]
/* uses req->mode */