From patchwork Thu Aug 27 02:33:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 511156 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 CC9621401EF for ; Thu, 27 Aug 2015 12:36:21 +1000 (AEST) Received: from localhost ([::1]:50414 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUn35-0005XA-V2 for incoming@patchwork.ozlabs.org; Wed, 26 Aug 2015 22:36:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45368) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUn0S-0001C0-JM for qemu-devel@nongnu.org; Wed, 26 Aug 2015 22:33:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZUn0R-0003ll-Ja for qemu-devel@nongnu.org; Wed, 26 Aug 2015 22:33:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43371) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUn0R-0003lh-CM for qemu-devel@nongnu.org; Wed, 26 Aug 2015 22:33:35 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 5BA5AC15CA8F; Thu, 27 Aug 2015 02:33:34 +0000 (UTC) Received: from thh440s.redhat.com (vpn1-7-173.ams2.redhat.com [10.36.7.173]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t7R2XPWB008792; Wed, 26 Aug 2015 22:33:32 -0400 From: Thomas Huth To: Stefan Hajnoczi , Jason Wang , qemu-devel@nongnu.org, yanghy@cn.fujitsu.com Date: Thu, 27 Aug 2015 04:33:22 +0200 Message-Id: <1440642804-29001-4-git-send-email-thuth@redhat.com> In-Reply-To: <1440642804-29001-1-git-send-email-thuth@redhat.com> References: <1440642804-29001-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Markus Armbruster , "Michael S. Tsirkin" Subject: [Qemu-devel] [PATCH RFC 3/5] net/dump: Separate the NetClientState from the DumpState 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 With the upcoming dumping-via-netfilter patch, the DumpState should not be related to NetClientState anymore, so move the related information to a new struct called DumpNetClient. Signed-off-by: Thomas Huth --- net/dump.c | 73 +++++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 25 deletions(-) diff --git a/net/dump.c b/net/dump.c index 27083d4..8317102 100644 --- a/net/dump.c +++ b/net/dump.c @@ -31,7 +31,6 @@ #include "hub.h" typedef struct DumpState { - NetClientState nc; int64_t start_ts; int fd; int pcap_caplen; @@ -58,10 +57,8 @@ struct pcap_sf_pkthdr { uint32_t len; }; -static ssize_t dump_receive_iov(NetClientState *nc, const struct iovec *iov, - int cnt) +static ssize_t dump_receive_iov(DumpState *s, const struct iovec *iov, int cnt) { - DumpState *s = DO_UPCAST(DumpState, nc, nc); struct pcap_sf_pkthdr hdr; int64_t ts; int caplen; @@ -94,30 +91,12 @@ static ssize_t dump_receive_iov(NetClientState *nc, const struct iovec *iov, return size; } -static ssize_t dump_receive(NetClientState *nc, const uint8_t *buf, size_t size) +static void dump_cleanup(DumpState *s) { - 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); - close(s->fd); + s->fd = -1; } -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, -}; - static int net_dump_state_init(DumpState *s, const char *filename, int len, Error **errp) { @@ -154,6 +133,48 @@ static int net_dump_state_init(DumpState *s, const char *filename, return 0; } +/* Dumping via VLAN netclient */ + +typedef struct DumpNetClient { + NetClientState nc; + DumpState ds; +} DumpNetClient; + +static ssize_t dumpclient_receive(NetClientState *nc, const uint8_t *buf, + size_t size) +{ + DumpNetClient *dc = DO_UPCAST(DumpNetClient, nc, nc); + struct iovec iov = { + .iov_base = (void *)buf, + .iov_len = size + }; + + return dump_receive_iov(&dc->ds, &iov, 1); +} + +static ssize_t dumpclient_receive_iov(NetClientState *nc, + const struct iovec *iov, int cnt) +{ + DumpNetClient *dc = DO_UPCAST(DumpNetClient, nc, nc); + + return dump_receive_iov(&dc->ds, iov, cnt); +} + +static void dumpclient_cleanup(NetClientState *nc) +{ + DumpNetClient *dc = DO_UPCAST(DumpNetClient, nc, nc); + + dump_cleanup(&dc->ds); +} + +static NetClientInfo net_dump_info = { + .type = NET_CLIENT_OPTIONS_KIND_DUMP, + .size = sizeof(DumpNetClient), + .receive = dumpclient_receive, + .receive_iov = dumpclient_receive_iov, + .cleanup = dumpclient_cleanup, +}; + int net_init_dump(const NetClientOptions *opts, const char *name, NetClientState *peer, Error **errp) { @@ -162,6 +183,7 @@ int net_init_dump(const NetClientOptions *opts, const char *name, char def_file[128]; const NetdevDumpOptions *dump; NetClientState *nc; + DumpNetClient *dnc; assert(opts->kind == NET_CLIENT_OPTIONS_KIND_DUMP); dump = opts->dump; @@ -195,7 +217,8 @@ int net_init_dump(const NetClientOptions *opts, const char *name, snprintf(nc->info_str, sizeof(nc->info_str), "dump to %s (len=%d)", file, len); - rc = net_dump_state_init(DO_UPCAST(DumpState, nc, nc), file, len, errp); + dnc = DO_UPCAST(DumpNetClient, nc, nc); + rc = net_dump_state_init(&dnc->ds, file, len, errp); if (rc) { qemu_del_net_client(nc); }