From patchwork Fri Sep 18 08:01:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 519165 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 1BF3D140180 for ; Fri, 18 Sep 2015 18:01:59 +1000 (AEST) Received: from localhost ([::1]:35994 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZcqcH-0002Uj-4M for incoming@patchwork.ozlabs.org; Fri, 18 Sep 2015 04:01:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50609) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zcqbm-0001Zq-E6 for qemu-devel@nongnu.org; Fri, 18 Sep 2015 04:01:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zcqbg-00015B-Ie for qemu-devel@nongnu.org; Fri, 18 Sep 2015 04:01:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34099) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zcqbg-000155-DX for qemu-devel@nongnu.org; Fri, 18 Sep 2015 04:01:20 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 11344A35BF for ; Fri, 18 Sep 2015 08:01:20 +0000 (UTC) Received: from jason-ThinkPad-T430s.nay.redhat.com (dhcp-14-122.nay.redhat.com [10.66.14.122]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t8I81C1S020108; Fri, 18 Sep 2015 04:01:17 -0400 From: Jason Wang To: mst@redhat.com, qemu-devel@nongnu.org Date: Fri, 18 Sep 2015 16:01:09 +0800 Message-Id: <1442563270-11615-2-git-send-email-jasowang@redhat.com> In-Reply-To: <1442563270-11615-1-git-send-email-jasowang@redhat.com> References: <1442563270-11615-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Jason Wang , ppandit@redhat.com Subject: [Qemu-devel] [PATCH 2/3] virtio: introduce virtqueue_discard() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 eb8d5ca..d24ee80 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -265,6 +265,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);