From patchwork Tue Oct 27 06:08:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 536455 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 C63A1141365 for ; Tue, 27 Oct 2015 17:13:00 +1100 (AEDT) Received: from localhost ([::1]:57703 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZqxVC-0001E5-Rz for incoming@patchwork.ozlabs.org; Tue, 27 Oct 2015 02:12:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59073) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZqxRc-0002b0-Vu for qemu-devel@nongnu.org; Tue, 27 Oct 2015 02:09:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZqxRc-0000bw-2Q for qemu-devel@nongnu.org; Tue, 27 Oct 2015 02:09:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50556) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZqxRb-0000bs-Ty for qemu-devel@nongnu.org; Tue, 27 Oct 2015 02:09:16 -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 835ED461D6; Tue, 27 Oct 2015 06:09:15 +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 t9R68v3c003000; Tue, 27 Oct 2015 02:09:12 -0400 From: Jason Wang To: peter.maydell@linaro.org, qemu-devel@nongnu.org Date: Tue, 27 Oct 2015 14:08:37 +0800 Message-Id: <1445926124-30681-4-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 03/10] net/dump: Rework net-dump init functions 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 Move the creation of the dump client from net_dump_init() into net_init_dump(), so we can later use the former function for dump via netfilter, too. Also rename net_dump_init() to net_dump_state_init() to make it easier distinguishable from net_init_dump(). Reviewed-by: Yang Hongyang Signed-off-by: Thomas Huth Signed-off-by: Jason Wang --- net/dump.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/net/dump.c b/net/dump.c index aa0d45d..e6f6be0 100644 --- a/net/dump.c +++ b/net/dump.c @@ -118,13 +118,10 @@ static NetClientInfo net_dump_info = { .cleanup = dump_cleanup, }; -static int net_dump_init(NetClientState *peer, const char *device, - const char *name, const char *filename, int len, - Error **errp) +static int net_dump_state_init(DumpState *s, const char *filename, + int len, Error **errp) { struct pcap_file_hdr hdr; - NetClientState *nc; - DumpState *s; struct tm tm; int fd; @@ -148,13 +145,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 = DO_UPCAST(DumpState, nc, nc); - s->fd = fd; s->pcap_caplen = len; @@ -167,10 +157,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; @@ -200,5 +191,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(DO_UPCAST(DumpState, nc, nc), file, len, errp); + if (rc) { + qemu_del_net_client(nc); + } + return rc; }