From patchwork Thu Dec 6 16:59:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincenzo Maffione X-Patchwork-Id: 10716425 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 485A915A6 for ; Thu, 6 Dec 2018 17:03:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 344A32F195 for ; Thu, 6 Dec 2018 17:03:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 27E102F197; Thu, 6 Dec 2018 17:03:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 89C9A2F195 for ; Thu, 6 Dec 2018 17:03:09 +0000 (UTC) Received: from localhost ([::1]:42092 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gUx3K-0004sI-WE for patchwork-qemu-devel@patchwork.kernel.org; Thu, 06 Dec 2018 12:03:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52261) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gUx1e-0003Zn-CB for qemu-devel@nongnu.org; Thu, 06 Dec 2018 12:01:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gUx1Z-0006of-18 for qemu-devel@nongnu.org; Thu, 06 Dec 2018 12:01:21 -0500 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:40616) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gUx1U-0006k0-Ie for qemu-devel@nongnu.org; Thu, 06 Dec 2018 12:01:15 -0500 Received: by mail-wr1-x444.google.com with SMTP id p4so1203196wrt.7 for ; Thu, 06 Dec 2018 09:01:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YZaWVhK9aZlYPe4Lk3s5yHZyVQRqkzdyzjMy8grX3mw=; b=ij6pIFEyy9FN2doDJcAPAcqAhO13jVm5z/nv59L6hoFBEJnZ4sPWsmxQ6QhxxEaPnH 6la/xate+4iCYXt511EJ6m3hNCkLGtLFL5LDYCqC1P5OSSn1BK//xRpVc2hqBS7lOWxM qZY+5zM+ZyKgzcGKfU8kkseCGFZT7b+oULkSXrCOJ9/S7UOa2INVG13EA0A+GkzeIagB TwqbbHGIlgV6+kdLfF18DjM7+7VOrH1d71AHAZbL4iop8ZI4/QI36buyFR5btIgnRBgY gRjqlNnYG88oOYLjUHeI/Gop6D14vtaGjxbdQyRDLLyGjgy0fJ0/bNzZLnhcF/Z19XxD nMog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YZaWVhK9aZlYPe4Lk3s5yHZyVQRqkzdyzjMy8grX3mw=; b=qwLrk+X14y+EGSv5f5/bIM1he3btJ20imbNij2gcVpqIiBBRKdDhYdnEYua4jXgng9 ck22jOh/e1NkmoiBtsFGuAORLUtB/r3vthlzBhhBA100jhOfiZeQ0fT9lfI+zxQKtWW1 xFR6Mp7Icc5VV6NI0OBB6MsGp3jS8v8dul5lKw96bHxYipF1qaS2E9zh/woEaIF35uga 859VXQTfkCOvNkDflUW2nj+KXOSMnBcw34ea0gSMHaAh+foBc2yv9jr/l0Fwnpjh4BK3 NaB78twPg+G/gMZ2AgItSaNy8kS4LfM4oW3pEqZFT3G8C+PQGGftEyZW2x3gEBRh0f7S jtOw== X-Gm-Message-State: AA+aEWZyAo635eHcTd/s6SkQqr7Zs+ubOBJxao+DN8Th7akCJ5oIwa6J ZqOX6SNKsE8k9FofZ2FY4zlVVN9vZ6E= X-Google-Smtp-Source: AFSGD/VcsSE8bq8nYs6qDFyQVCDuK/n1ASfSPmEYa9M4EIKv2HrYZBUWbSMpiI6GAQHrl0WLkhXqZg== X-Received: by 2002:a5d:4c8a:: with SMTP id z10mr25316378wrs.75.1544115669256; Thu, 06 Dec 2018 09:01:09 -0800 (PST) Received: from localhost.localdomain (prova.iet.unipi.it. [131.114.58.86]) by smtp.gmail.com with ESMTPSA id d4sm467556wrp.89.2018.12.06.09.01.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Dec 2018 09:01:08 -0800 (PST) From: Vincenzo Maffione To: qemu-devel@nongnu.org Date: Thu, 6 Dec 2018 17:59:06 +0100 Message-Id: <20181206165907.23465-3-v.maffione@gmail.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181206165907.23465-1-v.maffione@gmail.com> References: <20181206165907.23465-1-v.maffione@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 Subject: [Qemu-devel] [PATCH v1 2/3] 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: g.lettieri@iet.unipi.it, jasowang@redhat.com, Vincenzo Maffione Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Improve code reuse by implementing netmap_receive() with a call to netmap_receive_iov(). Signed-off-by: Vincenzo Maffione --- net/netmap.c | 50 +++++++++++--------------------------------------- 1 file changed, 11 insertions(+), 39 deletions(-) diff --git a/net/netmap.c b/net/netmap.c index 71a8122bdd..852106af29 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); } -static ssize_t netmap_receive(NetClientState *nc, - const uint8_t *buf, size_t size) -{ - NetmapState *s = DO_UPCAST(NetmapState, nc, nc); - struct netmap_ring *ring = 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 = ring->cur; - idx = ring->slot[i].buf_idx; - dst = (uint8_t *)NETMAP_BUF(ring, idx); - - ring->slot[i].len = size; - ring->slot[i].flags = 0; - pkt_copy(buf, dst, size); - ring->cur = ring->head = 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); } +static ssize_t netmap_receive(NetClientState *nc, + const uint8_t *buf, size_t size) +{ + struct iovec iov; + + iov.iov_base = (void *)buf; + iov.iov_len = 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)