From patchwork Wed Aug 1 12:54:39 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 174446 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 8EB3B2C00AF for ; Wed, 1 Aug 2012 22:56:19 +1000 (EST) Received: from localhost ([::1]:51818 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SwYTJ-0000zm-Ma for incoming@patchwork.ozlabs.org; Wed, 01 Aug 2012 08:56:17 -0400 Received: from eggs.gnu.org ([208.118.235.92]:60512) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SwYSG-000789-7T for qemu-devel@nongnu.org; Wed, 01 Aug 2012 08:55:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SwYSB-0007lz-CN for qemu-devel@nongnu.org; Wed, 01 Aug 2012 08:55:12 -0400 Received: from e06smtp15.uk.ibm.com ([195.75.94.111]:43514) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SwYSB-0007jA-0h for qemu-devel@nongnu.org; Wed, 01 Aug 2012 08:55:07 -0400 Received: from /spool/local by e06smtp15.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 1 Aug 2012 13:55:05 +0100 Received: from d06nrmr1507.portsmouth.uk.ibm.com (9.149.38.233) by e06smtp15.uk.ibm.com (192.168.101.145) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 1 Aug 2012 13:55:03 +0100 Received: from d06av11.portsmouth.uk.ibm.com (d06av11.portsmouth.uk.ibm.com [9.149.37.252]) by d06nrmr1507.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q71Ct2p62678992 for ; Wed, 1 Aug 2012 13:55:02 +0100 Received: from d06av11.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av11.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q71Ct15w020809 for ; Wed, 1 Aug 2012 06:55:02 -0600 Received: from localhost (sig-9-146-165-117.uk.ibm.com [9.146.165.117]) by d06av11.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q71Ct1kS020803; Wed, 1 Aug 2012 06:55:01 -0600 From: Stefan Hajnoczi To: Anthony Liguori Date: Wed, 1 Aug 2012 13:54:39 +0100 Message-Id: <1343825691-343-8-git-send-email-stefanha@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1343825691-343-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1343825691-343-1-git-send-email-stefanha@linux.vnet.ibm.com> x-cbid: 12080112-0342-0000-0000-00000274326D X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 195.75.94.111 Cc: Zhi Yong Wu , qemu-devel@nongnu.org, Stefan Hajnoczi Subject: [Qemu-devel] [PATCH 07/19] net: Convert qdev_prop_vlan to peer with hub 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 Instead of using VLANState use net/hub.h to support the vlan qdev property. The vlan qdev property becomes an alias for the peer qdev property but is represented as a VLAN ID number. When a VLAN ID is selected the device will really peer with a hub port. Signed-off-by: Zhi Yong Wu Signed-off-by: Stefan Hajnoczi Reviewed-by: Laszlo Ersek --- hw/qdev-properties.c | 41 ++++++++++++++++++++++++++--------------- hw/qdev.h | 2 +- net.h | 2 +- net/hub.c | 25 +++++++++++++++++++++++++ net/hub.h | 1 + 5 files changed, 54 insertions(+), 17 deletions(-) diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c index 24b39e8..7cc3eb7 100644 --- a/hw/qdev-properties.c +++ b/hw/qdev-properties.c @@ -3,6 +3,7 @@ #include "qerror.h" #include "blockdev.h" #include "hw/block-common.h" +#include "net/hub.h" void *qdev_get_prop_ptr(DeviceState *dev, Property *prop) { @@ -624,13 +625,16 @@ PropertyInfo qdev_prop_netdev = { static int print_vlan(DeviceState *dev, Property *prop, char *dest, size_t len) { - VLANState **ptr = qdev_get_prop_ptr(dev, prop); + VLANClientState **ptr = qdev_get_prop_ptr(dev, prop); if (*ptr) { - return snprintf(dest, len, "%d", (*ptr)->id); - } else { - return snprintf(dest, len, ""); + int id; + if (!net_hub_id_for_client(*ptr, &id)) { + return snprintf(dest, len, "%d", id); + } } + + return snprintf(dest, len, ""); } static void get_vlan(Object *obj, Visitor *v, void *opaque, @@ -638,11 +642,17 @@ static void get_vlan(Object *obj, Visitor *v, void *opaque, { DeviceState *dev = DEVICE(obj); Property *prop = opaque; - VLANState **ptr = qdev_get_prop_ptr(dev, prop); - int64_t id; + VLANClientState **ptr = qdev_get_prop_ptr(dev, prop); + int32_t id = -1; - id = *ptr ? (*ptr)->id : -1; - visit_type_int64(v, &id, name, errp); + if (*ptr) { + int hub_id; + if (!net_hub_id_for_client(*ptr, &hub_id)) { + id = hub_id; + } + } + + visit_type_int32(v, &id, name, errp); } static void set_vlan(Object *obj, Visitor *v, void *opaque, @@ -650,17 +660,17 @@ static void set_vlan(Object *obj, Visitor *v, void *opaque, { DeviceState *dev = DEVICE(obj); Property *prop = opaque; - VLANState **ptr = qdev_get_prop_ptr(dev, prop); + VLANClientState **ptr = qdev_get_prop_ptr(dev, prop); Error *local_err = NULL; - int64_t id; - VLANState *vlan; + int32_t id; + VLANClientState *hubport; if (dev->state != DEV_STATE_CREATED) { error_set(errp, QERR_PERMISSION_DENIED); return; } - visit_type_int64(v, &id, name, &local_err); + visit_type_int32(v, &id, name, &local_err); if (local_err) { error_propagate(errp, local_err); return; @@ -669,13 +679,14 @@ static void set_vlan(Object *obj, Visitor *v, void *opaque, *ptr = NULL; return; } - vlan = qemu_find_vlan(id, 1); - if (!vlan) { + + hubport = net_hub_port_find(id); + if (!hubport) { error_set(errp, QERR_INVALID_PARAMETER_VALUE, name, prop->info->name); return; } - *ptr = vlan; + *ptr = hubport; } PropertyInfo qdev_prop_vlan = { diff --git a/hw/qdev.h b/hw/qdev.h index a2cbd9d..ef430a0 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -291,7 +291,7 @@ extern PropertyInfo qdev_prop_pci_host_devaddr; #define DEFINE_PROP_NETDEV(_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, VLANClientState*) #define DEFINE_PROP_VLAN(_n, _s, _f) \ - DEFINE_PROP(_n, _s, _f, qdev_prop_vlan, VLANState*) + DEFINE_PROP(_n, _s, _f, qdev_prop_vlan, VLANClientState*) #define DEFINE_PROP_DRIVE(_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_drive, BlockDriverState *) #define DEFINE_PROP_MACADDR(_n, _s, _f) \ diff --git a/net.h b/net.h index e9c92b2..4bccead 100644 --- a/net.h +++ b/net.h @@ -24,7 +24,7 @@ typedef struct NICConf { #define DEFINE_NIC_PROPERTIES(_state, _conf) \ DEFINE_PROP_MACADDR("mac", _state, _conf.macaddr), \ - DEFINE_PROP_VLAN("vlan", _state, _conf.vlan), \ + DEFINE_PROP_VLAN("vlan", _state, _conf.peer), \ DEFINE_PROP_NETDEV("netdev", _state, _conf.peer), \ DEFINE_PROP_INT32("bootindex", _state, _conf.bootindex, -1) diff --git a/net/hub.c b/net/hub.c index 97198a2..e80d131 100644 --- a/net/hub.c +++ b/net/hub.c @@ -188,6 +188,31 @@ VLANClientState *net_hub_find_client_by_name(int hub_id, const char *name) } /** + * Find a available port on a hub; otherwise create one new port + */ +VLANClientState *net_hub_port_find(int hub_id) +{ + NetHub *hub; + NetHubPort *port; + VLANClientState *nc; + + QLIST_FOREACH(hub, &hubs, next) { + if (hub->id == hub_id) { + QLIST_FOREACH(port, &hub->ports, next) { + nc = port->nc.peer; + if (!nc) { + return &(port->nc); + } + } + break; + } + } + + nc = net_hub_add_port(hub_id, NULL); + return nc; +} + +/** * Print hub configuration */ void net_hub_info(Monitor *mon) diff --git a/net/hub.h b/net/hub.h index 9973da3..3906df2 100644 --- a/net/hub.h +++ b/net/hub.h @@ -24,5 +24,6 @@ VLANClientState *net_hub_find_client_by_name(int hub_id, const char *name); void net_hub_info(Monitor *mon); int net_hub_id_for_client(VLANClientState *nc, int *id); void net_hub_check_clients(void); +VLANClientState *net_hub_port_find(int hub_id); #endif /* NET_HUB_H */