[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 04/15] scsi: add scsi_req_init()
From: |
Gerd Hoffmann |
Subject: |
[Qemu-devel] [PATCH 04/15] scsi: add scsi_req_init() |
Date: |
Tue, 17 Nov 2009 11:17:40 +0100 |
Helper function to init SCSIRequest, so scsi-disk and scsi-generic
don't duplicate init code for the common bits.
Signed-off-by: Gerd Hoffmann <address@hidden>
---
hw/scsi-bus.c | 9 +++++++++
hw/scsi-disk.c | 9 +++------
hw/scsi-generic.c | 9 +++------
hw/scsi.h | 3 +++
4 files changed, 18 insertions(+), 12 deletions(-)
diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
index 801922b..c74d085 100644
--- a/hw/scsi-bus.c
+++ b/hw/scsi-bus.c
@@ -111,3 +111,12 @@ void scsi_bus_legacy_handle_cmdline(SCSIBus *bus)
scsi_bus_legacy_add_drive(bus, dinfo, unit);
}
}
+
+void scsi_req_init(SCSIRequest *req, SCSIDevice *d, uint32_t tag, uint32_t lun)
+{
+ req->bus = scsi_bus_from_device(d);
+ req->dev = d;
+ req->tag = tag;
+ req->lun = lun;
+ req->aiocb = NULL;
+}
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 2b13635..bb2d68c 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -74,7 +74,7 @@ struct SCSIDiskState
/* Global pool of SCSIRequest structures. */
static QTAILQ_HEAD(, SCSIRequest) free_requests =
QTAILQ_HEAD_INITIALIZER(free_requests);
-static SCSIDiskReq *scsi_new_request(SCSIDevice *d, uint32_t tag)
+static SCSIDiskReq *scsi_new_request(SCSIDevice *d, uint32_t tag, uint32_t lun)
{
SCSIDiskReq *r;
@@ -85,12 +85,9 @@ static SCSIDiskReq *scsi_new_request(SCSIDevice *d, uint32_t
tag)
r = qemu_malloc(sizeof(SCSIDiskReq));
r->iov.iov_base = qemu_memalign(512, SCSI_DMA_BUF_SIZE);
}
- r->req.bus = scsi_bus_from_device(d);
- r->req.dev = d;
- r->req.tag = tag;
+ scsi_req_init(&r->req, d, tag, lun);
r->sector_count = 0;
r->iov.iov_len = 0;
- r->req.aiocb = NULL;
r->status = 0;
QTAILQ_INSERT_TAIL(&d->requests, &r->req, next);
@@ -360,7 +357,7 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t
tag,
}
/* ??? Tags are not unique for different luns. We only implement a
single lun, so this should not matter. */
- r = scsi_new_request(d, tag);
+ r = scsi_new_request(d, tag, lun);
outbuf = (uint8_t *)r->iov.iov_base;
is_write = 0;
DPRINTF("Command: lun=%d tag=0x%x data=0x%02x", lun, tag, buf[0]);
diff --git a/hw/scsi-generic.c b/hw/scsi-generic.c
index 5ca6840..1e1907e 100644
--- a/hw/scsi-generic.c
+++ b/hw/scsi-generic.c
@@ -79,7 +79,7 @@ struct SCSIGenericState
/* Global pool of SCSIGenericReq structures. */
static QTAILQ_HEAD(, SCSIRequest) free_requests =
QTAILQ_HEAD_INITIALIZER(free_requests);
-static SCSIGenericReq *scsi_new_request(SCSIDevice *d, uint32_t tag)
+static SCSIGenericReq *scsi_new_request(SCSIDevice *d, uint32_t tag, uint32_t
lun)
{
SCSIGenericReq *r;
@@ -91,14 +91,11 @@ static SCSIGenericReq *scsi_new_request(SCSIDevice *d,
uint32_t tag)
r->buf = NULL;
r->buflen = 0;
}
- r->req.bus = scsi_bus_from_device(d);
- r->req.dev = d;
- r->req.tag = tag;
+ 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;
- r->req.aiocb = NULL;
QTAILQ_INSERT_TAIL(&d->requests, &r->req, next);
return r;
@@ -534,7 +531,7 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t
tag,
BADF("Tag 0x%x already in use %p\n", tag, r);
scsi_cancel_io(d, tag);
}
- r = scsi_new_request(d, tag);
+ r = scsi_new_request(d, tag, lun);
memcpy(r->cmd, cmd, cmdlen);
r->cmdlen = cmdlen;
diff --git a/hw/scsi.h b/hw/scsi.h
index a9b846c..85ce8a9 100644
--- a/hw/scsi.h
+++ b/hw/scsi.h
@@ -20,6 +20,7 @@ typedef struct SCSIRequest {
SCSIBus *bus;
SCSIDevice *dev;
uint32_t tag;
+ uint32_t lun;
BlockDriverAIOCB *aiocb;
QTAILQ_ENTRY(SCSIRequest) next;
} SCSIRequest;
@@ -74,4 +75,6 @@ static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d)
SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, DriveInfo *dinfo, int
unit);
void scsi_bus_legacy_handle_cmdline(SCSIBus *bus);
+void scsi_req_init(SCSIRequest *req, SCSIDevice *d, uint32_t tag, uint32_t
lun);
+
#endif
--
1.6.2.5