From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51262) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bZDNu-0001cz-9t for qemu-devel@nongnu.org; Mon, 15 Aug 2016 04:36:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bZDNr-0005gn-1L for qemu-devel@nongnu.org; Mon, 15 Aug 2016 04:36:38 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:34923 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bZDNq-0005g8-SD for qemu-devel@nongnu.org; Mon, 15 Aug 2016 04:36:34 -0400 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u7F8TC3o119253 for ; Mon, 15 Aug 2016 04:36:34 -0400 Received: from e06smtp07.uk.ibm.com (e06smtp07.uk.ibm.com [195.75.94.103]) by mx0b-001b2d01.pphosted.com with ESMTP id 24tgxrd872-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 15 Aug 2016 04:36:34 -0400 Received: from localhost by e06smtp07.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 15 Aug 2016 09:36:32 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id D05FA17D8056 for ; Mon, 15 Aug 2016 09:38:10 +0100 (BST) Received: from d06av04.portsmouth.uk.ibm.com (d06av04.portsmouth.uk.ibm.com [9.149.37.216]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u7F8aThe6685026 for ; Mon, 15 Aug 2016 08:36:29 GMT Received: from d06av04.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av04.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u7F8aS3F014569 for ; Mon, 15 Aug 2016 02:36:28 -0600 Date: Mon, 15 Aug 2016 10:36:25 +0200 From: Cornelia Huck In-Reply-To: <1471015978-1123-4-git-send-email-stefanha@redhat.com> References: <1471015978-1123-1-git-send-email-stefanha@redhat.com> <1471015978-1123-4-git-send-email-stefanha@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-Id: <20160815103625.1917288c.cornelia.huck@de.ibm.com> Subject: Re: [Qemu-devel] [PATCH for-2.7 3/4] virtio: add virtqueue_rewind() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: qemu-devel@nongnu.org, gaudenz@debian.org, "Michael S. Tsirkin" , Luiz Capitulino On Fri, 12 Aug 2016 16:32:57 +0100 Stefan Hajnoczi wrote: > virtqueue_discard() requires a VirtQueueElement but virtio-balloon does > not migrate its in-use element. Introduce a new function that is > similar to virtqueue_discard() but doesn't require a VirtQueueElement. > > This will allow virtio-balloon to access element again after migration > with the usual proviso that the guest may have modified the vring since > last time. > > Signed-off-by: Stefan Hajnoczi > --- > hw/virtio/virtio.c | 22 ++++++++++++++++++++++ > include/hw/virtio/virtio.h | 1 + > 2 files changed, 23 insertions(+) > > diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c > index 00158b6..22727ba 100644 > --- a/hw/virtio/virtio.c > +++ b/hw/virtio/virtio.c > @@ -272,6 +272,28 @@ void virtqueue_discard(VirtQueue *vq, const VirtQueueElement *elem, > virtqueue_unmap_sg(vq, elem, len); > } > > +/* virtqueue_rewind: > + * @vq: The #VirtQueue > + * @num: Number of elements to push back > + * > + * Pretend that elements weren't popped from the virtqueue. The next > + * virtqueue_pop() will refetch the oldest element. > + * > + * Use virtqueue_discard() instead if you have a VirtQueueElement. > + * > + * Returns: true on success, false if @num is greater than the number of in use > + * elements. Does it make sense at all to rewind multiple elements at once? Or does it make more sense for the caller to rewind one-by-one until they know that there are no more elements that could be refetched? > + */ > +bool virtqueue_rewind(VirtQueue *vq, unsigned int num) > +{ > + if (num > vq->inuse) { > + return false; > + } > + vq->last_avail_idx -= num; > + vq->inuse -= num; > + return true; > +} > + > void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem, > unsigned int len, unsigned int idx) > {