From patchwork Fri Oct 2 13:45:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 525580 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 BF33D1402F0 for ; Sat, 3 Oct 2015 01:15:13 +1000 (AEST) Received: from localhost ([::1]:60599 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zi23D-0004zn-JG for incoming@patchwork.ozlabs.org; Fri, 02 Oct 2015 11:15:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53545) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zi0eA-0002Yn-9m for qemu-devel@nongnu.org; Fri, 02 Oct 2015 09:45:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zi0e7-0008V2-6S for qemu-devel@nongnu.org; Fri, 02 Oct 2015 09:45:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:63254) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zi0e7-0008U9-28 for qemu-devel@nongnu.org; Fri, 02 Oct 2015 09:45:11 -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 BD23C91E8F; Fri, 2 Oct 2015 13:45:10 +0000 (UTC) Received: from redhat.com (ovpn-116-85.ams2.redhat.com [10.36.116.85]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id t92Dj7lR011261; Fri, 2 Oct 2015 09:45:08 -0400 Date: Fri, 2 Oct 2015 16:45:06 +0300 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <1443793405-15190-3-git-send-email-mst@redhat.com> References: <1443793405-15190-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1443793405-15190-1-git-send-email-mst@redhat.com> X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Peter Maydell , Jason Wang Subject: [Qemu-devel] [PULL 02/15] 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 From: Jason Wang 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 Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/virtio.h | 2 ++ hw/virtio/virtio.c | 7 +++++++ 2 files changed, 9 insertions(+) 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); diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 6f2b96c..d0bc72e 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -267,6 +267,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) {