diff mbox

[2/7] qdev: add "net-client" property

Message ID 1258057742-18699-3-git-send-email-markmc@redhat.com
State New
Headers show

Commit Message

Mark McLoughlin Nov. 12, 2009, 8:28 p.m. UTC
Rather than having each NIC create it's own client, let's create the
client early and pass it down to the NIC.

One advantage is that we can add parameters which only the client
knows about, without having the NIC know anything about it - e.g. NICs
shouldn't know about netdev vs. vlan.

Another advantage is that we can easily get the client associated with
a qdev.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 hw/qdev-properties.c |   25 +++++++++++++++++++++++++
 hw/qdev.h            |    5 +++++
 net.h                |    8 +++++---
 3 files changed, 35 insertions(+), 3 deletions(-)

Comments

Gerd Hoffmann Nov. 16, 2009, 9:03 a.m. UTC | #1
On 11/12/09 21:28, Mark McLoughlin wrote:
> Rather than having each NIC create it's own client, let's create the
> client early and pass it down to the NIC.

'-device $nic,net-client=$name' doesn't work ...

> One advantage is that we can add parameters which only the client
> knows about, without having the NIC know anything about it - e.g. NICs
> shouldn't know about netdev vs. vlan.

What this is needed for?

> Another advantage is that we can easily get the client associated with
> a qdev.

Looks like this is the *real* reason ...

cheers,
   Gerd
diff mbox

Patch

diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index bda6699..8ce0de7 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -279,6 +279,26 @@  PropertyInfo qdev_prop_chr = {
     .print = print_chr,
 };
 
+/* --- network client object --- */
+
+static int print_net_client(DeviceState *dev, Property *prop, char *dest, size_t len)
+{
+    VLANClientState **ptr = qdev_get_prop_ptr(dev, prop);
+
+    if (*ptr && (*ptr)->name) {
+        return snprintf(dest, len, "%s", (*ptr)->name);
+    } else {
+        return snprintf(dest, len, "<null>");
+    }
+}
+
+PropertyInfo qdev_prop_net_client = {
+    .name  = "net-client",
+    .type  = PROP_TYPE_NET_CLIENT,
+    .size  = sizeof(VLANClientState*),
+    .print = print_net_client,
+};
+
 /* --- netdev device --- */
 
 static int parse_netdev(DeviceState *dev, Property *prop, const char *str)
@@ -558,6 +578,11 @@  void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *valu
     qdev_prop_set(dev, name, &value, PROP_TYPE_CHR);
 }
 
+void qdev_prop_set_net_client(DeviceState *dev, const char *name, VLANClientState *value)
+{
+    qdev_prop_set(dev, name, &value, PROP_TYPE_NET_CLIENT);
+}
+
 void qdev_prop_set_netdev(DeviceState *dev, const char *name, VLANClientState *value)
 {
     qdev_prop_set(dev, name, &value, PROP_TYPE_NETDEV);
diff --git a/hw/qdev.h b/hw/qdev.h
index 41642ee..3e1510f 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -79,6 +79,7 @@  enum PropertyType {
     PROP_TYPE_DRIVE,
     PROP_TYPE_CHR,
     PROP_TYPE_STRING,
+    PROP_TYPE_NET_CLIENT,
     PROP_TYPE_NETDEV,
     PROP_TYPE_VLAN,
     PROP_TYPE_PTR,
@@ -194,6 +195,7 @@  extern PropertyInfo qdev_prop_chr;
 extern PropertyInfo qdev_prop_ptr;
 extern PropertyInfo qdev_prop_macaddr;
 extern PropertyInfo qdev_prop_drive;
+extern PropertyInfo qdev_prop_net_client;
 extern PropertyInfo qdev_prop_netdev;
 extern PropertyInfo qdev_prop_vlan;
 extern PropertyInfo qdev_prop_pci_devfn;
@@ -235,6 +237,8 @@  extern PropertyInfo qdev_prop_pci_devfn;
     DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharDriverState*)
 #define DEFINE_PROP_STRING(_n, _s, _f)             \
     DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*)
+#define DEFINE_PROP_NET_CLIENT(_n, _s, _f)         \
+    DEFINE_PROP(_n, _s, _f, qdev_prop_net_client, VLANClientState *)
 #define DEFINE_PROP_NETDEV(_n, _s, _f)             \
     DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, VLANClientState*)
 #define DEFINE_PROP_VLAN(_n, _s, _f)             \
@@ -258,6 +262,7 @@  void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value);
 void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value);
 void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value);
 void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *value);
+void qdev_prop_set_net_client(DeviceState *dev, const char *name, VLANClientState *value);
 void qdev_prop_set_netdev(DeviceState *dev, const char *name, VLANClientState *value);
 void qdev_prop_set_vlan(DeviceState *dev, const char *name, VLANState *value);
 void qdev_prop_set_drive(DeviceState *dev, const char *name, DriveInfo *value);
diff --git a/net.h b/net.h
index aa4b78a..d7235bb 100644
--- a/net.h
+++ b/net.h
@@ -14,15 +14,17 @@  struct MACAddr {
 /* qdev nic properties */
 
 typedef struct NICConf {
+    VLANClientState *client;
     MACAddr macaddr;
     VLANState *vlan;
     VLANClientState *peer;
 } NICConf;
 
 #define DEFINE_NIC_PROPERTIES(_state, _conf)                            \
-    DEFINE_PROP_MACADDR("mac",   _state, _conf.macaddr),                \
-    DEFINE_PROP_VLAN("vlan",     _state, _conf.vlan),                   \
-    DEFINE_PROP_NETDEV("netdev", _state, _conf.peer)
+    DEFINE_PROP_NET_CLIENT("net-client", _state, _conf.client),         \
+    DEFINE_PROP_MACADDR("mac",           _state, _conf.macaddr),        \
+    DEFINE_PROP_VLAN("vlan",             _state, _conf.vlan),           \
+    DEFINE_PROP_NETDEV("netdev",         _state, _conf.peer)
 
 /* VLANs support */