From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41046) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z7n2R-0007Vv-SN for qemu-devel@nongnu.org; Wed, 24 Jun 2015 11:56:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z7n2Q-0005Zj-Rn for qemu-devel@nongnu.org; Wed, 24 Jun 2015 11:56:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36368) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z7n2Q-0005Zf-NV for qemu-devel@nongnu.org; Wed, 24 Jun 2015 11:56:34 -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 4EAE1B8915 for ; Wed, 24 Jun 2015 15:56:34 +0000 (UTC) From: Thomas Huth Date: Wed, 24 Jun 2015 17:56:18 +0200 Message-Id: <1435161381-31521-3-git-send-email-thuth@redhat.com> In-Reply-To: <1435161381-31521-1-git-send-email-thuth@redhat.com> References: <1435161381-31521-1-git-send-email-thuth@redhat.com> Subject: [Qemu-devel] [PATCH 2/5] net/dump: Move DumpState into NetClientState List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, Stefan Hajnoczi , Jason Wang Cc: Markus Armbruster We want to provide (almost) every netdev device with the ability to dump network traffic, so let's embed the DumpState into the NetClientState structure. Signed-off-by: Thomas Huth --- include/net/net.h | 7 +++++++ net/dump.c | 17 +++++------------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/net/net.h b/include/net/net.h index 6a6cbef..b265047 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -58,6 +58,12 @@ typedef void (SetVnetHdrLen)(NetClientState *, int); typedef int (SetVnetLE)(NetClientState *, bool); typedef int (SetVnetBE)(NetClientState *, bool); +typedef struct NetDumpState { + int64_t start_ts; + int fd; + int pcap_caplen; +} NetDumpState; + typedef struct NetClientInfo { NetClientOptionsKind type; size_t size; @@ -92,6 +98,7 @@ struct NetClientState { NetClientDestructor *destructor; unsigned int queue_index; unsigned rxfilter_notify_enabled:1; + NetDumpState nds; }; typedef struct NICState { diff --git a/net/dump.c b/net/dump.c index 383718a..b7a8b30 100644 --- a/net/dump.c +++ b/net/dump.c @@ -29,13 +29,6 @@ #include "qemu/timer.h" #include "hub.h" -typedef struct DumpState { - NetClientState nc; - int64_t start_ts; - int fd; - int pcap_caplen; -} DumpState; - #define PCAP_MAGIC 0xa1b2c3d4 struct pcap_file_hdr { @@ -60,7 +53,7 @@ struct pcap_sf_pkthdr { ssize_t net_dump_receive_iov(NetClientState *nc, const struct iovec *iov, int cnt) { - DumpState *s = DO_UPCAST(DumpState, nc, nc); + NetDumpState *s = &nc->nds; struct pcap_sf_pkthdr hdr; int64_t ts; int caplen, i; @@ -119,14 +112,14 @@ ssize_t net_dump_receive(NetClientState *nc, const uint8_t *buf, size_t size) static void net_dump_cleanup(NetClientState *nc) { - DumpState *s = DO_UPCAST(DumpState, nc, nc); + NetDumpState *s = &nc->nds; close(s->fd); } static NetClientInfo net_dump_info = { .type = NET_CLIENT_OPTIONS_KIND_DUMP, - .size = sizeof(DumpState), + .size = sizeof(NetClientState), .receive = net_dump_receive, .receive_iov = net_dump_receive_iov, .cleanup = net_dump_cleanup, @@ -138,7 +131,7 @@ static int net_dump_init(NetClientState *peer, const char *device, { struct pcap_file_hdr hdr; NetClientState *nc; - DumpState *s; + NetDumpState *s; struct tm tm; int fd; @@ -167,7 +160,7 @@ static int net_dump_init(NetClientState *peer, const char *device, snprintf(nc->info_str, sizeof(nc->info_str), "dump to %s (len=%d)", filename, len); - s = DO_UPCAST(DumpState, nc, nc); + s = &nc->nds; s->fd = fd; s->pcap_caplen = len; -- 1.8.3.1