From patchwork Sat Jun 16 16:30:32 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhiyong Wu X-Patchwork-Id: 165310 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 CA803B70FD for ; Sun, 17 Jun 2012 02:31:27 +1000 (EST) Received: from localhost ([::1]:56075 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SfvuH-0005jJ-6w for incoming@patchwork.ozlabs.org; Sat, 16 Jun 2012 12:31:25 -0400 Received: from eggs.gnu.org ([208.118.235.92]:35868) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sfvu9-0005jB-9C for qemu-devel@nongnu.org; Sat, 16 Jun 2012 12:31:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sfvu7-0002p3-9j for qemu-devel@nongnu.org; Sat, 16 Jun 2012 12:31:16 -0400 Received: from e38.co.us.ibm.com ([32.97.110.159]:49963) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sfvu7-0002nr-1Z for qemu-devel@nongnu.org; Sat, 16 Jun 2012 12:31:15 -0400 Received: from /spool/local by e38.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sat, 16 Jun 2012 10:31:09 -0600 Received: from d03dlp02.boulder.ibm.com (9.17.202.178) by e38.co.us.ibm.com (192.168.1.138) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Sat, 16 Jun 2012 10:30:39 -0600 Received: from d03relay02.boulder.ibm.com (d03relay02.boulder.ibm.com [9.17.195.227]) by d03dlp02.boulder.ibm.com (Postfix) with ESMTP id 27CA33E40047 for ; Sat, 16 Jun 2012 16:30:38 +0000 (WET) Received: from d03av03.boulder.ibm.com (d03av03.boulder.ibm.com [9.17.195.169]) by d03relay02.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q5GGUcGU160812 for ; Sat, 16 Jun 2012 10:30:38 -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 q5GGUbDY021223 for ; Sat, 16 Jun 2012 10:30:38 -0600 Received: from us.ibm.com ([9.115.118.120]) by d03av03.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with SMTP id q5GGUY7b020451; Sat, 16 Jun 2012 10:30:35 -0600 Received: by us.ibm.com (sSMTP sendmail emulation); Sun, 17 Jun 2012 00:30:34 +0800 From: zwu.kernel@gmail.com To: qemu-devel@nongnu.org Date: Sun, 17 Jun 2012 00:30:32 +0800 Message-Id: <1339864232-9171-1-git-send-email-zwu.kernel@gmail.com> X-Mailer: git-send-email 1.7.6 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12061616-5518-0000-0000-00000538B9EC X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 32.97.110.159 Cc: nzini@redhat.com, Zhi Yong Wu , stefanha@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH] net: roll back qdev_prop_vlan 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 We're trying to preserve backward compatibility. This command-line break: x86_64-softmmu/qemu-system-x86_64 -net user,vlan=1 -device virtio-net-pci,vlan=1 Instead of dropping the qdev_prop_vlan completely the hw/qdev-properties.c code needs to call net/hub.h external functions to implement equivalent functionality. Signed-off-by: Zhi Yong Wu --- hw/qdev-properties.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/qdev.h | 3 ++ net.h | 1 + net/hub.c | 25 ++++++++++++++++ net/hub.h | 1 + 5 files changed, 106 insertions(+), 0 deletions(-) diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c index 1c13bda..91328eb 100644 --- a/hw/qdev-properties.c +++ b/hw/qdev-properties.c @@ -2,6 +2,7 @@ #include "qdev.h" #include "qerror.h" #include "blockdev.h" +#include "net/hub.h" void *qdev_get_prop_ptr(DeviceState *dev, Property *prop) { @@ -623,6 +624,81 @@ PropertyInfo qdev_prop_netdev = { .set = set_netdev, }; +/* --- vlan --- */ + +static int print_vlan(DeviceState *dev, Property *prop, char *dest, size_t len) +{ + NetClientState **ptr = qdev_get_prop_ptr(dev, prop); + + if (*ptr) { + unsigned 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, + const char *name, Error **errp) +{ + DeviceState *dev = DEVICE(obj); + Property *prop = opaque; + NetClientState **ptr = qdev_get_prop_ptr(dev, prop); + int64_t id = -1; + + if (*ptr) { + unsigned int hub_id; + net_hub_id_for_client(*ptr, &hub_id); + id = (int64_t)hub_id; + } + + visit_type_int(v, &id, name, errp); +} + +static void set_vlan(Object *obj, Visitor *v, void *opaque, + const char *name, Error **errp) +{ + DeviceState *dev = DEVICE(obj); + Property *prop = opaque; + NetClientState **ptr = qdev_get_prop_ptr(dev, prop); + Error *local_err = NULL; + int64_t id; + NetClientState *hubport; + + if (dev->state != DEV_STATE_CREATED) { + error_set(errp, QERR_PERMISSION_DENIED); + return; + } + + visit_type_int(v, &id, name, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + + if (id == -1) { + *ptr = NULL; + return; + } + + hubport = net_hub_port_find(id); + if (!hubport) { + error_set(errp, QERR_INVALID_PARAMETER_VALUE, + name, prop->info->name); + return; + } + *ptr = hubport; +} + +PropertyInfo qdev_prop_vlan = { + .name = "vlan", + .print = print_vlan, + .get = get_vlan, + .set = set_vlan, +}; + /* --- pointer --- */ /* Not a proper property, just for dirty hacks. TODO Remove it! */ diff --git a/hw/qdev.h b/hw/qdev.h index edbf8fa..f4aea27 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -222,6 +222,7 @@ extern PropertyInfo qdev_prop_macaddr; extern PropertyInfo qdev_prop_losttickpolicy; extern PropertyInfo qdev_prop_drive; extern PropertyInfo qdev_prop_netdev; +extern PropertyInfo qdev_prop_vlan; extern PropertyInfo qdev_prop_pci_devfn; extern PropertyInfo qdev_prop_blocksize; @@ -276,6 +277,8 @@ extern PropertyInfo qdev_prop_blocksize; DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*) #define DEFINE_PROP_NETDEV(_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, NetClientState*) +#define DEFINE_PROP_VLAN(_n, _s, _f) \ + DEFINE_PROP(_n, _s, _f, qdev_prop_vlan, NetClientState*) #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 08306a4..c4e56cc 100644 --- a/net.h +++ b/net.h @@ -22,6 +22,7 @@ typedef struct NICConf { #define DEFINE_NIC_PROPERTIES(_state, _conf) \ DEFINE_PROP_MACADDR("mac", _state, _conf.macaddr), \ + 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 efd90b5..001f818 100644 --- a/net/hub.c +++ b/net/hub.c @@ -205,6 +205,31 @@ NetClientState *net_hub_find_client_by_name(unsigned int hub_id, } /** + * Find a available port on a hub; otherwise create one new port + */ +NetClientState *net_hub_port_find(unsigned int hub_id) +{ + NetHub *hub; + NetHubPort *port; + NetClientState *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); + return nc; +} + +/** * Determine if one nc peers with one hub port */ bool net_hub_port_peer_nc(NetClientState *nc) diff --git a/net/hub.h b/net/hub.h index 550189b..54d6803 100644 --- a/net/hub.h +++ b/net/hub.h @@ -23,6 +23,7 @@ NetClientState *net_hub_find_client_by_name(unsigned int hub_id, void net_hub_info(Monitor *mon); int net_hub_id_for_client(NetClientState *nc, unsigned int *id); void net_hub_check_clients(void); +NetClientState *net_hub_port_find(unsigned int hub_id); bool net_hub_port_peer_nc(NetClientState *nc); #endif /* NET_HUB_H */