All of lore.kernel.org
 help / color / mirror / Atom feed
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] [RFC 3/9] net: adjust net common part for qomify -netdev
Date: Mon, 26 Mar 2012 13:40:17 +0800	[thread overview]
Message-ID: <1332740423-8426-6-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 |  108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 net.h |    1 +
 vl.c  |   12 +++---
 3 files changed, 109 insertions(+), 12 deletions(-)

diff --git a/net.c b/net.c
index 608c090..ff8ddaf 100644
--- a/net.c
+++ b/net.c
@@ -624,10 +624,7 @@ static int net_init_nic(QemuOpts *opts,
         .help = "identifier for monitor commands", \
      }
 
-typedef int NetClientInitFunc(QemuOpts *opts,
-                              Monitor *mon,
-                              const char *name,
-                              NetClientState *peer);
+typedef int NetClientInitFunc(NETDevice *host_dev);
 
 /* magic number, but compiler will warn if too small */
 #define NET_MAX_DESC 20
@@ -956,7 +953,13 @@ int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev)
 
             ret = 0;
             if (net_client_types[i].init) {
-                ret = net_client_types[i].init(opts, mon, name, peer);
+                NETDevice host_dev;
+                host_dev.mon = mon;
+                host_dev.opts = opts;
+                host_dev.name = g_strdup(name);
+                host_dev.peer = peer;
+                ret = net_client_types[i].init(&host_dev);
+                //ret = net_client_types[i].init(opts, mon, name, peer);
                 if (ret < 0) {
                     /* TODO push error reporting into init() methods */
                     qerror_report(QERR_DEVICE_INIT_FAILED, type);
@@ -972,6 +975,99 @@ int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev)
     return -1;
 }
 
+static bool netdev_device_add(Monitor *mon,
+                              QemuOpts *opts,
+                              const char *name,
+                              NetClientState *peer)
+{
+    const char *type, *id;
+    NETDevice *net_dev;
+    HOSTDevice *host_dev;
+
+    type = qemu_opt_get(opts, "type");
+    if (!type) {
+        qerror_report(QERR_MISSING_PARAMETER, "type");
+        return false;
+    }
+
+    host_dev = hostdev_device_create(type);
+    if (!host_dev) {
+        return false;
+    }
+
+    net_dev = NET_DEVICE(host_dev);
+    net_dev->mon = mon;
+    net_dev->opts = opts;
+    net_dev->name = g_strdup(name);
+    net_dev->peer = peer;
+
+    hostdev_prop_set_peer(&net_dev->host_dev, "peer", peer);
+    //hostdev_prop_set_string(&net_dev->host_dev, "name", g_strdup(name));
+    //hostdev_prop_set_string(&net_dev->host_dev, "model", g_strdup(model));
+    //hostdev_prop_set_bit(&net_dev->host_dev, "receive_disabled", receive_disabled);
+
+    id = qemu_opts_id(opts);
+    if (hostdev_device_init(&net_dev->host_dev, type, id)) {
+        return false;
+    }
+
+    return true;
+}
+
+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");
+    }
+
+    if (!netdev_device_add(mon, opts, (char *)name, NULL)) {
+        return -1;
+    }
+
+    return 0;
+}
+
 static int net_host_check_device(const char *device)
 {
     int i;
@@ -1188,7 +1284,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 912fa2d..3de60d4 100644
--- a/net.h
+++ b/net.h
@@ -88,6 +88,7 @@ typedef struct NetClientInfo {
 } NetClientInfo;
 
 struct NetClientState {
+    NETDevice net_dev;
     NetClientInfo *info;
     int link_down;
     QTAILQ_ENTRY(NetClientState) next;
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

  parent reply	other threads:[~2012-03-26  5:41 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 ` [Qemu-devel] [PATCH] net: qomify -netdev zwu.kernel
2012-03-26  5:40 ` 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 ` zwu.kernel [this message]
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-6-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.