From patchwork Tue Oct 27 06:08:36 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 536451 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 BB7A9141367 for ; Tue, 27 Oct 2015 17:11:22 +1100 (AEDT) Received: from localhost ([::1]:57687 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZqxTc-0006NO-Tz for incoming@patchwork.ozlabs.org; Tue, 27 Oct 2015 02:11:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59061) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZqxRY-0002Rx-DY for qemu-devel@nongnu.org; Tue, 27 Oct 2015 02:09:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZqxRX-0000bX-F9 for qemu-devel@nongnu.org; Tue, 27 Oct 2015 02:09:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57542) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZqxRX-0000bT-AK for qemu-devel@nongnu.org; Tue, 27 Oct 2015 02:09:11 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id E03FBC0B5921; Tue, 27 Oct 2015 06:09:10 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (vpn1-5-148.pek2.redhat.com [10.72.5.148]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t9R68v3b003000; Tue, 27 Oct 2015 02:09:08 -0400 From: Jason Wang To: peter.maydell@linaro.org, qemu-devel@nongnu.org Date: Tue, 27 Oct 2015 14:08:36 +0800 Message-Id: <1445926124-30681-3-git-send-email-jasowang@redhat.com> In-Reply-To: <1445926124-30681-1-git-send-email-jasowang@redhat.com> References: <1445926124-30681-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Thomas Huth , Jason Wang Subject: [Qemu-devel] [PULL 02/10] net/dump: Add support for receive_iov function 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: Thomas Huth Adding a proper receive_iov function to the net dump module. This will make it easier to support the dump filter feature for the -netdev option in later patches. Reviewed-by: Yang Hongyang Signed-off-by: Thomas Huth Signed-off-by: Jason Wang --- net/dump.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/net/dump.c b/net/dump.c index 08259af..aa0d45d 100644 --- a/net/dump.c +++ b/net/dump.c @@ -25,6 +25,7 @@ #include "clients.h" #include "qemu-common.h" #include "qemu/error-report.h" +#include "qemu/iov.h" #include "qemu/log.h" #include "qemu/timer.h" #include "hub.h" @@ -57,12 +58,15 @@ struct pcap_sf_pkthdr { uint32_t len; }; -static ssize_t dump_receive(NetClientState *nc, const uint8_t *buf, size_t size) +static ssize_t dump_receive_iov(NetClientState *nc, const struct iovec *iov, + int cnt) { DumpState *s = DO_UPCAST(DumpState, nc, nc); struct pcap_sf_pkthdr hdr; int64_t ts; int caplen; + size_t size = iov_size(iov, cnt); + struct iovec dumpiov[cnt + 1]; /* Early return in case of previous error. */ if (s->fd < 0) { @@ -76,8 +80,12 @@ static ssize_t dump_receive(NetClientState *nc, const uint8_t *buf, size_t size) hdr.ts.tv_usec = ts % 1000000; hdr.caplen = caplen; hdr.len = size; - if (write(s->fd, &hdr, sizeof(hdr)) != sizeof(hdr) || - write(s->fd, buf, caplen) != caplen) { + + dumpiov[0].iov_base = &hdr; + dumpiov[0].iov_len = sizeof(hdr); + cnt = iov_copy(&dumpiov[1], cnt, iov, cnt, 0, caplen); + + if (writev(s->fd, dumpiov, cnt + 1) != sizeof(hdr) + caplen) { qemu_log("-net dump write error - stop dump\n"); close(s->fd); s->fd = -1; @@ -86,6 +94,15 @@ static ssize_t dump_receive(NetClientState *nc, const uint8_t *buf, size_t size) return size; } +static ssize_t dump_receive(NetClientState *nc, const uint8_t *buf, size_t size) +{ + struct iovec iov = { + .iov_base = (void *)buf, + .iov_len = size + }; + return dump_receive_iov(nc, &iov, 1); +} + static void dump_cleanup(NetClientState *nc) { DumpState *s = DO_UPCAST(DumpState, nc, nc); @@ -97,6 +114,7 @@ static NetClientInfo net_dump_info = { .type = NET_CLIENT_OPTIONS_KIND_DUMP, .size = sizeof(DumpState), .receive = dump_receive, + .receive_iov = dump_receive_iov, .cleanup = dump_cleanup, };