From nobody Wed Apr 16 11:36:24 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1551770467131862.9048360518583; Mon, 4 Mar 2019 23:21:07 -0800 (PST) Received: from localhost ([127.0.0.1]:38726 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h14Ns-0000q9-4a for importer@patchew.org; Tue, 05 Mar 2019 02:21:04 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43360) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h14Fe-0002ce-Qr for qemu-devel@nongnu.org; Tue, 05 Mar 2019 02:12:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h14Fc-0000X3-Rj for qemu-devel@nongnu.org; Tue, 05 Mar 2019 02:12:34 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50560) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h14Fc-0000Uv-Gx for qemu-devel@nongnu.org; Tue, 05 Mar 2019 02:12:32 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4B36281DE0; Tue, 5 Mar 2019 07:12:31 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-234.pek2.redhat.com [10.72.12.234]) by smtp.corp.redhat.com (Postfix) with ESMTP id 98A3318009; Tue, 5 Mar 2019 07:12:29 +0000 (UTC) From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Tue, 5 Mar 2019 15:12:10 +0800 Message-Id: <1551769940-22739-4-git-send-email-jasowang@redhat.com> In-Reply-To: <1551769940-22739-1-git-send-email-jasowang@redhat.com> References: <1551769940-22739-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 05 Mar 2019 07:12:31 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL V2 03/13] net: netmap: simplify netmap_receive() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , Vincenzo Maffione Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vincenzo Maffione Improve code reuse by implementing netmap_receive() with a call to netmap_receive_iov(). Signed-off-by: Vincenzo Maffione Signed-off-by: Jason Wang --- net/netmap.c | 50 +++++++++++--------------------------------------- 1 file changed, 11 insertions(+), 39 deletions(-) diff --git a/net/netmap.c b/net/netmap.c index 71a8122..852106a 100644 --- a/net/netmap.c +++ b/net/netmap.c @@ -154,45 +154,6 @@ static void netmap_writable(void *opaque) qemu_flush_queued_packets(&s->nc); } =20 -static ssize_t netmap_receive(NetClientState *nc, - const uint8_t *buf, size_t size) -{ - NetmapState *s =3D DO_UPCAST(NetmapState, nc, nc); - struct netmap_ring *ring =3D s->tx; - uint32_t i; - uint32_t idx; - uint8_t *dst; - - if (unlikely(!ring)) { - /* Drop. */ - return size; - } - - if (unlikely(size > ring->nr_buf_size)) { - RD(5, "[netmap_receive] drop packet of size %d > %d\n", - (int)size, ring->nr_buf_size); - return size; - } - - if (nm_ring_empty(ring)) { - /* No available slots in the netmap TX ring. */ - netmap_write_poll(s, true); - return 0; - } - - i =3D ring->cur; - idx =3D ring->slot[i].buf_idx; - dst =3D (uint8_t *)NETMAP_BUF(ring, idx); - - ring->slot[i].len =3D size; - ring->slot[i].flags =3D 0; - pkt_copy(buf, dst, size); - ring->cur =3D ring->head =3D nm_ring_next(ring, i); - ioctl(s->nmd->fd, NIOCTXSYNC, NULL); - - return size; -} - static ssize_t netmap_receive_iov(NetClientState *nc, const struct iovec *iov, int iovcnt) { @@ -259,6 +220,17 @@ static ssize_t netmap_receive_iov(NetClientState *nc, return iov_size(iov, iovcnt); } =20 +static ssize_t netmap_receive(NetClientState *nc, + const uint8_t *buf, size_t size) +{ + struct iovec iov; + + iov.iov_base =3D (void *)buf; + iov.iov_len =3D size; + + return netmap_receive_iov(nc, &iov, 1); +} + /* Complete a previous send (backend --> guest) and enable the fd_read callback. */ static void netmap_send_completed(NetClientState *nc, ssize_t len) --=20 2.5.0