From patchwork Wed Nov 25 18:49:05 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark McLoughlin X-Patchwork-Id: 39428 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 009D8B7B63 for ; Thu, 26 Nov 2009 06:19:11 +1100 (EST) Received: from localhost ([127.0.0.1]:43835 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NDNOO-0002By-6M for incoming@patchwork.ozlabs.org; Wed, 25 Nov 2009 14:19:08 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NDMyk-0007Q6-PV for qemu-devel@nongnu.org; Wed, 25 Nov 2009 13:52:38 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NDMya-0007J0-Dk for qemu-devel@nongnu.org; Wed, 25 Nov 2009 13:52:34 -0500 Received: from [199.232.76.173] (port=49009 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NDMyZ-0007IM-NM for qemu-devel@nongnu.org; Wed, 25 Nov 2009 13:52:27 -0500 Received: from mx20.gnu.org ([199.232.41.8]:32783) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NDMyZ-0000FC-1Q for qemu-devel@nongnu.org; Wed, 25 Nov 2009 13:52:27 -0500 Received: from mx1.redhat.com ([209.132.183.28]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NDMyX-0000Rh-OX for qemu-devel@nongnu.org; Wed, 25 Nov 2009 13:52:26 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nAPIqNYe031855 (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-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nAPIqN3w030219; Wed, 25 Nov 2009 13:52:23 -0500 Received: by blaa.localdomain (Postfix, from userid 500) id BCFB2B0B3; Wed, 25 Nov 2009 18:49:40 +0000 (GMT) From: Mark McLoughlin To: qemu-devel@nongnu.org Date: Wed, 25 Nov 2009 18:49:05 +0000 Message-Id: <1259174977-26212-13-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.12 X-detected-operating-system: by mx20.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: Mark McLoughlin Subject: [Qemu-devel] [PATCH 12/44] net: convert tap-win32 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/tap-win32.c | 39 +++++++++++++++++++++++---------------- 1 files changed, 23 insertions(+), 16 deletions(-) diff --git a/net/tap-win32.c b/net/tap-win32.c index ea66471..ef63782 100644 --- a/net/tap-win32.c +++ b/net/tap-win32.c @@ -630,25 +630,24 @@ static int tap_win32_open(tap_win32_overlapped_t **phandle, /********************************************/ typedef struct TAPState { - VLANClientState *vc; + VLANClientState nc; tap_win32_overlapped_t *handle; } TAPState; -static void tap_cleanup(VLANClientState *vc) +static void tap_cleanup(VLANClientState *nc) { - TAPState *s = vc->opaque; + TAPState *s = DO_UPCAST(TAPState, nc, nc); qemu_del_wait_object(s->handle->tap_semaphore, NULL, NULL); /* FIXME: need to kill thread and close file handle: tap_win32_close(s); */ - qemu_free(s); } -static ssize_t tap_receive(VLANClientState *vc, const uint8_t *buf, size_t size) +static ssize_t tap_receive(VLANClientState *nc, const uint8_t *buf, size_t size) { - TAPState *s = vc->opaque; + TAPState *s = DO_UPCAST(TAPState, nc, nc); return tap_win32_write(s->handle, buf, size); } @@ -662,33 +661,41 @@ static void tap_win32_send(void *opaque) size = tap_win32_read(s->handle, &buf, max_size); if (size > 0) { - qemu_send_packet(s->vc, buf, size); + qemu_send_packet(&s->nc, buf, size); tap_win32_free_buffer(s->handle, buf); } } +static NetClientInfo net_tap_win32_info = { + .type = NET_CLIENT_TYPE_TAP, + .size = sizeof(TAPState), + .receive = tap_receive, + .cleanup = tap_cleanup, +}; + static int tap_win32_init(VLANState *vlan, const char *model, const char *name, const char *ifname) { + VLANClientState *nc; TAPState *s; + tap_win32_overlapped_t *handle; - s = qemu_mallocz(sizeof(TAPState)); - if (!s) - return -1; - if (tap_win32_open(&s->handle, ifname) < 0) { + if (tap_win32_open(&handle, ifname) < 0) { printf("tap: Could not open '%s'\n", ifname); return -1; } - s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_TAP, - vlan, NULL, model, name, - NULL, tap_receive, - NULL, NULL, tap_cleanup, s); + nc = qemu_new_net_client(&net_tap_win32_info, vlan, NULL, model, name); - snprintf(s->vc->info_str, sizeof(s->vc->info_str), + snprintf(s->nc.info_str, sizeof(s->nc.info_str), "tap: ifname=%s", ifname); + s = DO_UPCAST(TAPState, nc, nc); + + s->handle = handle; + qemu_add_wait_object(s->handle->tap_semaphore, tap_win32_send, s); + return 0; }