From mboxrd@z Thu Jan 1 00:00:00 1970 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 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 From: zwu.kernel@gmail.com Date: Mon, 26 Mar 2012 13:40:23 +0800 Message-Id: <1332740423-8426-12-git-send-email-zwu.kernel@gmail.com> In-Reply-To: <1332740423-8426-1-git-send-email-zwu.kernel@gmail.com> References: <1332740423-8426-1-git-send-email-zwu.kernel@gmail.com> Subject: [Qemu-devel] [RFC 9/9] net: qomify -netdev tap & -netdev bridge List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: zwu.kernel@gmail.com, pbonzini@redhat.com, Zhi Yong Wu , stefanha@linux.vnet.ibm.com 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 */ -- 1.7.6