From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35010) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZEYKs-0003Tm-7z for qemu-devel@nongnu.org; Mon, 13 Jul 2015 03:39:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZEYKp-0003tz-KL for qemu-devel@nongnu.org; Mon, 13 Jul 2015 03:39:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54426) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZEYKp-0003t5-Bu for qemu-devel@nongnu.org; Mon, 13 Jul 2015 03:39:31 -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 03F71BACAA for ; Mon, 13 Jul 2015 07:39:31 +0000 (UTC) From: Thomas Huth Date: Mon, 13 Jul 2015 09:39:22 +0200 Message-Id: <1436773166-12113-2-git-send-email-thuth@redhat.com> In-Reply-To: <1436773166-12113-1-git-send-email-thuth@redhat.com> References: <1436773166-12113-1-git-send-email-thuth@redhat.com> Subject: [Qemu-devel] [PATCH v2 1/5] net/dump: Add support for receive_iov function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, Stefan Hajnoczi , Jason Wang Cc: Markus Armbruster Adding a proper receive_iov function to the net dump module. This will make it easier to support the dump feature for the -netdev option in later patches. Also make the receive functions (and the cleanup function) available to the other parts of the source code so we can later use them for dumping from net.c, too. Signed-off-by: Thomas Huth --- net/clients.h | 4 ++++ net/dump.c | 30 ++++++++++++++++++++++++------ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/net/clients.h b/net/clients.h index d47530e..403dc88 100644 --- a/net/clients.h +++ b/net/clients.h @@ -29,6 +29,10 @@ int net_init_dump(const NetClientOptions *opts, const char *name, NetClientState *peer, Error **errp); +void net_dump_cleanup(NetClientState *nc); +ssize_t net_dump_receive(NetClientState *nc, const uint8_t *buf, size_t size); +ssize_t net_dump_receive_iov(NetClientState *nc, const struct iovec *iov, + int cnt); #ifdef CONFIG_SLIRP int net_init_slirp(const NetClientOptions *opts, const char *name, diff --git a/net/dump.c b/net/dump.c index 02c8064..935918e 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) +ssize_t net_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,7 +94,16 @@ static ssize_t dump_receive(NetClientState *nc, const uint8_t *buf, size_t size) return size; } -static void dump_cleanup(NetClientState *nc) +ssize_t net_dump_receive(NetClientState *nc, const uint8_t *buf, size_t size) +{ + struct iovec iov = { + .iov_base = (void *)buf, + .iov_len = size + }; + return net_dump_receive_iov(nc, &iov, 1); +} + +void net_dump_cleanup(NetClientState *nc) { DumpState *s = DO_UPCAST(DumpState, nc, nc); @@ -96,8 +113,9 @@ static void dump_cleanup(NetClientState *nc) static NetClientInfo net_dump_info = { .type = NET_CLIENT_OPTIONS_KIND_DUMP, .size = sizeof(DumpState), - .receive = dump_receive, - .cleanup = dump_cleanup, + .receive = net_dump_receive, + .receive_iov = net_dump_receive_iov, + .cleanup = net_dump_cleanup, }; static int net_dump_init(NetClientState *peer, const char *device, -- 1.8.3.1