scsi: create common SCSIRequest structure.

Rename the SCSIRequest structs in scsi-disk.c and scsi-generic.c to
SCSIDiskReq and SCSIGenericReq.  Create a SCSIRequest struct and move
the common elements over.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
Gerd Hoffmann 2009-11-26 15:33:48 +01:00 committed by Anthony Liguori
parent 1e37607b5e
commit 4c41d2ef5f
3 changed files with 114 additions and 107 deletions

View File

@ -46,10 +46,8 @@ do { fprintf(stderr, "scsi-disk: " fmt , ## __VA_ARGS__); } while (0)
typedef struct SCSIDiskState SCSIDiskState; typedef struct SCSIDiskState SCSIDiskState;
typedef struct SCSIRequest { typedef struct SCSIDiskReq {
SCSIBus *bus; SCSIRequest req;
SCSIDiskState *dev;
uint32_t tag;
/* ??? We should probably keep track of whether the data transfer is /* ??? We should probably keep track of whether the data transfer is
a read or a write. Currently we rely on the host getting it right. */ a read or a write. Currently we rely on the host getting it right. */
/* Both sector and sector_count are in terms of qemu 512 byte blocks. */ /* Both sector and sector_count are in terms of qemu 512 byte blocks. */
@ -57,16 +55,15 @@ typedef struct SCSIRequest {
uint32_t sector_count; uint32_t sector_count;
struct iovec iov; struct iovec iov;
QEMUIOVector qiov; QEMUIOVector qiov;
BlockDriverAIOCB *aiocb; struct SCSIDiskReq *next;
struct SCSIRequest *next;
uint32_t status; uint32_t status;
} SCSIRequest; } SCSIDiskReq;
struct SCSIDiskState struct SCSIDiskState
{ {
SCSIDevice qdev; SCSIDevice qdev;
DriveInfo *dinfo; DriveInfo *dinfo;
SCSIRequest *requests; SCSIDiskReq *requests;
/* The qemu block layer uses a fixed 512 byte sector size. /* The qemu block layer uses a fixed 512 byte sector size.
This is the number of 512 byte blocks in a single scsi sector. */ This is the number of 512 byte blocks in a single scsi sector. */
int cluster_size; int cluster_size;
@ -77,26 +74,26 @@ struct SCSIDiskState
}; };
/* Global pool of SCSIRequest structures. */ /* Global pool of SCSIRequest structures. */
static SCSIRequest *free_requests = NULL; static SCSIDiskReq *free_requests = NULL;
static SCSIRequest *scsi_new_request(SCSIDevice *d, uint32_t tag) static SCSIDiskReq *scsi_new_request(SCSIDevice *d, uint32_t tag)
{ {
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, d); SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, d);
SCSIRequest *r; SCSIDiskReq *r;
if (free_requests) { if (free_requests) {
r = free_requests; r = free_requests;
free_requests = r->next; free_requests = r->next;
} else { } else {
r = qemu_malloc(sizeof(SCSIRequest)); r = qemu_malloc(sizeof(SCSIDiskReq));
r->iov.iov_base = qemu_memalign(512, SCSI_DMA_BUF_SIZE); r->iov.iov_base = qemu_memalign(512, SCSI_DMA_BUF_SIZE);
} }
r->bus = scsi_bus_from_device(d); r->req.bus = scsi_bus_from_device(d);
r->dev = s; r->req.dev = d;
r->tag = tag; r->req.tag = tag;
r->sector_count = 0; r->sector_count = 0;
r->iov.iov_len = 0; r->iov.iov_len = 0;
r->aiocb = NULL; r->req.aiocb = NULL;
r->status = 0; r->status = 0;
r->next = s->requests; r->next = s->requests;
@ -104,10 +101,10 @@ static SCSIRequest *scsi_new_request(SCSIDevice *d, uint32_t tag)
return r; return r;
} }
static void scsi_remove_request(SCSIRequest *r) static void scsi_remove_request(SCSIDiskReq *r)
{ {
SCSIRequest *last; SCSIDiskReq *last;
SCSIDiskState *s = r->dev; SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev);
if (s->requests == r) { if (s->requests == r) {
s->requests = r->next; s->requests = r->next;
@ -125,64 +122,65 @@ static void scsi_remove_request(SCSIRequest *r)
free_requests = r; free_requests = r;
} }
static SCSIRequest *scsi_find_request(SCSIDiskState *s, uint32_t tag) static SCSIDiskReq *scsi_find_request(SCSIDiskState *s, uint32_t tag)
{ {
SCSIRequest *r; SCSIDiskReq *r;
r = s->requests; r = s->requests;
while (r && r->tag != tag) while (r && r->req.tag != tag)
r = r->next; r = r->next;
return r; return r;
} }
/* Helper function for command completion. */ /* Helper function for command completion. */
static void scsi_command_complete(SCSIRequest *r, int status, int sense) static void scsi_command_complete(SCSIDiskReq *r, int status, int sense)
{ {
SCSIDiskState *s = r->dev; SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev);
uint32_t tag; uint32_t tag;
DPRINTF("Command complete tag=0x%x status=%d sense=%d\n", r->tag, status, sense); DPRINTF("Command complete tag=0x%x status=%d sense=%d\n",
r->req.tag, status, sense);
s->sense = sense; s->sense = sense;
tag = r->tag; tag = r->req.tag;
scsi_remove_request(r); scsi_remove_request(r);
r->bus->complete(r->bus, SCSI_REASON_DONE, tag, status); r->req.bus->complete(r->req.bus, SCSI_REASON_DONE, tag, status);
} }
/* Cancel a pending data transfer. */ /* Cancel a pending data transfer. */
static void scsi_cancel_io(SCSIDevice *d, uint32_t tag) static void scsi_cancel_io(SCSIDevice *d, uint32_t tag)
{ {
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, d); SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, d);
SCSIRequest *r; SCSIDiskReq *r;
DPRINTF("Cancel tag=0x%x\n", tag); DPRINTF("Cancel tag=0x%x\n", tag);
r = scsi_find_request(s, tag); r = scsi_find_request(s, tag);
if (r) { if (r) {
if (r->aiocb) if (r->req.aiocb)
bdrv_aio_cancel(r->aiocb); bdrv_aio_cancel(r->req.aiocb);
r->aiocb = NULL; r->req.aiocb = NULL;
scsi_remove_request(r); scsi_remove_request(r);
} }
} }
static void scsi_read_complete(void * opaque, int ret) static void scsi_read_complete(void * opaque, int ret)
{ {
SCSIRequest *r = (SCSIRequest *)opaque; SCSIDiskReq *r = (SCSIDiskReq *)opaque;
if (ret) { if (ret) {
DPRINTF("IO error\n"); DPRINTF("IO error\n");
r->bus->complete(r->bus, SCSI_REASON_DATA, r->tag, 0); r->req.bus->complete(r->req.bus, SCSI_REASON_DATA, r->req.tag, 0);
scsi_command_complete(r, STATUS_CHECK_CONDITION, SENSE_NO_SENSE); scsi_command_complete(r, STATUS_CHECK_CONDITION, SENSE_NO_SENSE);
return; return;
} }
DPRINTF("Data ready tag=0x%x len=%" PRId64 "\n", r->tag, r->iov.iov_len); DPRINTF("Data ready tag=0x%x len=%" PRId64 "\n", r->req.tag, r->iov.iov_len);
r->bus->complete(r->bus, SCSI_REASON_DATA, r->tag, r->iov.iov_len); r->req.bus->complete(r->req.bus, SCSI_REASON_DATA, r->req.tag, r->iov.iov_len);
} }
/* Read more data from scsi device into buffer. */ /* Read more data from scsi device into buffer. */
static void scsi_read_data(SCSIDevice *d, uint32_t tag) static void scsi_read_data(SCSIDevice *d, uint32_t tag)
{ {
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, d); SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, d);
SCSIRequest *r; SCSIDiskReq *r;
uint32_t n; uint32_t n;
r = scsi_find_request(s, tag); r = scsi_find_request(s, tag);
@ -195,7 +193,7 @@ static void scsi_read_data(SCSIDevice *d, uint32_t tag)
if (r->sector_count == (uint32_t)-1) { if (r->sector_count == (uint32_t)-1) {
DPRINTF("Read buf_len=%" PRId64 "\n", r->iov.iov_len); DPRINTF("Read buf_len=%" PRId64 "\n", r->iov.iov_len);
r->sector_count = 0; r->sector_count = 0;
r->bus->complete(r->bus, SCSI_REASON_DATA, r->tag, r->iov.iov_len); r->req.bus->complete(r->req.bus, SCSI_REASON_DATA, r->req.tag, r->iov.iov_len);
return; return;
} }
DPRINTF("Read sector_count=%d\n", r->sector_count); DPRINTF("Read sector_count=%d\n", r->sector_count);
@ -210,17 +208,18 @@ static void scsi_read_data(SCSIDevice *d, uint32_t tag)
r->iov.iov_len = n * 512; r->iov.iov_len = n * 512;
qemu_iovec_init_external(&r->qiov, &r->iov, 1); qemu_iovec_init_external(&r->qiov, &r->iov, 1);
r->aiocb = bdrv_aio_readv(s->dinfo->bdrv, r->sector, &r->qiov, n, r->req.aiocb = bdrv_aio_readv(s->dinfo->bdrv, r->sector, &r->qiov, n,
scsi_read_complete, r); scsi_read_complete, r);
if (r->aiocb == NULL) if (r->req.aiocb == NULL)
scsi_command_complete(r, STATUS_CHECK_CONDITION, SENSE_HARDWARE_ERROR); scsi_command_complete(r, STATUS_CHECK_CONDITION, SENSE_HARDWARE_ERROR);
r->sector += n; r->sector += n;
r->sector_count -= n; r->sector_count -= n;
} }
static int scsi_handle_write_error(SCSIRequest *r, int error) static int scsi_handle_write_error(SCSIDiskReq *r, int error)
{ {
BlockInterfaceErrorAction action = drive_get_onerror(r->dev->dinfo->bdrv); SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev);
BlockInterfaceErrorAction action = drive_get_onerror(s->dinfo->bdrv);
if (action == BLOCK_ERR_IGNORE) if (action == BLOCK_ERR_IGNORE)
return 0; return 0;
@ -239,11 +238,11 @@ static int scsi_handle_write_error(SCSIRequest *r, int error)
static void scsi_write_complete(void * opaque, int ret) static void scsi_write_complete(void * opaque, int ret)
{ {
SCSIRequest *r = (SCSIRequest *)opaque; SCSIDiskReq *r = (SCSIDiskReq *)opaque;
uint32_t len; uint32_t len;
uint32_t n; uint32_t n;
r->aiocb = NULL; r->req.aiocb = NULL;
if (ret) { if (ret) {
if (scsi_handle_write_error(r, -ret)) if (scsi_handle_write_error(r, -ret))
@ -261,22 +260,22 @@ static void scsi_write_complete(void * opaque, int ret)
len = SCSI_DMA_BUF_SIZE; len = SCSI_DMA_BUF_SIZE;
} }
r->iov.iov_len = len; r->iov.iov_len = len;
DPRINTF("Write complete tag=0x%x more=%d\n", r->tag, len); DPRINTF("Write complete tag=0x%x more=%d\n", r->req.tag, len);
r->bus->complete(r->bus, SCSI_REASON_DATA, r->tag, len); r->req.bus->complete(r->req.bus, SCSI_REASON_DATA, r->req.tag, len);
} }
} }
static void scsi_write_request(SCSIRequest *r) static void scsi_write_request(SCSIDiskReq *r)
{ {
SCSIDiskState *s = r->dev; SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev);
uint32_t n; uint32_t n;
n = r->iov.iov_len / 512; n = r->iov.iov_len / 512;
if (n) { if (n) {
qemu_iovec_init_external(&r->qiov, &r->iov, 1); qemu_iovec_init_external(&r->qiov, &r->iov, 1);
r->aiocb = bdrv_aio_writev(s->dinfo->bdrv, r->sector, &r->qiov, n, r->req.aiocb = bdrv_aio_writev(s->dinfo->bdrv, r->sector, &r->qiov, n,
scsi_write_complete, r); scsi_write_complete, r);
if (r->aiocb == NULL) if (r->req.aiocb == NULL)
scsi_command_complete(r, STATUS_CHECK_CONDITION, scsi_command_complete(r, STATUS_CHECK_CONDITION,
SENSE_HARDWARE_ERROR); SENSE_HARDWARE_ERROR);
} else { } else {
@ -290,7 +289,7 @@ static void scsi_write_request(SCSIRequest *r)
static int scsi_write_data(SCSIDevice *d, uint32_t tag) static int scsi_write_data(SCSIDevice *d, uint32_t tag)
{ {
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, d); SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, d);
SCSIRequest *r; SCSIDiskReq *r;
DPRINTF("Write data tag=0x%x\n", tag); DPRINTF("Write data tag=0x%x\n", tag);
r = scsi_find_request(s, tag); r = scsi_find_request(s, tag);
@ -300,7 +299,7 @@ static int scsi_write_data(SCSIDevice *d, uint32_t tag)
return 1; return 1;
} }
if (r->aiocb) if (r->req.aiocb)
BADF("Data transfer already in progress\n"); BADF("Data transfer already in progress\n");
scsi_write_request(r); scsi_write_request(r);
@ -311,7 +310,7 @@ static int scsi_write_data(SCSIDevice *d, uint32_t tag)
static void scsi_dma_restart_bh(void *opaque) static void scsi_dma_restart_bh(void *opaque)
{ {
SCSIDiskState *s = opaque; SCSIDiskState *s = opaque;
SCSIRequest *r = s->requests; SCSIDiskReq *r = s->requests;
qemu_bh_delete(s->bh); qemu_bh_delete(s->bh);
s->bh = NULL; s->bh = NULL;
@ -342,7 +341,7 @@ static void scsi_dma_restart_cb(void *opaque, int running, int reason)
static uint8_t *scsi_get_buf(SCSIDevice *d, uint32_t tag) static uint8_t *scsi_get_buf(SCSIDevice *d, uint32_t tag)
{ {
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, d); SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, d);
SCSIRequest *r; SCSIDiskReq *r;
r = scsi_find_request(s, tag); r = scsi_find_request(s, tag);
if (!r) { if (!r) {
@ -368,7 +367,7 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag,
int is_write; int is_write;
uint8_t command; uint8_t command;
uint8_t *outbuf; uint8_t *outbuf;
SCSIRequest *r; SCSIDiskReq *r;
command = buf[0]; command = buf[0];
r = scsi_find_request(s, tag); r = scsi_find_request(s, tag);
@ -606,7 +605,7 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag,
outbuf[3] = 2; /* Format 2 */ outbuf[3] = 2; /* Format 2 */
outbuf[4] = len - 5; /* Additional Length = (Len - 1) - 4 */ outbuf[4] = len - 5; /* Additional Length = (Len - 1) - 4 */
/* Sync data transfer and TCQ. */ /* Sync data transfer and TCQ. */
outbuf[7] = 0x10 | (r->bus->tcq ? 0x02 : 0); outbuf[7] = 0x10 | (r->req.bus->tcq ? 0x02 : 0);
r->iov.iov_len = len; r->iov.iov_len = len;
break; break;
case 0x16: case 0x16:

View File

@ -54,24 +54,21 @@ do { fprintf(stderr, "scsi-generic: " fmt , ## __VA_ARGS__); } while (0)
typedef struct SCSIGenericState SCSIGenericState; typedef struct SCSIGenericState SCSIGenericState;
typedef struct SCSIRequest { typedef struct SCSIGenericReq {
BlockDriverAIOCB *aiocb; SCSIRequest req;
struct SCSIRequest *next; struct SCSIGenericReq *next;
SCSIBus *bus;
SCSIGenericState *dev;
uint32_t tag;
uint8_t cmd[SCSI_CMD_BUF_SIZE]; uint8_t cmd[SCSI_CMD_BUF_SIZE];
int cmdlen; int cmdlen;
uint8_t *buf; uint8_t *buf;
int buflen; int buflen;
int len; int len;
sg_io_hdr_t io_header; sg_io_hdr_t io_header;
} SCSIRequest; } SCSIGenericReq;
struct SCSIGenericState struct SCSIGenericState
{ {
SCSIDevice qdev; SCSIDevice qdev;
SCSIRequest *requests; SCSIGenericReq *requests;
DriveInfo *dinfo; DriveInfo *dinfo;
int type; int type;
int blocksize; int blocksize;
@ -81,30 +78,30 @@ struct SCSIGenericState
uint8_t senselen; uint8_t senselen;
}; };
/* Global pool of SCSIRequest structures. */ /* Global pool of SCSIGenericReq structures. */
static SCSIRequest *free_requests = NULL; static SCSIGenericReq *free_requests = NULL;
static SCSIRequest *scsi_new_request(SCSIDevice *d, uint32_t tag) static SCSIGenericReq *scsi_new_request(SCSIDevice *d, uint32_t tag)
{ {
SCSIGenericState *s = DO_UPCAST(SCSIGenericState, qdev, d); SCSIGenericState *s = DO_UPCAST(SCSIGenericState, qdev, d);
SCSIRequest *r; SCSIGenericReq *r;
if (free_requests) { if (free_requests) {
r = free_requests; r = free_requests;
free_requests = r->next; free_requests = r->next;
} else { } else {
r = qemu_malloc(sizeof(SCSIRequest)); r = qemu_malloc(sizeof(SCSIGenericReq));
r->buf = NULL; r->buf = NULL;
r->buflen = 0; r->buflen = 0;
} }
r->bus = scsi_bus_from_device(d); r->req.bus = scsi_bus_from_device(d);
r->dev = s; r->req.dev = d;
r->tag = tag; r->req.tag = tag;
memset(r->cmd, 0, sizeof(r->cmd)); memset(r->cmd, 0, sizeof(r->cmd));
memset(&r->io_header, 0, sizeof(r->io_header)); memset(&r->io_header, 0, sizeof(r->io_header));
r->cmdlen = 0; r->cmdlen = 0;
r->len = 0; r->len = 0;
r->aiocb = NULL; r->req.aiocb = NULL;
/* link */ /* link */
@ -113,10 +110,10 @@ static SCSIRequest *scsi_new_request(SCSIDevice *d, uint32_t tag)
return r; return r;
} }
static void scsi_remove_request(SCSIRequest *r) static void scsi_remove_request(SCSIGenericReq *r)
{ {
SCSIRequest *last; SCSIGenericReq *last;
SCSIGenericState *s = r->dev; SCSIGenericState *s = DO_UPCAST(SCSIGenericState, qdev, r->req.dev);
if (s->requests == r) { if (s->requests == r) {
s->requests = r->next; s->requests = r->next;
@ -134,12 +131,12 @@ static void scsi_remove_request(SCSIRequest *r)
free_requests = r; free_requests = r;
} }
static SCSIRequest *scsi_find_request(SCSIGenericState *s, uint32_t tag) static SCSIGenericReq *scsi_find_request(SCSIGenericState *s, uint32_t tag)
{ {
SCSIRequest *r; SCSIGenericReq *r;
r = s->requests; r = s->requests;
while (r && r->tag != tag) while (r && r->req.tag != tag)
r = r->next; r = r->next;
return r; return r;
@ -148,8 +145,8 @@ static SCSIRequest *scsi_find_request(SCSIGenericState *s, uint32_t tag)
/* Helper function for command completion. */ /* Helper function for command completion. */
static void scsi_command_complete(void *opaque, int ret) static void scsi_command_complete(void *opaque, int ret)
{ {
SCSIRequest *r = (SCSIRequest *)opaque; SCSIGenericReq *r = (SCSIGenericReq *)opaque;
SCSIGenericState *s = r->dev; SCSIGenericState *s = DO_UPCAST(SCSIGenericState, qdev, r->req.dev);
uint32_t tag; uint32_t tag;
int status; int status;
@ -171,10 +168,10 @@ static void scsi_command_complete(void *opaque, int ret)
status = GOOD << 1; status = GOOD << 1;
} }
DPRINTF("Command complete 0x%p tag=0x%x status=%d\n", DPRINTF("Command complete 0x%p tag=0x%x status=%d\n",
r, r->tag, status); r, r->req.tag, status);
tag = r->tag; tag = r->req.tag;
scsi_remove_request(r); scsi_remove_request(r);
r->bus->complete(r->bus, SCSI_REASON_DONE, tag, status); r->req.bus->complete(r->req.bus, SCSI_REASON_DONE, tag, status);
} }
/* Cancel a pending data transfer. */ /* Cancel a pending data transfer. */
@ -182,35 +179,37 @@ static void scsi_cancel_io(SCSIDevice *d, uint32_t tag)
{ {
DPRINTF("scsi_cancel_io 0x%x\n", tag); DPRINTF("scsi_cancel_io 0x%x\n", tag);
SCSIGenericState *s = DO_UPCAST(SCSIGenericState, qdev, d); SCSIGenericState *s = DO_UPCAST(SCSIGenericState, qdev, d);
SCSIRequest *r; SCSIGenericReq *r;
DPRINTF("Cancel tag=0x%x\n", tag); DPRINTF("Cancel tag=0x%x\n", tag);
r = scsi_find_request(s, tag); r = scsi_find_request(s, tag);
if (r) { if (r) {
if (r->aiocb) if (r->req.aiocb)
bdrv_aio_cancel(r->aiocb); bdrv_aio_cancel(r->req.aiocb);
r->aiocb = NULL; r->req.aiocb = NULL;
scsi_remove_request(r); scsi_remove_request(r);
} }
} }
static int execute_command(BlockDriverState *bdrv, static int execute_command(BlockDriverState *bdrv,
SCSIRequest *r, int direction, SCSIGenericReq *r, int direction,
BlockDriverCompletionFunc *complete) BlockDriverCompletionFunc *complete)
{ {
SCSIGenericState *s = DO_UPCAST(SCSIGenericState, qdev, r->req.dev);
r->io_header.interface_id = 'S'; r->io_header.interface_id = 'S';
r->io_header.dxfer_direction = direction; r->io_header.dxfer_direction = direction;
r->io_header.dxferp = r->buf; r->io_header.dxferp = r->buf;
r->io_header.dxfer_len = r->buflen; r->io_header.dxfer_len = r->buflen;
r->io_header.cmdp = r->cmd; r->io_header.cmdp = r->cmd;
r->io_header.cmd_len = r->cmdlen; r->io_header.cmd_len = r->cmdlen;
r->io_header.mx_sb_len = sizeof(r->dev->sensebuf); r->io_header.mx_sb_len = sizeof(s->sensebuf);
r->io_header.sbp = r->dev->sensebuf; r->io_header.sbp = s->sensebuf;
r->io_header.timeout = MAX_UINT; r->io_header.timeout = MAX_UINT;
r->io_header.usr_ptr = r; r->io_header.usr_ptr = r;
r->io_header.flags |= SG_FLAG_DIRECT_IO; r->io_header.flags |= SG_FLAG_DIRECT_IO;
r->aiocb = bdrv_aio_ioctl(bdrv, SG_IO, &r->io_header, complete, r); r->req.aiocb = bdrv_aio_ioctl(bdrv, SG_IO, &r->io_header, complete, r);
if (r->aiocb == NULL) { if (r->req.aiocb == NULL) {
BADF("execute_command: read failed !\n"); BADF("execute_command: read failed !\n");
return -1; return -1;
} }
@ -220,7 +219,7 @@ static int execute_command(BlockDriverState *bdrv,
static void scsi_read_complete(void * opaque, int ret) static void scsi_read_complete(void * opaque, int ret)
{ {
SCSIRequest *r = (SCSIRequest *)opaque; SCSIGenericReq *r = (SCSIGenericReq *)opaque;
int len; int len;
if (ret) { if (ret) {
@ -229,10 +228,10 @@ static void scsi_read_complete(void * opaque, int ret)
return; return;
} }
len = r->io_header.dxfer_len - r->io_header.resid; len = r->io_header.dxfer_len - r->io_header.resid;
DPRINTF("Data ready tag=0x%x len=%d\n", r->tag, len); DPRINTF("Data ready tag=0x%x len=%d\n", r->req.tag, len);
r->len = -1; r->len = -1;
r->bus->complete(r->bus, SCSI_REASON_DATA, r->tag, len); r->req.bus->complete(r->req.bus, SCSI_REASON_DATA, r->req.tag, len);
if (len == 0) if (len == 0)
scsi_command_complete(r, 0); scsi_command_complete(r, 0);
} }
@ -241,7 +240,7 @@ static void scsi_read_complete(void * opaque, int ret)
static void scsi_read_data(SCSIDevice *d, uint32_t tag) static void scsi_read_data(SCSIDevice *d, uint32_t tag)
{ {
SCSIGenericState *s = DO_UPCAST(SCSIGenericState, qdev, d); SCSIGenericState *s = DO_UPCAST(SCSIGenericState, qdev, d);
SCSIRequest *r; SCSIGenericReq *r;
int ret; int ret;
DPRINTF("scsi_read_data 0x%x\n", tag); DPRINTF("scsi_read_data 0x%x\n", tag);
@ -266,11 +265,11 @@ static void scsi_read_data(SCSIDevice *d, uint32_t tag)
r->io_header.status = 0; r->io_header.status = 0;
r->io_header.dxfer_len = s->senselen; r->io_header.dxfer_len = s->senselen;
r->len = -1; r->len = -1;
DPRINTF("Data ready tag=0x%x len=%d\n", r->tag, s->senselen); DPRINTF("Data ready tag=0x%x len=%d\n", r->req.tag, s->senselen);
DPRINTF("Sense: %d %d %d %d %d %d %d %d\n", DPRINTF("Sense: %d %d %d %d %d %d %d %d\n",
r->buf[0], r->buf[1], r->buf[2], r->buf[3], r->buf[0], r->buf[1], r->buf[2], r->buf[3],
r->buf[4], r->buf[5], r->buf[6], r->buf[7]); r->buf[4], r->buf[5], r->buf[6], r->buf[7]);
r->bus->complete(r->bus, SCSI_REASON_DATA, r->tag, s->senselen); r->req.bus->complete(r->req.bus, SCSI_REASON_DATA, r->req.tag, s->senselen);
return; return;
} }
@ -283,7 +282,8 @@ static void scsi_read_data(SCSIDevice *d, uint32_t tag)
static void scsi_write_complete(void * opaque, int ret) static void scsi_write_complete(void * opaque, int ret)
{ {
SCSIRequest *r = (SCSIRequest *)opaque; SCSIGenericReq *r = (SCSIGenericReq *)opaque;
SCSIGenericState *s = DO_UPCAST(SCSIGenericState, qdev, r->req.dev);
DPRINTF("scsi_write_complete() ret = %d\n", ret); DPRINTF("scsi_write_complete() ret = %d\n", ret);
if (ret) { if (ret) {
@ -293,9 +293,9 @@ static void scsi_write_complete(void * opaque, int ret)
} }
if (r->cmd[0] == MODE_SELECT && r->cmd[4] == 12 && if (r->cmd[0] == MODE_SELECT && r->cmd[4] == 12 &&
r->dev->type == TYPE_TAPE) { s->type == TYPE_TAPE) {
r->dev->blocksize = (r->buf[9] << 16) | (r->buf[10] << 8) | r->buf[11]; s->blocksize = (r->buf[9] << 16) | (r->buf[10] << 8) | r->buf[11];
DPRINTF("block size %d\n", r->dev->blocksize); DPRINTF("block size %d\n", s->blocksize);
} }
scsi_command_complete(r, ret); scsi_command_complete(r, ret);
@ -306,7 +306,7 @@ static void scsi_write_complete(void * opaque, int ret)
static int scsi_write_data(SCSIDevice *d, uint32_t tag) static int scsi_write_data(SCSIDevice *d, uint32_t tag)
{ {
SCSIGenericState *s = DO_UPCAST(SCSIGenericState, qdev, d); SCSIGenericState *s = DO_UPCAST(SCSIGenericState, qdev, d);
SCSIRequest *r; SCSIGenericReq *r;
int ret; int ret;
DPRINTF("scsi_write_data 0x%x\n", tag); DPRINTF("scsi_write_data 0x%x\n", tag);
@ -320,7 +320,7 @@ static int scsi_write_data(SCSIDevice *d, uint32_t tag)
if (r->len == 0) { if (r->len == 0) {
r->len = r->buflen; r->len = r->buflen;
r->bus->complete(r->bus, SCSI_REASON_DATA, r->tag, r->len); r->req.bus->complete(r->req.bus, SCSI_REASON_DATA, r->req.tag, r->len);
return 0; return 0;
} }
@ -337,7 +337,7 @@ static int scsi_write_data(SCSIDevice *d, uint32_t tag)
static uint8_t *scsi_get_buf(SCSIDevice *d, uint32_t tag) static uint8_t *scsi_get_buf(SCSIDevice *d, uint32_t tag)
{ {
SCSIGenericState *s = DO_UPCAST(SCSIGenericState, qdev, d); SCSIGenericState *s = DO_UPCAST(SCSIGenericState, qdev, d);
SCSIRequest *r; SCSIGenericReq *r;
r = scsi_find_request(s, tag); r = scsi_find_request(s, tag);
if (!r) { if (!r) {
BADF("Bad buffer tag 0x%x\n", tag); BADF("Bad buffer tag 0x%x\n", tag);
@ -512,7 +512,7 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag,
SCSIGenericState *s = DO_UPCAST(SCSIGenericState, qdev, d); SCSIGenericState *s = DO_UPCAST(SCSIGenericState, qdev, d);
uint32_t len=0; uint32_t len=0;
int cmdlen=0; int cmdlen=0;
SCSIRequest *r; SCSIGenericReq *r;
SCSIBus *bus; SCSIBus *bus;
int ret; int ret;
@ -653,7 +653,7 @@ static int get_stream_blocksize(BlockDriverState *bdrv)
static void scsi_destroy(SCSIDevice *d) static void scsi_destroy(SCSIDevice *d)
{ {
SCSIGenericState *s = DO_UPCAST(SCSIGenericState, qdev, d); SCSIGenericState *s = DO_UPCAST(SCSIGenericState, qdev, d);
SCSIRequest *r, *n; SCSIGenericReq *r, *n;
r = s->requests; r = s->requests;
while (r) { while (r) {

View File

@ -2,6 +2,7 @@
#define QEMU_HW_SCSI_H #define QEMU_HW_SCSI_H
#include "qdev.h" #include "qdev.h"
#include "block.h"
/* scsi-disk.c */ /* scsi-disk.c */
enum scsi_reason { enum scsi_reason {
@ -15,6 +16,13 @@ typedef struct SCSIDeviceInfo SCSIDeviceInfo;
typedef void (*scsi_completionfn)(SCSIBus *bus, int reason, uint32_t tag, typedef void (*scsi_completionfn)(SCSIBus *bus, int reason, uint32_t tag,
uint32_t arg); uint32_t arg);
typedef struct SCSIRequest {
SCSIBus *bus;
SCSIDevice *dev;
uint32_t tag;
BlockDriverAIOCB *aiocb;
} SCSIRequest;
struct SCSIDevice struct SCSIDevice
{ {
DeviceState qdev; DeviceState qdev;