From: zwu.kernel@gmail.com
To: qemu-devel@nongnu.org
Cc: zwu.kernel@gmail.com, pbonzini@redhat.com,
Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>,
stefanha@linux.vnet.ibm.com
Subject: [Qemu-devel] [PATCH] net: qomify -netdev
Date: Mon, 26 Mar 2012 13:40:14 +0800 [thread overview]
Message-ID: <1332740423-8426-3-git-send-email-zwu.kernel@gmail.com> (raw)
In-Reply-To: <1332740423-8426-1-git-send-email-zwu.kernel@gmail.com>
From: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
---
net.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
net.h | 2 ++
net/slirp.c | 33 +++++++++++++++++++++++++++++++++
net/slirp.h | 1 +
net/socket.c | 33 +++++++++++++++++++++++++++++----
net/socket.h | 7 +++++--
net/tap.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
net/tap.h | 1 +
qom/Makefile | 2 +-
vl.c | 12 ++++++------
10 files changed, 177 insertions(+), 14 deletions(-)
diff --git a/net.c b/net.c
index dd67d16..ee8737c 100644
--- a/net.c
+++ b/net.c
@@ -972,6 +972,58 @@ int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev)
return -1;
}
+static int net_client_netdev_init(Monitor *mon, QemuOpts *opts, int is_netdev)
+{
+ const char *name;
+ const char *type;
+
+ type = qemu_opt_get(opts, "type");
+ if (!type) {
+ qerror_report(QERR_MISSING_PARAMETER, "type");
+ return -1;
+ }
+
+ if (is_netdev) {
+ if (strcmp(type, "tap") != 0 &&
+#ifdef CONFIG_NET_BRIDGE
+ strcmp(type, "bridge") != 0 &&
+#endif
+#ifdef CONFIG_SLIRP
+ strcmp(type, "user") != 0 &&
+#endif
+#ifdef CONFIG_VDE
+ strcmp(type, "vde") != 0 &&
+#endif
+ strcmp(type, "socket") != 0) {
+ qerror_report(QERR_INVALID_PARAMETER_VALUE, "type",
+ "a netdev backend type");
+ return -1;
+ }
+
+ if (qemu_opt_get(opts, "vlan")) {
+ qerror_report(QERR_INVALID_PARAMETER, "vlan");
+ return -1;
+ }
+ if (qemu_opt_get(opts, "name")) {
+ qerror_report(QERR_INVALID_PARAMETER, "name");
+ return -1;
+ }
+ if (!qemu_opts_id(opts)) {
+ qerror_report(QERR_MISSING_PARAMETER, "id");
+ return -1;
+ }
+ }
+
+ name = qemu_opts_id(opts);
+ if (!name) {
+ name = qemu_opt_get(opts, "name");
+ }
+
+ hostdev_device_add(mon, opts, (char *)name, NULL);
+
+ return 0;
+}
+
static int net_host_check_device(const char *device)
{
int i;
@@ -1188,7 +1240,7 @@ static int net_init_client(QemuOpts *opts, void *dummy)
static int net_init_netdev(QemuOpts *opts, void *dummy)
{
- return net_client_init(NULL, opts, 1);
+ return net_client_netdev_init(NULL, opts, 1);
}
int net_init_clients(void)
diff --git a/net.h b/net.h
index 60837ab..0926a42 100644
--- a/net.h
+++ b/net.h
@@ -7,6 +7,7 @@
#include "qemu-option.h"
#include "net/queue.h"
#include "vmstate.h"
+#include "qemu/hostdev.h"
struct MACAddr {
uint8_t a[6];
@@ -61,6 +62,7 @@ typedef struct NetClientInfo {
} NetClientInfo;
struct NetClientState {
+ HOSTDevice host_dev;
NetClientInfo *info;
int link_down;
QTAILQ_ENTRY(NetClientState) next;
diff --git a/net/slirp.c b/net/slirp.c
index d3e56fc..a30b4f0 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -777,3 +777,36 @@ int net_slirp_parse_legacy(QemuOptsList *opts_list, const char *optarg, int *ret
return 1;
}
+static hostdevProperty net_user_properties[] = {
+ //DEFINE_PROP_STRING("type", NetClientState, info->type),
+ DEFINE_HOSTDEV_PROP_INT32("link_down", NetClientState,link_down, 0),
+ DEFINE_HOSTDEV_PROP_PEER("peer", NetClientState, peer),
+ //DEFINE_PROP_STRING("model", NetClientState, model),
+ DEFINE_HOSTDEV_PROP_STRING("name", NetClientState, name),
+ //DEFINE_PROP_BIT("receive_disabled", NetClientState, receive_disabled, 0, true),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
+static void net_user_class_init(ObjectClass *klass, void *data)
+{
+ HOSTDeviceClass *k = HOSTDEV_CLASS(klass);
+
+ k->init = net_init_slirp;
+ k->props = net_user_properties;
+}
+
+static TypeInfo net_user_type = {
+ .name = "user",
+ .parent = TYPE_HOSTDEV,
+ .instance_size = sizeof(NetClientState),
+ .class_init = net_user_class_init,
+};
+
+static void net_user_register_types(void)
+{
+#ifdef CONFIG_SLIRP
+ type_register_static(&net_user_type);
+#endif
+}
+
+type_init(net_user_register_types)
diff --git a/net/slirp.h b/net/slirp.h
index e6000af..c6f5079 100644
--- a/net/slirp.h
+++ b/net/slirp.h
@@ -27,6 +27,7 @@
#include "qemu-common.h"
#include "qdict.h"
#include "qemu-option.h"
+#include "qemu/hostdev.h"
#ifdef CONFIG_SLIRP
diff --git a/net/socket.c b/net/socket.c
index 55d9820..778a5a3 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -31,6 +31,7 @@
#include "qemu-error.h"
#include "qemu-option.h"
#include "qemu_socket.h"
+#include "qemu/hostdev.h"
typedef struct NetSocketState {
NetClientState nc;
@@ -587,10 +588,8 @@ static int net_socket_udp_init(NetClientState *peer,
return 0;
}
-int net_init_socket(QemuOpts *opts,
- Monitor *mon,
- const char *name,
- NetClientState *peer)
+int net_init_socket(QemuOpts *opts, Monitor *mon,
+ const char *name, NetClientState *peer)
{
if (qemu_opt_get(opts, "fd")) {
int fd;
@@ -690,3 +689,29 @@ int net_init_socket(QemuOpts *opts,
}
return 0;
}
+
+static hostdevProperty net_socket_properties[] = {
+ DEFINE_PROP_END_OF_LIST(),
+};
+
+static void net_socket_class_init(ObjectClass *klass, void *data)
+{
+ HOSTDeviceClass *k = HOSTDEV_CLASS(klass);
+
+ k->init = net_init_socket;
+ k->props = net_socket_properties;
+}
+
+static TypeInfo net_socket_type = {
+ .name = "socket",
+ .parent = TYPE_HOSTDEV,
+ .instance_size = sizeof(NetClientState),
+ .class_init = net_socket_class_init,
+};
+
+static void net_socket_register_types(void)
+{
+ type_register_static(&net_socket_type);
+}
+
+type_init(net_socket_register_types)
diff --git a/net/socket.h b/net/socket.h
index 5edf17c..70d07cb 100644
--- a/net/socket.h
+++ b/net/socket.h
@@ -26,8 +26,11 @@
#include "net.h"
#include "qemu-common.h"
+#include "qemu/hostdev.h"
-int net_init_socket(QemuOpts *opts, Monitor *mon,
- const char *name, NetClientState *peer);
+int net_init_socket(QemuOpts *opts,
+ Monitor *mon,
+ const char *name,
+ NetClientState *peer);
#endif /* QEMU_NET_SOCKET_H */
diff --git a/net/tap.c b/net/tap.c
index 65f45b8..bd948db 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -715,3 +715,49 @@ 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_PROP_END_OF_LIST(),
+};
+
+static void net_tap_class_init(ObjectClass *klass, void *data)
+{
+ HOSTDeviceClass *k = HOSTDEV_CLASS(klass);
+
+ k->init = net_init_tap;
+ k->props = net_tap_properties;
+}
+
+static TypeInfo net_tap_type = {
+ .name = "tap",
+ .parent = TYPE_HOSTDEV,
+ .instance_size = sizeof(NetClientState),
+ .class_init = net_tap_class_init,
+};
+
+static hostdevProperty net_bridge_properties[] = {
+ DEFINE_PROP_END_OF_LIST(),
+};
+
+static void net_bridge_class_init(ObjectClass *klass, void *data)
+{
+ HOSTDeviceClass *k = HOSTDEV_CLASS(klass);
+
+ k->init = net_init_bridge;
+ k->props = net_bridge_properties;
+}
+
+static TypeInfo net_bridge_type = {
+ .name = "bridge",
+ .parent = TYPE_HOSTDEV,
+ .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..832aa08 100644
--- a/net/tap.h
+++ b/net/tap.h
@@ -28,6 +28,7 @@
#include "qemu-common.h"
#include "qemu-option.h"
+#include "qemu/hostdev.h"
#define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"
#define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown"
diff --git a/qom/Makefile b/qom/Makefile
index 34c6de5..4731fb9 100644
--- a/qom/Makefile
+++ b/qom/Makefile
@@ -1,2 +1,2 @@
qom-y = object.o container.o qom-qobject.o
-qom-twice-y = cpu.o
+qom-twice-y = cpu.o hostdev.o
diff --git a/vl.c b/vl.c
index 112b0e0..0fa8e03 100644
--- a/vl.c
+++ b/vl.c
@@ -2299,8 +2299,6 @@ int main(int argc, char **argv, char **envp)
#endif
}
- module_call_init(MODULE_INIT_QOM);
-
runstate_init();
init_clocks();
@@ -3381,10 +3379,6 @@ int main(int argc, char **argv, char **envp)
}
configure_icount(icount_option);
- if (net_init_clients() < 0) {
- exit(1);
- }
-
/* init the bluetooth world */
if (foreach_device_config(DEV_BT, bt_parse))
exit(1);
@@ -3474,6 +3468,8 @@ int main(int argc, char **argv, char **envp)
if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0)
exit(1);
+ module_call_init(MODULE_INIT_QOM);
+
/* must be after qdev registration but before machine init */
if (vga_model) {
select_vgahw(vga_model);
@@ -3514,6 +3510,10 @@ int main(int argc, char **argv, char **envp)
exit(1);
}
+ if (net_init_clients() < 0) {
+ exit(1);
+ }
+
/* init generic devices */
if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, 1) != 0)
exit(1);
--
1.7.6
next prev parent reply other threads:[~2012-03-26 5:40 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-26 5:40 [Qemu-devel] [RFC 0/9] QOM: qomify -netdev zwu.kernel
2012-03-26 5:40 ` [Qemu-devel] [RFC 1/9] hostdev: introduce the infrastructure for host device model zwu.kernel
2012-03-26 5:54 ` Zhi Yong Wu
2012-03-27 8:23 ` Paolo Bonzini
2012-03-27 9:06 ` Zhi Yong Wu
2012-03-27 10:15 ` Paolo Bonzini
2012-03-27 11:59 ` Zhi Yong Wu
2012-03-27 13:58 ` Paolo Bonzini
2012-03-27 14:18 ` Zhi Yong Wu
2012-03-27 14:50 ` Paolo Bonzini
2012-03-27 21:21 ` Zhi Yong Wu
2012-03-28 6:41 ` Paolo Bonzini
2012-03-28 7:50 ` Zhi Yong Wu
2012-03-28 7:53 ` Zhi Yong Wu
2012-03-28 8:02 ` Paolo Bonzini
2012-03-28 8:05 ` 陳韋任
2012-03-28 8:25 ` Zhi Yong Wu
2012-03-28 8:29 ` 陳韋任
2012-03-26 5:40 ` zwu.kernel [this message]
2012-03-26 5:40 ` [Qemu-devel] [PATCH] net: qomify -netdev zwu.kernel
2012-03-26 5:44 ` Zhi Yong Wu
2012-03-26 5:40 ` [Qemu-devel] [RFC 2/9] net: introduce one net host device class zwu.kernel
2012-03-27 8:30 ` Paolo Bonzini
2012-03-27 9:13 ` Zhi Yong Wu
2012-03-26 5:40 ` [Qemu-devel] [RFC 3/9] net: adjust net common part for qomify -netdev zwu.kernel
2012-03-26 5:40 ` [Qemu-devel] [RFC 4/9] net: adjust nic init API zwu.kernel
2012-03-26 5:40 ` [Qemu-devel] [RFC 5/9] net: adjust dump " zwu.kernel
2012-03-26 5:40 ` [Qemu-devel] [RFC 6/9] net: qomify -netdev user zwu.kernel
2012-03-26 5:40 ` [Qemu-devel] [RFC 7/9] net: qomify -netdev socket zwu.kernel
2012-03-26 5:40 ` [Qemu-devel] [RFC 8/9] net: qomify -netdev vde zwu.kernel
2012-03-26 5:40 ` [Qemu-devel] [RFC 9/9] net: qomify -netdev tap & -netdev bridge zwu.kernel
2012-03-26 11:54 ` [Qemu-devel] [RFC 0/9] QOM: qomify -netdev Stefan Hajnoczi
2012-03-26 14:20 ` Zhi Yong Wu
2012-03-27 8:19 ` Paolo Bonzini
2012-03-27 9:03 ` Zhi Yong Wu
2012-03-26 14:39 ` Andreas Färber
2012-03-26 14:57 ` Stefan Hajnoczi
2012-03-26 15:01 ` Zhi Yong Wu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1332740423-8426-3-git-send-email-zwu.kernel@gmail.com \
--to=zwu.kernel@gmail.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@linux.vnet.ibm.com \
--cc=wuzhy@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.