From patchwork Mon Mar 26 05:40:17 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhiyong Wu X-Patchwork-Id: 148638 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 34277B6EE7 for ; Mon, 26 Mar 2012 16:57:23 +1100 (EST) Received: from localhost ([::1]:47734 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SC2gi-00031J-KX for incoming@patchwork.ozlabs.org; Mon, 26 Mar 2012 01:41:52 -0400 Received: from eggs.gnu.org ([208.118.235.92]:53390) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SC2gA-0001pi-Be for qemu-devel@nongnu.org; Mon, 26 Mar 2012 01:41:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SC2g8-0001WI-76 for qemu-devel@nongnu.org; Mon, 26 Mar 2012 01:41:17 -0400 Received: from e31.co.us.ibm.com ([32.97.110.149]:45878) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SC2g7-0001Vx-OP for qemu-devel@nongnu.org; Mon, 26 Mar 2012 01:41:15 -0400 Received: from /spool/local by e31.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sun, 25 Mar 2012 23:41:13 -0600 Received: from d03dlp02.boulder.ibm.com (9.17.202.178) by e31.co.us.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Sun, 25 Mar 2012 23:40:59 -0600 Received: from d03relay03.boulder.ibm.com (d03relay03.boulder.ibm.com [9.17.195.228]) by d03dlp02.boulder.ibm.com (Postfix) with ESMTP id 763983E40048 for ; Sun, 25 Mar 2012 23:40:58 -0600 (MDT) Received: from d03av03.boulder.ibm.com (d03av03.boulder.ibm.com [9.17.195.169]) by d03relay03.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q2Q5ewjB180276 for ; Sun, 25 Mar 2012 23:40:58 -0600 Received: from d03av03.boulder.ibm.com (loopback [127.0.0.1]) by d03av03.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q2Q5evua004325 for ; Sun, 25 Mar 2012 23:40:58 -0600 Received: from us.ibm.com (f15.cn.ibm.com [9.115.118.120] (may be forged)) by d03av03.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with SMTP id q2Q5esfh004227; Sun, 25 Mar 2012 23:40:55 -0600 Received: by us.ibm.com (sSMTP sendmail emulation); Mon, 26 Mar 2012 13:40:52 +0800 From: zwu.kernel@gmail.com To: qemu-devel@nongnu.org Date: Mon, 26 Mar 2012 13:40:17 +0800 Message-Id: <1332740423-8426-6-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-7282-0000-0000-000007AA3E95 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 32.97.110.149 Cc: zwu.kernel@gmail.com, pbonzini@redhat.com, Zhi Yong Wu , stefanha@linux.vnet.ibm.com Subject: [Qemu-devel] [RFC 3/9] net: adjust net common part for qomify -netdev 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.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);