From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41069) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z7n2W-0007dc-8n for qemu-devel@nongnu.org; Wed, 24 Jun 2015 11:56:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z7n2V-0005bb-3q for qemu-devel@nongnu.org; Wed, 24 Jun 2015 11:56:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36401) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z7n2U-0005bX-VT for qemu-devel@nongnu.org; Wed, 24 Jun 2015 11:56:39 -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 8C1DBB890D for ; Wed, 24 Jun 2015 15:56:38 +0000 (UTC) From: Thomas Huth Date: Wed, 24 Jun 2015 17:56:19 +0200 Message-Id: <1435161381-31521-4-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 3/5] net/dump: Rework net-dump init functions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, Stefan Hajnoczi , Jason Wang Cc: Markus Armbruster Moved the creation of the dump client from net_dump_init() into net_init_dump(), renamed net_dump_init() to net_dump_state_init() and make it available for other parts of the source code, too, so we can use it for the -netdev option in a later patch. Signed-off-by: Thomas Huth --- net/clients.h | 2 ++ net/dump.c | 24 +++++++++++++----------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/net/clients.h b/net/clients.h index 5092f3d..fc76503 100644 --- a/net/clients.h +++ b/net/clients.h @@ -29,6 +29,8 @@ int net_init_dump(const NetClientOptions *opts, const char *name, NetClientState *peer, Error **errp); +int net_dump_state_init(NetClientState *nc, const char *filename, int len, + Error **errp); 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); diff --git a/net/dump.c b/net/dump.c index b7a8b30..48a8087 100644 --- a/net/dump.c +++ b/net/dump.c @@ -125,12 +125,10 @@ static NetClientInfo net_dump_info = { .cleanup = net_dump_cleanup, }; -static int net_dump_init(NetClientState *peer, const char *device, - const char *name, const char *filename, int len, - Error **errp) +int net_dump_state_init(NetClientState *nc, const char *filename, int len, + Error **errp) { struct pcap_file_hdr hdr; - NetClientState *nc; NetDumpState *s; struct tm tm; int fd; @@ -155,11 +153,6 @@ static int net_dump_init(NetClientState *peer, const char *device, return -1; } - nc = qemu_new_net_client(&net_dump_info, peer, device, name); - - snprintf(nc->info_str, sizeof(nc->info_str), - "dump to %s (len=%d)", filename, len); - s = &nc->nds; s->fd = fd; @@ -174,10 +167,11 @@ static int net_dump_init(NetClientState *peer, const char *device, int net_init_dump(const NetClientOptions *opts, const char *name, NetClientState *peer, Error **errp) { - int len; + int len, rc; const char *file; char def_file[128]; const NetdevDumpOptions *dump; + NetClientState *nc; assert(opts->kind == NET_CLIENT_OPTIONS_KIND_DUMP); dump = opts->dump; @@ -207,5 +201,13 @@ int net_init_dump(const NetClientOptions *opts, const char *name, len = 65536; } - return net_dump_init(peer, "dump", name, file, len, errp); + nc = qemu_new_net_client(&net_dump_info, peer, "dump", name); + snprintf(nc->info_str, sizeof(nc->info_str), + "dump to %s (len=%d)", file, len); + + rc = net_dump_state_init(nc, file, len, errp); + if (rc) { + qemu_del_net_client(nc); + } + return rc; } -- 1.8.3.1