qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
To: Anthony Liguori <aliguori@us.ibm.com>
Cc: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>,
	qemu-devel@nongnu.org,
	Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH 07/19] net: Convert qdev_prop_vlan to peer with hub
Date: Wed,  1 Aug 2012 13:54:39 +0100	[thread overview]
Message-ID: <1343825691-343-8-git-send-email-stefanha@linux.vnet.ibm.com> (raw)
In-Reply-To: <1343825691-343-1-git-send-email-stefanha@linux.vnet.ibm.com>

From: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>

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 <wuzhy@linux.vnet.ibm.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
---
 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, "<null>");
+        int id;
+        if (!net_hub_id_for_client(*ptr, &id)) {
+            return snprintf(dest, len, "%d", id);
+        }
     }
+
+    return snprintf(dest, len, "<null>");
 }
 
 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 */
-- 
1.7.10.4

  parent reply	other threads:[~2012-08-01 12:55 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-01 12:54 [Qemu-devel] [PULL 00/19] Net patches for QEMU 1.2 Stefan Hajnoczi
2012-08-01 12:54 ` [Qemu-devel] [PATCH 01/19] net: Add interface to bridge when SIOCBRADDIF isn't available Stefan Hajnoczi
2012-08-01 12:54 ` [Qemu-devel] [PATCH 02/19] net: Add a hub net client Stefan Hajnoczi
2012-08-01 12:54 ` [Qemu-devel] [PATCH 03/19] net: Use hubs for the vlan feature Stefan Hajnoczi
2012-08-01 12:54 ` [Qemu-devel] [PATCH 04/19] net: Look up 'vlan' net clients using hubs Stefan Hajnoczi
2012-08-01 12:54 ` [Qemu-devel] [PATCH 05/19] hub: Check that hubs are configured correctly Stefan Hajnoczi
2012-08-01 12:54 ` [Qemu-devel] [PATCH 06/19] net: Drop vlan argument to qemu_new_net_client() Stefan Hajnoczi
2012-08-01 12:54 ` Stefan Hajnoczi [this message]
2012-08-01 12:54 ` [Qemu-devel] [PATCH 08/19] net: Remove vlan code from net.c Stefan Hajnoczi
2012-08-01 12:54 ` [Qemu-devel] [PATCH 09/19] net: Remove VLANState Stefan Hajnoczi
2012-08-01 12:54 ` [Qemu-devel] [PATCH 10/19] net: Rename non_vlan_clients to net_clients Stefan Hajnoczi
2012-08-01 12:54 ` [Qemu-devel] [PATCH 11/19] net: Rename VLANClientState to NetClientState Stefan Hajnoczi
2012-08-01 12:54 ` [Qemu-devel] [PATCH 12/19] net: Rename vc local variables to nc Stefan Hajnoczi
2012-08-01 12:54 ` [Qemu-devel] [PATCH 13/19] net: Rename qemu_del_vlan_client() to qemu_del_net_client() Stefan Hajnoczi
2012-08-01 12:54 ` [Qemu-devel] [PATCH 14/19] net: Make "info network" output more readable info Stefan Hajnoczi
2012-08-01 12:54 ` [Qemu-devel] [PATCH 15/19] net: cleanup deliver/deliver_iov func pointers Stefan Hajnoczi
2012-08-01 12:54 ` [Qemu-devel] [PATCH 16/19] net: determine if packets can be sent before net queue deliver packets Stefan Hajnoczi
2012-08-01 12:54 ` [Qemu-devel] [PATCH 17/19] hub: add the support for hub own flow control Stefan Hajnoczi
2012-08-01 12:54 ` [Qemu-devel] [PATCH 18/19] net: fix the coding style Stefan Hajnoczi
2012-08-01 12:54 ` [Qemu-devel] [PATCH 19/19] net: add the support for -netdev socket, listen Stefan Hajnoczi
2012-08-03 20:44 ` [Qemu-devel] [PULL 00/19] Net patches for QEMU 1.2 Anthony Liguori

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=1343825691-343-8-git-send-email-stefanha@linux.vnet.ibm.com \
    --to=stefanha@linux.vnet.ibm.com \
    --cc=aliguori@us.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).