From: zwu.kernel@gmail.com
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, aliguori@us.ibm.com,
Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>,
stefanha@linux.vnet.ibm.com, jan.kiszka@siemens.com
Subject: [Qemu-devel] [PATCH v6 17/17] net: roll back qdev_prop_vlan
Date: Wed, 20 Jun 2012 17:42:21 +0800 [thread overview]
Message-ID: <1340185341-30803-18-git-send-email-zwu.kernel@gmail.com> (raw)
In-Reply-To: <1340185341-30803-1-git-send-email-zwu.kernel@gmail.com>
From: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
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 <wuzhy@linux.vnet.ibm.com>
---
hw/qdev-properties.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++
hw/qdev.h | 3 ++
net.h | 1 +
net/hub.c | 25 ++++++++++++++++
net/hub.h | 1 +
5 files changed, 107 insertions(+), 0 deletions(-)
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index 5fc7483..fcec09e 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)
{
@@ -591,6 +592,82 @@ 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, "%u", id);
+ }
+ }
+
+ return snprintf(dest, len, "<null>");
+}
+
+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;
+ if(!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 2645d0c..1b32b3a 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -234,6 +234,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;
@@ -288,6 +289,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 99b43f4..0256ff9 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 */
--
1.7.6
next prev parent reply other threads:[~2012-06-20 9:43 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-20 9:42 [Qemu-devel] [PATCH v6 00/17] hub-based networking patchset zwu.kernel
2012-06-20 9:42 ` [Qemu-devel] [PATCH v6 01/17] net: Add a hub net client zwu.kernel
2012-06-20 9:42 ` [Qemu-devel] [PATCH v6 02/17] net: Use hubs for the vlan feature zwu.kernel
2012-06-20 9:42 ` [Qemu-devel] [PATCH v6 03/17] net: Look up 'vlan' net clients using hubs zwu.kernel
2012-06-20 9:42 ` [Qemu-devel] [PATCH v6 04/17] hub: Check that hubs are configured correctly zwu.kernel
2012-06-20 9:42 ` [Qemu-devel] [PATCH v6 05/17] net: Drop vlan argument to qemu_new_net_client() zwu.kernel
2012-06-20 9:42 ` [Qemu-devel] [PATCH v6 06/17] net: Remove vlan qdev property zwu.kernel
2012-06-20 9:42 ` [Qemu-devel] [PATCH v6 07/17] net: Remove vlan code from net.c zwu.kernel
2012-06-20 9:42 ` [Qemu-devel] [PATCH v6 08/17] net: Remove VLANState zwu.kernel
2012-06-20 9:42 ` [Qemu-devel] [PATCH v6 09/17] net: Rename non_vlan_clients to net_clients zwu.kernel
2012-06-20 9:42 ` [Qemu-devel] [PATCH v6 10/17] net: Rename VLANClientState to NetClientState zwu.kernel
2012-06-20 9:42 ` [Qemu-devel] [PATCH v6 11/17] net: Rename vc local variables to nc zwu.kernel
2012-06-20 9:42 ` [Qemu-devel] [PATCH v6 12/17] net: Rename qemu_del_vlan_client() to qemu_del_net_client() zwu.kernel
2012-06-20 9:42 ` [Qemu-devel] [PATCH v6 13/17] net: Make "info network" output more readable info zwu.kernel
2012-06-20 9:42 ` [Qemu-devel] [PATCH v6 14/17] net: cleanup deliver/deliver_iov func pointers zwu.kernel
2012-06-20 9:42 ` [Qemu-devel] [PATCH v6 15/17] net: determine if packets can be sent before net queue deliver packets zwu.kernel
2012-06-20 9:42 ` [Qemu-devel] [PATCH v6 16/17] hub: add the support for hub own flow control zwu.kernel
2012-06-20 9:42 ` zwu.kernel [this message]
2012-06-21 13:14 ` [Qemu-devel] [PATCH v6 00/17] hub-based networking patchset Stefan Hajnoczi
2012-06-24 15:11 ` Zhi Yong Wu
2012-07-19 15:40 ` Stefan Hajnoczi
2012-07-19 15:41 ` Paolo Bonzini
2012-07-19 15:48 ` Zhi Yong Wu
2012-07-19 15:49 ` Paolo Bonzini
2012-07-19 15:57 ` Zhi Yong Wu
2012-07-19 16:08 ` Paolo Bonzini
2012-07-19 16:16 ` Zhi Yong Wu
2012-07-19 15:48 ` Stefan Hajnoczi
2012-07-19 18:04 ` Laszlo Ersek
2012-07-20 5:16 ` Stefan Hajnoczi
2012-07-20 6:03 ` Laszlo Ersek
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=1340185341-30803-18-git-send-email-zwu.kernel@gmail.com \
--to=zwu.kernel@gmail.com \
--cc=aliguori@us.ibm.com \
--cc=jan.kiszka@siemens.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.