From patchwork Mon Mar 26 05:40:21 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhiyong Wu X-Patchwork-Id: 148639 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 4145EB6EF4 for ; Mon, 26 Mar 2012 16:58:48 +1100 (EST) Received: from localhost ([::1]:47736 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SC2gi-00031K-8x for incoming@patchwork.ozlabs.org; Mon, 26 Mar 2012 01:41:52 -0400 Received: from eggs.gnu.org ([208.118.235.92]:53488) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SC2gW-0002lX-1T for qemu-devel@nongnu.org; Mon, 26 Mar 2012 01:41:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SC2gU-0001aP-3N for qemu-devel@nongnu.org; Mon, 26 Mar 2012 01:41:39 -0400 Received: from e1.ny.us.ibm.com ([32.97.182.141]:53112) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SC2gT-0001a9-VD for qemu-devel@nongnu.org; Mon, 26 Mar 2012 01:41:38 -0400 Received: from /spool/local by e1.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 26 Mar 2012 01:41:35 -0400 Received: from d01dlp01.pok.ibm.com (9.56.224.56) by e1.ny.us.ibm.com (192.168.1.101) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 26 Mar 2012 01:41:16 -0400 Received: from d01relay01.pok.ibm.com (d01relay01.pok.ibm.com [9.56.227.233]) by d01dlp01.pok.ibm.com (Postfix) with ESMTP id 00AD038C803A for ; Mon, 26 Mar 2012 01:41:16 -0400 (EDT) Received: from d01av02.pok.ibm.com (d01av02.pok.ibm.com [9.56.224.216]) by d01relay01.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q2Q5fG5V282768 for ; Mon, 26 Mar 2012 01:41:16 -0400 Received: from d01av02.pok.ibm.com (loopback [127.0.0.1]) by d01av02.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q2Q5fFHM019601 for ; Mon, 26 Mar 2012 02:41:15 -0300 Received: from us.ibm.com (f15.cn.ibm.com [9.115.118.120] (may be forged)) by d01av02.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with SMTP id q2Q5fA3c019366; Mon, 26 Mar 2012 02:41:12 -0300 Received: by us.ibm.com (sSMTP sendmail emulation); Mon, 26 Mar 2012 13:41:09 +0800 From: zwu.kernel@gmail.com To: qemu-devel@nongnu.org Date: Mon, 26 Mar 2012 13:40:21 +0800 Message-Id: <1332740423-8426-10-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-6078-0000-0000-0000096B241D X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 32.97.182.141 Cc: zwu.kernel@gmail.com, pbonzini@redhat.com, Zhi Yong Wu , stefanha@linux.vnet.ibm.com Subject: [Qemu-devel] [RFC 7/9] net: qomify -netdev socket 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/socket.c | 38 ++++++++++++++++++++++++++++++++++---- net/socket.h | 4 ++-- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/net/socket.c b/net/socket.c index 55d9820..fe18e87 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,11 +588,13 @@ 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(NETDevice *net_dev) { + 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")) { int fd; @@ -690,3 +693,30 @@ int net_init_socket(QemuOpts *opts, } return 0; } + +static hostdevProperty net_socket_properties[] = { + DEFINE_HOSTDEV_PROP_END_OF_LIST(), +}; + +static void net_socket_class_init(ObjectClass *klass, void *data) +{ + NETDeviceClass *k = NETDEV_CLASS(klass); + HOSTDeviceClass *dc = HOSTDEV_CLASS(klass); + + k->init = net_init_socket; + dc->props = net_socket_properties; +} + +static TypeInfo net_socket_type = { + .name = "socket", + .parent = TYPE_NETDEV, + .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..1ac7c85 100644 --- a/net/socket.h +++ b/net/socket.h @@ -26,8 +26,8 @@ #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(NETDevice *net_dev); #endif /* QEMU_NET_SOCKET_H */