2011-02-11 09:40:59 +01:00
|
|
|
/*
|
|
|
|
* Virtio SCSI HBA
|
|
|
|
*
|
|
|
|
* Copyright IBM, Corp. 2010
|
|
|
|
* Copyright Red Hat, Inc. 2011
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
|
|
|
|
* Paolo Bonzini <pbonzini@redhat.com>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-01-26 19:17:07 +01:00
|
|
|
#include "qemu/osdep.h"
|
2015-02-16 22:36:20 +01:00
|
|
|
#include "standard-headers/linux/virtio_ids.h"
|
2013-02-05 17:06:20 +01:00
|
|
|
#include "hw/virtio/virtio-scsi.h"
|
2013-02-04 11:37:52 +01:00
|
|
|
#include "qemu/error-report.h"
|
2014-06-10 16:21:18 +02:00
|
|
|
#include "qemu/iov.h"
|
2014-10-07 13:59:18 +02:00
|
|
|
#include "sysemu/block-backend.h"
|
2013-02-05 17:06:20 +01:00
|
|
|
#include <hw/scsi/scsi.h>
|
|
|
|
#include <block/scsi.h>
|
|
|
|
#include <hw/virtio/virtio-bus.h>
|
2014-06-24 19:48:53 +02:00
|
|
|
#include "hw/virtio/virtio-access.h"
|
2011-02-11 09:40:59 +01:00
|
|
|
|
2011-11-14 16:58:41 +01:00
|
|
|
static inline int virtio_scsi_get_lun(uint8_t *lun)
|
|
|
|
{
|
|
|
|
return ((lun[2] << 8) | lun[3]) & 0x3FFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline SCSIDevice *virtio_scsi_device_find(VirtIOSCSI *s, uint8_t *lun)
|
|
|
|
{
|
|
|
|
if (lun[0] != 1) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (lun[2] != 0 && !(lun[2] >= 0x40 && lun[2] < 0x80)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return scsi_device_find(&s->bus, 0, lun[1], virtio_scsi_get_lun(lun));
|
|
|
|
}
|
|
|
|
|
2016-02-04 15:26:51 +01:00
|
|
|
void virtio_scsi_init_req(VirtIOSCSI *s, VirtQueue *vq, VirtIOSCSIReq *req)
|
2014-06-10 16:21:18 +02:00
|
|
|
{
|
2016-02-14 18:17:10 +01:00
|
|
|
const size_t zero_skip =
|
|
|
|
offsetof(VirtIOSCSIReq, resp_iov) + sizeof(req->resp_iov);
|
2014-06-10 16:21:18 +02:00
|
|
|
|
|
|
|
req->vq = vq;
|
|
|
|
req->dev = s;
|
|
|
|
qemu_sglist_init(&req->qsgl, DEVICE(s), 8, &address_space_memory);
|
2014-06-10 16:40:31 +02:00
|
|
|
qemu_iovec_init(&req->resp_iov, 1);
|
2014-09-16 09:20:18 +02:00
|
|
|
memset((uint8_t *)req + zero_skip, 0, sizeof(*req) - zero_skip);
|
2014-06-10 16:21:18 +02:00
|
|
|
}
|
|
|
|
|
2014-08-06 07:35:04 +02:00
|
|
|
void virtio_scsi_free_req(VirtIOSCSIReq *req)
|
2014-06-10 16:21:18 +02:00
|
|
|
{
|
2014-06-10 16:40:31 +02:00
|
|
|
qemu_iovec_destroy(&req->resp_iov);
|
2014-06-10 16:21:18 +02:00
|
|
|
qemu_sglist_destroy(&req->qsgl);
|
2015-10-01 12:59:01 +02:00
|
|
|
g_free(req);
|
2014-06-10 16:21:18 +02:00
|
|
|
}
|
|
|
|
|
2011-02-13 11:55:52 +01:00
|
|
|
static void virtio_scsi_complete_req(VirtIOSCSIReq *req)
|
|
|
|
{
|
|
|
|
VirtIOSCSI *s = req->dev;
|
|
|
|
VirtQueue *vq = req->vq;
|
2013-03-21 15:15:18 +01:00
|
|
|
VirtIODevice *vdev = VIRTIO_DEVICE(s);
|
2014-06-10 16:40:31 +02:00
|
|
|
|
|
|
|
qemu_iovec_from_buf(&req->resp_iov, 0, &req->resp, req->resp_size);
|
2016-02-14 18:17:10 +01:00
|
|
|
virtqueue_push(vq, &req->elem, req->qsgl.size + req->resp_iov.size);
|
|
|
|
if (s->dataplane_started) {
|
|
|
|
virtio_scsi_dataplane_notify(vdev, req);
|
2014-09-23 09:49:25 +02:00
|
|
|
} else {
|
|
|
|
virtio_notify(vdev, vq);
|
|
|
|
}
|
|
|
|
|
2011-02-13 11:55:52 +01:00
|
|
|
if (req->sreq) {
|
|
|
|
req->sreq->hba_private = NULL;
|
|
|
|
scsi_req_unref(req->sreq);
|
|
|
|
}
|
2014-06-10 16:21:18 +02:00
|
|
|
virtio_scsi_free_req(req);
|
2011-02-13 11:55:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void virtio_scsi_bad_req(void)
|
|
|
|
{
|
|
|
|
error_report("wrong size for virtio-scsi headers");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2014-06-10 16:39:24 +02:00
|
|
|
static size_t qemu_sgl_concat(VirtIOSCSIReq *req, struct iovec *iov,
|
|
|
|
hwaddr *addr, int num, size_t skip)
|
2011-02-13 11:55:52 +01:00
|
|
|
{
|
2013-06-03 14:17:19 +02:00
|
|
|
QEMUSGList *qsgl = &req->qsgl;
|
2014-06-10 16:39:24 +02:00
|
|
|
size_t copied = 0;
|
|
|
|
|
|
|
|
while (num) {
|
|
|
|
if (skip >= iov->iov_len) {
|
|
|
|
skip -= iov->iov_len;
|
|
|
|
} else {
|
|
|
|
qemu_sglist_add(qsgl, *addr + skip, iov->iov_len - skip);
|
|
|
|
copied += iov->iov_len - skip;
|
|
|
|
skip = 0;
|
|
|
|
}
|
|
|
|
iov++;
|
|
|
|
addr++;
|
|
|
|
num--;
|
2011-02-13 11:55:52 +01:00
|
|
|
}
|
2014-06-10 16:39:24 +02:00
|
|
|
|
|
|
|
assert(skip == 0);
|
|
|
|
return copied;
|
2011-02-13 11:55:52 +01:00
|
|
|
}
|
|
|
|
|
2014-06-10 16:21:18 +02:00
|
|
|
static int virtio_scsi_parse_req(VirtIOSCSIReq *req,
|
|
|
|
unsigned req_size, unsigned resp_size)
|
2011-02-13 11:55:52 +01:00
|
|
|
{
|
2014-11-07 14:00:02 +01:00
|
|
|
VirtIODevice *vdev = (VirtIODevice *) req->dev;
|
2014-06-10 16:40:31 +02:00
|
|
|
size_t in_size, out_size;
|
2014-06-10 16:21:18 +02:00
|
|
|
|
2014-06-10 16:40:31 +02:00
|
|
|
if (iov_to_buf(req->elem.out_sg, req->elem.out_num, 0,
|
|
|
|
&req->req, req_size) < req_size) {
|
2014-06-10 16:21:18 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2014-06-10 16:40:31 +02:00
|
|
|
if (qemu_iovec_concat_iov(&req->resp_iov,
|
|
|
|
req->elem.in_sg, req->elem.in_num, 0,
|
|
|
|
resp_size) < resp_size) {
|
2014-06-10 16:21:18 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2014-11-07 14:00:02 +01:00
|
|
|
|
2014-06-10 16:58:19 +02:00
|
|
|
req->resp_size = resp_size;
|
2011-02-13 11:55:52 +01:00
|
|
|
|
2014-11-07 14:00:02 +01:00
|
|
|
/* Old BIOSes left some padding by mistake after the req_size/resp_size.
|
|
|
|
* As a workaround, always consider the first buffer as the virtio-scsi
|
|
|
|
* request/response, making the payload start at the second element
|
|
|
|
* of the iovec.
|
|
|
|
*
|
|
|
|
* The actual length of the response header, stored in req->resp_size,
|
|
|
|
* does not change.
|
|
|
|
*
|
|
|
|
* TODO: always disable this workaround for virtio 1.0 devices.
|
|
|
|
*/
|
2015-08-17 11:48:29 +02:00
|
|
|
if (!virtio_vdev_has_feature(vdev, VIRTIO_F_ANY_LAYOUT)) {
|
2015-03-13 08:55:54 +01:00
|
|
|
if (req->elem.out_num) {
|
|
|
|
req_size = req->elem.out_sg[0].iov_len;
|
|
|
|
}
|
|
|
|
if (req->elem.in_num) {
|
|
|
|
resp_size = req->elem.in_sg[0].iov_len;
|
|
|
|
}
|
2014-11-07 14:00:02 +01:00
|
|
|
}
|
|
|
|
|
2014-06-10 16:40:31 +02:00
|
|
|
out_size = qemu_sgl_concat(req, req->elem.out_sg,
|
|
|
|
&req->elem.out_addr[0], req->elem.out_num,
|
|
|
|
req_size);
|
|
|
|
in_size = qemu_sgl_concat(req, req->elem.in_sg,
|
|
|
|
&req->elem.in_addr[0], req->elem.in_num,
|
|
|
|
resp_size);
|
|
|
|
|
|
|
|
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;
|
2011-02-13 11:55:52 +01:00
|
|
|
}
|
2014-06-10 16:21:18 +02:00
|
|
|
|
|
|
|
return 0;
|
2011-02-13 11:55:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static VirtIOSCSIReq *virtio_scsi_pop_req(VirtIOSCSI *s, VirtQueue *vq)
|
|
|
|
{
|
2016-02-04 15:26:51 +01:00
|
|
|
VirtIOSCSICommon *vs = (VirtIOSCSICommon *)s;
|
|
|
|
VirtIOSCSIReq *req;
|
|
|
|
|
|
|
|
req = virtqueue_pop(vq, sizeof(VirtIOSCSIReq) + vs->cdb_size);
|
|
|
|
if (!req) {
|
2011-02-13 11:55:52 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
2016-02-04 15:26:51 +01:00
|
|
|
virtio_scsi_init_req(s, vq, req);
|
2011-02-13 11:55:52 +01:00
|
|
|
return req;
|
|
|
|
}
|
|
|
|
|
2011-12-02 15:23:15 +01:00
|
|
|
static void virtio_scsi_save_request(QEMUFile *f, SCSIRequest *sreq)
|
|
|
|
{
|
|
|
|
VirtIOSCSIReq *req = sreq->hba_private;
|
2013-03-29 02:08:15 +01:00
|
|
|
VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(req->dev);
|
2012-04-06 10:39:46 +02:00
|
|
|
uint32_t n = virtio_queue_get_id(req->vq) - 2;
|
2011-12-02 15:23:15 +01:00
|
|
|
|
2013-03-29 02:08:15 +01:00
|
|
|
assert(n < vs->conf.num_queues);
|
2012-04-06 10:20:43 +02:00
|
|
|
qemu_put_be32s(f, &n);
|
2016-01-31 11:28:59 +01:00
|
|
|
qemu_put_virtqueue_element(f, &req->elem);
|
2011-12-02 15:23:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void *virtio_scsi_load_request(QEMUFile *f, SCSIRequest *sreq)
|
|
|
|
{
|
|
|
|
SCSIBus *bus = sreq->bus;
|
|
|
|
VirtIOSCSI *s = container_of(bus, VirtIOSCSI, bus);
|
2013-03-29 02:08:15 +01:00
|
|
|
VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(s);
|
2011-12-02 15:23:15 +01:00
|
|
|
VirtIOSCSIReq *req;
|
2012-04-06 10:20:43 +02:00
|
|
|
uint32_t n;
|
2011-12-02 15:23:15 +01:00
|
|
|
|
2012-04-06 10:20:43 +02:00
|
|
|
qemu_get_be32s(f, &n);
|
2013-03-29 02:08:15 +01:00
|
|
|
assert(n < vs->conf.num_queues);
|
2016-01-31 11:28:59 +01:00
|
|
|
req = qemu_get_virtqueue_element(f, sizeof(VirtIOSCSIReq) + vs->cdb_size);
|
2016-02-04 15:26:51 +01:00
|
|
|
virtio_scsi_init_req(s, vs->cmd_vqs[n], req);
|
2015-10-27 09:22:13 +01:00
|
|
|
|
2014-06-10 16:21:18 +02:00
|
|
|
if (virtio_scsi_parse_req(req, sizeof(VirtIOSCSICmdReq) + vs->cdb_size,
|
|
|
|
sizeof(VirtIOSCSICmdResp) + vs->sense_size) < 0) {
|
|
|
|
error_report("invalid SCSI request migration data");
|
|
|
|
exit(1);
|
|
|
|
}
|
2011-12-02 15:23:15 +01:00
|
|
|
|
|
|
|
scsi_req_ref(sreq);
|
|
|
|
req->sreq = sreq;
|
|
|
|
if (req->sreq->cmd.mode != SCSI_XFER_NONE) {
|
2014-06-10 16:40:31 +02:00
|
|
|
assert(req->sreq->cmd.mode == req->mode);
|
2011-12-02 15:23:15 +01:00
|
|
|
}
|
|
|
|
return req;
|
|
|
|
}
|
|
|
|
|
2014-09-30 05:40:23 +02:00
|
|
|
typedef struct {
|
|
|
|
Notifier notifier;
|
|
|
|
VirtIOSCSIReq *tmf_req;
|
|
|
|
} VirtIOSCSICancelNotifier;
|
|
|
|
|
|
|
|
static void virtio_scsi_cancel_notify(Notifier *notifier, void *data)
|
|
|
|
{
|
|
|
|
VirtIOSCSICancelNotifier *n = container_of(notifier,
|
|
|
|
VirtIOSCSICancelNotifier,
|
|
|
|
notifier);
|
|
|
|
|
|
|
|
if (--n->tmf_req->remaining == 0) {
|
|
|
|
virtio_scsi_complete_req(n->tmf_req);
|
|
|
|
}
|
2015-10-01 12:59:01 +02:00
|
|
|
g_free(n);
|
2014-09-30 05:40:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Return 0 if the request is ready to be completed and return to guest;
|
|
|
|
* -EINPROGRESS if the request is submitted and will be completed later, in the
|
|
|
|
* case of async cancellation. */
|
|
|
|
static int virtio_scsi_do_tmf(VirtIOSCSI *s, VirtIOSCSIReq *req)
|
2011-02-13 11:55:52 +01:00
|
|
|
{
|
2014-06-10 16:40:31 +02:00
|
|
|
SCSIDevice *d = virtio_scsi_device_find(s, req->req.tmf.lun);
|
2011-11-14 17:44:09 +01:00
|
|
|
SCSIRequest *r, *next;
|
2011-12-23 22:34:39 +01:00
|
|
|
BusChild *kid;
|
2011-11-14 17:44:09 +01:00
|
|
|
int target;
|
2014-09-30 05:40:23 +02:00
|
|
|
int ret = 0;
|
2011-11-14 17:44:09 +01:00
|
|
|
|
2015-11-26 15:45:35 +01:00
|
|
|
if (s->dataplane_started && d) {
|
2015-02-15 04:06:31 +01:00
|
|
|
assert(blk_get_aio_context(d->conf.blk) == s->ctx);
|
2014-09-23 09:49:25 +02:00
|
|
|
}
|
2011-11-14 17:44:09 +01:00
|
|
|
/* Here VIRTIO_SCSI_S_OK means "FUNCTION COMPLETE". */
|
2014-06-10 16:40:31 +02:00
|
|
|
req->resp.tmf.response = VIRTIO_SCSI_S_OK;
|
2011-11-14 17:44:09 +01:00
|
|
|
|
2014-06-24 19:48:53 +02:00
|
|
|
virtio_tswap32s(VIRTIO_DEVICE(s), &req->req.tmf.subtype);
|
2014-06-10 16:40:31 +02:00
|
|
|
switch (req->req.tmf.subtype) {
|
2011-11-14 17:44:09 +01:00
|
|
|
case VIRTIO_SCSI_T_TMF_ABORT_TASK:
|
|
|
|
case VIRTIO_SCSI_T_TMF_QUERY_TASK:
|
|
|
|
if (!d) {
|
|
|
|
goto fail;
|
|
|
|
}
|
2014-06-10 16:40:31 +02:00
|
|
|
if (d->lun != virtio_scsi_get_lun(req->req.tmf.lun)) {
|
2011-11-14 17:44:09 +01:00
|
|
|
goto incorrect_lun;
|
|
|
|
}
|
|
|
|
QTAILQ_FOREACH_SAFE(r, &d->requests, next, next) {
|
2012-08-08 16:26:16 +02:00
|
|
|
VirtIOSCSIReq *cmd_req = r->hba_private;
|
2014-06-10 16:40:31 +02:00
|
|
|
if (cmd_req && cmd_req->req.cmd.tag == req->req.tmf.tag) {
|
2011-11-14 17:44:09 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-08-08 16:26:16 +02:00
|
|
|
if (r) {
|
|
|
|
/*
|
|
|
|
* Assert that the request has not been completed yet, we
|
|
|
|
* check for it in the loop above.
|
|
|
|
*/
|
|
|
|
assert(r->hba_private);
|
2014-06-10 16:40:31 +02:00
|
|
|
if (req->req.tmf.subtype == VIRTIO_SCSI_T_TMF_QUERY_TASK) {
|
2011-11-14 17:44:09 +01:00
|
|
|
/* "If the specified command is present in the task set, then
|
|
|
|
* return a service response set to FUNCTION SUCCEEDED".
|
|
|
|
*/
|
2014-06-10 16:40:31 +02:00
|
|
|
req->resp.tmf.response = VIRTIO_SCSI_S_FUNCTION_SUCCEEDED;
|
2011-11-14 17:44:09 +01:00
|
|
|
} else {
|
2014-09-30 05:40:23 +02:00
|
|
|
VirtIOSCSICancelNotifier *notifier;
|
|
|
|
|
|
|
|
req->remaining = 1;
|
2015-10-01 12:59:01 +02:00
|
|
|
notifier = g_new(VirtIOSCSICancelNotifier, 1);
|
2014-09-30 05:40:23 +02:00
|
|
|
notifier->tmf_req = req;
|
|
|
|
notifier->notifier.notify = virtio_scsi_cancel_notify;
|
|
|
|
scsi_req_cancel_async(r, ¬ifier->notifier);
|
|
|
|
ret = -EINPROGRESS;
|
2011-11-14 17:44:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIRTIO_SCSI_T_TMF_LOGICAL_UNIT_RESET:
|
|
|
|
if (!d) {
|
|
|
|
goto fail;
|
|
|
|
}
|
2014-06-10 16:40:31 +02:00
|
|
|
if (d->lun != virtio_scsi_get_lun(req->req.tmf.lun)) {
|
2011-11-14 17:44:09 +01:00
|
|
|
goto incorrect_lun;
|
|
|
|
}
|
|
|
|
s->resetting++;
|
|
|
|
qdev_reset_all(&d->qdev);
|
|
|
|
s->resetting--;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIRTIO_SCSI_T_TMF_ABORT_TASK_SET:
|
|
|
|
case VIRTIO_SCSI_T_TMF_CLEAR_TASK_SET:
|
|
|
|
case VIRTIO_SCSI_T_TMF_QUERY_TASK_SET:
|
|
|
|
if (!d) {
|
|
|
|
goto fail;
|
|
|
|
}
|
2014-06-10 16:40:31 +02:00
|
|
|
if (d->lun != virtio_scsi_get_lun(req->req.tmf.lun)) {
|
2011-11-14 17:44:09 +01:00
|
|
|
goto incorrect_lun;
|
|
|
|
}
|
2014-09-30 05:40:23 +02:00
|
|
|
|
|
|
|
/* Add 1 to "remaining" until virtio_scsi_do_tmf returns.
|
|
|
|
* This way, if the bus starts calling back to the notifiers
|
|
|
|
* even before we finish the loop, virtio_scsi_cancel_notify
|
|
|
|
* will not complete the TMF too early.
|
|
|
|
*/
|
|
|
|
req->remaining = 1;
|
2011-11-14 17:44:09 +01:00
|
|
|
QTAILQ_FOREACH_SAFE(r, &d->requests, next, next) {
|
|
|
|
if (r->hba_private) {
|
2014-06-10 16:40:31 +02:00
|
|
|
if (req->req.tmf.subtype == VIRTIO_SCSI_T_TMF_QUERY_TASK_SET) {
|
2011-11-14 17:44:09 +01:00
|
|
|
/* "If there is any command present in the task set, then
|
|
|
|
* return a service response set to FUNCTION SUCCEEDED".
|
|
|
|
*/
|
2014-06-10 16:40:31 +02:00
|
|
|
req->resp.tmf.response = VIRTIO_SCSI_S_FUNCTION_SUCCEEDED;
|
2011-11-14 17:44:09 +01:00
|
|
|
break;
|
|
|
|
} else {
|
2014-09-30 05:40:23 +02:00
|
|
|
VirtIOSCSICancelNotifier *notifier;
|
|
|
|
|
|
|
|
req->remaining++;
|
2015-10-01 12:59:01 +02:00
|
|
|
notifier = g_new(VirtIOSCSICancelNotifier, 1);
|
2014-09-30 05:40:23 +02:00
|
|
|
notifier->notifier.notify = virtio_scsi_cancel_notify;
|
|
|
|
notifier->tmf_req = req;
|
|
|
|
scsi_req_cancel_async(r, ¬ifier->notifier);
|
2011-11-14 17:44:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-09-30 05:40:23 +02:00
|
|
|
if (--req->remaining > 0) {
|
|
|
|
ret = -EINPROGRESS;
|
|
|
|
}
|
2011-11-14 17:44:09 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VIRTIO_SCSI_T_TMF_I_T_NEXUS_RESET:
|
2014-06-10 16:40:31 +02:00
|
|
|
target = req->req.tmf.lun[1];
|
2011-11-14 17:44:09 +01:00
|
|
|
s->resetting++;
|
2011-12-23 22:34:39 +01:00
|
|
|
QTAILQ_FOREACH(kid, &s->bus.qbus.children, sibling) {
|
2016-01-06 10:37:46 +01:00
|
|
|
d = SCSI_DEVICE(kid->child);
|
2011-11-14 17:44:09 +01:00
|
|
|
if (d->channel == 0 && d->id == target) {
|
|
|
|
qdev_reset_all(&d->qdev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s->resetting--;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIRTIO_SCSI_T_TMF_CLEAR_ACA:
|
|
|
|
default:
|
2014-06-10 16:40:31 +02:00
|
|
|
req->resp.tmf.response = VIRTIO_SCSI_S_FUNCTION_REJECTED;
|
2011-11-14 17:44:09 +01:00
|
|
|
break;
|
2011-02-13 11:55:52 +01:00
|
|
|
}
|
|
|
|
|
2014-09-30 05:40:23 +02:00
|
|
|
return ret;
|
2011-11-14 17:44:09 +01:00
|
|
|
|
|
|
|
incorrect_lun:
|
2014-06-10 16:40:31 +02:00
|
|
|
req->resp.tmf.response = VIRTIO_SCSI_S_INCORRECT_LUN;
|
2014-09-30 05:40:23 +02:00
|
|
|
return ret;
|
2011-11-14 17:44:09 +01:00
|
|
|
|
|
|
|
fail:
|
2014-06-10 16:40:31 +02:00
|
|
|
req->resp.tmf.response = VIRTIO_SCSI_S_BAD_TARGET;
|
2014-09-30 05:40:23 +02:00
|
|
|
return ret;
|
2011-02-13 11:55:52 +01:00
|
|
|
}
|
|
|
|
|
2014-08-06 07:35:01 +02:00
|
|
|
void virtio_scsi_handle_ctrl_req(VirtIOSCSI *s, VirtIOSCSIReq *req)
|
2011-02-11 09:40:59 +01:00
|
|
|
{
|
2014-08-06 07:35:01 +02:00
|
|
|
VirtIODevice *vdev = (VirtIODevice *)s;
|
2014-10-25 04:43:44 +02:00
|
|
|
uint32_t type;
|
2014-09-30 05:40:23 +02:00
|
|
|
int r = 0;
|
2011-02-13 11:55:52 +01:00
|
|
|
|
2014-08-06 07:35:01 +02:00
|
|
|
if (iov_to_buf(req->elem.out_sg, req->elem.out_num, 0,
|
|
|
|
&type, sizeof(type)) < sizeof(type)) {
|
|
|
|
virtio_scsi_bad_req();
|
|
|
|
return;
|
|
|
|
}
|
2014-06-10 16:21:18 +02:00
|
|
|
|
2014-10-25 04:43:44 +02:00
|
|
|
virtio_tswap32s(vdev, &type);
|
|
|
|
if (type == VIRTIO_SCSI_T_TMF) {
|
2014-08-06 07:35:01 +02:00
|
|
|
if (virtio_scsi_parse_req(req, sizeof(VirtIOSCSICtrlTMFReq),
|
|
|
|
sizeof(VirtIOSCSICtrlTMFResp)) < 0) {
|
2011-11-14 17:44:09 +01:00
|
|
|
virtio_scsi_bad_req();
|
2014-08-06 07:35:01 +02:00
|
|
|
} else {
|
2014-09-30 05:40:23 +02:00
|
|
|
r = virtio_scsi_do_tmf(s, req);
|
2014-06-10 16:53:39 +02:00
|
|
|
}
|
2011-11-14 17:44:09 +01:00
|
|
|
|
2014-10-25 04:43:44 +02:00
|
|
|
} else if (type == VIRTIO_SCSI_T_AN_QUERY ||
|
|
|
|
type == VIRTIO_SCSI_T_AN_SUBSCRIBE) {
|
2014-08-06 07:35:01 +02:00
|
|
|
if (virtio_scsi_parse_req(req, sizeof(VirtIOSCSICtrlANReq),
|
|
|
|
sizeof(VirtIOSCSICtrlANResp)) < 0) {
|
|
|
|
virtio_scsi_bad_req();
|
|
|
|
} else {
|
|
|
|
req->resp.an.event_actual = 0;
|
|
|
|
req->resp.an.response = VIRTIO_SCSI_S_OK;
|
2011-11-14 17:44:09 +01:00
|
|
|
}
|
2014-08-06 07:35:01 +02:00
|
|
|
}
|
2014-09-30 05:40:23 +02:00
|
|
|
if (r == 0) {
|
|
|
|
virtio_scsi_complete_req(req);
|
|
|
|
} else {
|
|
|
|
assert(r == -EINPROGRESS);
|
|
|
|
}
|
2014-08-06 07:35:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void virtio_scsi_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
|
|
|
|
{
|
|
|
|
VirtIOSCSI *s = (VirtIOSCSI *)vdev;
|
|
|
|
VirtIOSCSIReq *req;
|
|
|
|
|
2016-02-14 18:17:10 +01:00
|
|
|
if (s->ctx && !s->dataplane_started) {
|
2014-09-23 09:49:25 +02:00
|
|
|
virtio_scsi_dataplane_start(s);
|
|
|
|
return;
|
|
|
|
}
|
2014-08-06 07:35:01 +02:00
|
|
|
while ((req = virtio_scsi_pop_req(s, vq))) {
|
|
|
|
virtio_scsi_handle_ctrl_req(s, req);
|
2011-02-13 11:55:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-10 20:16:20 +02:00
|
|
|
static void virtio_scsi_complete_cmd_req(VirtIOSCSIReq *req)
|
|
|
|
{
|
2014-06-10 16:40:31 +02:00
|
|
|
/* Sense data is not in req->resp and is copied separately
|
|
|
|
* in virtio_scsi_command_complete.
|
|
|
|
*/
|
|
|
|
req->resp_size = sizeof(VirtIOSCSICmdResp);
|
2014-06-10 20:16:20 +02:00
|
|
|
virtio_scsi_complete_req(req);
|
|
|
|
}
|
|
|
|
|
2011-11-14 16:58:41 +01:00
|
|
|
static void virtio_scsi_command_complete(SCSIRequest *r, uint32_t status,
|
|
|
|
size_t resid)
|
|
|
|
{
|
|
|
|
VirtIOSCSIReq *req = r->hba_private;
|
2014-06-10 16:58:19 +02:00
|
|
|
uint8_t sense[SCSI_SENSE_BUF_SIZE];
|
2012-11-23 06:08:44 +01:00
|
|
|
uint32_t sense_len;
|
2014-06-24 19:48:53 +02:00
|
|
|
VirtIODevice *vdev = VIRTIO_DEVICE(req->dev);
|
2011-11-14 16:58:41 +01:00
|
|
|
|
2014-01-14 20:16:25 +01:00
|
|
|
if (r->io_canceled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-10 16:40:31 +02:00
|
|
|
req->resp.cmd.response = VIRTIO_SCSI_S_OK;
|
|
|
|
req->resp.cmd.status = status;
|
|
|
|
if (req->resp.cmd.status == GOOD) {
|
2014-06-24 19:48:53 +02:00
|
|
|
req->resp.cmd.resid = virtio_tswap32(vdev, resid);
|
2011-11-14 16:58:41 +01:00
|
|
|
} else {
|
2014-06-10 16:40:31 +02:00
|
|
|
req->resp.cmd.resid = 0;
|
2014-06-10 16:58:19 +02:00
|
|
|
sense_len = scsi_req_get_sense(r, sense, sizeof(sense));
|
2014-06-10 16:40:31 +02:00
|
|
|
sense_len = MIN(sense_len, req->resp_iov.size - sizeof(req->resp.cmd));
|
|
|
|
qemu_iovec_from_buf(&req->resp_iov, sizeof(req->resp.cmd),
|
2014-10-27 09:51:41 +01:00
|
|
|
sense, sense_len);
|
2014-06-24 19:48:53 +02:00
|
|
|
req->resp.cmd.sense_len = virtio_tswap32(vdev, sense_len);
|
2011-11-14 16:58:41 +01:00
|
|
|
}
|
2014-06-10 20:16:20 +02:00
|
|
|
virtio_scsi_complete_cmd_req(req);
|
2011-11-14 16:58:41 +01:00
|
|
|
}
|
|
|
|
|
2014-07-16 11:04:37 +02:00
|
|
|
static int virtio_scsi_parse_cdb(SCSIDevice *dev, SCSICommand *cmd,
|
|
|
|
uint8_t *buf, void *hba_private)
|
|
|
|
{
|
|
|
|
VirtIOSCSIReq *req = hba_private;
|
|
|
|
|
|
|
|
if (cmd->len == 0) {
|
2015-03-11 14:31:29 +01:00
|
|
|
cmd->len = MIN(VIRTIO_SCSI_CDB_DEFAULT_SIZE, SCSI_CMD_BUF_SIZE);
|
2014-07-16 11:04:37 +02:00
|
|
|
memcpy(cmd->buf, buf, cmd->len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Extract the direction and mode directly from the request, for
|
|
|
|
* host device passthrough.
|
|
|
|
*/
|
|
|
|
cmd->xfer = req->qsgl.size;
|
2014-09-17 18:10:37 +02:00
|
|
|
cmd->mode = req->mode;
|
2014-07-16 11:04:37 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-11-14 16:58:41 +01:00
|
|
|
static QEMUSGList *virtio_scsi_get_sg_list(SCSIRequest *r)
|
|
|
|
{
|
|
|
|
VirtIOSCSIReq *req = r->hba_private;
|
|
|
|
|
|
|
|
return &req->qsgl;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void virtio_scsi_request_cancelled(SCSIRequest *r)
|
|
|
|
{
|
|
|
|
VirtIOSCSIReq *req = r->hba_private;
|
|
|
|
|
|
|
|
if (!req) {
|
|
|
|
return;
|
|
|
|
}
|
2011-11-14 17:44:09 +01:00
|
|
|
if (req->dev->resetting) {
|
2014-06-10 16:40:31 +02:00
|
|
|
req->resp.cmd.response = VIRTIO_SCSI_S_RESET;
|
2011-11-14 17:44:09 +01:00
|
|
|
} else {
|
2014-06-10 16:40:31 +02:00
|
|
|
req->resp.cmd.response = VIRTIO_SCSI_S_ABORTED;
|
2011-11-14 17:44:09 +01:00
|
|
|
}
|
2014-06-10 20:16:20 +02:00
|
|
|
virtio_scsi_complete_cmd_req(req);
|
2011-11-14 16:58:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void virtio_scsi_fail_cmd_req(VirtIOSCSIReq *req)
|
2011-02-13 11:55:52 +01:00
|
|
|
{
|
2014-06-10 16:40:31 +02:00
|
|
|
req->resp.cmd.response = VIRTIO_SCSI_S_FAILURE;
|
2014-06-10 20:16:20 +02:00
|
|
|
virtio_scsi_complete_cmd_req(req);
|
2011-02-11 09:40:59 +01:00
|
|
|
}
|
|
|
|
|
2014-09-23 09:49:27 +02:00
|
|
|
bool virtio_scsi_handle_cmd_req_prepare(VirtIOSCSI *s, VirtIOSCSIReq *req)
|
2014-08-06 07:35:00 +02:00
|
|
|
{
|
|
|
|
VirtIOSCSICommon *vs = &s->parent_obj;
|
|
|
|
SCSIDevice *d;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = virtio_scsi_parse_req(req, sizeof(VirtIOSCSICmdReq) + vs->cdb_size,
|
|
|
|
sizeof(VirtIOSCSICmdResp) + vs->sense_size);
|
|
|
|
if (rc < 0) {
|
|
|
|
if (rc == -ENOTSUP) {
|
|
|
|
virtio_scsi_fail_cmd_req(req);
|
|
|
|
} else {
|
|
|
|
virtio_scsi_bad_req();
|
|
|
|
}
|
2014-09-23 09:49:27 +02:00
|
|
|
return false;
|
2014-08-06 07:35:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
d = virtio_scsi_device_find(s, req->req.cmd.lun);
|
|
|
|
if (!d) {
|
|
|
|
req->resp.cmd.response = VIRTIO_SCSI_S_BAD_TARGET;
|
|
|
|
virtio_scsi_complete_cmd_req(req);
|
2014-09-23 09:49:27 +02:00
|
|
|
return false;
|
2014-08-06 07:35:00 +02:00
|
|
|
}
|
2015-02-15 04:06:31 +01:00
|
|
|
if (s->dataplane_started) {
|
|
|
|
assert(blk_get_aio_context(d->conf.blk) == s->ctx);
|
2014-09-23 09:49:25 +02:00
|
|
|
}
|
2014-08-06 07:35:00 +02:00
|
|
|
req->sreq = scsi_req_new(d, req->req.cmd.tag,
|
|
|
|
virtio_scsi_get_lun(req->req.cmd.lun),
|
2015-03-11 14:35:47 +01:00
|
|
|
req->req.cmd.cdb, req);
|
2014-08-06 07:35:00 +02:00
|
|
|
|
|
|
|
if (req->sreq->cmd.mode != SCSI_XFER_NONE
|
|
|
|
&& (req->sreq->cmd.mode != req->mode ||
|
|
|
|
req->sreq->cmd.xfer > req->qsgl.size)) {
|
|
|
|
req->resp.cmd.response = VIRTIO_SCSI_S_OVERRUN;
|
|
|
|
virtio_scsi_complete_cmd_req(req);
|
2014-09-23 09:49:27 +02:00
|
|
|
return false;
|
2014-08-06 07:35:00 +02:00
|
|
|
}
|
2014-09-23 09:49:29 +02:00
|
|
|
scsi_req_ref(req->sreq);
|
2014-10-07 13:59:18 +02:00
|
|
|
blk_io_plug(d->conf.blk);
|
2014-09-23 09:49:27 +02:00
|
|
|
return true;
|
|
|
|
}
|
2014-08-06 07:35:00 +02:00
|
|
|
|
2014-09-23 09:49:27 +02:00
|
|
|
void virtio_scsi_handle_cmd_req_submit(VirtIOSCSI *s, VirtIOSCSIReq *req)
|
|
|
|
{
|
2014-10-08 01:19:00 +02:00
|
|
|
SCSIRequest *sreq = req->sreq;
|
|
|
|
if (scsi_req_enqueue(sreq)) {
|
|
|
|
scsi_req_continue(sreq);
|
2014-08-06 07:35:00 +02:00
|
|
|
}
|
2014-10-07 13:59:18 +02:00
|
|
|
blk_io_unplug(sreq->dev->conf.blk);
|
2014-10-08 01:19:00 +02:00
|
|
|
scsi_req_unref(sreq);
|
2014-08-06 07:35:00 +02:00
|
|
|
}
|
|
|
|
|
2011-02-11 09:40:59 +01:00
|
|
|
static void virtio_scsi_handle_cmd(VirtIODevice *vdev, VirtQueue *vq)
|
|
|
|
{
|
2013-03-29 02:08:15 +01:00
|
|
|
/* use non-QOM casts in the data path */
|
2011-02-13 11:55:52 +01:00
|
|
|
VirtIOSCSI *s = (VirtIOSCSI *)vdev;
|
2014-09-23 09:49:28 +02:00
|
|
|
VirtIOSCSIReq *req, *next;
|
|
|
|
QTAILQ_HEAD(, VirtIOSCSIReq) reqs = QTAILQ_HEAD_INITIALIZER(reqs);
|
2011-02-13 11:55:52 +01:00
|
|
|
|
2016-02-14 18:17:10 +01:00
|
|
|
if (s->ctx && !s->dataplane_started) {
|
2014-09-23 09:49:25 +02:00
|
|
|
virtio_scsi_dataplane_start(s);
|
|
|
|
return;
|
|
|
|
}
|
2011-02-13 11:55:52 +01:00
|
|
|
while ((req = virtio_scsi_pop_req(s, vq))) {
|
2014-09-23 09:49:27 +02:00
|
|
|
if (virtio_scsi_handle_cmd_req_prepare(s, req)) {
|
2014-09-23 09:49:28 +02:00
|
|
|
QTAILQ_INSERT_TAIL(&reqs, req, next);
|
2014-09-23 09:49:27 +02:00
|
|
|
}
|
2011-02-13 11:55:52 +01:00
|
|
|
}
|
2014-09-23 09:49:28 +02:00
|
|
|
|
|
|
|
QTAILQ_FOREACH_SAFE(req, &reqs, next, next) {
|
|
|
|
virtio_scsi_handle_cmd_req_submit(s, req);
|
|
|
|
}
|
2011-02-11 09:40:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void virtio_scsi_get_config(VirtIODevice *vdev,
|
|
|
|
uint8_t *config)
|
|
|
|
{
|
|
|
|
VirtIOSCSIConfig *scsiconf = (VirtIOSCSIConfig *)config;
|
2013-03-29 02:08:15 +01:00
|
|
|
VirtIOSCSICommon *s = VIRTIO_SCSI_COMMON(vdev);
|
2011-02-11 09:40:59 +01:00
|
|
|
|
2014-06-24 19:48:53 +02:00
|
|
|
virtio_stl_p(vdev, &scsiconf->num_queues, s->conf.num_queues);
|
|
|
|
virtio_stl_p(vdev, &scsiconf->seg_max, 128 - 2);
|
|
|
|
virtio_stl_p(vdev, &scsiconf->max_sectors, s->conf.max_sectors);
|
|
|
|
virtio_stl_p(vdev, &scsiconf->cmd_per_lun, s->conf.cmd_per_lun);
|
|
|
|
virtio_stl_p(vdev, &scsiconf->event_info_size, sizeof(VirtIOSCSIEvent));
|
|
|
|
virtio_stl_p(vdev, &scsiconf->sense_size, s->sense_size);
|
|
|
|
virtio_stl_p(vdev, &scsiconf->cdb_size, s->cdb_size);
|
|
|
|
virtio_stw_p(vdev, &scsiconf->max_channel, VIRTIO_SCSI_MAX_CHANNEL);
|
|
|
|
virtio_stw_p(vdev, &scsiconf->max_target, VIRTIO_SCSI_MAX_TARGET);
|
|
|
|
virtio_stl_p(vdev, &scsiconf->max_lun, VIRTIO_SCSI_MAX_LUN);
|
2011-02-11 09:40:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void virtio_scsi_set_config(VirtIODevice *vdev,
|
|
|
|
const uint8_t *config)
|
|
|
|
{
|
|
|
|
VirtIOSCSIConfig *scsiconf = (VirtIOSCSIConfig *)config;
|
2013-03-29 02:08:15 +01:00
|
|
|
VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(vdev);
|
2011-02-11 09:40:59 +01:00
|
|
|
|
2014-06-24 19:48:53 +02:00
|
|
|
if ((uint32_t) virtio_ldl_p(vdev, &scsiconf->sense_size) >= 65536 ||
|
|
|
|
(uint32_t) virtio_ldl_p(vdev, &scsiconf->cdb_size) >= 256) {
|
2011-02-11 09:40:59 +01:00
|
|
|
error_report("bad data written to virtio-scsi configuration space");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2014-06-24 19:48:53 +02:00
|
|
|
vs->sense_size = virtio_ldl_p(vdev, &scsiconf->sense_size);
|
|
|
|
vs->cdb_size = virtio_ldl_p(vdev, &scsiconf->cdb_size);
|
2011-02-11 09:40:59 +01:00
|
|
|
}
|
|
|
|
|
2015-06-01 10:45:40 +02:00
|
|
|
static uint64_t virtio_scsi_get_features(VirtIODevice *vdev,
|
2015-07-27 11:49:19 +02:00
|
|
|
uint64_t requested_features,
|
|
|
|
Error **errp)
|
2011-02-11 09:40:59 +01:00
|
|
|
{
|
2015-04-28 13:51:13 +02:00
|
|
|
VirtIOSCSI *s = VIRTIO_SCSI(vdev);
|
|
|
|
|
|
|
|
/* Firstly sync all virtio-scsi possible supported features */
|
|
|
|
requested_features |= s->host_features;
|
2011-02-11 09:40:59 +01:00
|
|
|
return requested_features;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void virtio_scsi_reset(VirtIODevice *vdev)
|
|
|
|
{
|
2013-03-29 02:08:15 +01:00
|
|
|
VirtIOSCSI *s = VIRTIO_SCSI(vdev);
|
|
|
|
VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(vdev);
|
2011-02-11 09:40:59 +01:00
|
|
|
|
2014-09-23 09:49:25 +02:00
|
|
|
if (s->ctx) {
|
|
|
|
virtio_scsi_dataplane_stop(s);
|
|
|
|
}
|
2013-01-10 15:49:08 +01:00
|
|
|
s->resetting++;
|
|
|
|
qbus_reset_all(&s->bus.qbus);
|
|
|
|
s->resetting--;
|
|
|
|
|
2015-03-11 14:31:29 +01:00
|
|
|
vs->sense_size = VIRTIO_SCSI_SENSE_DEFAULT_SIZE;
|
|
|
|
vs->cdb_size = VIRTIO_SCSI_CDB_DEFAULT_SIZE;
|
2012-07-16 14:50:27 +02:00
|
|
|
s->events_dropped = false;
|
2011-02-11 09:40:59 +01:00
|
|
|
}
|
|
|
|
|
2011-12-02 15:23:15 +01:00
|
|
|
/* The device does not have anything to save beyond the virtio data.
|
|
|
|
* Request data is saved with callbacks from SCSI devices.
|
|
|
|
*/
|
|
|
|
static void virtio_scsi_save(QEMUFile *f, void *opaque)
|
|
|
|
{
|
2013-03-21 15:15:18 +01:00
|
|
|
VirtIODevice *vdev = VIRTIO_DEVICE(opaque);
|
virtio: sync the dataplane vring state to the virtqueue before virtio_save
When creating snapshot with the dataplane enabled, the snapshot file gets
not the actual state of virtqueue, because the current state is stored in
VirtIOBlockDataPlane. Therefore, before saving snapshot need to sync
the dataplane vring state to the virtqueue. The dataplane will resume its
work at the next notify virtqueue.
When snapshot loads with loadvm we get a message:
VQ 0 size 0x80 Guest index 0x15f5 inconsistent with Host index 0x0:
delta 0x15f5
error while loading state for instance 0x0 of device
'0000:00:08.0/virtio-blk'
Error -1 while loading VM state
to reproduce the error I used the following hmp commands:
savevm snap1
loadvm snap1
qemu parameters:
--enable-kvm -smp 4 -m 1024 -drive file=/var/lib/libvirt/images/centos6.4.qcow2,if=none,id=drive-virtio-disk0,format=qcow2,cache=none,aio=native -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x8,drive=drive-virtio-disk0,id=virtio-disk0 -set device.virtio-disk0.x-data-plane=on
Signed-off-by: Pavel Butsykin <pbutsykin@virtuozzo.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
Message-id: 1445859777-2982-1-git-send-email-den@openvz.org
CC: Stefan Hajnoczi <stefanha@redhat.com>
CC: "Michael S. Tsirkin" <mst@redhat.com>
CC: Kevin Wolf <kwolf@redhat.com>
CC: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2015-10-26 12:42:57 +01:00
|
|
|
VirtIOSCSI *s = VIRTIO_SCSI(vdev);
|
|
|
|
|
|
|
|
if (s->dataplane_started) {
|
|
|
|
virtio_scsi_dataplane_stop(s);
|
|
|
|
}
|
2013-03-21 15:15:18 +01:00
|
|
|
virtio_save(vdev, f);
|
2011-12-02 15:23:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int virtio_scsi_load(QEMUFile *f, void *opaque, int version_id)
|
|
|
|
{
|
2013-03-21 15:15:18 +01:00
|
|
|
VirtIODevice *vdev = VIRTIO_DEVICE(opaque);
|
2012-05-16 12:21:35 +02:00
|
|
|
int ret;
|
|
|
|
|
2014-06-24 19:15:31 +02:00
|
|
|
ret = virtio_load(vdev, f, version_id);
|
2012-05-16 12:21:35 +02:00
|
|
|
if (ret) {
|
|
|
|
return ret;
|
|
|
|
}
|
2011-12-02 15:23:15 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-08-06 07:35:05 +02:00
|
|
|
void virtio_scsi_push_event(VirtIOSCSI *s, SCSIDevice *dev,
|
|
|
|
uint32_t event, uint32_t reason)
|
2012-06-20 08:47:11 +02:00
|
|
|
{
|
2013-03-29 02:08:15 +01:00
|
|
|
VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(s);
|
2014-05-16 17:44:06 +02:00
|
|
|
VirtIOSCSIReq *req;
|
2012-06-20 08:47:11 +02:00
|
|
|
VirtIOSCSIEvent *evt;
|
2013-03-21 15:15:18 +01:00
|
|
|
VirtIODevice *vdev = VIRTIO_DEVICE(s);
|
2012-06-20 08:47:11 +02:00
|
|
|
|
2013-03-21 15:15:18 +01:00
|
|
|
if (!(vdev->status & VIRTIO_CONFIG_S_DRIVER_OK)) {
|
2012-10-08 16:50:51 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-23 09:49:25 +02:00
|
|
|
if (s->dataplane_started) {
|
|
|
|
assert(s->ctx);
|
|
|
|
aio_context_acquire(s->ctx);
|
|
|
|
}
|
|
|
|
|
2016-02-14 18:17:10 +01:00
|
|
|
req = virtio_scsi_pop_req(s, vs->event_vq);
|
2012-07-02 10:47:35 +02:00
|
|
|
if (!req) {
|
|
|
|
s->events_dropped = true;
|
2014-09-23 09:49:25 +02:00
|
|
|
goto out;
|
2012-07-02 10:47:35 +02:00
|
|
|
}
|
2012-06-20 08:47:11 +02:00
|
|
|
|
2012-07-02 10:47:35 +02:00
|
|
|
if (s->events_dropped) {
|
|
|
|
event |= VIRTIO_SCSI_T_EVENTS_MISSED;
|
|
|
|
s->events_dropped = false;
|
|
|
|
}
|
|
|
|
|
2014-06-30 17:33:18 +02:00
|
|
|
if (virtio_scsi_parse_req(req, 0, sizeof(VirtIOSCSIEvent))) {
|
2012-07-02 10:47:35 +02:00
|
|
|
virtio_scsi_bad_req();
|
|
|
|
}
|
|
|
|
|
2014-06-10 16:40:31 +02:00
|
|
|
evt = &req->resp.event;
|
2012-07-02 10:47:35 +02:00
|
|
|
memset(evt, 0, sizeof(VirtIOSCSIEvent));
|
2014-06-30 17:17:17 +02:00
|
|
|
evt->event = virtio_tswap32(vdev, event);
|
|
|
|
evt->reason = virtio_tswap32(vdev, reason);
|
2012-07-02 10:47:35 +02:00
|
|
|
if (!dev) {
|
2014-01-14 20:16:26 +01:00
|
|
|
assert(event == VIRTIO_SCSI_T_EVENTS_MISSED);
|
2012-07-02 10:47:35 +02:00
|
|
|
} else {
|
2012-06-20 08:47:11 +02:00
|
|
|
evt->lun[0] = 1;
|
|
|
|
evt->lun[1] = dev->id;
|
|
|
|
|
|
|
|
/* Linux wants us to keep the same encoding we use for REPORT LUNS. */
|
|
|
|
if (dev->lun >= 256) {
|
|
|
|
evt->lun[2] = (dev->lun >> 8) | 0x40;
|
|
|
|
}
|
|
|
|
evt->lun[3] = dev->lun & 0xFF;
|
2012-07-02 10:47:35 +02:00
|
|
|
}
|
|
|
|
virtio_scsi_complete_req(req);
|
2014-09-23 09:49:25 +02:00
|
|
|
out:
|
|
|
|
if (s->dataplane_started) {
|
|
|
|
aio_context_release(s->ctx);
|
|
|
|
}
|
2012-07-02 10:47:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void virtio_scsi_handle_event(VirtIODevice *vdev, VirtQueue *vq)
|
|
|
|
{
|
2013-03-21 15:15:18 +01:00
|
|
|
VirtIOSCSI *s = VIRTIO_SCSI(vdev);
|
2012-07-02 10:47:35 +02:00
|
|
|
|
2016-02-14 18:17:10 +01:00
|
|
|
if (s->ctx && !s->dataplane_started) {
|
2014-09-23 09:49:25 +02:00
|
|
|
virtio_scsi_dataplane_start(s);
|
|
|
|
return;
|
|
|
|
}
|
2012-07-02 10:47:35 +02:00
|
|
|
if (s->events_dropped) {
|
|
|
|
virtio_scsi_push_event(s, NULL, VIRTIO_SCSI_T_NO_EVENT, 0);
|
2012-06-20 08:47:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-16 14:22:52 +02:00
|
|
|
static void virtio_scsi_change(SCSIBus *bus, SCSIDevice *dev, SCSISense sense)
|
|
|
|
{
|
|
|
|
VirtIOSCSI *s = container_of(bus, VirtIOSCSI, bus);
|
2013-03-21 15:15:18 +01:00
|
|
|
VirtIODevice *vdev = VIRTIO_DEVICE(s);
|
2012-07-16 14:22:52 +02:00
|
|
|
|
2015-08-17 11:48:29 +02:00
|
|
|
if (virtio_vdev_has_feature(vdev, VIRTIO_SCSI_F_CHANGE) &&
|
2012-07-16 14:22:52 +02:00
|
|
|
dev->type != TYPE_ROM) {
|
|
|
|
virtio_scsi_push_event(s, dev, VIRTIO_SCSI_T_PARAM_CHANGE,
|
|
|
|
sense.asc | (sense.ascq << 8));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-29 16:36:05 +01:00
|
|
|
static void virtio_scsi_blk_insert_notifier(Notifier *n, void *data)
|
|
|
|
{
|
|
|
|
VirtIOSCSIBlkChangeNotifier *cn = DO_UPCAST(VirtIOSCSIBlkChangeNotifier,
|
|
|
|
n, n);
|
|
|
|
assert(cn->sd->conf.blk == data);
|
|
|
|
blk_op_block_all(cn->sd->conf.blk, cn->s->blocker);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void virtio_scsi_blk_remove_notifier(Notifier *n, void *data)
|
|
|
|
{
|
|
|
|
VirtIOSCSIBlkChangeNotifier *cn = DO_UPCAST(VirtIOSCSIBlkChangeNotifier,
|
|
|
|
n, n);
|
|
|
|
assert(cn->sd->conf.blk == data);
|
|
|
|
blk_op_unblock_all(cn->sd->conf.blk, cn->s->blocker);
|
|
|
|
}
|
|
|
|
|
2014-09-26 11:28:33 +02:00
|
|
|
static void virtio_scsi_hotplug(HotplugHandler *hotplug_dev, DeviceState *dev,
|
|
|
|
Error **errp)
|
2012-06-20 08:47:11 +02:00
|
|
|
{
|
2014-09-26 11:28:33 +02:00
|
|
|
VirtIODevice *vdev = VIRTIO_DEVICE(hotplug_dev);
|
2014-10-19 06:47:42 +02:00
|
|
|
VirtIOSCSI *s = VIRTIO_SCSI(vdev);
|
|
|
|
SCSIDevice *sd = SCSI_DEVICE(dev);
|
|
|
|
|
|
|
|
if (s->ctx && !s->dataplane_disabled) {
|
2016-01-29 16:36:05 +01:00
|
|
|
VirtIOSCSIBlkChangeNotifier *insert_notifier, *remove_notifier;
|
|
|
|
|
2014-10-19 06:47:42 +02:00
|
|
|
if (blk_op_is_blocked(sd->conf.blk, BLOCK_OP_TYPE_DATAPLANE, errp)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
blk_op_block_all(sd->conf.blk, s->blocker);
|
2015-02-15 04:06:31 +01:00
|
|
|
aio_context_acquire(s->ctx);
|
|
|
|
blk_set_aio_context(sd->conf.blk, s->ctx);
|
|
|
|
aio_context_release(s->ctx);
|
2016-01-29 16:36:05 +01:00
|
|
|
|
|
|
|
insert_notifier = g_new0(VirtIOSCSIBlkChangeNotifier, 1);
|
|
|
|
insert_notifier->n.notify = virtio_scsi_blk_insert_notifier;
|
|
|
|
insert_notifier->s = s;
|
|
|
|
insert_notifier->sd = sd;
|
|
|
|
blk_add_insert_bs_notifier(sd->conf.blk, &insert_notifier->n);
|
|
|
|
QTAILQ_INSERT_TAIL(&s->insert_notifiers, insert_notifier, next);
|
|
|
|
|
|
|
|
remove_notifier = g_new0(VirtIOSCSIBlkChangeNotifier, 1);
|
|
|
|
remove_notifier->n.notify = virtio_scsi_blk_remove_notifier;
|
|
|
|
remove_notifier->s = s;
|
|
|
|
remove_notifier->sd = sd;
|
|
|
|
blk_add_remove_bs_notifier(sd->conf.blk, &remove_notifier->n);
|
|
|
|
QTAILQ_INSERT_TAIL(&s->remove_notifiers, remove_notifier, next);
|
2014-10-19 06:47:42 +02:00
|
|
|
}
|
2012-06-20 08:47:11 +02:00
|
|
|
|
2015-08-17 11:48:29 +02:00
|
|
|
if (virtio_vdev_has_feature(vdev, VIRTIO_SCSI_F_HOTPLUG)) {
|
2014-10-19 06:47:42 +02:00
|
|
|
virtio_scsi_push_event(s, sd,
|
2014-09-26 11:28:33 +02:00
|
|
|
VIRTIO_SCSI_T_TRANSPORT_RESET,
|
2012-06-20 08:47:11 +02:00
|
|
|
VIRTIO_SCSI_EVT_RESET_RESCAN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-26 11:28:33 +02:00
|
|
|
static void virtio_scsi_hotunplug(HotplugHandler *hotplug_dev, DeviceState *dev,
|
|
|
|
Error **errp)
|
2012-06-20 08:47:11 +02:00
|
|
|
{
|
2014-09-26 11:28:33 +02:00
|
|
|
VirtIODevice *vdev = VIRTIO_DEVICE(hotplug_dev);
|
2014-10-19 06:47:42 +02:00
|
|
|
VirtIOSCSI *s = VIRTIO_SCSI(vdev);
|
|
|
|
SCSIDevice *sd = SCSI_DEVICE(dev);
|
2016-01-29 16:36:05 +01:00
|
|
|
VirtIOSCSIBlkChangeNotifier *insert_notifier, *remove_notifier;
|
2012-06-20 08:47:11 +02:00
|
|
|
|
2015-08-17 11:48:29 +02:00
|
|
|
if (virtio_vdev_has_feature(vdev, VIRTIO_SCSI_F_HOTPLUG)) {
|
2014-10-19 06:47:42 +02:00
|
|
|
virtio_scsi_push_event(s, sd,
|
2014-09-26 11:28:33 +02:00
|
|
|
VIRTIO_SCSI_T_TRANSPORT_RESET,
|
2012-06-20 08:47:11 +02:00
|
|
|
VIRTIO_SCSI_EVT_RESET_REMOVED);
|
|
|
|
}
|
2014-10-19 06:47:42 +02:00
|
|
|
|
|
|
|
if (s->ctx) {
|
|
|
|
blk_op_unblock_all(sd->conf.blk, s->blocker);
|
|
|
|
}
|
2016-01-29 16:36:05 +01:00
|
|
|
|
|
|
|
QTAILQ_FOREACH(insert_notifier, &s->insert_notifiers, next) {
|
|
|
|
if (insert_notifier->sd == sd) {
|
|
|
|
notifier_remove(&insert_notifier->n);
|
|
|
|
QTAILQ_REMOVE(&s->insert_notifiers, insert_notifier, next);
|
|
|
|
g_free(insert_notifier);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QTAILQ_FOREACH(remove_notifier, &s->remove_notifiers, next) {
|
|
|
|
if (remove_notifier->sd == sd) {
|
|
|
|
notifier_remove(&remove_notifier->n);
|
|
|
|
QTAILQ_REMOVE(&s->remove_notifiers, remove_notifier, next);
|
|
|
|
g_free(remove_notifier);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-26 11:28:33 +02:00
|
|
|
qdev_simple_device_unplug_cb(hotplug_dev, dev, errp);
|
2012-06-20 08:47:11 +02:00
|
|
|
}
|
|
|
|
|
2011-11-14 16:58:41 +01:00
|
|
|
static struct SCSIBusInfo virtio_scsi_scsi_info = {
|
|
|
|
.tcq = true,
|
|
|
|
.max_channel = VIRTIO_SCSI_MAX_CHANNEL,
|
|
|
|
.max_target = VIRTIO_SCSI_MAX_TARGET,
|
|
|
|
.max_lun = VIRTIO_SCSI_MAX_LUN,
|
|
|
|
|
|
|
|
.complete = virtio_scsi_command_complete,
|
|
|
|
.cancel = virtio_scsi_request_cancelled,
|
2012-07-16 14:22:52 +02:00
|
|
|
.change = virtio_scsi_change,
|
2014-07-16 11:04:37 +02:00
|
|
|
.parse_cdb = virtio_scsi_parse_cdb,
|
2011-11-14 16:58:41 +01:00
|
|
|
.get_sg_list = virtio_scsi_get_sg_list,
|
2011-12-02 15:23:15 +01:00
|
|
|
.save_request = virtio_scsi_save_request,
|
|
|
|
.load_request = virtio_scsi_load_request,
|
2011-11-14 16:58:41 +01:00
|
|
|
};
|
|
|
|
|
2014-06-19 10:12:00 +02:00
|
|
|
void virtio_scsi_common_realize(DeviceState *dev, Error **errp,
|
|
|
|
HandleOutput ctrl, HandleOutput evt,
|
|
|
|
HandleOutput cmd)
|
2011-02-11 09:40:59 +01:00
|
|
|
{
|
2013-07-30 03:19:55 +02:00
|
|
|
VirtIODevice *vdev = VIRTIO_DEVICE(dev);
|
|
|
|
VirtIOSCSICommon *s = VIRTIO_SCSI_COMMON(dev);
|
2012-04-06 10:39:46 +02:00
|
|
|
int i;
|
2011-02-11 09:40:59 +01:00
|
|
|
|
2013-07-30 05:41:42 +02:00
|
|
|
virtio_init(vdev, "virtio-scsi", VIRTIO_ID_SCSI,
|
2013-03-21 15:15:19 +01:00
|
|
|
sizeof(VirtIOSCSIConfig));
|
2013-03-21 15:15:14 +01:00
|
|
|
|
2014-10-31 04:04:31 +01:00
|
|
|
if (s->conf.num_queues == 0 ||
|
2015-05-29 08:15:31 +02:00
|
|
|
s->conf.num_queues > VIRTIO_QUEUE_MAX - 2) {
|
2014-10-31 04:04:31 +01:00
|
|
|
error_setg(errp, "Invalid number of queues (= %" PRIu32 "), "
|
2014-08-26 08:30:30 +02:00
|
|
|
"must be a positive integer less than %d.",
|
2015-05-29 08:15:31 +02:00
|
|
|
s->conf.num_queues, VIRTIO_QUEUE_MAX - 2);
|
2014-10-30 12:50:26 +01:00
|
|
|
virtio_cleanup(vdev);
|
2014-08-26 08:30:30 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-12-04 14:12:45 +01:00
|
|
|
s->cmd_vqs = g_new0(VirtQueue *, s->conf.num_queues);
|
2015-03-11 14:31:29 +01:00
|
|
|
s->sense_size = VIRTIO_SCSI_SENSE_DEFAULT_SIZE;
|
|
|
|
s->cdb_size = VIRTIO_SCSI_CDB_DEFAULT_SIZE;
|
2013-03-21 15:15:14 +01:00
|
|
|
|
2013-03-21 15:15:18 +01:00
|
|
|
s->ctrl_vq = virtio_add_queue(vdev, VIRTIO_SCSI_VQ_SIZE,
|
2014-06-19 10:12:00 +02:00
|
|
|
ctrl);
|
2013-03-21 15:15:18 +01:00
|
|
|
s->event_vq = virtio_add_queue(vdev, VIRTIO_SCSI_VQ_SIZE,
|
2014-06-19 10:12:00 +02:00
|
|
|
evt);
|
2013-03-21 15:15:11 +01:00
|
|
|
for (i = 0; i < s->conf.num_queues; i++) {
|
2013-03-21 15:15:18 +01:00
|
|
|
s->cmd_vqs[i] = virtio_add_queue(vdev, VIRTIO_SCSI_VQ_SIZE,
|
2014-06-19 10:12:00 +02:00
|
|
|
cmd);
|
2012-04-06 10:39:46 +02:00
|
|
|
}
|
2014-09-23 09:49:30 +02:00
|
|
|
|
|
|
|
if (s->conf.iothread) {
|
|
|
|
virtio_scsi_set_iothread(VIRTIO_SCSI(s), s->conf.iothread);
|
|
|
|
}
|
2013-03-29 02:08:15 +01:00
|
|
|
}
|
|
|
|
|
2013-07-30 03:19:55 +02:00
|
|
|
static void virtio_scsi_device_realize(DeviceState *dev, Error **errp)
|
2013-03-29 02:08:15 +01:00
|
|
|
{
|
2013-07-30 03:19:55 +02:00
|
|
|
VirtIODevice *vdev = VIRTIO_DEVICE(dev);
|
2013-07-30 05:41:42 +02:00
|
|
|
VirtIOSCSI *s = VIRTIO_SCSI(dev);
|
2013-03-29 02:08:15 +01:00
|
|
|
static int virtio_scsi_id;
|
2013-07-21 12:16:34 +02:00
|
|
|
Error *err = NULL;
|
2013-03-29 02:08:15 +01:00
|
|
|
|
2014-06-19 10:12:00 +02:00
|
|
|
virtio_scsi_common_realize(dev, &err, virtio_scsi_handle_ctrl,
|
|
|
|
virtio_scsi_handle_event,
|
|
|
|
virtio_scsi_handle_cmd);
|
2013-07-30 03:19:55 +02:00
|
|
|
if (err != NULL) {
|
|
|
|
error_propagate(errp, err);
|
|
|
|
return;
|
2013-03-29 02:08:15 +01:00
|
|
|
}
|
|
|
|
|
2013-07-30 05:41:42 +02:00
|
|
|
scsi_bus_new(&s->bus, sizeof(s->bus), dev,
|
2013-08-23 20:30:03 +02:00
|
|
|
&virtio_scsi_scsi_info, vdev->bus_name);
|
2014-09-26 11:28:33 +02:00
|
|
|
/* override default SCSI bus hotplug-handler, with virtio-scsi's one */
|
|
|
|
qbus_set_hotplug_handler(BUS(&s->bus), dev, &error_abort);
|
2013-04-30 16:08:51 +02:00
|
|
|
|
2013-07-30 05:41:42 +02:00
|
|
|
if (!dev->hotplugged) {
|
2013-07-21 12:16:34 +02:00
|
|
|
scsi_bus_legacy_handle_cmdline(&s->bus, &err);
|
|
|
|
if (err != NULL) {
|
2013-07-30 03:19:55 +02:00
|
|
|
error_propagate(errp, err);
|
|
|
|
return;
|
2013-07-21 12:16:34 +02:00
|
|
|
}
|
2011-11-14 16:58:41 +01:00
|
|
|
}
|
|
|
|
|
2013-07-30 05:41:42 +02:00
|
|
|
register_savevm(dev, "virtio-scsi", virtio_scsi_id++, 1,
|
2011-12-02 15:23:15 +01:00
|
|
|
virtio_scsi_save, virtio_scsi_load, s);
|
2015-02-27 18:11:53 +01:00
|
|
|
|
|
|
|
error_setg(&s->blocker, "block device is in use by data plane");
|
2016-01-29 16:36:05 +01:00
|
|
|
|
|
|
|
QTAILQ_INIT(&s->insert_notifiers);
|
|
|
|
QTAILQ_INIT(&s->remove_notifiers);
|
2013-03-21 15:15:14 +01:00
|
|
|
}
|
|
|
|
|
2014-08-06 07:35:06 +02:00
|
|
|
static void virtio_scsi_instance_init(Object *obj)
|
|
|
|
{
|
|
|
|
VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(obj);
|
|
|
|
|
|
|
|
object_property_add_link(obj, "iothread", TYPE_IOTHREAD,
|
|
|
|
(Object **)&vs->conf.iothread,
|
|
|
|
qdev_prop_allow_set_link_before_realize,
|
|
|
|
OBJ_PROP_LINK_UNREF_ON_RELEASE, &error_abort);
|
|
|
|
}
|
|
|
|
|
2013-07-30 03:50:44 +02:00
|
|
|
void virtio_scsi_common_unrealize(DeviceState *dev, Error **errp)
|
2013-03-29 02:08:15 +01:00
|
|
|
{
|
2013-07-30 03:50:44 +02:00
|
|
|
VirtIODevice *vdev = VIRTIO_DEVICE(dev);
|
|
|
|
VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(dev);
|
2013-03-29 02:08:15 +01:00
|
|
|
|
|
|
|
g_free(vs->cmd_vqs);
|
2013-04-24 10:21:22 +02:00
|
|
|
virtio_cleanup(vdev);
|
2013-03-29 02:08:15 +01:00
|
|
|
}
|
|
|
|
|
2013-07-30 03:50:44 +02:00
|
|
|
static void virtio_scsi_device_unrealize(DeviceState *dev, Error **errp)
|
2013-03-21 15:15:14 +01:00
|
|
|
{
|
2013-07-30 03:50:44 +02:00
|
|
|
VirtIOSCSI *s = VIRTIO_SCSI(dev);
|
|
|
|
|
2015-02-27 18:11:53 +01:00
|
|
|
error_free(s->blocker);
|
|
|
|
|
2013-07-30 03:50:44 +02:00
|
|
|
unregister_savevm(dev, "virtio-scsi", s);
|
|
|
|
virtio_scsi_common_unrealize(dev, errp);
|
2013-03-21 15:15:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Property virtio_scsi_properties[] = {
|
2015-06-10 17:04:32 +02:00
|
|
|
DEFINE_PROP_UINT32("num_queues", VirtIOSCSI, parent_obj.conf.num_queues, 1),
|
|
|
|
DEFINE_PROP_UINT32("max_sectors", VirtIOSCSI, parent_obj.conf.max_sectors,
|
|
|
|
0xFFFF),
|
|
|
|
DEFINE_PROP_UINT32("cmd_per_lun", VirtIOSCSI, parent_obj.conf.cmd_per_lun,
|
|
|
|
128),
|
|
|
|
DEFINE_PROP_BIT("hotplug", VirtIOSCSI, host_features,
|
|
|
|
VIRTIO_SCSI_F_HOTPLUG, true),
|
|
|
|
DEFINE_PROP_BIT("param_change", VirtIOSCSI, host_features,
|
|
|
|
VIRTIO_SCSI_F_CHANGE, true),
|
2013-03-21 15:15:14 +01:00
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
2013-03-29 02:08:15 +01:00
|
|
|
static void virtio_scsi_common_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
|
2013-07-29 16:17:45 +02:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2013-03-29 02:08:15 +01:00
|
|
|
|
|
|
|
vdc->get_config = virtio_scsi_get_config;
|
2013-07-29 16:17:45 +02:00
|
|
|
set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
|
2013-03-29 02:08:15 +01:00
|
|
|
}
|
|
|
|
|
2013-03-21 15:15:14 +01:00
|
|
|
static void virtio_scsi_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
|
|
|
VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
|
2014-09-26 11:28:33 +02:00
|
|
|
HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(klass);
|
2013-07-30 03:19:55 +02:00
|
|
|
|
2013-03-21 15:15:14 +01:00
|
|
|
dc->props = virtio_scsi_properties;
|
2013-07-29 16:17:45 +02:00
|
|
|
set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
|
2013-07-30 03:19:55 +02:00
|
|
|
vdc->realize = virtio_scsi_device_realize;
|
2013-07-30 03:50:44 +02:00
|
|
|
vdc->unrealize = virtio_scsi_device_unrealize;
|
2013-03-21 15:15:14 +01:00
|
|
|
vdc->set_config = virtio_scsi_set_config;
|
|
|
|
vdc->get_features = virtio_scsi_get_features;
|
|
|
|
vdc->reset = virtio_scsi_reset;
|
2014-09-26 11:28:33 +02:00
|
|
|
hc->plug = virtio_scsi_hotplug;
|
|
|
|
hc->unplug = virtio_scsi_hotunplug;
|
2013-03-21 15:15:14 +01:00
|
|
|
}
|
|
|
|
|
2013-03-29 02:08:15 +01:00
|
|
|
static const TypeInfo virtio_scsi_common_info = {
|
|
|
|
.name = TYPE_VIRTIO_SCSI_COMMON,
|
|
|
|
.parent = TYPE_VIRTIO_DEVICE,
|
|
|
|
.instance_size = sizeof(VirtIOSCSICommon),
|
2013-08-19 17:53:15 +02:00
|
|
|
.abstract = true,
|
2013-03-29 02:08:15 +01:00
|
|
|
.class_init = virtio_scsi_common_class_init,
|
|
|
|
};
|
|
|
|
|
2013-03-21 15:15:14 +01:00
|
|
|
static const TypeInfo virtio_scsi_info = {
|
|
|
|
.name = TYPE_VIRTIO_SCSI,
|
2013-03-29 02:08:15 +01:00
|
|
|
.parent = TYPE_VIRTIO_SCSI_COMMON,
|
2013-03-21 15:15:14 +01:00
|
|
|
.instance_size = sizeof(VirtIOSCSI),
|
2014-08-06 07:35:06 +02:00
|
|
|
.instance_init = virtio_scsi_instance_init,
|
2013-03-21 15:15:14 +01:00
|
|
|
.class_init = virtio_scsi_class_init,
|
2014-09-26 11:28:33 +02:00
|
|
|
.interfaces = (InterfaceInfo[]) {
|
|
|
|
{ TYPE_HOTPLUG_HANDLER },
|
|
|
|
{ }
|
|
|
|
}
|
2013-03-21 15:15:14 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static void virtio_register_types(void)
|
|
|
|
{
|
2013-03-29 02:08:15 +01:00
|
|
|
type_register_static(&virtio_scsi_common_info);
|
2013-03-21 15:15:14 +01:00
|
|
|
type_register_static(&virtio_scsi_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_init(virtio_register_types)
|