The core of the function is useful to transform from VirtQueueElement to VirtQueueElementOld. Extract these from qemu_put_virtqueue_element, and leave there the handling of QEMUFile.
No functional change intended. Signed-off-by: Eugenio Pérez <epere...@redhat.com> --- hw/virtio/virtio.c | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index b0245ce4e8..bc3b474065 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -2360,36 +2360,43 @@ void *qemu_get_virtqueue_element(VirtIODevice *vdev, QEMUFile *f, size_t sz) return elem; } -void qemu_put_virtqueue_element(VirtIODevice *vdev, QEMUFile *f, - VirtQueueElement *elem) +/* Convert VirtQueueElement to VirtQueueElementOld */ +static void qemu_put_virtqueue_element_old(const VirtQueueElement *elem, + VirtQueueElementOld *data) { - VirtQueueElementOld data; - int i; + memset(data, 0, sizeof(*data)); + data->index = elem->index; + data->in_num = elem->in_num; + data->out_num = elem->out_num; - memset(&data, 0, sizeof(data)); - data.index = elem->index; - data.in_num = elem->in_num; - data.out_num = elem->out_num; - - for (i = 0; i < elem->in_num; i++) { - data.in_addr[i] = elem->in_addr[i]; + for (int i = 0; i < elem->in_num; i++) { + data->in_addr[i] = elem->in_addr[i]; } - for (i = 0; i < elem->out_num; i++) { - data.out_addr[i] = elem->out_addr[i]; + for (int i = 0; i < elem->out_num; i++) { + data->out_addr[i] = elem->out_addr[i]; } - for (i = 0; i < elem->in_num; i++) { - /* Base is overwritten by virtqueue_map when loading. Do not - * save it, as it would leak the QEMU address space layout. */ - data.in_sg[i].iov_len = elem->in_sg[i].iov_len; + for (int i = 0; i < elem->in_num; i++) { + /* + * Base is overwritten by virtqueue_map when loading. Do not + * save it, as it would leak the QEMU address space layout. + */ + data->in_sg[i].iov_len = elem->in_sg[i].iov_len; } - for (i = 0; i < elem->out_num; i++) { + for (int i = 0; i < elem->out_num; i++) { /* Do not save iov_base as above. */ - data.out_sg[i].iov_len = elem->out_sg[i].iov_len; + data->out_sg[i].iov_len = elem->out_sg[i].iov_len; } +} + +void qemu_put_virtqueue_element(VirtIODevice *vdev, QEMUFile *f, + VirtQueueElement *elem) +{ + VirtQueueElementOld data; + qemu_put_virtqueue_element_old(elem, &data); if (virtio_host_has_feature(vdev, VIRTIO_F_RING_PACKED)) { qemu_put_be32s(f, &elem->ndescs); } -- 2.31.1