virtio: move VirtQueueElement at the beginning of the structs
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 <pbonzini@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
This commit is contained in:
parent
0734fb083c
commit
6aa46d8ff1
|
@ -45,8 +45,7 @@ VirtIOSCSIReq *virtio_scsi_init_req(VirtIOSCSI *s, VirtQueue *vq)
|
||||||
{
|
{
|
||||||
VirtIOSCSIReq *req;
|
VirtIOSCSIReq *req;
|
||||||
VirtIOSCSICommon *vs = (VirtIOSCSICommon *)s;
|
VirtIOSCSICommon *vs = (VirtIOSCSICommon *)s;
|
||||||
const size_t zero_skip = offsetof(VirtIOSCSIReq, elem)
|
const size_t zero_skip = offsetof(VirtIOSCSIReq, vring);
|
||||||
+ sizeof(VirtQueueElement);
|
|
||||||
|
|
||||||
req = g_malloc(sizeof(*req) + vs->cdb_size);
|
req = g_malloc(sizeof(*req) + vs->cdb_size);
|
||||||
req->vq = vq;
|
req->vq = vq;
|
||||||
|
|
|
@ -60,9 +60,9 @@ typedef struct VirtIOBlock {
|
||||||
} VirtIOBlock;
|
} VirtIOBlock;
|
||||||
|
|
||||||
typedef struct VirtIOBlockReq {
|
typedef struct VirtIOBlockReq {
|
||||||
|
VirtQueueElement elem;
|
||||||
int64_t sector_num;
|
int64_t sector_num;
|
||||||
VirtIOBlock *dev;
|
VirtIOBlock *dev;
|
||||||
VirtQueueElement elem;
|
|
||||||
struct virtio_blk_inhdr *in;
|
struct virtio_blk_inhdr *in;
|
||||||
struct virtio_blk_outhdr out;
|
struct virtio_blk_outhdr out;
|
||||||
QEMUIOVector qiov;
|
QEMUIOVector qiov;
|
||||||
|
|
|
@ -112,18 +112,17 @@ typedef struct VirtIOSCSI {
|
||||||
} VirtIOSCSI;
|
} VirtIOSCSI;
|
||||||
|
|
||||||
typedef struct VirtIOSCSIReq {
|
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;
|
VirtIOSCSI *dev;
|
||||||
VirtQueue *vq;
|
VirtQueue *vq;
|
||||||
QEMUSGList qsgl;
|
QEMUSGList qsgl;
|
||||||
QEMUIOVector resp_iov;
|
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. */
|
/* Set by dataplane code. */
|
||||||
VirtIOSCSIVring *vring;
|
VirtIOSCSIVring *vring;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue