[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL v2 05/45] virtio: move VirtQueueElement at the beginn
From: |
Michael S. Tsirkin |
Subject: |
[Qemu-devel] [PULL v2 05/45] virtio: move VirtQueueElement at the beginning of the structs |
Date: |
Sat, 6 Feb 2016 21:12:26 +0200 |
From: Paolo Bonzini <address@hidden>
The next patch will make virtqueue_pop/vring_pop allocate memory for
the VirtQueueElement. In some cases (blk, scsi, gpu) the device wants
to extend VirtQueueElement with device-specific fields and, until now,
the place of the VirtQueueElement within the containing struct didn't
matter. When allocating the entire block in virtqueue_pop/vring_pop,
however, the containing struct must basically be a "subclass" of
VirtQueueElement, with the VirtQueueElement as the first field. Make
that the case for blk and scsi; gpu is already doing it.
Signed-off-by: Paolo Bonzini <address@hidden>
Reviewed-by: Michael S. Tsirkin <address@hidden>
Signed-off-by: Michael S. Tsirkin <address@hidden>
Reviewed-by: Cornelia Huck <address@hidden>
---
include/hw/virtio/virtio-blk.h | 2 +-
include/hw/virtio/virtio-scsi.h | 13 ++++++-------
hw/scsi/virtio-scsi.c | 3 +--
3 files changed, 8 insertions(+), 10 deletions(-)
diff --git a/include/hw/virtio/virtio-blk.h b/include/hw/virtio/virtio-blk.h
index ae11a63..403ab86 100644
--- a/include/hw/virtio/virtio-blk.h
+++ b/include/hw/virtio/virtio-blk.h
@@ -60,9 +60,9 @@ typedef struct VirtIOBlock {
} VirtIOBlock;
typedef struct VirtIOBlockReq {
+ VirtQueueElement elem;
int64_t sector_num;
VirtIOBlock *dev;
- VirtQueueElement elem;
struct virtio_blk_inhdr *in;
struct virtio_blk_outhdr out;
QEMUIOVector qiov;
diff --git a/include/hw/virtio/virtio-scsi.h b/include/hw/virtio/virtio-scsi.h
index 0394eb2..eb9d25b 100644
--- a/include/hw/virtio/virtio-scsi.h
+++ b/include/hw/virtio/virtio-scsi.h
@@ -112,18 +112,17 @@ typedef struct VirtIOSCSI {
} VirtIOSCSI;
typedef struct VirtIOSCSIReq {
+ /* Note:
+ * - fields up to resp_iov are initialized by virtio_scsi_init_req;
+ * - fields starting at vring are zeroed by virtio_scsi_init_req.
+ * */
+ VirtQueueElement elem;
+
VirtIOSCSI *dev;
VirtQueue *vq;
QEMUSGList qsgl;
QEMUIOVector resp_iov;
- /* Note:
- * - fields before elem are initialized by virtio_scsi_init_req;
- * - elem is uninitialized at the time of allocation.
- * - fields after elem are zeroed by virtio_scsi_init_req.
- * */
-
- VirtQueueElement elem;
/* Set by dataplane code. */
VirtIOSCSIVring *vring;
diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
index 1500c42..7fdf6ad 100644
--- a/hw/scsi/virtio-scsi.c
+++ b/hw/scsi/virtio-scsi.c
@@ -45,8 +45,7 @@ VirtIOSCSIReq *virtio_scsi_init_req(VirtIOSCSI *s, VirtQueue
*vq)
{
VirtIOSCSIReq *req;
VirtIOSCSICommon *vs = (VirtIOSCSICommon *)s;
- const size_t zero_skip = offsetof(VirtIOSCSIReq, elem)
- + sizeof(VirtQueueElement);
+ const size_t zero_skip = offsetof(VirtIOSCSIReq, vring);
req = g_malloc(sizeof(*req) + vs->cdb_size);
req->vq = vq;
--
MST
- [Qemu-devel] [PULL v2 00/45] pc and misc cleanups and fixes, virtio optimizations, Michael S. Tsirkin, 2016/02/06
- [Qemu-devel] [PULL v2 01/45] Fix virtio migration, Michael S. Tsirkin, 2016/02/06
- [Qemu-devel] [PULL v2 02/45] pc: acpi: merge SSDT into DSDT, Michael S. Tsirkin, 2016/02/06
- [Qemu-devel] [PULL v2 03/45] tests: pc: acpi: drop not needed 'expected SSDT' blobs, Michael S. Tsirkin, 2016/02/06
- [Qemu-devel] [PULL v2 04/45] tests: pc: acpi: add expected DSDT.bridge blobs and update DSDT blobs, Michael S. Tsirkin, 2016/02/06
- [Qemu-devel] [PULL v2 05/45] virtio: move VirtQueueElement at the beginning of the structs,
Michael S. Tsirkin <=
- [Qemu-devel] [PULL v2 07/45] virtio: introduce qemu_get/put_virtqueue_element, Michael S. Tsirkin, 2016/02/06
- [Qemu-devel] [PULL v2 08/45] virtio: introduce virtqueue_alloc_element, Michael S. Tsirkin, 2016/02/06
- [Qemu-devel] [PULL v2 09/45] virtio: slim down allocation of VirtQueueElements, Michael S. Tsirkin, 2016/02/06
- [Qemu-devel] [PULL v2 06/45] virtio: move allocation to virtqueue_pop/vring_pop, Michael S. Tsirkin, 2016/02/06
- [Qemu-devel] [PULL v2 10/45] vring: slim down allocation of VirtQueueElements, Michael S. Tsirkin, 2016/02/06
- [Qemu-devel] [PULL v2 12/45] virtio: cache used_idx in a VirtQueue field, Michael S. Tsirkin, 2016/02/06
- [Qemu-devel] [PULL v2 11/45] virtio: combine the read of a descriptor, Michael S. Tsirkin, 2016/02/06
- [Qemu-devel] [PULL v2 13/45] virtio: read avail_idx from VQ only when necessary, Michael S. Tsirkin, 2016/02/06
- [Qemu-devel] [PULL v2 14/45] virtio: combine write of an entry into used ring, Michael S. Tsirkin, 2016/02/06
- [Qemu-devel] [PULL v2 15/45] hw/pxb: add pxb devices to the bridge category, Michael S. Tsirkin, 2016/02/06