scsi: introduce SCSIReqOps
This will let allow requests to be dispatched through different callbacks, either common or per-device. This patch adjusts the API, the next one will move members to SCSIReqOps. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
b45ef674f4
commit
8dbd457488
@ -133,12 +133,12 @@ int scsi_bus_legacy_handle_cmdline(SCSIBus *bus)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
SCSIRequest *scsi_req_alloc(size_t size, SCSIDevice *d, uint32_t tag,
|
SCSIRequest *scsi_req_alloc(SCSIReqOps *reqops, SCSIDevice *d, uint32_t tag,
|
||||||
uint32_t lun, void *hba_private)
|
uint32_t lun, void *hba_private)
|
||||||
{
|
{
|
||||||
SCSIRequest *req;
|
SCSIRequest *req;
|
||||||
|
|
||||||
req = qemu_mallocz(size);
|
req = qemu_mallocz(reqops->size);
|
||||||
req->refcount = 1;
|
req->refcount = 1;
|
||||||
req->bus = scsi_bus_from_device(d);
|
req->bus = scsi_bus_from_device(d);
|
||||||
req->dev = d;
|
req->dev = d;
|
||||||
@ -147,6 +147,7 @@ SCSIRequest *scsi_req_alloc(size_t size, SCSIDevice *d, uint32_t tag,
|
|||||||
req->hba_private = hba_private;
|
req->hba_private = hba_private;
|
||||||
req->status = -1;
|
req->status = -1;
|
||||||
req->sense_len = 0;
|
req->sense_len = 0;
|
||||||
|
req->ops = reqops;
|
||||||
trace_scsi_req_alloc(req->dev->id, req->lun, req->tag);
|
trace_scsi_req_alloc(req->dev->id, req->lun, req->tag);
|
||||||
return req;
|
return req;
|
||||||
}
|
}
|
||||||
|
@ -76,19 +76,6 @@ struct SCSIDiskState
|
|||||||
static int scsi_handle_rw_error(SCSIDiskReq *r, int error, int type);
|
static int scsi_handle_rw_error(SCSIDiskReq *r, int error, int type);
|
||||||
static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf);
|
static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf);
|
||||||
|
|
||||||
static SCSIRequest *scsi_new_request(SCSIDevice *d, uint32_t tag,
|
|
||||||
uint32_t lun, void *hba_private)
|
|
||||||
{
|
|
||||||
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, d);
|
|
||||||
SCSIRequest *req;
|
|
||||||
SCSIDiskReq *r;
|
|
||||||
|
|
||||||
req = scsi_req_alloc(sizeof(SCSIDiskReq), &s->qdev, tag, lun, hba_private);
|
|
||||||
r = DO_UPCAST(SCSIDiskReq, req, req);
|
|
||||||
r->iov.iov_base = qemu_blockalign(s->bs, SCSI_DMA_BUF_SIZE);
|
|
||||||
return req;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void scsi_free_request(SCSIRequest *req)
|
static void scsi_free_request(SCSIRequest *req)
|
||||||
{
|
{
|
||||||
SCSIDiskReq *r = DO_UPCAST(SCSIDiskReq, req, req);
|
SCSIDiskReq *r = DO_UPCAST(SCSIDiskReq, req, req);
|
||||||
@ -1225,6 +1212,23 @@ static int scsi_disk_initfn(SCSIDevice *dev)
|
|||||||
return scsi_initfn(dev, scsi_type);
|
return scsi_initfn(dev, scsi_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static SCSIReqOps scsi_disk_reqops = {
|
||||||
|
.size = sizeof(SCSIDiskReq),
|
||||||
|
};
|
||||||
|
|
||||||
|
static SCSIRequest *scsi_new_request(SCSIDevice *d, uint32_t tag,
|
||||||
|
uint32_t lun, void *hba_private)
|
||||||
|
{
|
||||||
|
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, d);
|
||||||
|
SCSIRequest *req;
|
||||||
|
SCSIDiskReq *r;
|
||||||
|
|
||||||
|
req = scsi_req_alloc(&scsi_disk_reqops, &s->qdev, tag, lun, hba_private);
|
||||||
|
r = DO_UPCAST(SCSIDiskReq, req, req);
|
||||||
|
r->iov.iov_base = qemu_blockalign(s->bs, SCSI_DMA_BUF_SIZE);
|
||||||
|
return req;
|
||||||
|
}
|
||||||
|
|
||||||
#define DEFINE_SCSI_DISK_PROPERTIES() \
|
#define DEFINE_SCSI_DISK_PROPERTIES() \
|
||||||
DEFINE_BLOCK_PROPERTIES(SCSIDiskState, qdev.conf), \
|
DEFINE_BLOCK_PROPERTIES(SCSIDiskState, qdev.conf), \
|
||||||
DEFINE_PROP_STRING("ver", SCSIDiskState, version), \
|
DEFINE_PROP_STRING("ver", SCSIDiskState, version), \
|
||||||
|
@ -63,15 +63,6 @@ struct SCSIGenericState
|
|||||||
int lun;
|
int lun;
|
||||||
};
|
};
|
||||||
|
|
||||||
static SCSIRequest *scsi_new_request(SCSIDevice *d, uint32_t tag, uint32_t lun,
|
|
||||||
void *hba_private)
|
|
||||||
{
|
|
||||||
SCSIRequest *req;
|
|
||||||
|
|
||||||
req = scsi_req_alloc(sizeof(SCSIGenericReq), d, tag, lun, hba_private);
|
|
||||||
return req;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void scsi_free_request(SCSIRequest *req)
|
static void scsi_free_request(SCSIRequest *req)
|
||||||
{
|
{
|
||||||
SCSIGenericReq *r = DO_UPCAST(SCSIGenericReq, req, req);
|
SCSIGenericReq *r = DO_UPCAST(SCSIGenericReq, req, req);
|
||||||
@ -498,6 +489,19 @@ static int scsi_generic_initfn(SCSIDevice *dev)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static SCSIReqOps scsi_generic_req_ops = {
|
||||||
|
.size = sizeof(SCSIGenericReq),
|
||||||
|
};
|
||||||
|
|
||||||
|
static SCSIRequest *scsi_new_request(SCSIDevice *d, uint32_t tag, uint32_t lun,
|
||||||
|
void *hba_private)
|
||||||
|
{
|
||||||
|
SCSIRequest *req;
|
||||||
|
|
||||||
|
req = scsi_req_alloc(&scsi_generic_req_ops, d, tag, lun, hba_private);
|
||||||
|
return req;
|
||||||
|
}
|
||||||
|
|
||||||
static SCSIDeviceInfo scsi_generic_info = {
|
static SCSIDeviceInfo scsi_generic_info = {
|
||||||
.qdev.name = "scsi-generic",
|
.qdev.name = "scsi-generic",
|
||||||
.qdev.desc = "pass through generic scsi device (/dev/sg*)",
|
.qdev.desc = "pass through generic scsi device (/dev/sg*)",
|
||||||
|
@ -14,6 +14,7 @@ typedef struct SCSIBusOps SCSIBusOps;
|
|||||||
typedef struct SCSIDevice SCSIDevice;
|
typedef struct SCSIDevice SCSIDevice;
|
||||||
typedef struct SCSIDeviceInfo SCSIDeviceInfo;
|
typedef struct SCSIDeviceInfo SCSIDeviceInfo;
|
||||||
typedef struct SCSIRequest SCSIRequest;
|
typedef struct SCSIRequest SCSIRequest;
|
||||||
|
typedef struct SCSIReqOps SCSIReqOps;
|
||||||
|
|
||||||
enum SCSIXferMode {
|
enum SCSIXferMode {
|
||||||
SCSI_XFER_NONE, /* TEST_UNIT_READY, ... */
|
SCSI_XFER_NONE, /* TEST_UNIT_READY, ... */
|
||||||
@ -32,6 +33,7 @@ typedef struct SCSISense {
|
|||||||
struct SCSIRequest {
|
struct SCSIRequest {
|
||||||
SCSIBus *bus;
|
SCSIBus *bus;
|
||||||
SCSIDevice *dev;
|
SCSIDevice *dev;
|
||||||
|
SCSIReqOps *ops;
|
||||||
uint32_t refcount;
|
uint32_t refcount;
|
||||||
uint32_t tag;
|
uint32_t tag;
|
||||||
uint32_t lun;
|
uint32_t lun;
|
||||||
@ -69,6 +71,10 @@ int cdrom_read_toc(int nb_sectors, uint8_t *buf, int msf, int start_track);
|
|||||||
int cdrom_read_toc_raw(int nb_sectors, uint8_t *buf, int msf, int session_num);
|
int cdrom_read_toc_raw(int nb_sectors, uint8_t *buf, int msf, int session_num);
|
||||||
|
|
||||||
/* scsi-bus.c */
|
/* scsi-bus.c */
|
||||||
|
struct SCSIReqOps {
|
||||||
|
size_t size;
|
||||||
|
};
|
||||||
|
|
||||||
typedef int (*scsi_qdev_initfn)(SCSIDevice *dev);
|
typedef int (*scsi_qdev_initfn)(SCSIDevice *dev);
|
||||||
struct SCSIDeviceInfo {
|
struct SCSIDeviceInfo {
|
||||||
DeviceInfo qdev;
|
DeviceInfo qdev;
|
||||||
@ -144,7 +150,7 @@ extern const struct SCSISense sense_code_LUN_FAILURE;
|
|||||||
|
|
||||||
int scsi_sense_valid(SCSISense sense);
|
int scsi_sense_valid(SCSISense sense);
|
||||||
|
|
||||||
SCSIRequest *scsi_req_alloc(size_t size, SCSIDevice *d, uint32_t tag,
|
SCSIRequest *scsi_req_alloc(SCSIReqOps *reqops, SCSIDevice *d, uint32_t tag,
|
||||||
uint32_t lun, void *hba_private);
|
uint32_t lun, void *hba_private);
|
||||||
SCSIRequest *scsi_req_new(SCSIDevice *d, uint32_t tag, uint32_t lun,
|
SCSIRequest *scsi_req_new(SCSIDevice *d, uint32_t tag, uint32_t lun,
|
||||||
void *hba_private);
|
void *hba_private);
|
||||||
|
Loading…
Reference in New Issue
Block a user