static void vhost_virtqueue_stop(struct vhost_dev *dev,

                                    struct VirtIODevice *vdev,

                                    struct vhost_virtqueue *vq,

                                    unsigned idx)

{

    int vhost_vq_index = dev->vhost_ops->vhost_get_vq_index(dev, idx);

    struct vhost_vring_state state = {

        .index = vhost_vq_index,

    };

    int r;



    r = dev->vhost_ops->vhost_get_vring_base(dev, &state);

    if (r < 0) {

        fprintf(stderr, "vhost VQ %d ring restore failed: %d\n", idx, r);

        fflush(stderr);

    }

    virtio_queue_set_last_avail_idx(vdev, idx, state.num);

    virtio_queue_invalidate_signalled_used(vdev, idx);



    /* In the cross-endian case, we need to reset the vring endianness to

     * native as legacy devices expect so by default.

     */

    if (!virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1) &&

        vhost_needs_vring_endian(vdev)) {

        r = vhost_virtqueue_set_vring_endian_legacy(dev,

                                                    !virtio_is_big_endian(vdev),

                                                    vhost_vq_index);

        if (r < 0) {

            error_report("failed to reset vring endianness");

        }

    }



    assert (r >= 0);

    cpu_physical_memory_unmap(vq->ring, virtio_queue_get_ring_size(vdev, idx),

                              0, virtio_queue_get_ring_size(vdev, idx));

    cpu_physical_memory_unmap(vq->used, virtio_queue_get_used_size(vdev, idx),

                              1, virtio_queue_get_used_size(vdev, idx));

    cpu_physical_memory_unmap(vq->avail, virtio_queue_get_avail_size(vdev, idx),

                              0, virtio_queue_get_avail_size(vdev, idx));

    cpu_physical_memory_unmap(vq->desc, virtio_queue_get_desc_size(vdev, idx),

                              0, virtio_queue_get_desc_size(vdev, idx));

}

static void vhost_virtqueue_stop(struct vhost_dev *dev,

                                    struct VirtIODevice *vdev,

                                    struct vhost_virtqueue *vq,

                                    unsigned idx)

{

    int vhost_vq_index = dev->vhost_ops->vhost_get_vq_index(dev, idx);

    struct vhost_vring_state state = {

        .index = vhost_vq_index,

    };

    int r;



    r = dev->vhost_ops->vhost_get_vring_base(dev, &state);

    if (r < 0) {

        fprintf(stderr, "vhost VQ %d ring restore failed: %d\n", idx, r);

        fflush(stderr);

    }

    virtio_queue_set_last_avail_idx(vdev, idx, state.num);

    virtio_queue_invalidate_signalled_used(vdev, idx);



    





    if (!virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1) &&

        vhost_needs_vring_endian(vdev)) {

        r = vhost_virtqueue_set_vring_endian_legacy(dev,

                                                    !virtio_is_big_endian(vdev),

                                                    vhost_vq_index);

        if (r < 0) {

            error_report("failed to reset vring endianness");

        }

    }



    assert (r >= 0);

    cpu_physical_memory_unmap(vq->ring, virtio_queue_get_ring_size(vdev, idx),

                              0, virtio_queue_get_ring_size(vdev, idx));

    cpu_physical_memory_unmap(vq->used, virtio_queue_get_used_size(vdev, idx),

                              1, virtio_queue_get_used_size(vdev, idx));

    cpu_physical_memory_unmap(vq->avail, virtio_queue_get_avail_size(vdev, idx),

                              0, virtio_queue_get_avail_size(vdev, idx));

    cpu_physical_memory_unmap(vq->desc, virtio_queue_get_desc_size(vdev, idx),

                              0, virtio_queue_get_desc_size(vdev, idx));

}

static void FUNC_0(struct vhost_dev *VAR_0,

                                    struct VirtIODevice *VAR_1,

                                    struct vhost_virtqueue *VAR_2,

                                    unsigned VAR_3)

{

    int VAR_4 = VAR_0->vhost_ops->vhost_get_vq_index(VAR_0, VAR_3);

    struct vhost_vring_state VAR_5 = {

        .index = VAR_4,

    };

    int VAR_6;



    VAR_6 = VAR_0->vhost_ops->vhost_get_vring_base(VAR_0, &VAR_5);

    if (VAR_6 < 0) {

        fprintf(stderr, "vhost VQ %d ring restore failed: %d\n", VAR_3, VAR_6);

        fflush(stderr);

    }

    virtio_queue_set_last_avail_idx(VAR_1, VAR_3, VAR_5.num);

    virtio_queue_invalidate_signalled_used(VAR_1, VAR_3);



    





    if (!virtio_vdev_has_feature(VAR_1, VIRTIO_F_VERSION_1) &&

        vhost_needs_vring_endian(VAR_1)) {

        VAR_6 = vhost_virtqueue_set_vring_endian_legacy(VAR_0,

                                                    !virtio_is_big_endian(VAR_1),

                                                    VAR_4);

        if (VAR_6 < 0) {

            error_report("failed to reset vring endianness");

        }

    }



    assert (VAR_6 >= 0);

    cpu_physical_memory_unmap(VAR_2->ring, virtio_queue_get_ring_size(VAR_1, VAR_3),

                              0, virtio_queue_get_ring_size(VAR_1, VAR_3));

    cpu_physical_memory_unmap(VAR_2->used, virtio_queue_get_used_size(VAR_1, VAR_3),

                              1, virtio_queue_get_used_size(VAR_1, VAR_3));

    cpu_physical_memory_unmap(VAR_2->avail, virtio_queue_get_avail_size(VAR_1, VAR_3),

                              0, virtio_queue_get_avail_size(VAR_1, VAR_3));

    cpu_physical_memory_unmap(VAR_2->desc, virtio_queue_get_desc_size(VAR_1, VAR_3),

                              0, virtio_queue_get_desc_size(VAR_1, VAR_3));

}

static void FUNC_0(struct vhost_dev *VAR_0,
struct VirtIODevice *VAR_1,
struct vhost_virtqueue *VAR_2,
unsigned VAR_3)
{ int VAR_4 = VAR_0->vhost_ops->vhost_get_vq_index(VAR_0, VAR_3); struct vhost_vring_state VAR_5 = { .index = VAR_4,
}; int VAR_6; VAR_6 = VAR_0->vhost_ops->vhost_get_vring_base(VAR_0, &VAR_5); if (VAR_6 < 0) { fprintf(stderr, "vhost VQ %d ring restore failed: %d\n", VAR_3, VAR_6); fflush(stderr); } virtio_queue_set_last_avail_idx(VAR_1, VAR_3, VAR_5.num); virtio_queue_invalidate_signalled_used(VAR_1, VAR_3); if (!virtio_vdev_has_feature(VAR_1, VIRTIO_F_VERSION_1) &&
vhost_needs_vring_endian(VAR_1)) { VAR_6 = vhost_virtqueue_set_vring_endian_legacy(VAR_0,
!virtio_is_big_endian(VAR_1),
VAR_4); if (VAR_6 < 0) { error_report("failed to reset vring endianness"); } } assert (VAR_6 >= 0); cpu_physical_memory_unmap(VAR_2->ring, virtio_queue_get_ring_size(VAR_1, VAR_3),
0, virtio_queue_get_ring_size(VAR_1, VAR_3)); cpu_physical_memory_unmap(VAR_2->used, virtio_queue_get_used_size(VAR_1, VAR_3),
1, virtio_queue_get_used_size(VAR_1, VAR_3)); cpu_physical_memory_unmap(VAR_2->avail, virtio_queue_get_avail_size(VAR_1, VAR_3),
0, virtio_queue_get_avail_size(VAR_1, VAR_3)); cpu_physical_memory_unmap(VAR_2->desc, virtio_queue_get_desc_size(VAR_1, VAR_3),
0, virtio_queue_get_desc_size(VAR_1, VAR_3)); }