qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 1/2] qdev: add string and binary properties.
@ 2009-05-28 22:44 Gerd Hoffmann
  2009-05-28 22:44 ` [Qemu-devel] [PATCH 2/2] qdev: kill DeviceState->nd, use properties instead Gerd Hoffmann
  0 siblings, 1 reply; 4+ messages in thread
From: Gerd Hoffmann @ 2009-05-28 22:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann


Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/qdev.c |   61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/qdev.h |    5 +++++
 2 files changed, 66 insertions(+), 0 deletions(-)

diff --git a/hw/qdev.c b/hw/qdev.c
index f271b7f..d723b3e 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -35,12 +35,17 @@ struct DeviceProperty {
     const char *name;
     enum {
         PROP_INT,
+        PROP_STR,
+        PROP_BIN,
         PROP_PTR,
     } type;
     union {
         uint64_t i;
+        char *str;
+        uint8_t *bin;
         void *ptr;
     } value;
+    size_t len;
     DeviceProperty *next;
 };
 
@@ -146,6 +151,26 @@ void qdev_set_prop_int(DeviceState *dev, const char *name, uint64_t value)
     prop->value.i = value;
 }
 
+void qdev_set_prop_str(DeviceState *dev, const char *name, const char *str)
+{
+    DeviceProperty *prop;
+
+    prop = create_prop(dev, name);
+    prop->type = PROP_STR;
+    prop->value.str = qemu_strdup(str);
+}
+
+void qdev_set_prop_bin(DeviceState *dev, const char *name, const uint8_t *bin, size_t len)
+{
+    DeviceProperty *prop;
+
+    prop = create_prop(dev, name);
+    prop->type = PROP_BIN;
+    prop->value.bin = qemu_malloc(len);
+    prop->len = len;
+    memcpy(prop->value.bin, bin, len);
+}
+
 void qdev_set_prop_ptr(DeviceState *dev, const char *name, void *value)
 {
     DeviceProperty *prop;
@@ -203,6 +228,30 @@ uint64_t qdev_get_prop_int(DeviceState *dev, const char *name, uint64_t def)
     return prop->value.i;
 }
 
+const char *qdev_get_prop_str(DeviceState *dev, const char *name, const char *def)
+{
+    DeviceProperty *prop;
+
+    prop = find_prop(dev, name);
+    if (!prop || prop->type != PROP_STR)
+        return def;
+
+    return prop->value.str;
+}
+
+int qdev_get_prop_bin(DeviceState *dev, const char *name, uint8_t *dest, size_t size)
+{
+    DeviceProperty *prop;
+
+    prop = find_prop(dev, name);
+    if (!prop || prop->type != PROP_BIN)
+        return -1;
+    if (size < prop->len)
+        return -1;
+    memcpy(dest, prop->value.bin, prop->len);
+    return 0;
+}
+
 void *qdev_get_prop_ptr(DeviceState *dev, const char *name)
 {
     DeviceProperty *prop;
@@ -326,6 +375,7 @@ void qbus_print(Monitor *mon, BusState *bus, int indent)
     struct DeviceState *dev;
     struct BusState *child;
     struct DeviceProperty *prop;
+    int i;
 
     monitor_printf(mon, "%*sbus: name %s, type %d\n", indent, "",
                    bus->name, bus->type);
@@ -336,6 +386,17 @@ void qbus_print(Monitor *mon, BusState *bus, int indent)
             case PROP_INT:
                 monitor_printf(mon, ", %s=%" PRId64, prop->name, prop->value.i);
                 break;
+            case PROP_STR:
+                monitor_printf(mon, ", %s=\"%s\"", prop->name, prop->value.str);
+                break;
+            case PROP_BIN:
+                monitor_printf(mon, ", %s=", prop->name);
+                for (i = 0; i < prop->len && i < 8; i++) {
+                    monitor_printf(mon, "%s%02x", 0 == i ? "" : ",",
+                                   prop->value.bin[i]);
+                }
+                monitor_printf(mon, "%s", i == prop->len ? "" : ",...");
+                break;
             case PROP_PTR:
                 monitor_printf(mon, ", %s=%p", prop->name, prop->value.ptr);
                 break;
diff --git a/hw/qdev.h b/hw/qdev.h
index ab670de..2f5d9dc 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -50,6 +50,9 @@ void qdev_free(DeviceState *dev);
 
 /* Set properties between creation and init.  */
 void qdev_set_prop_int(DeviceState *dev, const char *name, uint64_t value);
+void qdev_set_prop_str(DeviceState *dev, const char *name, const char *str);
+void qdev_set_prop_bin(DeviceState *dev, const char *name, const uint8_t *bin,
+                       size_t len);
 void qdev_set_prop_ptr(DeviceState *dev, const char *name, void *value);
 void qdev_set_netdev(DeviceState *dev, NICInfo *nd);
 
@@ -84,6 +87,8 @@ CharDriverState *qdev_init_chardev(DeviceState *dev);
 
 BusState *qdev_get_parent_bus(DeviceState *dev);
 uint64_t qdev_get_prop_int(DeviceState *dev, const char *name, uint64_t def);
+const char *qdev_get_prop_str(DeviceState *dev, const char *name, const char *def);
+int qdev_get_prop_bin(DeviceState *dev, const char *name, uint8_t *dest, size_t size);
 void *qdev_get_prop_ptr(DeviceState *dev, const char *name);
 
 /* Convery from a base type to a parent type, with compile time checking.  */
-- 
1.6.2.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [Qemu-devel] [PATCH 2/2] qdev: kill DeviceState->nd, use properties instead.
  2009-05-28 22:44 [Qemu-devel] [PATCH 1/2] qdev: add string and binary properties Gerd Hoffmann
@ 2009-05-28 22:44 ` Gerd Hoffmann
  2009-05-29 12:10   ` Paul Brook
  0 siblings, 1 reply; 4+ messages in thread
From: Gerd Hoffmann @ 2009-05-28 22:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann


Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/qdev.c |   18 ++++++++++++------
 hw/qdev.h |    1 -
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/hw/qdev.c b/hw/qdev.c
index d723b3e..8c06fce 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -182,8 +182,12 @@ void qdev_set_prop_ptr(DeviceState *dev, const char *name, void *value)
 
 void qdev_set_netdev(DeviceState *dev, NICInfo *nd)
 {
-    assert(!dev->nd);
-    dev->nd = nd;
+    qdev_set_prop_int(dev, "nic_vlan", nd->vlan->id);
+    qdev_set_prop_bin(dev, "nic_addr", nd->macaddr, 6);
+    if (nd->name)
+        qdev_set_prop_str(dev, "nic_name", nd->name);
+    if (nd->model)
+        qdev_set_prop_str(dev, "nic_model", nd->model);
 }
 
 
@@ -294,16 +298,18 @@ VLANClientState *qdev_get_vlan_client(DeviceState *dev,
                                       NetCleanup *cleanup,
                                       void *opaque)
 {
-    NICInfo *nd = dev->nd;
-    assert(nd);
-    return qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
+    int vlan = qdev_get_prop_int(dev, "nic_vlan", 0);
+
+    return qemu_new_vlan_client(qemu_find_vlan(vlan),
+                                qdev_get_prop_str(dev, "nic_model", NULL),
+                                qdev_get_prop_str(dev, "nic_name", NULL),
                                 fd_read, fd_can_read, cleanup, opaque);
 }
 
 
 void qdev_get_macaddr(DeviceState *dev, uint8_t *macaddr)
 {
-    memcpy(macaddr, dev->nd->macaddr, 6);
+    qdev_get_prop_bin(dev, "nic_addr", macaddr, 6);
 }
 
 static int next_block_unit[IF_COUNT];
diff --git a/hw/qdev.h b/hw/qdev.h
index 2f5d9dc..3adc680 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -21,7 +21,6 @@ struct DeviceState {
     int num_gpio_in;
     qemu_irq *gpio_in;
     LIST_HEAD(, BusState) child_bus;
-    NICInfo *nd;
     LIST_ENTRY(DeviceState) sibling;
 };
 
-- 
1.6.2.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH 2/2] qdev: kill DeviceState->nd, use properties instead.
  2009-05-28 22:44 ` [Qemu-devel] [PATCH 2/2] qdev: kill DeviceState->nd, use properties instead Gerd Hoffmann
@ 2009-05-29 12:10   ` Paul Brook
  2009-05-29 13:17     ` Gerd Hoffmann
  0 siblings, 1 reply; 4+ messages in thread
From: Paul Brook @ 2009-05-29 12:10 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

> kill DeviceState->nd, use properties instead.

I'm not sure this is the right solution. Before changing this I think we need 
to figure out how we want to link devices to the host network configuration.

Paul

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH 2/2] qdev: kill DeviceState->nd, use properties instead.
  2009-05-29 12:10   ` Paul Brook
@ 2009-05-29 13:17     ` Gerd Hoffmann
  0 siblings, 0 replies; 4+ messages in thread
From: Gerd Hoffmann @ 2009-05-29 13:17 UTC (permalink / raw)
  To: Paul Brook; +Cc: qemu-devel

On 05/29/09 14:10, Paul Brook wrote:
>> kill DeviceState->nd, use properties instead.
>
> I'm not sure this is the right solution. Before changing this I think we need
> to figure out how we want to link devices to the host network configuration.

Sure, when we replace the vlans with something else the vlan property 
wouldn't make sense any more (guess this is the discussion you are 
referring to).  We can drop it once we have a replacement for the 
current model.  Not (yet) having a replacement shouldn't stop us from 
putting qdev into use though.

cheers,
   Gerd

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-05-29 13:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-28 22:44 [Qemu-devel] [PATCH 1/2] qdev: add string and binary properties Gerd Hoffmann
2009-05-28 22:44 ` [Qemu-devel] [PATCH 2/2] qdev: kill DeviceState->nd, use properties instead Gerd Hoffmann
2009-05-29 12:10   ` Paul Brook
2009-05-29 13:17     ` Gerd Hoffmann

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).