Signed-off-by: Gerd Hoffmann <kra...@redhat.com> --- hw/scsi-bus.c | 1 + hw/scsi-generic.c | 17 ++++++----------- hw/scsi.h | 6 ++++++ 3 files changed, 13 insertions(+), 11 deletions(-)
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; -- 1.6.2.5