aboutsummaryrefslogtreecommitdiff
path: root/tests/virtio-scsi-test.c
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2016-06-20 15:07:56 +0100
committerPeter Maydell <peter.maydell@linaro.org>2016-06-20 15:07:56 +0100
commitfd2590bccc0bd63833813592a3e193686cf1c623 (patch)
tree2be06d9fe8553ef621282a2f068b133e160eeec7 /tests/virtio-scsi-test.c
parent5edbd4e30426d3a0d712510b2509a521e35192b1 (diff)
parent5ab4b69ce29908b327a91966dc78ea0fd7424075 (diff)
Merge remote-tracking branch 'remotes/stefanha/tags/block-pull-request' into staging
# gpg: Signature made Mon 20 Jun 2016 15:05:24 BST # gpg: using RSA key 0x9CA4ABB381AB73C8 # gpg: Good signature from "Stefan Hajnoczi <stefanha@redhat.com>" # gpg: aka "Stefan Hajnoczi <stefanha@gmail.com>" # Primary key fingerprint: 8695 A8BF D3F9 7CDA AC35 775A 9CA4 ABB3 81AB 73C8 * remotes/stefanha/tags/block-pull-request: backup: follow AioContext change gracefully mirror: follow AioContext change gracefully blockjob: add AioContext attached callback block: use safe iteration over AioContext notifiers blockjob: add block_job_get_aio_context() blockjob: add pause points blockjob: rename block_job_is_paused() blockjob: move iostatus reset out of block_job_enter() block: process before_write_notifiers in bdrv_co_discard block: fix race in bdrv_co_discard with drive-mirror block: fixed BdrvTrackedRequest filling in bdrv_co_discard libqos: add qvirtqueue_cleanup() libqos: drop duplicated virtio_pci.h definitions libqos: drop duplicated virtio_scsi.h definitions libqos: drop duplicated virtio_blk.h definitions libqos: drop duplicated virtio_vring.h structs libqos: drop duplicated virtio_ring.h bit definitions libqos: drop duplicated virtio_config.h definitions libqos: drop duplicated PCI vendor ID definition libqos: use virtio_ids.h for device ID definitions Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'tests/virtio-scsi-test.c')
-rw-r--r--tests/virtio-scsi-test.c55
1 files changed, 21 insertions, 34 deletions
diff --git a/tests/virtio-scsi-test.c b/tests/virtio-scsi-test.c
index 5f1a8aefeb..cbe5dcca24 100644
--- a/tests/virtio-scsi-test.c
+++ b/tests/virtio-scsi-test.c
@@ -17,11 +17,13 @@
#include "libqos/malloc.h"
#include "libqos/malloc-pc.h"
#include "libqos/malloc-generic.h"
+#include "standard-headers/linux/virtio_ids.h"
+#include "standard-headers/linux/virtio_pci.h"
+#include "standard-headers/linux/virtio_scsi.h"
#define PCI_SLOT 0x02
#define PCI_FN 0x00
#define QVIRTIO_SCSI_TIMEOUT_US (1 * 1000 * 1000)
-#define CDB_SIZE 32
#define MAX_NUM_QUEUES 64
@@ -33,24 +35,6 @@ typedef struct {
QVirtQueue *vq[MAX_NUM_QUEUES + 2];
} QVirtIOSCSI;
-typedef struct {
- uint8_t lun[8];
- int64_t tag;
- uint8_t task_attr;
- uint8_t prio;
- uint8_t crn;
- uint8_t cdb[CDB_SIZE];
-} QEMU_PACKED QVirtIOSCSICmdReq;
-
-typedef struct {
- uint32_t sense_len;
- uint32_t resid;
- uint16_t status_qualifier;
- uint8_t status;
- uint8_t response;
- uint8_t sense[96];
-} QEMU_PACKED QVirtIOSCSICmdResp;
-
static void qvirtio_scsi_start(const char *extra_opts)
{
char *cmdline;
@@ -74,7 +58,7 @@ static void qvirtio_scsi_pci_free(QVirtIOSCSI *vs)
int i;
for (i = 0; i < vs->num_queues + 2; i++) {
- guest_free(vs->alloc, vs->vq[i]->desc);
+ qvirtqueue_cleanup(&qvirtio_pci, vs->vq[i], vs->alloc);
}
pc_alloc_uninit(vs->alloc);
qvirtio_pci_device_disable(container_of(vs->dev, QVirtioPCIDevice, vdev));
@@ -99,11 +83,11 @@ static uint8_t virtio_scsi_do_command(QVirtIOSCSI *vs, const uint8_t *cdb,
const uint8_t *data_in,
size_t data_in_len,
uint8_t *data_out, size_t data_out_len,
- QVirtIOSCSICmdResp *resp_out)
+ struct virtio_scsi_cmd_resp *resp_out)
{
QVirtQueue *vq;
- QVirtIOSCSICmdReq req = { { 0 } };
- QVirtIOSCSICmdResp resp = { .response = 0xff, .status = 0xff };
+ struct virtio_scsi_cmd_req req = { { 0 } };
+ struct virtio_scsi_cmd_resp resp = { .response = 0xff, .status = 0xff };
uint64_t req_addr, resp_addr, data_in_addr = 0, data_out_addr = 0;
uint8_t response;
uint32_t free_head;
@@ -112,7 +96,7 @@ static uint8_t virtio_scsi_do_command(QVirtIOSCSI *vs, const uint8_t *cdb,
req.lun[0] = 1; /* Select LUN */
req.lun[1] = 1; /* Select target 1 */
- memcpy(req.cdb, cdb, CDB_SIZE);
+ memcpy(req.cdb, cdb, VIRTIO_SCSI_CDB_SIZE);
/* XXX: Fix endian if any multi-byte field in req/resp is used */
@@ -137,7 +121,8 @@ static uint8_t virtio_scsi_do_command(QVirtIOSCSI *vs, const uint8_t *cdb,
qvirtqueue_kick(&qvirtio_pci, vs->dev, vq, free_head);
qvirtio_wait_queue_isr(&qvirtio_pci, vs->dev, vq, QVIRTIO_SCSI_TIMEOUT_US);
- response = readb(resp_addr + offsetof(QVirtIOSCSICmdResp, response));
+ response = readb(resp_addr +
+ offsetof(struct virtio_scsi_cmd_resp, response));
if (resp_out) {
memread(resp_addr, resp_out, sizeof(*resp_out));
@@ -152,10 +137,10 @@ static uint8_t virtio_scsi_do_command(QVirtIOSCSI *vs, const uint8_t *cdb,
static QVirtIOSCSI *qvirtio_scsi_pci_init(int slot)
{
- const uint8_t test_unit_ready_cdb[CDB_SIZE] = {};
+ const uint8_t test_unit_ready_cdb[VIRTIO_SCSI_CDB_SIZE] = {};
QVirtIOSCSI *vs;
QVirtioPCIDevice *dev;
- QVirtIOSCSICmdResp resp;
+ struct virtio_scsi_cmd_resp resp;
void *addr;
int i;
@@ -163,17 +148,17 @@ static QVirtIOSCSI *qvirtio_scsi_pci_init(int slot)
vs->alloc = pc_alloc_init();
vs->bus = qpci_init_pc();
- dev = qvirtio_pci_device_find(vs->bus, QVIRTIO_SCSI_DEVICE_ID);
+ dev = qvirtio_pci_device_find(vs->bus, VIRTIO_ID_SCSI);
vs->dev = (QVirtioDevice *)dev;
g_assert(dev != NULL);
- g_assert_cmphex(vs->dev->device_type, ==, QVIRTIO_SCSI_DEVICE_ID);
+ g_assert_cmphex(vs->dev->device_type, ==, VIRTIO_ID_SCSI);
qvirtio_pci_device_enable(dev);
qvirtio_reset(&qvirtio_pci, vs->dev);
qvirtio_set_acknowledge(&qvirtio_pci, vs->dev);
qvirtio_set_driver(&qvirtio_pci, vs->dev);
- addr = dev->addr + QVIRTIO_PCI_DEVICE_SPECIFIC_NO_MSIX;
+ addr = dev->addr + VIRTIO_PCI_CONFIG_OFF(false);
vs->num_queues = qvirtio_config_readl(&qvirtio_pci, vs->dev,
(uint64_t)(uintptr_t)addr);
@@ -238,10 +223,12 @@ static void test_unaligned_write_same(void)
QVirtIOSCSI *vs;
uint8_t buf1[512] = { 0 };
uint8_t buf2[512] = { 1 };
- const uint8_t write_same_cdb_1[CDB_SIZE] = { 0x41, 0x00, 0x00, 0x00, 0x00,
- 0x01, 0x00, 0x00, 0x02, 0x00 };
- const uint8_t write_same_cdb_2[CDB_SIZE] = { 0x41, 0x00, 0x00, 0x00, 0x00,
- 0x01, 0x00, 0x33, 0x00, 0x00 };
+ const uint8_t write_same_cdb_1[VIRTIO_SCSI_CDB_SIZE] = {
+ 0x41, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x02, 0x00
+ };
+ const uint8_t write_same_cdb_2[VIRTIO_SCSI_CDB_SIZE] = {
+ 0x41, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x33, 0x00, 0x00
+ };
qvirtio_scsi_start("-drive file=blkdebug::null-co://,if=none,id=dr1"
",format=raw,file.align=4k "