diff mbox

[05/15] scsi: move scsi command from SCSIGenericReq to SCSIRequest.

Message ID 1258453071-3496-6-git-send-email-kraxel@redhat.com
State New
Headers show

Commit Message

Gerd Hoffmann Nov. 17, 2009, 10:17 a.m. UTC
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/scsi-bus.c     |    1 +
 hw/scsi-generic.c |   17 ++++++-----------
 hw/scsi.h         |    6 ++++++
 3 files changed, 13 insertions(+), 11 deletions(-)

Comments

Christoph Hellwig Nov. 17, 2009, 11:17 a.m. UTC | #1
On Tue, Nov 17, 2009 at 11:17:41AM +0100, Gerd Hoffmann wrote:
> 
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>

A little description of why you can it would be good.  I will
defintively help with my SBC thin provisioning implementation later, so
no complaints from me :)


Reviewed-by: Christoph Hellwig <hch@lst.de>
Paul Brook Nov. 17, 2009, 11:55 a.m. UTC | #2
> move scsi command from SCSIGenericReq to SCSIRequest.

Why? AFAICS This has precisely one user, and more importantly it is not 
populated by scsi-disk.c.

Sharing common code is good. Implementing shared fields inconsistently or 
putting implementation specific fields in common structures.

Paul
Gerd Hoffmann Nov. 17, 2009, 12:45 p.m. UTC | #3
On 11/17/09 12:55, Paul Brook wrote:
>> move scsi command from SCSIGenericReq to SCSIRequest.
>
> Why? AFAICS This has precisely one user, and more importantly it is not
> populated by scsi-disk.c.

Next patch of scsi patches will make scsi-disk use it too.

(in the git tree: a bunch of patches prefixed "scsi-disk: ").

cheers,
   Gerd
diff mbox

Patch

diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
index c74d085..73cfe58 100644
--- a/hw/scsi-bus.c
+++ b/hw/scsi-bus.c
@@ -119,4 +119,5 @@  void scsi_req_init(SCSIRequest *req, SCSIDevice *d, uint32_t tag, uint32_t lun)
     req->tag = tag;
     req->lun = lun;
     req->aiocb = NULL;
+    memset(&req->cmd, 0, sizeof(req->cmd));
 }
diff --git a/hw/scsi-generic.c b/hw/scsi-generic.c
index 1e1907e..68518da 100644
--- a/hw/scsi-generic.c
+++ b/hw/scsi-generic.c
@@ -42,7 +42,6 @@  do { fprintf(stderr, "scsi-generic: " fmt , ## __VA_ARGS__); } while (0)
 #define SET_CD_SPEED 0xbb
 #define BLANK 0xa1
 
-#define SCSI_CMD_BUF_SIZE     16
 #define SCSI_SENSE_BUF_SIZE 96
 
 #define SG_ERR_DRIVER_TIMEOUT 0x06
@@ -56,8 +55,6 @@  typedef struct SCSIGenericState SCSIGenericState;
 
 typedef struct SCSIGenericReq {
     SCSIRequest req;
-    uint8_t cmd[SCSI_CMD_BUF_SIZE];
-    int cmdlen;
     uint8_t *buf;
     int buflen;
     int len;
@@ -92,9 +89,7 @@  static SCSIGenericReq *scsi_new_request(SCSIDevice *d, uint32_t tag, uint32_t lu
         r->buflen = 0;
     }
     scsi_req_init(&r->req, d, tag, lun);
-    memset(r->cmd, 0, sizeof(r->cmd));
     memset(&r->io_header, 0, sizeof(r->io_header));
-    r->cmdlen = 0;
     r->len = 0;
 
     QTAILQ_INSERT_TAIL(&d->requests, &r->req, next);
@@ -177,8 +172,8 @@  static int execute_command(BlockDriverState *bdrv,
     r->io_header.dxfer_direction = direction;
     r->io_header.dxferp = r->buf;
     r->io_header.dxfer_len = r->buflen;
-    r->io_header.cmdp = r->cmd;
-    r->io_header.cmd_len = r->cmdlen;
+    r->io_header.cmdp = r->req.cmd.buf;
+    r->io_header.cmd_len = r->req.cmd.len;
     r->io_header.mx_sb_len = sizeof(s->sensebuf);
     r->io_header.sbp = s->sensebuf;
     r->io_header.timeout = MAX_UINT;
@@ -234,7 +229,7 @@  static void scsi_read_data(SCSIDevice *d, uint32_t tag)
         return;
     }
 
-    if (r->cmd[0] == REQUEST_SENSE && s->driver_status & SG_ERR_DRIVER_SENSE)
+    if (r->req.cmd.buf[0] == REQUEST_SENSE && s->driver_status & SG_ERR_DRIVER_SENSE)
     {
         s->senselen = MIN(r->len, s->senselen);
         memcpy(r->buf, s->sensebuf, s->senselen);
@@ -269,7 +264,7 @@  static void scsi_write_complete(void * opaque, int ret)
         return;
     }
 
-    if (r->cmd[0] == MODE_SELECT && r->cmd[4] == 12 &&
+    if (r->req.cmd.buf[0] == MODE_SELECT && r->req.cmd.buf[4] == 12 &&
         s->type == TYPE_TAPE) {
         s->blocksize = (r->buf[9] << 16) | (r->buf[10] << 8) | r->buf[11];
         DPRINTF("block size %d\n", s->blocksize);
@@ -533,8 +528,8 @@  static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag,
     }
     r = scsi_new_request(d, tag, lun);
 
-    memcpy(r->cmd, cmd, cmdlen);
-    r->cmdlen = cmdlen;
+    memcpy(r->req.cmd.buf, cmd, cmdlen);
+    r->req.cmd.len = cmdlen;
 
     if (len == 0) {
         if (r->buf != NULL)
diff --git a/hw/scsi.h b/hw/scsi.h
index 85ce8a9..e3f28ea 100644
--- a/hw/scsi.h
+++ b/hw/scsi.h
@@ -4,6 +4,8 @@ 
 #include "qdev.h"
 #include "block.h"
 
+#define SCSI_CMD_BUF_SIZE     16
+
 /* scsi-disk.c */
 enum scsi_reason {
     SCSI_REASON_DONE, /* Command complete.  */
@@ -21,6 +23,10 @@  typedef struct SCSIRequest {
     SCSIDevice        *dev;
     uint32_t          tag;
     uint32_t          lun;
+    struct {
+        uint8_t buf[SCSI_CMD_BUF_SIZE];
+        int len;
+    } cmd;
     BlockDriverAIOCB  *aiocb;
     QTAILQ_ENTRY(SCSIRequest) next;
 } SCSIRequest;