virtio-scsi: add support for the any_layout feature
Store the request and response headers by value, and let virtio_scsi_parse_req check that there is only one of datain and dataout. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
a3de269ccc
commit
3eff1f46f0
|
@ -27,21 +27,27 @@ typedef struct VirtIOSCSIReq {
|
||||||
QEMUSGList qsgl;
|
QEMUSGList qsgl;
|
||||||
SCSIRequest *sreq;
|
SCSIRequest *sreq;
|
||||||
size_t resp_size;
|
size_t resp_size;
|
||||||
|
enum SCSIXferMode mode;
|
||||||
|
QEMUIOVector resp_iov;
|
||||||
union {
|
union {
|
||||||
char *buf;
|
VirtIOSCSICmdResp cmd;
|
||||||
VirtIOSCSICmdResp *cmd;
|
VirtIOSCSICtrlTMFResp tmf;
|
||||||
VirtIOSCSICtrlTMFResp *tmf;
|
VirtIOSCSICtrlANResp an;
|
||||||
VirtIOSCSICtrlANResp *an;
|
VirtIOSCSIEvent event;
|
||||||
VirtIOSCSIEvent *event;
|
|
||||||
} resp;
|
} resp;
|
||||||
union {
|
union {
|
||||||
char *buf;
|
struct {
|
||||||
VirtIOSCSICmdReq *cmd;
|
VirtIOSCSICmdReq cmd;
|
||||||
VirtIOSCSICtrlTMFReq *tmf;
|
uint8_t cdb[];
|
||||||
VirtIOSCSICtrlANReq *an;
|
} QEMU_PACKED;
|
||||||
|
VirtIOSCSICtrlTMFReq tmf;
|
||||||
|
VirtIOSCSICtrlANReq an;
|
||||||
} req;
|
} req;
|
||||||
} VirtIOSCSIReq;
|
} VirtIOSCSIReq;
|
||||||
|
|
||||||
|
QEMU_BUILD_BUG_ON(offsetof(VirtIOSCSIReq, req.cdb) !=
|
||||||
|
offsetof(VirtIOSCSIReq, req.cmd) + sizeof(VirtIOSCSICmdReq));
|
||||||
|
|
||||||
static inline int virtio_scsi_get_lun(uint8_t *lun)
|
static inline int virtio_scsi_get_lun(uint8_t *lun)
|
||||||
{
|
{
|
||||||
return ((lun[2] << 8) | lun[3]) & 0x3FFF;
|
return ((lun[2] << 8) | lun[3]) & 0x3FFF;
|
||||||
|
@ -61,17 +67,21 @@ static inline SCSIDevice *virtio_scsi_device_find(VirtIOSCSI *s, uint8_t *lun)
|
||||||
static VirtIOSCSIReq *virtio_scsi_init_req(VirtIOSCSI *s, VirtQueue *vq)
|
static VirtIOSCSIReq *virtio_scsi_init_req(VirtIOSCSI *s, VirtQueue *vq)
|
||||||
{
|
{
|
||||||
VirtIOSCSIReq *req;
|
VirtIOSCSIReq *req;
|
||||||
req = g_malloc(sizeof(*req));
|
VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(s);
|
||||||
|
|
||||||
|
req = g_malloc0(sizeof(*req) + vs->cdb_size);
|
||||||
|
|
||||||
req->vq = vq;
|
req->vq = vq;
|
||||||
req->dev = s;
|
req->dev = s;
|
||||||
req->sreq = NULL;
|
req->sreq = NULL;
|
||||||
qemu_sglist_init(&req->qsgl, DEVICE(s), 8, &address_space_memory);
|
qemu_sglist_init(&req->qsgl, DEVICE(s), 8, &address_space_memory);
|
||||||
|
qemu_iovec_init(&req->resp_iov, 1);
|
||||||
return req;
|
return req;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void virtio_scsi_free_req(VirtIOSCSIReq *req)
|
static void virtio_scsi_free_req(VirtIOSCSIReq *req)
|
||||||
{
|
{
|
||||||
|
qemu_iovec_destroy(&req->resp_iov);
|
||||||
qemu_sglist_destroy(&req->qsgl);
|
qemu_sglist_destroy(&req->qsgl);
|
||||||
g_free(req);
|
g_free(req);
|
||||||
}
|
}
|
||||||
|
@ -81,7 +91,9 @@ static void virtio_scsi_complete_req(VirtIOSCSIReq *req)
|
||||||
VirtIOSCSI *s = req->dev;
|
VirtIOSCSI *s = req->dev;
|
||||||
VirtQueue *vq = req->vq;
|
VirtQueue *vq = req->vq;
|
||||||
VirtIODevice *vdev = VIRTIO_DEVICE(s);
|
VirtIODevice *vdev = VIRTIO_DEVICE(s);
|
||||||
virtqueue_push(vq, &req->elem, req->qsgl.size + req->elem.in_sg[0].iov_len);
|
|
||||||
|
qemu_iovec_from_buf(&req->resp_iov, 0, &req->resp, req->resp_size);
|
||||||
|
virtqueue_push(vq, &req->elem, req->qsgl.size + req->resp_iov.size);
|
||||||
if (req->sreq) {
|
if (req->sreq) {
|
||||||
req->sreq->hba_private = NULL;
|
req->sreq->hba_private = NULL;
|
||||||
scsi_req_unref(req->sreq);
|
scsi_req_unref(req->sreq);
|
||||||
|
@ -122,31 +134,35 @@ static size_t qemu_sgl_concat(VirtIOSCSIReq *req, struct iovec *iov,
|
||||||
static int virtio_scsi_parse_req(VirtIOSCSIReq *req,
|
static int virtio_scsi_parse_req(VirtIOSCSIReq *req,
|
||||||
unsigned req_size, unsigned resp_size)
|
unsigned req_size, unsigned resp_size)
|
||||||
{
|
{
|
||||||
if (req->elem.in_num == 0) {
|
size_t in_size, out_size;
|
||||||
|
|
||||||
|
if (iov_to_buf(req->elem.out_sg, req->elem.out_num, 0,
|
||||||
|
&req->req, req_size) < req_size) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req->elem.out_sg[0].iov_len < req_size) {
|
if (qemu_iovec_concat_iov(&req->resp_iov,
|
||||||
|
req->elem.in_sg, req->elem.in_num, 0,
|
||||||
|
resp_size) < resp_size) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
if (req->elem.out_num) {
|
|
||||||
req->req.buf = req->elem.out_sg[0].iov_base;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (req->elem.in_sg[0].iov_len < resp_size) {
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
req->resp.buf = req->elem.in_sg[0].iov_base;
|
|
||||||
req->resp_size = resp_size;
|
req->resp_size = resp_size;
|
||||||
|
|
||||||
if (req->elem.out_num > 1) {
|
out_size = qemu_sgl_concat(req, req->elem.out_sg,
|
||||||
qemu_sgl_concat(req, &req->elem.out_sg[1],
|
&req->elem.out_addr[0], req->elem.out_num,
|
||||||
&req->elem.out_addr[1],
|
req_size);
|
||||||
req->elem.out_num - 1, 0);
|
in_size = qemu_sgl_concat(req, req->elem.in_sg,
|
||||||
} else {
|
&req->elem.in_addr[0], req->elem.in_num,
|
||||||
qemu_sgl_concat(req, &req->elem.in_sg[1],
|
resp_size);
|
||||||
&req->elem.in_addr[1],
|
|
||||||
req->elem.in_num - 1, 0);
|
if (out_size && in_size) {
|
||||||
|
return -ENOTSUP;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (out_size) {
|
||||||
|
req->mode = SCSI_XFER_TO_DEV;
|
||||||
|
} else if (in_size) {
|
||||||
|
req->mode = SCSI_XFER_FROM_DEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -204,37 +220,34 @@ static void *virtio_scsi_load_request(QEMUFile *f, SCSIRequest *sreq)
|
||||||
scsi_req_ref(sreq);
|
scsi_req_ref(sreq);
|
||||||
req->sreq = sreq;
|
req->sreq = sreq;
|
||||||
if (req->sreq->cmd.mode != SCSI_XFER_NONE) {
|
if (req->sreq->cmd.mode != SCSI_XFER_NONE) {
|
||||||
int req_mode =
|
assert(req->sreq->cmd.mode == req->mode);
|
||||||
(req->elem.in_num > 1 ? SCSI_XFER_FROM_DEV : SCSI_XFER_TO_DEV);
|
|
||||||
|
|
||||||
assert(req->sreq->cmd.mode == req_mode);
|
|
||||||
}
|
}
|
||||||
return req;
|
return req;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void virtio_scsi_do_tmf(VirtIOSCSI *s, VirtIOSCSIReq *req)
|
static void virtio_scsi_do_tmf(VirtIOSCSI *s, VirtIOSCSIReq *req)
|
||||||
{
|
{
|
||||||
SCSIDevice *d = virtio_scsi_device_find(s, req->req.tmf->lun);
|
SCSIDevice *d = virtio_scsi_device_find(s, req->req.tmf.lun);
|
||||||
SCSIRequest *r, *next;
|
SCSIRequest *r, *next;
|
||||||
BusChild *kid;
|
BusChild *kid;
|
||||||
int target;
|
int target;
|
||||||
|
|
||||||
/* Here VIRTIO_SCSI_S_OK means "FUNCTION COMPLETE". */
|
/* Here VIRTIO_SCSI_S_OK means "FUNCTION COMPLETE". */
|
||||||
req->resp.tmf->response = VIRTIO_SCSI_S_OK;
|
req->resp.tmf.response = VIRTIO_SCSI_S_OK;
|
||||||
|
|
||||||
tswap32s(&req->req.tmf->subtype);
|
tswap32s(&req->req.tmf.subtype);
|
||||||
switch (req->req.tmf->subtype) {
|
switch (req->req.tmf.subtype) {
|
||||||
case VIRTIO_SCSI_T_TMF_ABORT_TASK:
|
case VIRTIO_SCSI_T_TMF_ABORT_TASK:
|
||||||
case VIRTIO_SCSI_T_TMF_QUERY_TASK:
|
case VIRTIO_SCSI_T_TMF_QUERY_TASK:
|
||||||
if (!d) {
|
if (!d) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
if (d->lun != virtio_scsi_get_lun(req->req.tmf->lun)) {
|
if (d->lun != virtio_scsi_get_lun(req->req.tmf.lun)) {
|
||||||
goto incorrect_lun;
|
goto incorrect_lun;
|
||||||
}
|
}
|
||||||
QTAILQ_FOREACH_SAFE(r, &d->requests, next, next) {
|
QTAILQ_FOREACH_SAFE(r, &d->requests, next, next) {
|
||||||
VirtIOSCSIReq *cmd_req = r->hba_private;
|
VirtIOSCSIReq *cmd_req = r->hba_private;
|
||||||
if (cmd_req && cmd_req->req.cmd->tag == req->req.tmf->tag) {
|
if (cmd_req && cmd_req->req.cmd.tag == req->req.tmf.tag) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -244,11 +257,11 @@ static void virtio_scsi_do_tmf(VirtIOSCSI *s, VirtIOSCSIReq *req)
|
||||||
* check for it in the loop above.
|
* check for it in the loop above.
|
||||||
*/
|
*/
|
||||||
assert(r->hba_private);
|
assert(r->hba_private);
|
||||||
if (req->req.tmf->subtype == VIRTIO_SCSI_T_TMF_QUERY_TASK) {
|
if (req->req.tmf.subtype == VIRTIO_SCSI_T_TMF_QUERY_TASK) {
|
||||||
/* "If the specified command is present in the task set, then
|
/* "If the specified command is present in the task set, then
|
||||||
* return a service response set to FUNCTION SUCCEEDED".
|
* return a service response set to FUNCTION SUCCEEDED".
|
||||||
*/
|
*/
|
||||||
req->resp.tmf->response = VIRTIO_SCSI_S_FUNCTION_SUCCEEDED;
|
req->resp.tmf.response = VIRTIO_SCSI_S_FUNCTION_SUCCEEDED;
|
||||||
} else {
|
} else {
|
||||||
scsi_req_cancel(r);
|
scsi_req_cancel(r);
|
||||||
}
|
}
|
||||||
|
@ -259,7 +272,7 @@ static void virtio_scsi_do_tmf(VirtIOSCSI *s, VirtIOSCSIReq *req)
|
||||||
if (!d) {
|
if (!d) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
if (d->lun != virtio_scsi_get_lun(req->req.tmf->lun)) {
|
if (d->lun != virtio_scsi_get_lun(req->req.tmf.lun)) {
|
||||||
goto incorrect_lun;
|
goto incorrect_lun;
|
||||||
}
|
}
|
||||||
s->resetting++;
|
s->resetting++;
|
||||||
|
@ -273,16 +286,16 @@ static void virtio_scsi_do_tmf(VirtIOSCSI *s, VirtIOSCSIReq *req)
|
||||||
if (!d) {
|
if (!d) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
if (d->lun != virtio_scsi_get_lun(req->req.tmf->lun)) {
|
if (d->lun != virtio_scsi_get_lun(req->req.tmf.lun)) {
|
||||||
goto incorrect_lun;
|
goto incorrect_lun;
|
||||||
}
|
}
|
||||||
QTAILQ_FOREACH_SAFE(r, &d->requests, next, next) {
|
QTAILQ_FOREACH_SAFE(r, &d->requests, next, next) {
|
||||||
if (r->hba_private) {
|
if (r->hba_private) {
|
||||||
if (req->req.tmf->subtype == VIRTIO_SCSI_T_TMF_QUERY_TASK_SET) {
|
if (req->req.tmf.subtype == VIRTIO_SCSI_T_TMF_QUERY_TASK_SET) {
|
||||||
/* "If there is any command present in the task set, then
|
/* "If there is any command present in the task set, then
|
||||||
* return a service response set to FUNCTION SUCCEEDED".
|
* return a service response set to FUNCTION SUCCEEDED".
|
||||||
*/
|
*/
|
||||||
req->resp.tmf->response = VIRTIO_SCSI_S_FUNCTION_SUCCEEDED;
|
req->resp.tmf.response = VIRTIO_SCSI_S_FUNCTION_SUCCEEDED;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
scsi_req_cancel(r);
|
scsi_req_cancel(r);
|
||||||
|
@ -292,7 +305,7 @@ static void virtio_scsi_do_tmf(VirtIOSCSI *s, VirtIOSCSIReq *req)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIRTIO_SCSI_T_TMF_I_T_NEXUS_RESET:
|
case VIRTIO_SCSI_T_TMF_I_T_NEXUS_RESET:
|
||||||
target = req->req.tmf->lun[1];
|
target = req->req.tmf.lun[1];
|
||||||
s->resetting++;
|
s->resetting++;
|
||||||
QTAILQ_FOREACH(kid, &s->bus.qbus.children, sibling) {
|
QTAILQ_FOREACH(kid, &s->bus.qbus.children, sibling) {
|
||||||
d = DO_UPCAST(SCSIDevice, qdev, kid->child);
|
d = DO_UPCAST(SCSIDevice, qdev, kid->child);
|
||||||
|
@ -305,18 +318,18 @@ static void virtio_scsi_do_tmf(VirtIOSCSI *s, VirtIOSCSIReq *req)
|
||||||
|
|
||||||
case VIRTIO_SCSI_T_TMF_CLEAR_ACA:
|
case VIRTIO_SCSI_T_TMF_CLEAR_ACA:
|
||||||
default:
|
default:
|
||||||
req->resp.tmf->response = VIRTIO_SCSI_S_FUNCTION_REJECTED;
|
req->resp.tmf.response = VIRTIO_SCSI_S_FUNCTION_REJECTED;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
incorrect_lun:
|
incorrect_lun:
|
||||||
req->resp.tmf->response = VIRTIO_SCSI_S_INCORRECT_LUN;
|
req->resp.tmf.response = VIRTIO_SCSI_S_INCORRECT_LUN;
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
req->resp.tmf->response = VIRTIO_SCSI_S_BAD_TARGET;
|
req->resp.tmf.response = VIRTIO_SCSI_S_BAD_TARGET;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void virtio_scsi_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
|
static void virtio_scsi_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
|
||||||
|
@ -333,8 +346,8 @@ static void virtio_scsi_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
tswap32s(&req->req.tmf->type);
|
tswap32s(&req->req.tmf.type);
|
||||||
if (req->req.tmf->type == VIRTIO_SCSI_T_TMF) {
|
if (req->req.tmf.type == VIRTIO_SCSI_T_TMF) {
|
||||||
if (virtio_scsi_parse_req(req, sizeof(VirtIOSCSICtrlTMFReq),
|
if (virtio_scsi_parse_req(req, sizeof(VirtIOSCSICtrlTMFReq),
|
||||||
sizeof(VirtIOSCSICtrlTMFResp)) < 0) {
|
sizeof(VirtIOSCSICtrlTMFResp)) < 0) {
|
||||||
virtio_scsi_bad_req();
|
virtio_scsi_bad_req();
|
||||||
|
@ -342,14 +355,14 @@ static void virtio_scsi_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
|
||||||
virtio_scsi_do_tmf(s, req);
|
virtio_scsi_do_tmf(s, req);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (req->req.tmf->type == VIRTIO_SCSI_T_AN_QUERY ||
|
} else if (req->req.tmf.type == VIRTIO_SCSI_T_AN_QUERY ||
|
||||||
req->req.tmf->type == VIRTIO_SCSI_T_AN_SUBSCRIBE) {
|
req->req.tmf.type == VIRTIO_SCSI_T_AN_SUBSCRIBE) {
|
||||||
if (virtio_scsi_parse_req(req, sizeof(VirtIOSCSICtrlANReq),
|
if (virtio_scsi_parse_req(req, sizeof(VirtIOSCSICtrlANReq),
|
||||||
sizeof(VirtIOSCSICtrlANResp)) < 0) {
|
sizeof(VirtIOSCSICtrlANResp)) < 0) {
|
||||||
virtio_scsi_bad_req();
|
virtio_scsi_bad_req();
|
||||||
} else {
|
} else {
|
||||||
req->resp.an->event_actual = 0;
|
req->resp.an.event_actual = 0;
|
||||||
req->resp.an->response = VIRTIO_SCSI_S_OK;
|
req->resp.an.response = VIRTIO_SCSI_S_OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
virtio_scsi_complete_req(req);
|
virtio_scsi_complete_req(req);
|
||||||
|
@ -358,6 +371,10 @@ static void virtio_scsi_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
|
||||||
|
|
||||||
static void virtio_scsi_complete_cmd_req(VirtIOSCSIReq *req)
|
static void virtio_scsi_complete_cmd_req(VirtIOSCSIReq *req)
|
||||||
{
|
{
|
||||||
|
/* Sense data is not in req->resp and is copied separately
|
||||||
|
* in virtio_scsi_command_complete.
|
||||||
|
*/
|
||||||
|
req->resp_size = sizeof(VirtIOSCSICmdResp);
|
||||||
virtio_scsi_complete_req(req);
|
virtio_scsi_complete_req(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -372,16 +389,17 @@ static void virtio_scsi_command_complete(SCSIRequest *r, uint32_t status,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
req->resp.cmd->response = VIRTIO_SCSI_S_OK;
|
req->resp.cmd.response = VIRTIO_SCSI_S_OK;
|
||||||
req->resp.cmd->status = status;
|
req->resp.cmd.status = status;
|
||||||
if (req->resp.cmd->status == GOOD) {
|
if (req->resp.cmd.status == GOOD) {
|
||||||
req->resp.cmd->resid = tswap32(resid);
|
req->resp.cmd.resid = tswap32(resid);
|
||||||
} else {
|
} else {
|
||||||
req->resp.cmd->resid = 0;
|
req->resp.cmd.resid = 0;
|
||||||
sense_len = scsi_req_get_sense(r, sense, sizeof(sense));
|
sense_len = scsi_req_get_sense(r, sense, sizeof(sense));
|
||||||
sense_len = MIN(sense_len, req->resp_size - sizeof(req->resp.cmd));
|
sense_len = MIN(sense_len, req->resp_iov.size - sizeof(req->resp.cmd));
|
||||||
memcpy(req->resp.cmd->sense, sense, sense_len);
|
qemu_iovec_from_buf(&req->resp_iov, sizeof(req->resp.cmd),
|
||||||
req->resp.cmd->sense_len = tswap32(sense_len);
|
&req->resp, sense_len);
|
||||||
|
req->resp.cmd.sense_len = tswap32(sense_len);
|
||||||
}
|
}
|
||||||
virtio_scsi_complete_cmd_req(req);
|
virtio_scsi_complete_cmd_req(req);
|
||||||
}
|
}
|
||||||
|
@ -401,16 +419,16 @@ static void virtio_scsi_request_cancelled(SCSIRequest *r)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (req->dev->resetting) {
|
if (req->dev->resetting) {
|
||||||
req->resp.cmd->response = VIRTIO_SCSI_S_RESET;
|
req->resp.cmd.response = VIRTIO_SCSI_S_RESET;
|
||||||
} else {
|
} else {
|
||||||
req->resp.cmd->response = VIRTIO_SCSI_S_ABORTED;
|
req->resp.cmd.response = VIRTIO_SCSI_S_ABORTED;
|
||||||
}
|
}
|
||||||
virtio_scsi_complete_cmd_req(req);
|
virtio_scsi_complete_cmd_req(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void virtio_scsi_fail_cmd_req(VirtIOSCSIReq *req)
|
static void virtio_scsi_fail_cmd_req(VirtIOSCSIReq *req)
|
||||||
{
|
{
|
||||||
req->resp.cmd->response = VIRTIO_SCSI_S_FAILURE;
|
req->resp.cmd.response = VIRTIO_SCSI_S_FAILURE;
|
||||||
virtio_scsi_complete_cmd_req(req);
|
virtio_scsi_complete_cmd_req(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -426,37 +444,34 @@ static void virtio_scsi_handle_cmd(VirtIODevice *vdev, VirtQueue *vq)
|
||||||
while ((req = virtio_scsi_pop_req(s, vq))) {
|
while ((req = virtio_scsi_pop_req(s, vq))) {
|
||||||
SCSIDevice *d;
|
SCSIDevice *d;
|
||||||
int rc;
|
int rc;
|
||||||
if (req->elem.out_num > 1 && req->elem.in_num > 1) {
|
|
||||||
virtio_scsi_fail_cmd_req(req);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
rc = virtio_scsi_parse_req(req, sizeof(VirtIOSCSICmdReq) + vs->cdb_size,
|
rc = virtio_scsi_parse_req(req, sizeof(VirtIOSCSICmdReq) + vs->cdb_size,
|
||||||
sizeof(VirtIOSCSICmdResp) + vs->sense_size);
|
sizeof(VirtIOSCSICmdResp) + vs->sense_size);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
virtio_scsi_bad_req();
|
if (rc == -ENOTSUP) {
|
||||||
|
virtio_scsi_fail_cmd_req(req);
|
||||||
|
} else {
|
||||||
|
virtio_scsi_bad_req();
|
||||||
|
}
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
d = virtio_scsi_device_find(s, req->req.cmd->lun);
|
d = virtio_scsi_device_find(s, req->req.cmd.lun);
|
||||||
if (!d) {
|
if (!d) {
|
||||||
req->resp.cmd->response = VIRTIO_SCSI_S_BAD_TARGET;
|
req->resp.cmd.response = VIRTIO_SCSI_S_BAD_TARGET;
|
||||||
virtio_scsi_complete_cmd_req(req);
|
virtio_scsi_complete_cmd_req(req);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
req->sreq = scsi_req_new(d, req->req.cmd->tag,
|
req->sreq = scsi_req_new(d, req->req.cmd.tag,
|
||||||
virtio_scsi_get_lun(req->req.cmd->lun),
|
virtio_scsi_get_lun(req->req.cmd.lun),
|
||||||
req->req.cmd->cdb, req);
|
req->req.cdb, req);
|
||||||
|
|
||||||
if (req->sreq->cmd.mode != SCSI_XFER_NONE) {
|
if (req->sreq->cmd.mode != SCSI_XFER_NONE
|
||||||
int req_mode =
|
&& (req->sreq->cmd.mode != req->mode ||
|
||||||
(req->elem.in_num > 1 ? SCSI_XFER_FROM_DEV : SCSI_XFER_TO_DEV);
|
req->sreq->cmd.xfer > req->qsgl.size)) {
|
||||||
|
req->resp.cmd.response = VIRTIO_SCSI_S_OVERRUN;
|
||||||
if (req->sreq->cmd.mode != req_mode ||
|
virtio_scsi_complete_cmd_req(req);
|
||||||
req->sreq->cmd.xfer > req->qsgl.size) {
|
continue;
|
||||||
req->resp.cmd->response = VIRTIO_SCSI_S_OVERRUN;
|
|
||||||
virtio_scsi_complete_cmd_req(req);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
n = scsi_req_enqueue(req->sreq);
|
n = scsi_req_enqueue(req->sreq);
|
||||||
|
@ -560,7 +575,7 @@ static void virtio_scsi_push_event(VirtIOSCSI *s, SCSIDevice *dev,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req->elem.out_num || req->elem.in_num != 1) {
|
if (req->elem.out_num) {
|
||||||
virtio_scsi_bad_req();
|
virtio_scsi_bad_req();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -569,12 +584,12 @@ static void virtio_scsi_push_event(VirtIOSCSI *s, SCSIDevice *dev,
|
||||||
s->events_dropped = false;
|
s->events_dropped = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
in_size = req->elem.in_sg[0].iov_len;
|
in_size = iov_size(req->elem.in_sg, req->elem.in_num);
|
||||||
if (in_size < sizeof(VirtIOSCSIEvent)) {
|
if (in_size < sizeof(VirtIOSCSIEvent)) {
|
||||||
virtio_scsi_bad_req();
|
virtio_scsi_bad_req();
|
||||||
}
|
}
|
||||||
|
|
||||||
evt = req->resp.event;
|
evt = &req->resp.event;
|
||||||
memset(evt, 0, sizeof(VirtIOSCSIEvent));
|
memset(evt, 0, sizeof(VirtIOSCSIEvent));
|
||||||
evt->event = event;
|
evt->event = event;
|
||||||
evt->reason = reason;
|
evt->reason = reason;
|
||||||
|
|
|
@ -268,6 +268,10 @@ bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *);
|
||||||
|
|
||||||
#define PC_COMPAT_2_0 \
|
#define PC_COMPAT_2_0 \
|
||||||
{\
|
{\
|
||||||
|
.driver = "virtio-scsi-pci",\
|
||||||
|
.property = "any_layout",\
|
||||||
|
.value = "off",\
|
||||||
|
},{\
|
||||||
.driver = "apic",\
|
.driver = "apic",\
|
||||||
.property = "version",\
|
.property = "version",\
|
||||||
.value = stringify(0x11),\
|
.value = stringify(0x11),\
|
||||||
|
|
|
@ -84,14 +84,13 @@
|
||||||
#define VIRTIO_SCSI_EVT_RESET_RESCAN 1
|
#define VIRTIO_SCSI_EVT_RESET_RESCAN 1
|
||||||
#define VIRTIO_SCSI_EVT_RESET_REMOVED 2
|
#define VIRTIO_SCSI_EVT_RESET_REMOVED 2
|
||||||
|
|
||||||
/* SCSI command request, followed by data-out */
|
/* SCSI command request, followed by CDB and data-out */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t lun[8]; /* Logical Unit Number */
|
uint8_t lun[8]; /* Logical Unit Number */
|
||||||
uint64_t tag; /* Command identifier */
|
uint64_t tag; /* Command identifier */
|
||||||
uint8_t task_attr; /* Task attribute */
|
uint8_t task_attr; /* Task attribute */
|
||||||
uint8_t prio;
|
uint8_t prio;
|
||||||
uint8_t crn;
|
uint8_t crn;
|
||||||
uint8_t cdb[];
|
|
||||||
} QEMU_PACKED VirtIOSCSICmdReq;
|
} QEMU_PACKED VirtIOSCSICmdReq;
|
||||||
|
|
||||||
/* Response, followed by sense data and data-in */
|
/* Response, followed by sense data and data-in */
|
||||||
|
@ -101,7 +100,6 @@ typedef struct {
|
||||||
uint16_t status_qualifier; /* Status qualifier */
|
uint16_t status_qualifier; /* Status qualifier */
|
||||||
uint8_t status; /* Command completion status */
|
uint8_t status; /* Command completion status */
|
||||||
uint8_t response; /* Response values */
|
uint8_t response; /* Response values */
|
||||||
uint8_t sense[];
|
|
||||||
} QEMU_PACKED VirtIOSCSICmdResp;
|
} QEMU_PACKED VirtIOSCSICmdResp;
|
||||||
|
|
||||||
/* Task Management Request */
|
/* Task Management Request */
|
||||||
|
|
Loading…
Reference in a new issue