From patchwork Mon Mar 26 05:40:23 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhiyong Wu X-Patchwork-Id: 148645 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 733CBB6F98 for ; Mon, 26 Mar 2012 17:26:22 +1100 (EST) Received: from localhost ([::1]:39364 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SC3Nk-00035A-9i for incoming@patchwork.ozlabs.org; Mon, 26 Mar 2012 02:26:20 -0400 Received: from eggs.gnu.org ([208.118.235.92]:53540) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SC2gn-0003BG-IX for qemu-devel@nongnu.org; Mon, 26 Mar 2012 01:41:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SC2gl-0001cq-K5 for qemu-devel@nongnu.org; Mon, 26 Mar 2012 01:41:57 -0400 Received: from e8.ny.us.ibm.com ([32.97.182.138]:51220) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SC2gl-0001cg-FU for qemu-devel@nongnu.org; Mon, 26 Mar 2012 01:41:55 -0400 Received: from /spool/local by e8.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 26 Mar 2012 01:41:53 -0400 Received: from d01dlp01.pok.ibm.com (9.56.224.56) by e8.ny.us.ibm.com (192.168.1.108) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 26 Mar 2012 01:41:26 -0400 Received: from d01relay06.pok.ibm.com (d01relay06.pok.ibm.com [9.56.227.116]) by d01dlp01.pok.ibm.com (Postfix) with ESMTP id 6CFEB38C803A for ; Mon, 26 Mar 2012 01:41:25 -0400 (EDT) Received: from d01av04.pok.ibm.com (d01av04.pok.ibm.com [9.56.224.64]) by d01relay06.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q2Q5fPWO3522628 for ; Mon, 26 Mar 2012 01:41:25 -0400 Received: from d01av04.pok.ibm.com (loopback [127.0.0.1]) by d01av04.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q2Q5fNxX002532 for ; Mon, 26 Mar 2012 01:41:24 -0400 Received: from us.ibm.com (f15.cn.ibm.com [9.115.118.120] (may be forged)) by d01av04.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with SMTP id q2Q5fJ4t002431; Mon, 26 Mar 2012 01:41:21 -0400 Received: by us.ibm.com (sSMTP sendmail emulation); Mon, 26 Mar 2012 13:41:18 +0800 From: zwu.kernel@gmail.com To: qemu-devel@nongnu.org Date: Mon, 26 Mar 2012 13:40:23 +0800 Message-Id: <1332740423-8426-12-git-send-email-zwu.kernel@gmail.com> X-Mailer: git-send-email 1.7.6 In-Reply-To: <1332740423-8426-1-git-send-email-zwu.kernel@gmail.com> References: <1332740423-8426-1-git-send-email-zwu.kernel@gmail.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12032605-9360-0000-0000-000004D9DFCA X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 32.97.182.138 Cc: zwu.kernel@gmail.com, pbonzini@redhat.com, Zhi Yong Wu , stefanha@linux.vnet.ibm.com Subject: [Qemu-devel] [RFC 9/9] net: qomify -netdev tap & -netdev bridge 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: Zhi Yong Wu Signed-off-by: Zhi Yong Wu --- net/tap.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- net/tap.h | 8 +++--- 2 files changed, 64 insertions(+), 8 deletions(-) diff --git a/net/tap.c b/net/tap.c index 65f45b8..81d022b 100644 --- a/net/tap.c +++ b/net/tap.c @@ -512,12 +512,16 @@ static int net_bridge_run_helper(const char *helper, const char *bridge) return -1; } -int net_init_bridge(QemuOpts *opts, Monitor *mon, const char *name, - NetClientState *peer) +int net_init_bridge(NETDevice *net_dev) { TAPState *s; int fd, vnet_hdr; + QemuOpts *opts = net_dev->opts; + //Monitor *mon = net_dev->mon; + char *name = g_strdup(net_dev->name); + NetClientState *peer = net_dev->peer; + if (!qemu_opt_get(opts, "br")) { qemu_opt_set(opts, "br", DEFAULT_BRIDGE_INTERFACE); } @@ -583,13 +587,17 @@ static int net_tap_init(QemuOpts *opts, int *vnet_hdr) return fd; } -int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, - NetClientState *peer) +int net_init_tap(NETDevice *net_dev) { TAPState *s; int fd, vnet_hdr = 0; const char *model; + QemuOpts *opts = net_dev->opts; + Monitor *mon = net_dev->mon; + char *name = g_strdup(net_dev->name); + NetClientState *peer = net_dev->peer; + if (qemu_opt_get(opts, "fd")) { if (qemu_opt_get(opts, "ifname") || qemu_opt_get(opts, "script") || @@ -715,3 +723,51 @@ VHostNetState *tap_get_vhost_net(NetClientState *nc) assert(nc->info->type == NET_CLIENT_TYPE_TAP); return s->vhost_net; } + +static hostdevProperty net_tap_properties[] = { + DEFINE_HOSTDEV_PROP_END_OF_LIST(), +}; + +static void net_tap_class_init(ObjectClass *klass, void *data) +{ + NETDeviceClass *k = NETDEV_CLASS(klass); + HOSTDeviceClass *dc = HOSTDEV_CLASS(klass); + + k->init = net_init_tap; + dc->props = net_tap_properties; +} + +static TypeInfo net_tap_type = { + .name = "tap", + .parent = TYPE_NETDEV, + .instance_size = sizeof(NetClientState), + .class_init = net_tap_class_init, +}; + +static hostdevProperty net_bridge_properties[] = { + DEFINE_HOSTDEV_PROP_END_OF_LIST(), +}; + +static void net_bridge_class_init(ObjectClass *klass, void *data) +{ + NETDeviceClass *k = NETDEV_CLASS(klass); + HOSTDeviceClass *dc = HOSTDEV_CLASS(klass); + + k->init = net_init_bridge; + dc->props = net_bridge_properties; +} + +static TypeInfo net_bridge_type = { + .name = "bridge", + .parent = TYPE_NETDEV, + .instance_size = sizeof(NetClientState), + .class_init = net_bridge_class_init, +}; + +static void net_tap_register_types(void) +{ + type_register_static(&net_tap_type); + type_register_static(&net_bridge_type); +} + +type_init(net_tap_register_types) diff --git a/net/tap.h b/net/tap.h index 0e35e81..5344d24 100644 --- a/net/tap.h +++ b/net/tap.h @@ -28,12 +28,13 @@ #include "qemu-common.h" #include "qemu-option.h" +#include "qemu/hostdev.h" +#include "net.h" #define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup" #define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown" -int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, - NetClientState *peer); +int net_init_tap(NETDevice *net_dev); int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required); @@ -58,7 +59,6 @@ int tap_get_fd(NetClientState *nc); struct vhost_net; struct vhost_net *tap_get_vhost_net(NetClientState *nc); -int net_init_bridge(QemuOpts *opts, Monitor *mon, const char *name, - NetClientState *peer); +int net_init_bridge(NETDevice *net_dev); #endif /* QEMU_NET_TAP_H */