From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59577) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZfLRy-0007BR-Ui for qemu-devel@nongnu.org; Fri, 25 Sep 2015 01:21:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZfLRw-0001c4-VE for qemu-devel@nongnu.org; Fri, 25 Sep 2015 01:21:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49301) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZfLRw-0001bz-Pu for qemu-devel@nongnu.org; Fri, 25 Sep 2015 01:21:36 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 54ECDC0AD288 for ; Fri, 25 Sep 2015 05:21:36 +0000 (UTC) From: Jason Wang Date: Fri, 25 Sep 2015 13:21:29 +0800 Message-Id: <1443158490-16469-2-git-send-email-jasowang@redhat.com> In-Reply-To: <1443158490-16469-1-git-send-email-jasowang@redhat.com> References: <1443158490-16469-1-git-send-email-jasowang@redhat.com> Subject: [Qemu-devel] [PATCH V2 2/3] virtio: introduce virtqueue_discard() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: mst@redhat.com, qemu-devel@nongnu.org Cc: Jason Wang , ppandit@redhat.com This patch introduces virtqueue_discard() to discard a descriptor and unmap the sgs. This will be used by the patch that will discard descriptor when packet is truncated. Cc: Michael S. Tsirkin Signed-off-by: Jason Wang --- hw/virtio/virtio.c | 7 +++++++ include/hw/virtio/virtio.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index bb2c4cf..d24f775 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -266,6 +266,13 @@ static void virtqueue_unmap_sg(VirtQueue *vq, const VirtQueueElement *elem, 0, elem->out_sg[i].iov_len); } +void virtqueue_discard(VirtQueue *vq, const VirtQueueElement *elem, + unsigned int len) +{ + vq->last_avail_idx--; + virtqueue_unmap_sg(vq, elem, len); +} + 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 6201ee8..9d09115 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -146,6 +146,8 @@ void virtio_del_queue(VirtIODevice *vdev, int n); void virtqueue_push(VirtQueue *vq, const VirtQueueElement *elem, unsigned int len); void virtqueue_flush(VirtQueue *vq, unsigned int count); +void virtqueue_discard(VirtQueue *vq, const VirtQueueElement *elem, + unsigned int len); void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem, unsigned int len, unsigned int idx); -- 2.1.4