From patchwork Wed Nov 25 18:49:07 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark McLoughlin X-Patchwork-Id: 39436 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 54BC4B7BBA for ; Thu, 26 Nov 2009 06:36:38 +1100 (EST) Received: from localhost ([127.0.0.1]:53773 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NDNfH-0004MC-9W for incoming@patchwork.ozlabs.org; Wed, 25 Nov 2009 14:36:35 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NDMym-0007Qc-TD for qemu-devel@nongnu.org; Wed, 25 Nov 2009 13:52:40 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NDMyY-0007HT-MP for qemu-devel@nongnu.org; Wed, 25 Nov 2009 13:52:34 -0500 Received: from [199.232.76.173] (port=48999 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NDMyY-0007H6-4q for qemu-devel@nongnu.org; Wed, 25 Nov 2009 13:52:26 -0500 Received: from mx1.redhat.com ([209.132.183.28]:62865) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NDMyX-0000EH-BU for qemu-devel@nongnu.org; Wed, 25 Nov 2009 13:52:25 -0500 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nAPIqO6c016116 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 25 Nov 2009 13:52:24 -0500 Received: from blaa.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nAPIqNfR026876; Wed, 25 Nov 2009 13:52:23 -0500 Received: by blaa.localdomain (Postfix, from userid 500) id EA3A7B0B5; Wed, 25 Nov 2009 18:49:40 +0000 (GMT) From: Mark McLoughlin To: qemu-devel@nongnu.org Date: Wed, 25 Nov 2009 18:49:07 +0000 Message-Id: <1259174977-26212-15-git-send-email-markmc@redhat.com> In-Reply-To: <1259174977-26212-1-git-send-email-markmc@redhat.com> References: <1259174977-26212-1-git-send-email-markmc@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Mark McLoughlin Subject: [Qemu-devel] [PATCH 14/44] net: convert vde to NetClientInfo X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Mark McLoughlin --- net/vde.c | 45 ++++++++++++++++++++++++++++----------------- 1 files changed, 28 insertions(+), 17 deletions(-) diff --git a/net/vde.c b/net/vde.c index 4d09967..42b4633 100644 --- a/net/vde.c +++ b/net/vde.c @@ -34,7 +34,7 @@ #include "sysemu.h" typedef struct VDEState { - VLANClientState *vc; + VLANClientState nc; VDECONN *vde; } VDEState; @@ -46,13 +46,13 @@ static void vde_to_qemu(void *opaque) size = vde_recv(s->vde, (char *)buf, sizeof(buf), 0); if (size > 0) { - qemu_send_packet(s->vc, buf, size); + qemu_send_packet(&s->nc, buf, size); } } -static ssize_t vde_receive(VLANClientState *vc, const uint8_t *buf, size_t size) +static ssize_t vde_receive(VLANClientState *nc, const uint8_t *buf, size_t size) { - VDEState *s = vc->opaque; + VDEState *s = DO_UPCAST(VDEState, nc, nc); ssize_t ret; do { @@ -62,19 +62,27 @@ static ssize_t vde_receive(VLANClientState *vc, const uint8_t *buf, size_t size) return ret; } -static void vde_cleanup(VLANClientState *vc) +static void vde_cleanup(VLANClientState *nc) { - VDEState *s = vc->opaque; + VDEState *s = DO_UPCAST(VDEState, nc, nc); qemu_set_fd_handler(vde_datafd(s->vde), NULL, NULL, NULL); vde_close(s->vde); - qemu_free(s); } +static NetClientInfo net_vde_info = { + .type = NET_CLIENT_TYPE_VDE, + .size = sizeof(VDEState), + .receive = vde_receive, + .cleanup = vde_cleanup, +}; + static int net_vde_init(VLANState *vlan, const char *model, const char *name, const char *sock, int port, const char *group, int mode) { + VLANClientState *nc; VDEState *s; + VDECONN *vde; char *init_group = (char *)group; char *init_sock = (char *)sock; @@ -84,19 +92,22 @@ static int net_vde_init(VLANState *vlan, const char *model, .mode = mode, }; - s = qemu_mallocz(sizeof(VDEState)); - s->vde = vde_open(init_sock, (char *)"QEMU", &args); - if (!s->vde){ - free(s); + vde = vde_open(init_sock, (char *)"QEMU", &args); + if (!vde){ return -1; } - s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_VDE, - vlan, NULL, model, name, NULL, - vde_receive, NULL, NULL, - vde_cleanup, s); + + nc = qemu_new_net_client(&net_vde_info, vlan, NULL, model, name); + + snprintf(nc->info_str, sizeof(nc->info_str), "sock=%s,fd=%d", + sock, vde_datafd(vde)); + + s = DO_UPCAST(VDEState, nc, nc); + + s->vde = vde; + qemu_set_fd_handler(vde_datafd(s->vde), vde_to_qemu, NULL, s); - snprintf(s->vc->info_str, sizeof(s->vc->info_str), "sock=%s,fd=%d", - sock, vde_datafd(s->vde)); + return 0; }