Received: from eggs.gnu.org ([2001:4830:134:3::10]:53226) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bfWVU-0001wb-Rs for qemu-devel@nongnu.org; Thu, 01 Sep 2016 14:14:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bfWVL-00035j-3V for qemu-devel@nongnu.org; Thu, 01 Sep 2016 14:14:31 -0400 Received: from mail-ve1eur01on0116.outbound.protection.outlook.com ([104.47.1.116]:47724 helo=EUR01-VE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bfWVK-00035O-Rc for qemu-devel@nongnu.org; Thu, 01 Sep 2016 14:14:23 -0400 From: Roman Kagan Date: Thu, 1 Sep 2016 21:13:59 +0300 Message-ID: <1472753640-18375-2-git-send-email-rkagan@virtuozzo.com> In-Reply-To: <1472753640-18375-1-git-send-email-rkagan@virtuozzo.com> References: <1472753640-18375-1-git-send-email-rkagan@virtuozzo.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH 1/2] virtio: add virtqueue_rewind List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Roman Kagan , "Michael S. Tsirkin" , Ladi Prosek , Stefan Hajnoczi If the in-use elements aren't migrated (like is the case with virtio-balloon stats vq), make virtqueue forget about them and pretend they haven't been popped yet, to allow to start over on load. Signed-off-by: Roman Kagan Cc: "Michael S. Tsirkin" Cc: Ladi Prosek Cc: Stefan Hajnoczi --- hw/virtio/virtio.c | 6 ++++++ include/hw/virtio/virtio.h | 1 + 2 files changed, 7 insertions(+) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 74c085c..844d2a1 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -272,6 +272,12 @@ void virtqueue_discard(VirtQueue *vq, const VirtQueueElement *elem, virtqueue_unmap_sg(vq, elem, len); } +void virtqueue_rewind(VirtQueue *vq) +{ + vq->last_avail_idx -= vq->inuse; + vq->inuse = 0; +} + void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem, unsigned int len, unsigned int idx) { diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index d2490c1..9f49fa4 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -154,6 +154,7 @@ void virtqueue_push(VirtQueue *vq, const VirtQueueElement *elem, void virtqueue_flush(VirtQueue *vq, unsigned int count); void virtqueue_discard(VirtQueue *vq, const VirtQueueElement *elem, unsigned int len); +void virtqueue_rewind(VirtQueue *vq); void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem, unsigned int len, unsigned int idx); -- 2.7.4