All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [RFC 0/9] QOM: qomify -netdev
@ 2012-03-26  5:40 zwu.kernel
  2012-03-26  5:40 ` [Qemu-devel] [RFC 1/9] hostdev: introduce the infrastructure for host device model zwu.kernel
                   ` (11 more replies)
  0 siblings, 12 replies; 38+ messages in thread
From: zwu.kernel @ 2012-03-26  5:40 UTC (permalink / raw)
  To: qemu-devel; +Cc: zwu.kernel, pbonzini, Zhi Yong Wu, stefanha

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

Sending the patchset is mainly intended to get some comments and void the wrong development direction.

The patchset is used to qomify -netdev, but it introduce one infrastructure for host devices based on raw Class and Object, not qdev. So they are not related with DeviceClass and DeviceState.

patch #1 introduce one new class and object for host devices.

patch #2 introduce one net host device class and object.

Note: the code changes still have some issues, but it doesn't affect that we talk with its infrastructure.


Zhi Yong Wu (9):
  hostdev: introduce the infrastructure for host device model
  net: introduce one net host device class
  net: adjust net common part for qomify -netdev
  net: adjust nic init API
  net: adjust dump init API
  net: qomify -netdev user
  net: qomify -netdev socket
  net: qomify -netdev vde
  net: qomify -netdev tap & -netdev bridge

 include/qemu/hostdev.h |  128 ++++++++++++++++++
 net.c                  |  153 +++++++++++++++++++++--
 net.h                  |   28 ++++
 net/dump.c             |    8 +-
 net/dump.h             |    3 +-
 net/slirp.c            |   42 ++++++-
 net/slirp.h            |    7 +-
 net/socket.c           |   38 +++++-
 net/socket.h           |    4 +-
 net/tap.c              |   64 +++++++++-
 net/tap.h              |    8 +-
 net/vde.c              |   34 +++++-
 net/vde.h              |    4 +-
 qom/Makefile           |    2 +-
 qom/hostdev.c          |  333 ++++++++++++++++++++++++++++++++++++++++++++++++
 vl.c                   |   12 +-
 16 files changed, 821 insertions(+), 47 deletions(-)
 create mode 100644 include/qemu/hostdev.h
 create mode 100644 qom/hostdev.c

-- 
1.7.6

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

* [Qemu-devel] [RFC 1/9] hostdev: introduce the infrastructure for host device model
  2012-03-26  5:40 [Qemu-devel] [RFC 0/9] QOM: qomify -netdev zwu.kernel
@ 2012-03-26  5:40 ` zwu.kernel
  2012-03-26  5:54   ` Zhi Yong Wu
  2012-03-27  8:23   ` Paolo Bonzini
  2012-03-26  5:40 ` [Qemu-devel] [PATCH] net: qomify -netdev zwu.kernel
                   ` (10 subsequent siblings)
  11 siblings, 2 replies; 38+ messages in thread
From: zwu.kernel @ 2012-03-26  5:40 UTC (permalink / raw)
  To: qemu-devel; +Cc: zwu.kernel, pbonzini, Zhi Yong Wu, stefanha

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

Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
---
 include/qemu/hostdev.h |  128 ++++++++++++++++++
 qom/Makefile           |    2 +-
 qom/hostdev.c          |  333 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 462 insertions(+), 1 deletions(-)
 create mode 100644 include/qemu/hostdev.h
 create mode 100644 qom/hostdev.c

diff --git a/include/qemu/hostdev.h b/include/qemu/hostdev.h
new file mode 100644
index 0000000..a291761
--- /dev/null
+++ b/include/qemu/hostdev.h
@@ -0,0 +1,128 @@
+/*
+ * QEMU host device model
+ *
+ * Copyright IBM, Corp. 2012
+ *
+ * Authors:
+ *  Zhi Yong Wu   <wuzhy@linux.vnet.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#ifndef QEMU_HOSTDEV_H
+#define QEMU_HOSTDEV_H
+
+#include "qemu-queue.h"
+#include "qemu-char.h"
+#include "qemu-option.h"
+#include "qapi/qapi-visit-core.h"
+#include "qemu/object.h"
+
+typedef struct hostdevProperty hostdevProperty;
+typedef struct hostdevPropertyInfo hostdevPropertyInfo;
+
+/**
+ * SECTION: hostdev
+ * @section_id: QEMU-hostdev
+ * @title: hostdev Class
+ * @short_description: Base class for all host devices
+ */
+
+typedef struct HOSTDevice HOSTDevice;
+
+#define TYPE_HOSTDEV "host-dev"
+#define HOST_DEVICE(obj) \
+     OBJECT_CHECK(HOSTDevice, (obj), TYPE_HOSTDEV)
+#define HOSTDEV_CLASS(klass) \
+     OBJECT_CLASS_CHECK(HOSTDeviceClass, (klass), TYPE_HOSTDEV)
+#define HOSTDEV_GET_CLASS(obj) \
+     OBJECT_GET_CLASS(HOSTDeviceClass, (obj), TYPE_HOSTDEV)
+
+/**
+ * HOSTDeviceClass:
+ *
+ * Represents a host device model.
+ */
+typedef struct HOSTDeviceClass {
+    ObjectClass parent_class;
+    hostdevProperty *props;
+
+    int (*init)(HOSTDevice *host_dv);
+} HOSTDeviceClass;
+
+/**
+ * HOSTDevice:
+ *
+ * State of one host device.
+ */
+struct HOSTDevice {
+    /*< private >*/
+    Object parent_obj;
+
+    /*< public >*/
+};
+
+struct hostdevProperty {
+    const char   *name;
+    hostdevPropertyInfo *info;
+    int          offset;
+    uint8_t      bitnr;
+    uint8_t      qtype;
+    int64_t      defval;
+};
+
+struct hostdevPropertyInfo {
+    const char *name;
+    const char *legacy_name;
+    const char **enum_table;
+    int64_t min;
+    int64_t max;
+    int (*parse)(HOSTDevice *dev,
+                 hostdevProperty *prop,
+                 const char *str);
+    int (*print)(HOSTDevice *dev,
+                 hostdevProperty *prop,
+                 char *dest,
+                 size_t len);
+    ObjectPropertyAccessor *get;
+    ObjectPropertyAccessor *set;
+    ObjectPropertyRelease *release;
+};
+
+extern hostdevPropertyInfo hostdev_prop_int32;
+extern hostdevPropertyInfo hostdev_prop_string;
+extern hostdevPropertyInfo hostdev_prop_netdev;
+
+#define DEFINE_HOSTDEV_PROP(_name, _state, _field, _prop, _type) { \
+        .name      = (_name),                                    \
+        .info      = &(_prop),                                   \
+        .offset    = offsetof(_state, _field)                    \
+            + type_check(_type,typeof_field(_state, _field)),    \
+        }
+#define DEFINE_HOSTDEV_PROP_DEFAULT(_name, _state, _field, _defval, _prop, _type) { \
+        .name      = (_name),                                           \
+        .info      = &(_prop),                                          \
+        .offset    = offsetof(_state, _field)                           \
+            + type_check(_type,typeof_field(_state, _field)),           \
+        .qtype     = QTYPE_QINT,                                        \
+        .defval    = (_type)_defval,                                    \
+        }
+#define DEFINE_HOSTDEV_PROP_END_OF_LIST()               \
+    {}
+#define DEFINE_HOSTDEV_PROP_INT32(_n, _s, _f, _d)              \
+    DEFINE_HOSTDEV_PROP_DEFAULT(_n, _s, _f, _d, hostdev_prop_int32, int32_t)
+#define DEFINE_HOSTDEV_PROP_PEER(_n, _s, _f)             \
+    DEFINE_HOSTDEV_PROP(_n, _s, _f, hostdev_prop_netdev, NetClientState*)
+#define DEFINE_HOSTDEV_PROP_STRING(_n, _s, _f)             \
+    DEFINE_HOSTDEV_PROP(_n, _s, _f, hostdev_prop_string, char*)
+
+HOSTDevice *hostdev_device_create(const char *type);
+int hostdev_device_init(HOSTDevice *dev, const char *type, const char *id);
+void hostdev_prop_set_string(HOSTDevice *dev,
+                             const char *name, char *value);
+void hostdev_prop_set_peer(HOSTDevice *dev,
+                           const char *name, NetClientState *value);
+
+#endif
diff --git a/qom/Makefile b/qom/Makefile
index 34c6de5..4731fb9 100644
--- a/qom/Makefile
+++ b/qom/Makefile
@@ -1,2 +1,2 @@
 qom-y = object.o container.o qom-qobject.o
-qom-twice-y = cpu.o
+qom-twice-y = cpu.o hostdev.o
diff --git a/qom/hostdev.c b/qom/hostdev.c
new file mode 100644
index 0000000..867e869
--- /dev/null
+++ b/qom/hostdev.c
@@ -0,0 +1,333 @@
+/*
+ * QEMU host device model
+ *
+ * Copyright IBM, Corp. 2012
+ *
+ * Authors:
+ *  Zhi Yong Wu   <wuzhy@linux.vnet.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#include "qemu/hostdev.h"
+#include "qemu-common.h"
+#include "net.h"
+
+void hostdev_prop_set_string(HOSTDevice *dev,
+                             const char *name, char *value)
+{
+    Error *errp = NULL;
+    object_property_set_str(OBJECT(dev), value, name, &errp);
+    assert_no_error(errp);
+}
+
+void hostdev_prop_set_peer(HOSTDevice *dev,
+                           const char *name, NetClientState *value)
+{
+    Error *errp = NULL;
+    assert(!value || value->name);
+    object_property_set_str(OBJECT(dev),
+                            value ? value->name : "", name, &errp);
+    assert_no_error(errp);
+}
+
+static Object *hostdev_get_hostdev(void)
+{
+    static Object *dev;
+
+    if (dev == NULL) {
+        dev = object_new("container");
+        object_property_add_child(object_get_root(), "hostdev",
+                                  OBJECT(dev), NULL);
+    }
+
+    return dev;
+}
+
+HOSTDevice *hostdev_device_create(const char *type)
+{
+    HOSTDevice *hostdev;
+
+    hostdev = HOST_DEVICE(object_new(type));
+    if (!hostdev) {
+        return NULL;
+    }
+
+    return hostdev;
+}
+
+int hostdev_device_init(HOSTDevice *dev, const char *type, const char *id)
+{
+    HOSTDeviceClass *dc = HOSTDEV_GET_CLASS(dev);
+    gchar *dev_id;
+    int rc;
+
+    rc = dc->init(dev);
+    if (rc < 0) {
+        object_delete(OBJECT(dev));
+        return rc;
+    }
+
+    if (id) {
+        dev_id = g_strdup(id);
+    } else {
+        static int anon_count;
+        dev_id = g_strdup_printf("%s[%d]", (char *)type, anon_count++);
+    }
+
+    object_property_add_child(hostdev_get_hostdev(), dev_id,
+                              OBJECT(dev), NULL);
+    g_free(dev_id);
+
+    return 0;
+}
+
+static void *hostdev_get_prop_ptr(HOSTDevice *dev, hostdevProperty *prop)
+{
+    void *ptr = dev;
+    ptr += prop->offset;
+    return ptr;
+}
+
+static void error_set_from_hostdev_prop_error(Error **errp, int ret,
+                                              HOSTDevice *dev, hostdevProperty *prop,
+                                              const char *value)
+{
+    switch (ret) {
+    case -EEXIST:
+        error_set(errp, QERR_PROPERTY_VALUE_IN_USE,
+                  object_get_typename(OBJECT(dev)), prop->name, value);
+        break;
+    default:
+    case -EINVAL:
+        error_set(errp, QERR_PROPERTY_VALUE_BAD,
+                  object_get_typename(OBJECT(dev)), prop->name, value);
+        break;
+    case -ENOENT:
+        error_set(errp, QERR_PROPERTY_VALUE_NOT_FOUND,
+                  object_get_typename(OBJECT(dev)), prop->name, value);
+        break;
+    case 0:
+        break;
+    }
+}
+
+/* --- netdev device --- */
+static void get_pointer(Object *obj, Visitor *v, hostdevProperty *prop,
+                        const char *(*print)(void *ptr),
+                        const char *name, Error **errp)
+{
+    HOSTDevice *dev = HOST_DEVICE(obj);
+    void **ptr = hostdev_get_prop_ptr(dev, prop);
+    char *p;
+
+    p = (char *) (*ptr ? print(*ptr) : "");
+    visit_type_str(v, &p, name, errp);
+}
+
+static void set_pointer(Object *obj, Visitor *v, hostdevProperty *prop,
+                        int (*parse)(HOSTDevice *dev, const char *str, void **ptr),
+                        const char *name, Error **errp)
+{
+    HOSTDevice *dev = HOST_DEVICE(obj);
+    Error *local_err = NULL;
+    void **ptr = hostdev_get_prop_ptr(dev, prop);
+    char *str;
+    int ret;
+
+    visit_type_str(v, &str, name, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
+    }
+    if (!*str) {
+        g_free(str);
+        *ptr = NULL;
+        return;
+    }
+    ret = parse(dev, str, ptr);
+    error_set_from_hostdev_prop_error(errp, ret, dev, prop, str);
+    g_free(str);
+}
+
+/* --- 32bit integer --- */
+static void get_int32(Object *obj, Visitor *v, void *opaque,
+                      const char *name, Error **errp)
+{
+    HOSTDevice *dev = HOST_DEVICE(obj);
+    hostdevProperty *prop = opaque;
+    int32_t *ptr = hostdev_get_prop_ptr(dev, prop);
+    int64_t value;
+
+    value = *ptr;
+    visit_type_int(v, &value, name, errp);
+}
+
+static void set_int32(Object *obj, Visitor *v, void *opaque,
+                      const char *name, Error **errp)
+{
+    HOSTDevice *dev = HOST_DEVICE(obj);
+    hostdevProperty *prop = opaque;
+    int32_t *ptr = hostdev_get_prop_ptr(dev, prop);
+    Error *local_err = NULL;
+    int64_t value;
+
+    visit_type_int(v, &value, name, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
+    }
+    if (value >= prop->info->min && value <= prop->info->max) {
+        *ptr = value;
+    } else {
+        error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE,
+                  "", name, value, prop->info->min,
+                  prop->info->max);
+    }
+}
+
+hostdevPropertyInfo hostdev_prop_int32 = {
+    .name  = "int32",
+    .get   = get_int32,
+    .set   = set_int32,
+    .min   = -0x80000000LL,
+    .max   = 0x7FFFFFFFLL,
+};
+
+/* --- netdev --- */
+static int parse_netdev(HOSTDevice *dev, const char *str, void **ptr)
+{
+    NetClientState *netdev = qemu_find_netdev(str);
+
+    if (netdev == NULL) {
+        return -ENOENT;
+    }
+    if (netdev->peer) {
+        return -EEXIST;
+    }
+    *ptr = netdev;
+    return 0;
+}
+
+static const char *print_netdev(void *ptr)
+{
+    NetClientState *netdev = ptr;
+
+    return netdev->name ? netdev->name : "";
+}
+
+static void get_netdev(Object *obj, Visitor *v, void *opaque,
+                       const char *name, Error **errp)
+{
+    get_pointer(obj, v, opaque, print_netdev, name, errp);
+}
+
+static void set_netdev(Object *obj, Visitor *v, void *opaque,
+                       const char *name, Error **errp)
+{
+    set_pointer(obj, v, opaque, parse_netdev, name, errp);
+}
+
+hostdevPropertyInfo hostdev_prop_netdev = {
+    .name  = "peer",
+    .get   = get_netdev,
+    .set   = set_netdev,
+};
+
+/* --- string --- */
+static void release_string(Object *obj, const char *name, void *opaque)
+{
+    hostdevProperty *prop = opaque;
+    g_free(*(char **)hostdev_get_prop_ptr(HOST_DEVICE(obj), prop));
+}
+
+static void get_string(Object *obj, Visitor *v, void *opaque,
+                       const char *name, Error **errp)
+{
+    HOSTDevice *dev = HOST_DEVICE(obj);
+    hostdevProperty *prop = opaque;
+    char **ptr = hostdev_get_prop_ptr(dev, prop);
+
+    if (!*ptr) {
+        char *str = (char *)"";
+        visit_type_str(v, &str, name, errp);
+    } else {
+        visit_type_str(v, ptr, name, errp);
+    }
+}
+
+static void set_string(Object *obj, Visitor *v, void *opaque,
+                       const char *name, Error **errp)
+{
+    HOSTDevice *dev = HOST_DEVICE(obj);
+    hostdevProperty *prop = opaque;
+    char **ptr = hostdev_get_prop_ptr(dev, prop);
+    Error *local_err = NULL;
+    char *str;
+
+    visit_type_str(v, &str, name, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
+    }
+    if (*ptr) {
+        g_free(*ptr);
+    }
+    *ptr = str;
+}
+
+hostdevPropertyInfo hostdev_prop_string = {
+    .name  = "string",
+    .release = release_string,
+    .get   = get_string,
+    .set   = set_string,
+};
+/*
+static char *hostdev_get_type(Object *obj, Error **errp)
+{
+    return g_strdup(object_get_typename(obj));
+}
+*/
+static void hostdev_property_add_static(HOSTDevice *dev, hostdevProperty *prop,
+                                        Error **errp)
+{
+    if (!prop->info->get && !prop->info->set) {
+        return;
+    }
+
+    object_property_add(OBJECT(dev), prop->name, prop->info->name,
+                        prop->info->get, prop->info->set,
+                        prop->info->release,
+                        prop, errp);
+}
+
+static void hostdev_init(Object *obj)
+{
+    HOSTDevice *s = HOST_DEVICE(obj);
+    HOSTDeviceClass *dc = HOSTDEV_GET_CLASS(obj);
+    hostdevProperty *prop;
+
+    for (prop = dc->props; prop && prop->name; prop++) {
+        hostdev_property_add_static(s, prop, NULL);
+    }
+
+    //object_property_add_str(OBJECT(s), "type", hostdev_get_type, NULL, NULL);
+}
+
+static TypeInfo hostdev_type_info = {
+    .name          = TYPE_HOSTDEV,
+    .parent        = TYPE_OBJECT,
+    .instance_size = sizeof(HOSTDevice),
+    .instance_init = hostdev_init,
+    .abstract      = true,
+    .class_size    = sizeof(HOSTDeviceClass),
+};
+
+static void hostdev_register_types(void)
+{
+    type_register_static(&hostdev_type_info);
+}
+
+type_init(hostdev_register_types)
-- 
1.7.6

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

* [Qemu-devel] [PATCH] net: qomify -netdev
  2012-03-26  5:40 [Qemu-devel] [RFC 0/9] QOM: qomify -netdev zwu.kernel
  2012-03-26  5:40 ` [Qemu-devel] [RFC 1/9] hostdev: introduce the infrastructure for host device model zwu.kernel
@ 2012-03-26  5:40 ` zwu.kernel
  2012-03-26  5:40 ` zwu.kernel
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 38+ messages in thread
From: zwu.kernel @ 2012-03-26  5:40 UTC (permalink / raw)
  To: qemu-devel; +Cc: zwu.kernel, pbonzini, Zhi Yong Wu, stefanha

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

Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
---
 net.c        |   54 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 net.h        |    2 ++
 net/slirp.c  |   33 +++++++++++++++++++++++++++++++++
 net/slirp.h  |    1 +
 net/socket.c |   33 +++++++++++++++++++++++++++++----
 net/socket.h |    7 +++++--
 net/tap.c    |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 net/tap.h    |    1 +
 qom/Makefile |    2 +-
 vl.c         |   12 ++++++------
 10 files changed, 177 insertions(+), 14 deletions(-)

diff --git a/net.c b/net.c
index dd67d16..ee8737c 100644
--- a/net.c
+++ b/net.c
@@ -972,6 +972,58 @@ int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev)
     return -1;
 }
 
+static int net_client_netdev_init(Monitor *mon, QemuOpts *opts, int is_netdev)
+{
+    const char *name;
+    const char *type;
+
+    type = qemu_opt_get(opts, "type");
+    if (!type) {
+        qerror_report(QERR_MISSING_PARAMETER, "type");
+        return -1;
+    }
+
+    if (is_netdev) {
+        if (strcmp(type, "tap") != 0 &&
+#ifdef CONFIG_NET_BRIDGE
+            strcmp(type, "bridge") != 0 &&
+#endif
+#ifdef CONFIG_SLIRP
+            strcmp(type, "user") != 0 &&
+#endif
+#ifdef CONFIG_VDE
+            strcmp(type, "vde") != 0 &&
+#endif
+            strcmp(type, "socket") != 0) {
+            qerror_report(QERR_INVALID_PARAMETER_VALUE, "type",
+                          "a netdev backend type");
+            return -1;
+        }
+
+        if (qemu_opt_get(opts, "vlan")) {
+            qerror_report(QERR_INVALID_PARAMETER, "vlan");
+            return -1;
+        }
+        if (qemu_opt_get(opts, "name")) {
+            qerror_report(QERR_INVALID_PARAMETER, "name");
+            return -1;
+        }
+        if (!qemu_opts_id(opts)) {
+            qerror_report(QERR_MISSING_PARAMETER, "id");
+            return -1;
+        }
+    }
+
+    name = qemu_opts_id(opts);
+    if (!name) {
+        name = qemu_opt_get(opts, "name");
+    }
+
+    hostdev_device_add(mon, opts, (char *)name, NULL);
+
+    return 0;
+}
+
 static int net_host_check_device(const char *device)
 {
     int i;
@@ -1188,7 +1240,7 @@ static int net_init_client(QemuOpts *opts, void *dummy)
 
 static int net_init_netdev(QemuOpts *opts, void *dummy)
 {
-    return net_client_init(NULL, opts, 1);
+    return net_client_netdev_init(NULL, opts, 1);
 }
 
 int net_init_clients(void)
diff --git a/net.h b/net.h
index 60837ab..0926a42 100644
--- a/net.h
+++ b/net.h
@@ -7,6 +7,7 @@
 #include "qemu-option.h"
 #include "net/queue.h"
 #include "vmstate.h"
+#include "qemu/hostdev.h"
 
 struct MACAddr {
     uint8_t a[6];
@@ -61,6 +62,7 @@ typedef struct NetClientInfo {
 } NetClientInfo;
 
 struct NetClientState {
+    HOSTDevice host_dev;
     NetClientInfo *info;
     int link_down;
     QTAILQ_ENTRY(NetClientState) next;
diff --git a/net/slirp.c b/net/slirp.c
index d3e56fc..a30b4f0 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -777,3 +777,36 @@ int net_slirp_parse_legacy(QemuOptsList *opts_list, const char *optarg, int *ret
     return 1;
 }
 
+static hostdevProperty net_user_properties[] = {
+    //DEFINE_PROP_STRING("type", NetClientState, info->type),
+    DEFINE_HOSTDEV_PROP_INT32("link_down", NetClientState,link_down, 0),
+    DEFINE_HOSTDEV_PROP_PEER("peer", NetClientState, peer),
+    //DEFINE_PROP_STRING("model", NetClientState, model),
+    DEFINE_HOSTDEV_PROP_STRING("name", NetClientState, name),
+    //DEFINE_PROP_BIT("receive_disabled", NetClientState, receive_disabled, 0, true),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void net_user_class_init(ObjectClass *klass, void *data)
+{
+    HOSTDeviceClass *k = HOSTDEV_CLASS(klass);
+
+    k->init = net_init_slirp;
+    k->props = net_user_properties;
+}
+
+static TypeInfo net_user_type = {
+    .name          = "user",
+    .parent        = TYPE_HOSTDEV,
+    .instance_size = sizeof(NetClientState),
+    .class_init    = net_user_class_init,
+};
+
+static void net_user_register_types(void)
+{
+#ifdef CONFIG_SLIRP
+    type_register_static(&net_user_type);
+#endif
+}
+
+type_init(net_user_register_types)
diff --git a/net/slirp.h b/net/slirp.h
index e6000af..c6f5079 100644
--- a/net/slirp.h
+++ b/net/slirp.h
@@ -27,6 +27,7 @@
 #include "qemu-common.h"
 #include "qdict.h"
 #include "qemu-option.h"
+#include "qemu/hostdev.h"
 
 #ifdef CONFIG_SLIRP
 
diff --git a/net/socket.c b/net/socket.c
index 55d9820..778a5a3 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -31,6 +31,7 @@
 #include "qemu-error.h"
 #include "qemu-option.h"
 #include "qemu_socket.h"
+#include "qemu/hostdev.h"
 
 typedef struct NetSocketState {
     NetClientState nc;
@@ -587,10 +588,8 @@ static int net_socket_udp_init(NetClientState *peer,
     return 0;
 }
 
-int net_init_socket(QemuOpts *opts,
-                    Monitor *mon,
-                    const char *name,
-                    NetClientState *peer)
+int net_init_socket(QemuOpts *opts, Monitor *mon,
+                    const char *name, NetClientState *peer)
 {
     if (qemu_opt_get(opts, "fd")) {
         int fd;
@@ -690,3 +689,29 @@ int net_init_socket(QemuOpts *opts,
     }
     return 0;
 }
+
+static hostdevProperty net_socket_properties[] = {
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void net_socket_class_init(ObjectClass *klass, void *data)
+{
+    HOSTDeviceClass *k = HOSTDEV_CLASS(klass);
+
+    k->init = net_init_socket;
+    k->props = net_socket_properties;
+}
+
+static TypeInfo net_socket_type = {
+    .name          = "socket",
+    .parent        = TYPE_HOSTDEV,
+    .instance_size = sizeof(NetClientState),
+    .class_init    = net_socket_class_init,
+};
+
+static void net_socket_register_types(void)
+{
+    type_register_static(&net_socket_type);
+}
+
+type_init(net_socket_register_types)
diff --git a/net/socket.h b/net/socket.h
index 5edf17c..70d07cb 100644
--- a/net/socket.h
+++ b/net/socket.h
@@ -26,8 +26,11 @@
 
 #include "net.h"
 #include "qemu-common.h"
+#include "qemu/hostdev.h"
 
-int net_init_socket(QemuOpts *opts, Monitor *mon,
-                    const char *name, NetClientState *peer);
+int net_init_socket(QemuOpts *opts,
+                    Monitor *mon,
+                    const char *name,
+                    NetClientState *peer);
 
 #endif /* QEMU_NET_SOCKET_H */
diff --git a/net/tap.c b/net/tap.c
index 65f45b8..bd948db 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -715,3 +715,49 @@ VHostNetState *tap_get_vhost_net(NetClientState *nc)
     assert(nc->info->type == NET_CLIENT_TYPE_TAP);
     return s->vhost_net;
 }
+
+static hostdevProperty net_tap_properties[] = {
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void net_tap_class_init(ObjectClass *klass, void *data)
+{
+    HOSTDeviceClass *k = HOSTDEV_CLASS(klass);
+
+    k->init = net_init_tap;
+    k->props = net_tap_properties;
+}
+
+static TypeInfo net_tap_type = {
+    .name          = "tap",
+    .parent        = TYPE_HOSTDEV,
+    .instance_size = sizeof(NetClientState),
+    .class_init    = net_tap_class_init,
+};
+
+static hostdevProperty net_bridge_properties[] = {
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void net_bridge_class_init(ObjectClass *klass, void *data)
+{
+    HOSTDeviceClass *k = HOSTDEV_CLASS(klass);
+
+    k->init = net_init_bridge;
+    k->props = net_bridge_properties;
+}
+
+static TypeInfo net_bridge_type = {
+    .name          = "bridge",
+    .parent        = TYPE_HOSTDEV,
+    .instance_size = sizeof(NetClientState),
+    .class_init    = net_bridge_class_init,
+};
+
+static void net_tap_register_types(void)
+{
+    type_register_static(&net_tap_type);
+    type_register_static(&net_bridge_type);
+}
+
+type_init(net_tap_register_types)
diff --git a/net/tap.h b/net/tap.h
index 0e35e81..832aa08 100644
--- a/net/tap.h
+++ b/net/tap.h
@@ -28,6 +28,7 @@
 
 #include "qemu-common.h"
 #include "qemu-option.h"
+#include "qemu/hostdev.h"
 
 #define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"
 #define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown"
diff --git a/qom/Makefile b/qom/Makefile
index 34c6de5..4731fb9 100644
--- a/qom/Makefile
+++ b/qom/Makefile
@@ -1,2 +1,2 @@
 qom-y = object.o container.o qom-qobject.o
-qom-twice-y = cpu.o
+qom-twice-y = cpu.o hostdev.o
diff --git a/vl.c b/vl.c
index 112b0e0..0fa8e03 100644
--- a/vl.c
+++ b/vl.c
@@ -2299,8 +2299,6 @@ int main(int argc, char **argv, char **envp)
 #endif
     }
 
-    module_call_init(MODULE_INIT_QOM);
-
     runstate_init();
 
     init_clocks();
@@ -3381,10 +3379,6 @@ int main(int argc, char **argv, char **envp)
     }
     configure_icount(icount_option);
 
-    if (net_init_clients() < 0) {
-        exit(1);
-    }
-
     /* init the bluetooth world */
     if (foreach_device_config(DEV_BT, bt_parse))
         exit(1);
@@ -3474,6 +3468,8 @@ int main(int argc, char **argv, char **envp)
     if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0)
         exit(1);
 
+    module_call_init(MODULE_INIT_QOM);
+
     /* must be after qdev registration but before machine init */
     if (vga_model) {
         select_vgahw(vga_model);
@@ -3514,6 +3510,10 @@ int main(int argc, char **argv, char **envp)
             exit(1);
     }
 
+    if (net_init_clients() < 0) {
+        exit(1);
+    }
+
     /* init generic devices */
     if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, 1) != 0)
         exit(1);
-- 
1.7.6

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

* [Qemu-devel] [PATCH] net: qomify -netdev
  2012-03-26  5:40 [Qemu-devel] [RFC 0/9] QOM: qomify -netdev zwu.kernel
  2012-03-26  5:40 ` [Qemu-devel] [RFC 1/9] hostdev: introduce the infrastructure for host device model zwu.kernel
  2012-03-26  5:40 ` [Qemu-devel] [PATCH] net: qomify -netdev zwu.kernel
@ 2012-03-26  5:40 ` zwu.kernel
  2012-03-26  5:44   ` Zhi Yong Wu
  2012-03-26  5:40 ` [Qemu-devel] [RFC 2/9] net: introduce one net host device class zwu.kernel
                   ` (8 subsequent siblings)
  11 siblings, 1 reply; 38+ messages in thread
From: zwu.kernel @ 2012-03-26  5:40 UTC (permalink / raw)
  To: qemu-devel; +Cc: zwu.kernel, pbonzini, Zhi Yong Wu, stefanha

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

Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
---
 cpu-common.h      |   13 +++++++++-
 hw/qdev-monitor.c |    4 ++-
 hw/qdev.h         |    2 +
 net.c             |   62 +++++++++++++++++++++++++++++++++++++++++++++++-----
 net.h             |    5 ++++
 net/dump.c        |    6 ++++-
 net/dump.h        |   14 ++++++++++-
 net/slirp.c       |   35 +++++++++++++++++++++++++++++
 net/slirp.h       |   13 +++++++++++
 net/socket.c      |   53 ++++++++++++++++++++++++++++++++++++--------
 net/socket.h      |   18 +++++++++++++-
 net/tap-win32.c   |    8 +++++-
 net/tap.c         |   56 ++++++++++++++++++++++++++++++++++++++++++++++-
 net/tap.h         |   26 ++++++++++++++++++++-
 net/vde.c         |    4 ++-
 net/vde.h         |    3 +-
 qemu-log.h        |    6 ++--
 qemu-timer.c      |    2 +-
 qom/Makefile      |    2 +-
 qom/object.c      |    1 -
 vl.c              |   17 ++++++++------
 21 files changed, 304 insertions(+), 46 deletions(-)

diff --git a/cpu-common.h b/cpu-common.h
index dca5175..81279aa 100644
--- a/cpu-common.h
+++ b/cpu-common.h
@@ -3,9 +3,7 @@
 
 /* CPU interfaces that are target independent.  */
 
-#ifdef TARGET_PHYS_ADDR_BITS
 #include "targphys.h"
-#endif
 
 #ifndef NEED_CPU_H
 #include "poison.h"
@@ -23,6 +21,7 @@ enum device_endian {
 };
 
 /* address in the RAM (different from a physical address) */
+#define TARGET_PHYS_ADDR_BITS 64
 #if defined(CONFIG_XEN_BACKEND) && TARGET_PHYS_ADDR_BITS == 64
 typedef uint64_t ram_addr_t;
 #  define RAM_ADDR_MAX UINT64_MAX
@@ -35,6 +34,16 @@ typedef uintptr_t ram_addr_t;
 
 /* memory API */
 
+#if TARGET_PHYS_ADDR_BITS == 32
+typedef uint32_t target_phys_addr_t;
+#define TARGET_PHYS_ADDR_MAX UINT32_MAX
+#define TARGET_FMT_plx "%08x"
+#elif TARGET_PHYS_ADDR_BITS == 64
+typedef uint64_t target_phys_addr_t;
+#define TARGET_PHYS_ADDR_MAX UINT64_MAX
+#define TARGET_FMT_plx "%016" PRIx64
+#endif
+
 typedef void CPUWriteMemoryFunc(void *opaque, target_phys_addr_t addr, uint32_t value);
 typedef uint32_t CPUReadMemoryFunc(void *opaque, target_phys_addr_t addr);
 
diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c
index a310cc7..82d5c50 100644
--- a/hw/qdev-monitor.c
+++ b/hw/qdev-monitor.c
@@ -19,6 +19,7 @@
 
 #include "qdev.h"
 #include "monitor.h"
+#include "net.h"
 
 /*
  * Aliases were a bad idea from the start.  Let's keep them
@@ -97,6 +98,8 @@ static int set_property(const char *name, const char *value, void *opaque)
         return 0;
     if (strcmp(name, "bus") == 0)
         return 0;
+    if (strcmp(name, "type") == 0)
+        return 0;
 
     if (qdev_prop_parse(dev, name, value) == -1) {
         return -1;
@@ -480,7 +483,6 @@ DeviceState *qdev_device_add(QemuOpts *opts)
     return qdev;
 }
 
-
 #define qdev_printf(fmt, ...) monitor_printf(mon, "%*s" fmt, indent, "", ## __VA_ARGS__)
 static void qbus_print(Monitor *mon, BusState *bus, int indent);
 
diff --git a/hw/qdev.h b/hw/qdev.h
index c638b98..e0c8ffa 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -144,6 +144,8 @@ DeviceState *qdev_try_create(BusState *bus, const char *name);
 bool qdev_exists(const char *name);
 int qdev_device_help(QemuOpts *opts);
 DeviceState *qdev_device_add(QemuOpts *opts);
+void *qdev_hostdev_add(Monitor *mon, QemuOpts *opts,
+                       char *name, NetClientState *peer);
 int qdev_init(DeviceState *dev) QEMU_WARN_UNUSED_RESULT;
 void qdev_init_nofail(DeviceState *dev);
 void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
diff --git a/net.c b/net.c
index dd67d16..5e4f871 100644
--- a/net.c
+++ b/net.c
@@ -624,10 +624,7 @@ static int net_init_nic(QemuOpts *opts,
         .help = "identifier for monitor commands", \
      }
 
-typedef int NetClientInitFunc(QemuOpts *opts,
-                              Monitor *mon,
-                              const char *name,
-                              NetClientState *peer);
+typedef int NetClientInitFunc(QemuOpts *opts, Monitor *mon, const char *name, NetClientState *peer);
 
 /* magic number, but compiler will warn if too small */
 #define NET_MAX_DESC 20
@@ -972,6 +969,58 @@ int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev)
     return -1;
 }
 
+static int net_client_netdev_init(Monitor *mon, QemuOpts *opts, int is_netdev)
+{
+    const char *name;
+    const char *type;
+
+    type = qemu_opt_get(opts, "type");
+    if (!type) {
+        qerror_report(QERR_MISSING_PARAMETER, "type");
+        return -1;
+    }
+
+    if (is_netdev) {
+        if (strcmp(type, "tap") != 0 &&
+#ifdef CONFIG_NET_BRIDGE
+            strcmp(type, "bridge") != 0 &&
+#endif
+#ifdef CONFIG_SLIRP
+            strcmp(type, "user") != 0 &&
+#endif
+#ifdef CONFIG_VDE
+            strcmp(type, "vde") != 0 &&
+#endif
+            strcmp(type, "socket") != 0) {
+            qerror_report(QERR_INVALID_PARAMETER_VALUE, "type",
+                          "a netdev backend type");
+            return -1;
+        }
+
+        if (qemu_opt_get(opts, "vlan")) {
+            qerror_report(QERR_INVALID_PARAMETER, "vlan");
+            return -1;
+        }
+        if (qemu_opt_get(opts, "name")) {
+            qerror_report(QERR_INVALID_PARAMETER, "name");
+            return -1;
+        }
+        if (!qemu_opts_id(opts)) {
+            qerror_report(QERR_MISSING_PARAMETER, "id");
+            return -1;
+        }
+    }
+
+    name = qemu_opts_id(opts);
+    if (!name) {
+        name = qemu_opt_get(opts, "name");
+    }
+
+    hostdev_device_add(mon, opts, (char *)name, NULL);
+
+    return 0;
+}
+
 static int net_host_check_device(const char *device)
 {
     int i;
@@ -1188,7 +1237,7 @@ static int net_init_client(QemuOpts *opts, void *dummy)
 
 static int net_init_netdev(QemuOpts *opts, void *dummy)
 {
-    return net_client_init(NULL, opts, 1);
+    return net_client_netdev_init(NULL, opts, 1);
 }
 
 int net_init_clients(void)
@@ -1205,8 +1254,9 @@ int net_init_clients(void)
 
     QTAILQ_INIT(&net_clients);
 
-    if (qemu_opts_foreach(qemu_find_opts("netdev"), net_init_netdev, NULL, 1) == -1)
+    if (qemu_opts_foreach(qemu_find_opts("netdev"), net_init_netdev, NULL, 1) == -1) {
         return -1;
+    }
 
     if (qemu_opts_foreach(net, net_init_client, NULL, 1) == -1) {
         return -1;
diff --git a/net.h b/net.h
index 60837ab..69d93b1 100644
--- a/net.h
+++ b/net.h
@@ -6,7 +6,11 @@
 #include "qdict.h"
 #include "qemu-option.h"
 #include "net/queue.h"
+#include "hw/qdev.h"
 #include "vmstate.h"
+#include "hw/hw.h"
+#include "hw/pci.h"
+#include "qemu/hostdev.h"
 
 struct MACAddr {
     uint8_t a[6];
@@ -61,6 +65,7 @@ typedef struct NetClientInfo {
 } NetClientInfo;
 
 struct NetClientState {
+    HOSTDevice host_dev;
     NetClientInfo *info;
     int link_down;
     QTAILQ_ENTRY(NetClientState) next;
diff --git a/net/dump.c b/net/dump.c
index 0f191d3..9152b2e 100644
--- a/net/dump.c
+++ b/net/dump.c
@@ -29,12 +29,14 @@
 #include "qemu-timer.h"
 #include "hub.h"
 
+/*
 typedef struct DumpState {
     NetClientState nc;
     int64_t start_ts;
     int fd;
     int pcap_caplen;
 } DumpState;
+*/
 
 #define PCAP_MAGIC 0xa1b2c3d4
 
@@ -145,7 +147,9 @@ static int net_dump_init(NetClientState *peer, const char *device,
     return 0;
 }
 
-int net_init_dump(QemuOpts *opts, Monitor *mon, const char *name,
+int net_init_dump(QemuOpts *opts,
+                  Monitor *mon,
+                  const char *name,
                   NetClientState *peer)
 {
     int len;
diff --git a/net/dump.h b/net/dump.h
index df22afe..9066ff7 100644
--- a/net/dump.h
+++ b/net/dump.h
@@ -26,8 +26,18 @@
 
 #include "net.h"
 #include "qemu-common.h"
+#include "qemu/hostdev.h"
 
-int net_init_dump(QemuOpts *opts, Monitor *mon,
-                  const char *name, NetClientState *peer);
+typedef struct DumpState {
+    NetClientState nc;
+    int64_t start_ts;
+    int fd;
+    int pcap_caplen;
+} DumpState;
+
+int net_init_dump(QemuOpts *opts,
+                  Monitor *mon,
+                  const char *name,
+                  NetClientState *peer);
 
 #endif /* QEMU_NET_DUMP_H */
diff --git a/net/slirp.c b/net/slirp.c
index d3e56fc..0838fd5 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -66,6 +66,7 @@ struct slirp_config_str {
     int legacy_format;
 };
 
+/*
 typedef struct SlirpState {
     NetClientState nc;
     QTAILQ_ENTRY(SlirpState) entry;
@@ -74,6 +75,7 @@ typedef struct SlirpState {
     char smb_dir[128];
 #endif
 } SlirpState;
+*/
 
 static struct slirp_config_str *slirp_configs;
 const char *legacy_tftp_prefix;
@@ -777,3 +779,36 @@ int net_slirp_parse_legacy(QemuOptsList *opts_list, const char *optarg, int *ret
     return 1;
 }
 
+static hostdevProperty net_user_properties[] = {
+    //DEFINE_PROP_STRING("type", NetClientState, info->type),
+    DEFINE_HOSTDEV_PROP_INT32("link_down", NetClientState,link_down, 0),
+    DEFINE_HOSTDEV_PROP_PEER("peer", NetClientState, peer),
+    //DEFINE_PROP_STRING("model", NetClientState, model),
+    DEFINE_HOSTDEV_PROP_STRING("name", NetClientState, name),
+    //DEFINE_PROP_BIT("receive_disabled", NetClientState, receive_disabled, 0, true),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void net_user_class_init(ObjectClass *klass, void *data)
+{
+    HOSTDeviceClass *k = HOSTDEV_CLASS(klass);
+
+    k->init = net_init_slirp;
+    k->props = net_user_properties;
+}
+
+static TypeInfo net_user_type = {
+    .name          = "user",
+    .parent        = TYPE_HOSTDEV,
+    .instance_size = sizeof(NetClientState),
+    .class_init    = net_user_class_init,
+};
+
+static void net_user_register_types(void)
+{
+#ifdef CONFIG_SLIRP
+    type_register_static(&net_user_type);
+#endif
+}
+
+type_init(net_user_register_types)
diff --git a/net/slirp.h b/net/slirp.h
index e6000af..8a7622e 100644
--- a/net/slirp.h
+++ b/net/slirp.h
@@ -27,6 +27,19 @@
 #include "qemu-common.h"
 #include "qdict.h"
 #include "qemu-option.h"
+#include "qemu_socket.h"
+#include "slirp/libslirp.h"
+#include "net.h"
+#include "qemu/hostdev.h"
+
+typedef struct SlirpState {
+    NetClientState nc;
+    QTAILQ_ENTRY(SlirpState) entry;
+    Slirp *slirp;
+#ifndef _WIN32
+    char smb_dir[128];
+#endif
+} SlirpState;
 
 #ifdef CONFIG_SLIRP
 
diff --git a/net/socket.c b/net/socket.c
index 55d9820..4ea3e07 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -31,16 +31,17 @@
 #include "qemu-error.h"
 #include "qemu-option.h"
 #include "qemu_socket.h"
-
-typedef struct NetSocketState {
-    NetClientState nc;
-    int fd;
-    int state; /* 0 = getting length, 1 = getting data */
-    unsigned int index;
-    unsigned int packet_len;
-    uint8_t buf[4096];
-    struct sockaddr_in dgram_dst; /* contains inet host and port destination iff connectionless (SOCK_DGRAM) */
-} NetSocketState;
+#include "qemu/hostdev.h"
+
+//typedef struct NetSocketState {
+//    NetClientState nc;
+//    int fd;
+//    int state; /* 0 = getting length, 1 = getting data */
+//    unsigned int index;
+//    unsigned int packet_len;
+//    uint8_t buf[4096];
+//    struct sockaddr_in dgram_dst; /* contains inet host and port destination iff connectionless (SOCK_DGRAM) */
+//} NetSocketState;
 
 typedef struct NetSocketListenState {
     NetClientState *peer;
@@ -592,6 +593,12 @@ int net_init_socket(QemuOpts *opts,
                     const char *name,
                     NetClientState *peer)
 {
+/*
+    QemuOpts *opts = host_dev->opts;
+    Monitor *mon = host_dev->mon;
+    const char *name = strdup(host_dev->name);
+    NetClientState *peer = host_dev->peer;
+*/
     if (qemu_opt_get(opts, "fd")) {
         int fd;
 
@@ -690,3 +697,29 @@ int net_init_socket(QemuOpts *opts,
     }
     return 0;
 }
+
+static hostdevProperty net_socket_properties[] = {
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void net_socket_class_init(ObjectClass *klass, void *data)
+{
+    HOSTDeviceClass *k = HOSTDEV_CLASS(klass);
+
+    k->init = net_init_socket;
+    k->props = net_socket_properties;
+}
+
+static TypeInfo net_socket_type = {
+    .name          = "socket",
+    .parent        = TYPE_HOSTDEV,
+    .instance_size = sizeof(NetClientState),
+    .class_init    = net_socket_class_init,
+};
+
+static void net_socket_register_types(void)
+{
+    type_register_static(&net_socket_type);
+}
+
+type_init(net_socket_register_types)
diff --git a/net/socket.h b/net/socket.h
index 5edf17c..128af01 100644
--- a/net/socket.h
+++ b/net/socket.h
@@ -26,8 +26,22 @@
 
 #include "net.h"
 #include "qemu-common.h"
+#include "qemu_socket.h"
+#include "qemu/hostdev.h"
 
-int net_init_socket(QemuOpts *opts, Monitor *mon,
-                    const char *name, NetClientState *peer);
+typedef struct NetSocketState {
+    NetClientState nc;
+    int fd;
+    int state; /* 0 = getting length, 1 = getting data */
+    unsigned int index;
+    unsigned int packet_len;
+    uint8_t buf[4096];
+    struct sockaddr_in dgram_dst; /* contains inet host and port destination iff connectionless (SOCK_DGRAM) */
+} NetSocketState;
+
+int net_init_socket(QemuOpts *opts,
+                    Monitor *mon,
+                    const char *name,
+                    NetClientState *peer);
 
 #endif /* QEMU_NET_SOCKET_H */
diff --git a/net/tap-win32.c b/net/tap-win32.c
index 3406717..fa17239 100644
--- a/net/tap-win32.c
+++ b/net/tap-win32.c
@@ -699,11 +699,15 @@ static int tap_win32_init(NetClientState *peer, const char *model,
     return 0;
 }
 
-int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name,
-                 NetClientState *peer)
+int net_init_tap(HOSTDevice *host_dev)
 {
     const char *ifname;
 
+    QemuOpts *opts = host_dev->opts;
+    Monitor *mon = host_dev->mon;
+    const char *name = strdup(host_dev->name);
+    NetClientState *peer = host_dev->peer;
+
     ifname = qemu_opt_get(opts, "ifname");
 
     if (!ifname) {
diff --git a/net/tap.c b/net/tap.c
index 65f45b8..f568c50 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -46,6 +46,7 @@
 /* Maximum GSO packet size (64k) plus plenty of room for
  * the ethernet and virtio_net headers
  */
+/*
 #define TAP_BUFSIZE (4096 + 65536)
 
 typedef struct TAPState {
@@ -61,6 +62,7 @@ typedef struct TAPState {
     VHostNetState *vhost_net;
     unsigned host_vnet_hdr_len;
 } TAPState;
+*/
 
 static int launch_script(const char *setup_script, const char *ifname, int fd);
 
@@ -512,7 +514,9 @@ static int net_bridge_run_helper(const char *helper, const char *bridge)
     return -1;
 }
 
-int net_init_bridge(QemuOpts *opts, Monitor *mon, const char *name,
+int net_init_bridge(QemuOpts *opts,
+                    Monitor *mon,
+                    const char *name,
                     NetClientState *peer)
 {
     TAPState *s;
@@ -583,7 +587,9 @@ static int net_tap_init(QemuOpts *opts, int *vnet_hdr)
     return fd;
 }
 
-int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name,
+int net_init_tap(QemuOpts *opts,
+                 Monitor *mon,
+                 const char *name,
                  NetClientState *peer)
 {
     TAPState *s;
@@ -715,3 +721,49 @@ VHostNetState *tap_get_vhost_net(NetClientState *nc)
     assert(nc->info->type == NET_CLIENT_TYPE_TAP);
     return s->vhost_net;
 }
+
+static hostdevProperty net_tap_properties[] = {
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void net_tap_class_init(ObjectClass *klass, void *data)
+{
+    HOSTDeviceClass *k = HOSTDEV_CLASS(klass);
+
+    k->init = net_init_tap;
+    k->props = net_tap_properties;
+}
+
+static TypeInfo net_tap_type = {
+    .name          = "tap",
+    .parent        = TYPE_HOSTDEV,
+    .instance_size = sizeof(NetClientState),
+    .class_init    = net_tap_class_init,
+};
+
+static hostdevProperty net_bridge_properties[] = {
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void net_bridge_class_init(ObjectClass *klass, void *data)
+{
+    HOSTDeviceClass *k = HOSTDEV_CLASS(klass);
+
+    k->init = net_init_bridge;
+    k->props = net_bridge_properties;
+}
+
+static TypeInfo net_bridge_type = {
+    .name          = "bridge",
+    .parent        = TYPE_HOSTDEV,
+    .instance_size = sizeof(NetClientState),
+    .class_init    = net_bridge_class_init,
+};
+
+static void net_tap_register_types(void)
+{
+    type_register_static(&net_tap_type);
+    type_register_static(&net_bridge_type);
+}
+
+type_init(net_tap_register_types)
diff --git a/net/tap.h b/net/tap.h
index 0e35e81..a687d9a 100644
--- a/net/tap.h
+++ b/net/tap.h
@@ -28,11 +28,31 @@
 
 #include "qemu-common.h"
 #include "qemu-option.h"
+#include "hw/vhost_net.h"
+#include "qemu/hostdev.h"
 
 #define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"
 #define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown"
 
-int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name,
+#define TAP_BUFSIZE (4096 + 65536)
+
+typedef struct TAPState {
+    NetClientState nc;
+    int fd;
+    char down_script[1024];
+    char down_script_arg[128];
+    uint8_t buf[TAP_BUFSIZE];
+    unsigned int read_poll : 1;
+    unsigned int write_poll : 1;
+    unsigned int using_vnet_hdr : 1;
+    unsigned int has_ufo: 1;
+    VHostNetState *vhost_net;
+    unsigned host_vnet_hdr_len;
+} TAPState;
+
+int net_init_tap(QemuOpts *opts,
+                 Monitor *mon,
+                 const char *name,
                  NetClientState *peer);
 
 int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required);
@@ -58,7 +78,9 @@ int tap_get_fd(NetClientState *nc);
 struct vhost_net;
 struct vhost_net *tap_get_vhost_net(NetClientState *nc);
 
-int net_init_bridge(QemuOpts *opts, Monitor *mon, const char *name,
+int net_init_bridge(QemuOpts *opts,
+                    Monitor *mon,
+                    const char *name,
                     NetClientState *peer);
 
 #endif /* QEMU_NET_TAP_H */
diff --git a/net/vde.c b/net/vde.c
index 8d9e1c6..5b06f67 100644
--- a/net/vde.c
+++ b/net/vde.c
@@ -110,7 +110,9 @@ static int net_vde_init(NetClientState *peer, const char *model,
     return 0;
 }
 
-int net_init_vde(QemuOpts *opts, Monitor *mon, const char *name,
+int net_init_vde(QemuOpts *opts,
+                 Monitor *mon,
+                 const char *name,
                  NetClientState *peer)
 {
     const char *sock;
diff --git a/net/vde.h b/net/vde.h
index 276e1ff..4400fa5 100644
--- a/net/vde.h
+++ b/net/vde.h
@@ -29,8 +29,7 @@
 
 #ifdef CONFIG_VDE
 
-int net_init_vde(QemuOpts *opts, Monitor *mon, const char *name,
-                 NetClientState *peer);
+int net_init_vde(HOSTDevice *host_dev);
 
 #endif /* CONFIG_VDE */
 
diff --git a/qemu-log.h b/qemu-log.h
index fccfb110..611f796 100644
--- a/qemu-log.h
+++ b/qemu-log.h
@@ -51,9 +51,9 @@ extern int loglevel;
 /* Special cases: */
 
 /* cpu_dump_state() logging functions: */
-#define log_cpu_state(env, f) cpu_dump_state((env), logfile, fprintf, (f));
-#define log_cpu_state_mask(b, env, f) do {           \
-      if (loglevel & (b)) log_cpu_state((env), (f)); \
+#define log_cpu_state(env1, f) cpu_dump_state((env1), logfile, fprintf, (f));
+#define log_cpu_state_mask(b, env1, f) do {           \
+      if (loglevel & (b)) log_cpu_state((env1), (f)); \
   } while (0)
 
 /* disas() and target_disas() to logfile: */
diff --git a/qemu-timer.c b/qemu-timer.c
index d7f56e5..8e48483 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -23,7 +23,7 @@
  */
 
 #include "sysemu.h"
-#include "net.h"
+//#include "net.h"
 #include "monitor.h"
 #include "console.h"
 
diff --git a/qom/Makefile b/qom/Makefile
index 34c6de5..4731fb9 100644
--- a/qom/Makefile
+++ b/qom/Makefile
@@ -1,2 +1,2 @@
 qom-y = object.o container.o qom-qobject.o
-qom-twice-y = cpu.o
+qom-twice-y = cpu.o hostdev.o
diff --git a/qom/object.c b/qom/object.c
index 9cd9506..6f60426 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -101,7 +101,6 @@ TypeImpl *type_register(const TypeInfo *info)
     g_assert(info->name != NULL);
 
     if (type_table_lookup(info->name) != NULL) {
-        fprintf(stderr, "Registering `%s' which already exists\n", info->name);
         abort();
     }
 
diff --git a/vl.c b/vl.c
index 112b0e0..5a3f425 100644
--- a/vl.c
+++ b/vl.c
@@ -2299,8 +2299,6 @@ int main(int argc, char **argv, char **envp)
 #endif
     }
 
-    module_call_init(MODULE_INIT_QOM);
-
     runstate_init();
 
     init_clocks();
@@ -3381,10 +3379,6 @@ int main(int argc, char **argv, char **envp)
     }
     configure_icount(icount_option);
 
-    if (net_init_clients() < 0) {
-        exit(1);
-    }
-
     /* init the bluetooth world */
     if (foreach_device_config(DEV_BT, bt_parse))
         exit(1);
@@ -3474,6 +3468,8 @@ int main(int argc, char **argv, char **envp)
     if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0)
         exit(1);
 
+    module_call_init(MODULE_INIT_QOM);
+
     /* must be after qdev registration but before machine init */
     if (vga_model) {
         select_vgahw(vga_model);
@@ -3514,9 +3510,16 @@ int main(int argc, char **argv, char **envp)
             exit(1);
     }
 
+    if (net_init_clients() < 0) {
+printf("%s: net_init_clients failed\n", __func__);
+        exit(1);
+    }
+
     /* init generic devices */
-    if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, 1) != 0)
+    if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, 1) != 0) {
+printf("%s: device_init_func failed\n", __func__);
         exit(1);
+    }
 
     net_check_clients();
 
-- 
1.7.6

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

* [Qemu-devel] [RFC 2/9] net: introduce one net host device class
  2012-03-26  5:40 [Qemu-devel] [RFC 0/9] QOM: qomify -netdev zwu.kernel
                   ` (2 preceding siblings ...)
  2012-03-26  5:40 ` zwu.kernel
@ 2012-03-26  5:40 ` zwu.kernel
  2012-03-27  8:30   ` Paolo Bonzini
  2012-03-26  5:40 ` [Qemu-devel] [RFC 3/9] net: adjust net common part for qomify -netdev zwu.kernel
                   ` (7 subsequent siblings)
  11 siblings, 1 reply; 38+ messages in thread
From: zwu.kernel @ 2012-03-26  5:40 UTC (permalink / raw)
  To: qemu-devel; +Cc: zwu.kernel, pbonzini, Zhi Yong Wu, stefanha

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

Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
---
 net.c |   35 +++++++++++++++++++++++++++++++++++
 net.h |   27 +++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 0 deletions(-)

diff --git a/net.c b/net.c
index dd67d16..608c090 100644
--- a/net.c
+++ b/net.c
@@ -1231,3 +1231,38 @@ int net_client_parse(QemuOptsList *opts_list, const char *optarg)
     default_net = 0;
     return 0;
 }
+
+static int net_dev_init(HOSTDevice *host_dev)
+{
+    NETDevice *net_dev = NET_DEVICE(host_dev);
+    NETDeviceClass *dc = NETDEV_GET_CLASS(host_dev);
+
+    if (dc->init) {
+        return dc->init(net_dev);
+    }
+
+    return 0;
+}
+
+static void net_class_init(ObjectClass *klass, void *data)
+{
+
+    HOSTDeviceClass *k = HOSTDEV_CLASS(klass);
+
+    k->init = net_dev_init;
+}
+
+static TypeInfo net_type = {
+    .name          = TYPE_NETDEV,
+    .parent        = TYPE_HOSTDEV,
+    .instance_size = sizeof(NETDevice),
+    .class_init    = net_class_init,
+};
+
+static void net_register_types(void)
+{
+    type_register_static(&net_type);
+}
+
+type_init(net_register_types)
+
diff --git a/net.h b/net.h
index 60837ab..912fa2d 100644
--- a/net.h
+++ b/net.h
@@ -7,6 +7,33 @@
 #include "qemu-option.h"
 #include "net/queue.h"
 #include "vmstate.h"
+#include "qemu/hostdev.h"
+
+typedef struct NETDevice NETDevice;
+
+#define TYPE_NETDEV "net-dev"
+#define NET_DEVICE(obj) \
+     OBJECT_CHECK(NETDevice, (obj), TYPE_NETDEV)
+#define NETDEV_CLASS(klass) \
+     OBJECT_CLASS_CHECK(NETDeviceClass, (klass), TYPE_NETDEV)
+#define NETDEV_GET_CLASS(obj) \
+     OBJECT_GET_CLASS(NETDeviceClass, (obj), TYPE_NETDEV)
+
+typedef struct NETDeviceClass {
+    HOSTDeviceClass parent_class;
+    int (*init)(NETDevice *net_dev);
+} NETDeviceClass;
+
+struct NETDevice {
+    /*< private >*/
+    HOSTDevice host_dev;
+
+    /*< public >*/
+    QemuOpts *opts;
+    Monitor *mon;
+    const char *name;
+    NetClientState *peer;
+};
 
 struct MACAddr {
     uint8_t a[6];
-- 
1.7.6

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

* [Qemu-devel] [RFC 3/9] net: adjust net common part for qomify -netdev
  2012-03-26  5:40 [Qemu-devel] [RFC 0/9] QOM: qomify -netdev zwu.kernel
                   ` (3 preceding siblings ...)
  2012-03-26  5:40 ` [Qemu-devel] [RFC 2/9] net: introduce one net host device class zwu.kernel
@ 2012-03-26  5:40 ` zwu.kernel
  2012-03-26  5:40 ` [Qemu-devel] [RFC 4/9] net: adjust nic init API zwu.kernel
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 38+ messages in thread
From: zwu.kernel @ 2012-03-26  5:40 UTC (permalink / raw)
  To: qemu-devel; +Cc: zwu.kernel, pbonzini, Zhi Yong Wu, stefanha

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

Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
---
 net.c |  108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 net.h |    1 +
 vl.c  |   12 +++---
 3 files changed, 109 insertions(+), 12 deletions(-)

diff --git a/net.c b/net.c
index 608c090..ff8ddaf 100644
--- a/net.c
+++ b/net.c
@@ -624,10 +624,7 @@ static int net_init_nic(QemuOpts *opts,
         .help = "identifier for monitor commands", \
      }
 
-typedef int NetClientInitFunc(QemuOpts *opts,
-                              Monitor *mon,
-                              const char *name,
-                              NetClientState *peer);
+typedef int NetClientInitFunc(NETDevice *host_dev);
 
 /* magic number, but compiler will warn if too small */
 #define NET_MAX_DESC 20
@@ -956,7 +953,13 @@ int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev)
 
             ret = 0;
             if (net_client_types[i].init) {
-                ret = net_client_types[i].init(opts, mon, name, peer);
+                NETDevice host_dev;
+                host_dev.mon = mon;
+                host_dev.opts = opts;
+                host_dev.name = g_strdup(name);
+                host_dev.peer = peer;
+                ret = net_client_types[i].init(&host_dev);
+                //ret = net_client_types[i].init(opts, mon, name, peer);
                 if (ret < 0) {
                     /* TODO push error reporting into init() methods */
                     qerror_report(QERR_DEVICE_INIT_FAILED, type);
@@ -972,6 +975,99 @@ int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev)
     return -1;
 }
 
+static bool netdev_device_add(Monitor *mon,
+                              QemuOpts *opts,
+                              const char *name,
+                              NetClientState *peer)
+{
+    const char *type, *id;
+    NETDevice *net_dev;
+    HOSTDevice *host_dev;
+
+    type = qemu_opt_get(opts, "type");
+    if (!type) {
+        qerror_report(QERR_MISSING_PARAMETER, "type");
+        return false;
+    }
+
+    host_dev = hostdev_device_create(type);
+    if (!host_dev) {
+        return false;
+    }
+
+    net_dev = NET_DEVICE(host_dev);
+    net_dev->mon = mon;
+    net_dev->opts = opts;
+    net_dev->name = g_strdup(name);
+    net_dev->peer = peer;
+
+    hostdev_prop_set_peer(&net_dev->host_dev, "peer", peer);
+    //hostdev_prop_set_string(&net_dev->host_dev, "name", g_strdup(name));
+    //hostdev_prop_set_string(&net_dev->host_dev, "model", g_strdup(model));
+    //hostdev_prop_set_bit(&net_dev->host_dev, "receive_disabled", receive_disabled);
+
+    id = qemu_opts_id(opts);
+    if (hostdev_device_init(&net_dev->host_dev, type, id)) {
+        return false;
+    }
+
+    return true;
+}
+
+static int net_client_netdev_init(Monitor *mon, QemuOpts *opts, int is_netdev)
+{
+    const char *name;
+    const char *type;
+
+    type = qemu_opt_get(opts, "type");
+    if (!type) {
+        qerror_report(QERR_MISSING_PARAMETER, "type");
+        return -1;
+    }
+
+    if (is_netdev) {
+        if (strcmp(type, "tap") != 0 &&
+#ifdef CONFIG_NET_BRIDGE
+            strcmp(type, "bridge") != 0 &&
+#endif
+#ifdef CONFIG_SLIRP
+            strcmp(type, "user") != 0 &&
+#endif
+#ifdef CONFIG_VDE
+            strcmp(type, "vde") != 0 &&
+#endif
+            strcmp(type, "socket") != 0) {
+            qerror_report(QERR_INVALID_PARAMETER_VALUE, "type",
+                          "a netdev backend type");
+            return -1;
+        }
+
+        if (qemu_opt_get(opts, "vlan")) {
+            qerror_report(QERR_INVALID_PARAMETER, "vlan");
+            return -1;
+        }
+        if (qemu_opt_get(opts, "name")) {
+            qerror_report(QERR_INVALID_PARAMETER, "name");
+            return -1;
+        }
+        if (!qemu_opts_id(opts)) {
+            qerror_report(QERR_MISSING_PARAMETER, "id");
+            return -1;
+        }
+    }
+
+    name = qemu_opts_id(opts);
+    if (!name) {
+        name = qemu_opt_get(opts, "name");
+    }
+
+    if (!netdev_device_add(mon, opts, (char *)name, NULL)) {
+        return -1;
+    }
+
+    return 0;
+}
+
 static int net_host_check_device(const char *device)
 {
     int i;
@@ -1188,7 +1284,7 @@ static int net_init_client(QemuOpts *opts, void *dummy)
 
 static int net_init_netdev(QemuOpts *opts, void *dummy)
 {
-    return net_client_init(NULL, opts, 1);
+    return net_client_netdev_init(NULL, opts, 1);
 }
 
 int net_init_clients(void)
diff --git a/net.h b/net.h
index 912fa2d..3de60d4 100644
--- a/net.h
+++ b/net.h
@@ -88,6 +88,7 @@ typedef struct NetClientInfo {
 } NetClientInfo;
 
 struct NetClientState {
+    NETDevice net_dev;
     NetClientInfo *info;
     int link_down;
     QTAILQ_ENTRY(NetClientState) next;
diff --git a/vl.c b/vl.c
index 112b0e0..0fa8e03 100644
--- a/vl.c
+++ b/vl.c
@@ -2299,8 +2299,6 @@ int main(int argc, char **argv, char **envp)
 #endif
     }
 
-    module_call_init(MODULE_INIT_QOM);
-
     runstate_init();
 
     init_clocks();
@@ -3381,10 +3379,6 @@ int main(int argc, char **argv, char **envp)
     }
     configure_icount(icount_option);
 
-    if (net_init_clients() < 0) {
-        exit(1);
-    }
-
     /* init the bluetooth world */
     if (foreach_device_config(DEV_BT, bt_parse))
         exit(1);
@@ -3474,6 +3468,8 @@ int main(int argc, char **argv, char **envp)
     if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0)
         exit(1);
 
+    module_call_init(MODULE_INIT_QOM);
+
     /* must be after qdev registration but before machine init */
     if (vga_model) {
         select_vgahw(vga_model);
@@ -3514,6 +3510,10 @@ int main(int argc, char **argv, char **envp)
             exit(1);
     }
 
+    if (net_init_clients() < 0) {
+        exit(1);
+    }
+
     /* init generic devices */
     if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, 1) != 0)
         exit(1);
-- 
1.7.6

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

* [Qemu-devel] [RFC 4/9] net: adjust nic init API
  2012-03-26  5:40 [Qemu-devel] [RFC 0/9] QOM: qomify -netdev zwu.kernel
                   ` (4 preceding siblings ...)
  2012-03-26  5:40 ` [Qemu-devel] [RFC 3/9] net: adjust net common part for qomify -netdev zwu.kernel
@ 2012-03-26  5:40 ` zwu.kernel
  2012-03-26  5:40 ` [Qemu-devel] [RFC 5/9] net: adjust dump " zwu.kernel
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 38+ messages in thread
From: zwu.kernel @ 2012-03-26  5:40 UTC (permalink / raw)
  To: qemu-devel; +Cc: zwu.kernel, pbonzini, Zhi Yong Wu, stefanha

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

Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
---
 net.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/net.c b/net.c
index ff8ddaf..22ed51b 100644
--- a/net.c
+++ b/net.c
@@ -549,15 +549,17 @@ int net_handle_fd_param(Monitor *mon, const char *param)
     return fd;
 }
 
-static int net_init_nic(QemuOpts *opts,
-                        Monitor *mon,
-                        const char *name,
-                        NetClientState *peer)
+static int net_init_nic(NETDevice *host_dev)
 {
     int idx;
     NICInfo *nd;
     const char *netdev;
 
+    QemuOpts *opts = host_dev->opts;
+    //Monitor *mon = host_dev->mon;
+    char *name = g_strdup(host_dev->name);
+    NetClientState *peer = host_dev->peer;
+
     idx = nic_get_free_idx();
     if (idx == -1 || nb_nics >= MAX_NICS) {
         error_report("Too Many NICs");
-- 
1.7.6

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

* [Qemu-devel] [RFC 5/9] net: adjust dump init API
  2012-03-26  5:40 [Qemu-devel] [RFC 0/9] QOM: qomify -netdev zwu.kernel
                   ` (5 preceding siblings ...)
  2012-03-26  5:40 ` [Qemu-devel] [RFC 4/9] net: adjust nic init API zwu.kernel
@ 2012-03-26  5:40 ` zwu.kernel
  2012-03-26  5:40 ` [Qemu-devel] [RFC 6/9] net: qomify -netdev user zwu.kernel
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 38+ messages in thread
From: zwu.kernel @ 2012-03-26  5:40 UTC (permalink / raw)
  To: qemu-devel; +Cc: zwu.kernel, pbonzini, Zhi Yong Wu, stefanha

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

Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
---
 net/dump.c |    8 ++++++--
 net/dump.h |    3 +--
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/net/dump.c b/net/dump.c
index 0f191d3..16e6efc 100644
--- a/net/dump.c
+++ b/net/dump.c
@@ -145,13 +145,17 @@ static int net_dump_init(NetClientState *peer, const char *device,
     return 0;
 }
 
-int net_init_dump(QemuOpts *opts, Monitor *mon, const char *name,
-                  NetClientState *peer)
+int net_init_dump(NETDevice *net_dev)
 {
     int len;
     const char *file;
     char def_file[128];
 
+    QemuOpts *opts = net_dev->opts;
+    //Monitor *mon = net_dev->mon;
+    char *name = g_strdup(net_dev->name);
+    NetClientState *peer = net_dev->peer;
+
     assert(peer);
 
     file = qemu_opt_get(opts, "file");
diff --git a/net/dump.h b/net/dump.h
index df22afe..4bccdcf 100644
--- a/net/dump.h
+++ b/net/dump.h
@@ -27,7 +27,6 @@
 #include "net.h"
 #include "qemu-common.h"
 
-int net_init_dump(QemuOpts *opts, Monitor *mon,
-                  const char *name, NetClientState *peer);
+int net_init_dump(NETDevice *net_dev);
 
 #endif /* QEMU_NET_DUMP_H */
-- 
1.7.6

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

* [Qemu-devel] [RFC 6/9] net: qomify -netdev user
  2012-03-26  5:40 [Qemu-devel] [RFC 0/9] QOM: qomify -netdev zwu.kernel
                   ` (6 preceding siblings ...)
  2012-03-26  5:40 ` [Qemu-devel] [RFC 5/9] net: adjust dump " zwu.kernel
@ 2012-03-26  5:40 ` zwu.kernel
  2012-03-26  5:40 ` [Qemu-devel] [RFC 7/9] net: qomify -netdev socket zwu.kernel
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 38+ messages in thread
From: zwu.kernel @ 2012-03-26  5:40 UTC (permalink / raw)
  To: qemu-devel; +Cc: zwu.kernel, pbonzini, Zhi Yong Wu, stefanha

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

Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
---
 net/slirp.c |   42 ++++++++++++++++++++++++++++++++++++++----
 net/slirp.h |    7 +++----
 2 files changed, 41 insertions(+), 8 deletions(-)

diff --git a/net/slirp.c b/net/slirp.c
index d3e56fc..62fea09 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -676,10 +676,7 @@ static int net_init_slirp_configs(const char *name, const char *value, void *opa
     return 0;
 }
 
-int net_init_slirp(QemuOpts *opts,
-                   Monitor *mon,
-                   const char *name,
-                   NetClientState *peer)
+int net_init_slirp(NETDevice *net_dev)
 {
     struct slirp_config_str *config;
     const char *vhost;
@@ -695,6 +692,11 @@ int net_init_slirp(QemuOpts *opts,
     int restricted = 0;
     int ret;
 
+    QemuOpts *opts = net_dev->opts;
+    //Monitor *mon = net_dev->mon;
+    char *name = g_strdup(net_dev->name);
+    NetClientState *peer = net_dev->peer;
+
     vhost       = qemu_opt_get(opts, "host");
     vhostname   = qemu_opt_get(opts, "hostname");
     vdhcp_start = qemu_opt_get(opts, "dhcpstart");
@@ -777,3 +779,35 @@ int net_slirp_parse_legacy(QemuOptsList *opts_list, const char *optarg, int *ret
     return 1;
 }
 
+static hostdevProperty net_user_properties[] = {
+    //DEFINE_HOSTDEV_PROP_INT32("link_down", NetClientState,link_down, 0),
+    DEFINE_HOSTDEV_PROP_PEER("peer", NetClientState, peer),
+    DEFINE_HOSTDEV_PROP_STRING("name", NetClientState, name),
+    //DEFINE_HOSTDEV_PROP_BIT("receive_disabled", NetClientState, receive_disabled, 0, true),
+    DEFINE_HOSTDEV_PROP_END_OF_LIST(),
+};
+
+static void net_user_class_init(ObjectClass *klass, void *data)
+{
+    NETDeviceClass *k = NETDEV_CLASS(klass);
+    HOSTDeviceClass *dc = HOSTDEV_CLASS(klass);
+
+    k->init = net_init_slirp;
+    dc->props = net_user_properties;
+}
+
+static TypeInfo net_user_type = {
+    .name          = "user",
+    .parent        = TYPE_NETDEV,
+    .instance_size = sizeof(NETDevice),
+    .class_init    = net_user_class_init,
+};
+
+static void net_user_register_types(void)
+{
+#ifdef CONFIG_SLIRP
+    type_register_static(&net_user_type);
+#endif
+}
+
+type_init(net_user_register_types)
diff --git a/net/slirp.h b/net/slirp.h
index e6000af..1364347 100644
--- a/net/slirp.h
+++ b/net/slirp.h
@@ -27,13 +27,12 @@
 #include "qemu-common.h"
 #include "qdict.h"
 #include "qemu-option.h"
+#include "qemu/hostdev.h"
+#include "net.h"
 
 #ifdef CONFIG_SLIRP
 
-int net_init_slirp(QemuOpts *opts,
-                   Monitor *mon,
-                   const char *name,
-                   NetClientState *peer);
+int net_init_slirp(NETDevice *net_dev);
 
 void net_slirp_hostfwd_add(Monitor *mon, const QDict *qdict);
 void net_slirp_hostfwd_remove(Monitor *mon, const QDict *qdict);
-- 
1.7.6

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

* [Qemu-devel] [RFC 7/9] net: qomify -netdev socket
  2012-03-26  5:40 [Qemu-devel] [RFC 0/9] QOM: qomify -netdev zwu.kernel
                   ` (7 preceding siblings ...)
  2012-03-26  5:40 ` [Qemu-devel] [RFC 6/9] net: qomify -netdev user zwu.kernel
@ 2012-03-26  5:40 ` zwu.kernel
  2012-03-26  5:40 ` [Qemu-devel] [RFC 8/9] net: qomify -netdev vde zwu.kernel
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 38+ messages in thread
From: zwu.kernel @ 2012-03-26  5:40 UTC (permalink / raw)
  To: qemu-devel; +Cc: zwu.kernel, pbonzini, Zhi Yong Wu, stefanha

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

Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
---
 net/socket.c |   38 ++++++++++++++++++++++++++++++++++----
 net/socket.h |    4 ++--
 2 files changed, 36 insertions(+), 6 deletions(-)

diff --git a/net/socket.c b/net/socket.c
index 55d9820..fe18e87 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -31,6 +31,7 @@
 #include "qemu-error.h"
 #include "qemu-option.h"
 #include "qemu_socket.h"
+#include "qemu/hostdev.h"
 
 typedef struct NetSocketState {
     NetClientState nc;
@@ -587,11 +588,13 @@ static int net_socket_udp_init(NetClientState *peer,
     return 0;
 }
 
-int net_init_socket(QemuOpts *opts,
-                    Monitor *mon,
-                    const char *name,
-                    NetClientState *peer)
+int net_init_socket(NETDevice *net_dev)
 {
+    QemuOpts *opts = net_dev->opts;
+    Monitor *mon = net_dev->mon;
+    char *name = g_strdup(net_dev->name);
+    NetClientState *peer = net_dev->peer;
+
     if (qemu_opt_get(opts, "fd")) {
         int fd;
 
@@ -690,3 +693,30 @@ int net_init_socket(QemuOpts *opts,
     }
     return 0;
 }
+
+static hostdevProperty net_socket_properties[] = {
+    DEFINE_HOSTDEV_PROP_END_OF_LIST(),
+};
+
+static void net_socket_class_init(ObjectClass *klass, void *data)
+{
+    NETDeviceClass *k = NETDEV_CLASS(klass);
+    HOSTDeviceClass *dc = HOSTDEV_CLASS(klass);
+
+    k->init = net_init_socket;
+    dc->props = net_socket_properties;
+}
+
+static TypeInfo net_socket_type = {
+    .name          = "socket",
+    .parent        = TYPE_NETDEV,
+    .instance_size = sizeof(NetClientState),
+    .class_init    = net_socket_class_init,
+};
+
+static void net_socket_register_types(void)
+{
+    type_register_static(&net_socket_type);
+}
+
+type_init(net_socket_register_types)
diff --git a/net/socket.h b/net/socket.h
index 5edf17c..1ac7c85 100644
--- a/net/socket.h
+++ b/net/socket.h
@@ -26,8 +26,8 @@
 
 #include "net.h"
 #include "qemu-common.h"
+#include "qemu/hostdev.h"
 
-int net_init_socket(QemuOpts *opts, Monitor *mon,
-                    const char *name, NetClientState *peer);
+int net_init_socket(NETDevice *net_dev);
 
 #endif /* QEMU_NET_SOCKET_H */
-- 
1.7.6

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

* [Qemu-devel] [RFC 8/9] net: qomify -netdev vde
  2012-03-26  5:40 [Qemu-devel] [RFC 0/9] QOM: qomify -netdev zwu.kernel
                   ` (8 preceding siblings ...)
  2012-03-26  5:40 ` [Qemu-devel] [RFC 7/9] net: qomify -netdev socket zwu.kernel
@ 2012-03-26  5:40 ` zwu.kernel
  2012-03-26  5:40 ` [Qemu-devel] [RFC 9/9] net: qomify -netdev tap & -netdev bridge zwu.kernel
  2012-03-26 11:54 ` [Qemu-devel] [RFC 0/9] QOM: qomify -netdev Stefan Hajnoczi
  11 siblings, 0 replies; 38+ messages in thread
From: zwu.kernel @ 2012-03-26  5:40 UTC (permalink / raw)
  To: qemu-devel; +Cc: zwu.kernel, pbonzini, Zhi Yong Wu, stefanha

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

Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
---
 net/vde.c |   34 ++++++++++++++++++++++++++++++++--
 net/vde.h |    4 ++--
 2 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/net/vde.c b/net/vde.c
index 8d9e1c6..c06716d 100644
--- a/net/vde.c
+++ b/net/vde.c
@@ -110,13 +110,17 @@ static int net_vde_init(NetClientState *peer, const char *model,
     return 0;
 }
 
-int net_init_vde(QemuOpts *opts, Monitor *mon, const char *name,
-                 NetClientState *peer)
+int net_init_vde(HOSTDevice *net_dev)
 {
     const char *sock;
     const char *group;
     int port, mode;
 
+    QemuOpts *opts = net_dev->opts;
+    Monitor *mon = net_dev->mon;
+    char *name = g_strdup(net_dev->name);
+    NetClientState *peer = net_dev->peer;
+
     sock  = qemu_opt_get(opts, "sock");
     group = qemu_opt_get(opts, "group");
 
@@ -129,3 +133,29 @@ int net_init_vde(QemuOpts *opts, Monitor *mon, const char *name,
 
     return 0;
 }
+
+static hostdevProperty net_vde_properties[] = {
+    DEFINE_HOSTDEV_PROP_END_OF_LIST(),
+};
+
+static void net_vde_class_init(ObjectClass *klass, void *data)
+{
+    HOSTDeviceClass *k = HOSTDEV_CLASS(klass);
+
+    k->init = net_init_vde;
+    k->props = net_vde_properties;
+}
+
+static TypeInfo net_vde_type = {
+    .name          = "vde",
+    .parent        = TYPE_HOSTDEV,
+    .instance_size = sizeof(NetClientState),
+    .class_init    = net_vde_class_init,
+};
+
+static void net_vde_register_types(void)
+{
+    type_register_static(&net_user_type);
+}
+
+type_init(net_vde_register_types)
diff --git a/net/vde.h b/net/vde.h
index 276e1ff..c99a3a9 100644
--- a/net/vde.h
+++ b/net/vde.h
@@ -26,11 +26,11 @@
 
 #include "qemu-common.h"
 #include "qemu-option.h"
+#include "qemu/hostdev.h"
 
 #ifdef CONFIG_VDE
 
-int net_init_vde(QemuOpts *opts, Monitor *mon, const char *name,
-                 NetClientState *peer);
+int net_init_vde(NETDevice *net_dev);
 
 #endif /* CONFIG_VDE */
 
-- 
1.7.6

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

* [Qemu-devel] [RFC 9/9] net: qomify -netdev tap & -netdev bridge
  2012-03-26  5:40 [Qemu-devel] [RFC 0/9] QOM: qomify -netdev zwu.kernel
                   ` (9 preceding siblings ...)
  2012-03-26  5:40 ` [Qemu-devel] [RFC 8/9] net: qomify -netdev vde zwu.kernel
@ 2012-03-26  5:40 ` zwu.kernel
  2012-03-26 11:54 ` [Qemu-devel] [RFC 0/9] QOM: qomify -netdev Stefan Hajnoczi
  11 siblings, 0 replies; 38+ messages in thread
From: zwu.kernel @ 2012-03-26  5:40 UTC (permalink / raw)
  To: qemu-devel; +Cc: zwu.kernel, pbonzini, Zhi Yong Wu, stefanha

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

Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
---
 net/tap.c |   64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 net/tap.h |    8 +++---
 2 files changed, 64 insertions(+), 8 deletions(-)

diff --git a/net/tap.c b/net/tap.c
index 65f45b8..81d022b 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -512,12 +512,16 @@ static int net_bridge_run_helper(const char *helper, const char *bridge)
     return -1;
 }
 
-int net_init_bridge(QemuOpts *opts, Monitor *mon, const char *name,
-                    NetClientState *peer)
+int net_init_bridge(NETDevice *net_dev)
 {
     TAPState *s;
     int fd, vnet_hdr;
 
+    QemuOpts *opts = net_dev->opts;
+    //Monitor *mon = net_dev->mon;
+    char *name = g_strdup(net_dev->name);
+    NetClientState *peer = net_dev->peer;
+
     if (!qemu_opt_get(opts, "br")) {
         qemu_opt_set(opts, "br", DEFAULT_BRIDGE_INTERFACE);
     }
@@ -583,13 +587,17 @@ static int net_tap_init(QemuOpts *opts, int *vnet_hdr)
     return fd;
 }
 
-int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name,
-                 NetClientState *peer)
+int net_init_tap(NETDevice *net_dev)
 {
     TAPState *s;
     int fd, vnet_hdr = 0;
     const char *model;
 
+    QemuOpts *opts = net_dev->opts;
+    Monitor *mon = net_dev->mon;
+    char *name = g_strdup(net_dev->name);
+    NetClientState *peer = net_dev->peer;
+
     if (qemu_opt_get(opts, "fd")) {
         if (qemu_opt_get(opts, "ifname") ||
             qemu_opt_get(opts, "script") ||
@@ -715,3 +723,51 @@ VHostNetState *tap_get_vhost_net(NetClientState *nc)
     assert(nc->info->type == NET_CLIENT_TYPE_TAP);
     return s->vhost_net;
 }
+
+static hostdevProperty net_tap_properties[] = {
+    DEFINE_HOSTDEV_PROP_END_OF_LIST(),
+};
+
+static void net_tap_class_init(ObjectClass *klass, void *data)
+{
+    NETDeviceClass *k = NETDEV_CLASS(klass);
+    HOSTDeviceClass *dc = HOSTDEV_CLASS(klass);
+
+    k->init = net_init_tap;
+    dc->props = net_tap_properties;
+}
+
+static TypeInfo net_tap_type = {
+    .name          = "tap",
+    .parent        = TYPE_NETDEV,
+    .instance_size = sizeof(NetClientState),
+    .class_init    = net_tap_class_init,
+};
+
+static hostdevProperty net_bridge_properties[] = {
+    DEFINE_HOSTDEV_PROP_END_OF_LIST(),
+};
+
+static void net_bridge_class_init(ObjectClass *klass, void *data)
+{
+    NETDeviceClass *k = NETDEV_CLASS(klass);
+    HOSTDeviceClass *dc = HOSTDEV_CLASS(klass);
+
+    k->init = net_init_bridge;
+    dc->props = net_bridge_properties;
+}
+
+static TypeInfo net_bridge_type = {
+    .name          = "bridge",
+    .parent        = TYPE_NETDEV,
+    .instance_size = sizeof(NetClientState),
+    .class_init    = net_bridge_class_init,
+};
+
+static void net_tap_register_types(void)
+{
+    type_register_static(&net_tap_type);
+    type_register_static(&net_bridge_type);
+}
+
+type_init(net_tap_register_types)
diff --git a/net/tap.h b/net/tap.h
index 0e35e81..5344d24 100644
--- a/net/tap.h
+++ b/net/tap.h
@@ -28,12 +28,13 @@
 
 #include "qemu-common.h"
 #include "qemu-option.h"
+#include "qemu/hostdev.h"
+#include "net.h"
 
 #define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"
 #define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown"
 
-int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name,
-                 NetClientState *peer);
+int net_init_tap(NETDevice *net_dev);
 
 int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required);
 
@@ -58,7 +59,6 @@ int tap_get_fd(NetClientState *nc);
 struct vhost_net;
 struct vhost_net *tap_get_vhost_net(NetClientState *nc);
 
-int net_init_bridge(QemuOpts *opts, Monitor *mon, const char *name,
-                    NetClientState *peer);
+int net_init_bridge(NETDevice *net_dev);
 
 #endif /* QEMU_NET_TAP_H */
-- 
1.7.6

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

* Re: [Qemu-devel] [PATCH] net: qomify -netdev
  2012-03-26  5:40 ` zwu.kernel
@ 2012-03-26  5:44   ` Zhi Yong Wu
  0 siblings, 0 replies; 38+ messages in thread
From: Zhi Yong Wu @ 2012-03-26  5:44 UTC (permalink / raw)
  To: qemu-devel

Sorry, pls ignore this patch

On Mon, Mar 26, 2012 at 1:40 PM,  <zwu.kernel@gmail.com> wrote:
> From: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
>
> Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
> ---
>  cpu-common.h      |   13 +++++++++-
>  hw/qdev-monitor.c |    4 ++-
>  hw/qdev.h         |    2 +
>  net.c             |   62 +++++++++++++++++++++++++++++++++++++++++++++++-----
>  net.h             |    5 ++++
>  net/dump.c        |    6 ++++-
>  net/dump.h        |   14 ++++++++++-
>  net/slirp.c       |   35 +++++++++++++++++++++++++++++
>  net/slirp.h       |   13 +++++++++++
>  net/socket.c      |   53 ++++++++++++++++++++++++++++++++++++--------
>  net/socket.h      |   18 +++++++++++++-
>  net/tap-win32.c   |    8 +++++-
>  net/tap.c         |   56 ++++++++++++++++++++++++++++++++++++++++++++++-
>  net/tap.h         |   26 ++++++++++++++++++++-
>  net/vde.c         |    4 ++-
>  net/vde.h         |    3 +-
>  qemu-log.h        |    6 ++--
>  qemu-timer.c      |    2 +-
>  qom/Makefile      |    2 +-
>  qom/object.c      |    1 -
>  vl.c              |   17 ++++++++------
>  21 files changed, 304 insertions(+), 46 deletions(-)
>
> diff --git a/cpu-common.h b/cpu-common.h
> index dca5175..81279aa 100644
> --- a/cpu-common.h
> +++ b/cpu-common.h
> @@ -3,9 +3,7 @@
>
>  /* CPU interfaces that are target independent.  */
>
> -#ifdef TARGET_PHYS_ADDR_BITS
>  #include "targphys.h"
> -#endif
>
>  #ifndef NEED_CPU_H
>  #include "poison.h"
> @@ -23,6 +21,7 @@ enum device_endian {
>  };
>
>  /* address in the RAM (different from a physical address) */
> +#define TARGET_PHYS_ADDR_BITS 64
>  #if defined(CONFIG_XEN_BACKEND) && TARGET_PHYS_ADDR_BITS == 64
>  typedef uint64_t ram_addr_t;
>  #  define RAM_ADDR_MAX UINT64_MAX
> @@ -35,6 +34,16 @@ typedef uintptr_t ram_addr_t;
>
>  /* memory API */
>
> +#if TARGET_PHYS_ADDR_BITS == 32
> +typedef uint32_t target_phys_addr_t;
> +#define TARGET_PHYS_ADDR_MAX UINT32_MAX
> +#define TARGET_FMT_plx "%08x"
> +#elif TARGET_PHYS_ADDR_BITS == 64
> +typedef uint64_t target_phys_addr_t;
> +#define TARGET_PHYS_ADDR_MAX UINT64_MAX
> +#define TARGET_FMT_plx "%016" PRIx64
> +#endif
> +
>  typedef void CPUWriteMemoryFunc(void *opaque, target_phys_addr_t addr, uint32_t value);
>  typedef uint32_t CPUReadMemoryFunc(void *opaque, target_phys_addr_t addr);
>
> diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c
> index a310cc7..82d5c50 100644
> --- a/hw/qdev-monitor.c
> +++ b/hw/qdev-monitor.c
> @@ -19,6 +19,7 @@
>
>  #include "qdev.h"
>  #include "monitor.h"
> +#include "net.h"
>
>  /*
>  * Aliases were a bad idea from the start.  Let's keep them
> @@ -97,6 +98,8 @@ static int set_property(const char *name, const char *value, void *opaque)
>         return 0;
>     if (strcmp(name, "bus") == 0)
>         return 0;
> +    if (strcmp(name, "type") == 0)
> +        return 0;
>
>     if (qdev_prop_parse(dev, name, value) == -1) {
>         return -1;
> @@ -480,7 +483,6 @@ DeviceState *qdev_device_add(QemuOpts *opts)
>     return qdev;
>  }
>
> -
>  #define qdev_printf(fmt, ...) monitor_printf(mon, "%*s" fmt, indent, "", ## __VA_ARGS__)
>  static void qbus_print(Monitor *mon, BusState *bus, int indent);
>
> diff --git a/hw/qdev.h b/hw/qdev.h
> index c638b98..e0c8ffa 100644
> --- a/hw/qdev.h
> +++ b/hw/qdev.h
> @@ -144,6 +144,8 @@ DeviceState *qdev_try_create(BusState *bus, const char *name);
>  bool qdev_exists(const char *name);
>  int qdev_device_help(QemuOpts *opts);
>  DeviceState *qdev_device_add(QemuOpts *opts);
> +void *qdev_hostdev_add(Monitor *mon, QemuOpts *opts,
> +                       char *name, NetClientState *peer);
>  int qdev_init(DeviceState *dev) QEMU_WARN_UNUSED_RESULT;
>  void qdev_init_nofail(DeviceState *dev);
>  void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
> diff --git a/net.c b/net.c
> index dd67d16..5e4f871 100644
> --- a/net.c
> +++ b/net.c
> @@ -624,10 +624,7 @@ static int net_init_nic(QemuOpts *opts,
>         .help = "identifier for monitor commands", \
>      }
>
> -typedef int NetClientInitFunc(QemuOpts *opts,
> -                              Monitor *mon,
> -                              const char *name,
> -                              NetClientState *peer);
> +typedef int NetClientInitFunc(QemuOpts *opts, Monitor *mon, const char *name, NetClientState *peer);
>
>  /* magic number, but compiler will warn if too small */
>  #define NET_MAX_DESC 20
> @@ -972,6 +969,58 @@ int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev)
>     return -1;
>  }
>
> +static int net_client_netdev_init(Monitor *mon, QemuOpts *opts, int is_netdev)
> +{
> +    const char *name;
> +    const char *type;
> +
> +    type = qemu_opt_get(opts, "type");
> +    if (!type) {
> +        qerror_report(QERR_MISSING_PARAMETER, "type");
> +        return -1;
> +    }
> +
> +    if (is_netdev) {
> +        if (strcmp(type, "tap") != 0 &&
> +#ifdef CONFIG_NET_BRIDGE
> +            strcmp(type, "bridge") != 0 &&
> +#endif
> +#ifdef CONFIG_SLIRP
> +            strcmp(type, "user") != 0 &&
> +#endif
> +#ifdef CONFIG_VDE
> +            strcmp(type, "vde") != 0 &&
> +#endif
> +            strcmp(type, "socket") != 0) {
> +            qerror_report(QERR_INVALID_PARAMETER_VALUE, "type",
> +                          "a netdev backend type");
> +            return -1;
> +        }
> +
> +        if (qemu_opt_get(opts, "vlan")) {
> +            qerror_report(QERR_INVALID_PARAMETER, "vlan");
> +            return -1;
> +        }
> +        if (qemu_opt_get(opts, "name")) {
> +            qerror_report(QERR_INVALID_PARAMETER, "name");
> +            return -1;
> +        }
> +        if (!qemu_opts_id(opts)) {
> +            qerror_report(QERR_MISSING_PARAMETER, "id");
> +            return -1;
> +        }
> +    }
> +
> +    name = qemu_opts_id(opts);
> +    if (!name) {
> +        name = qemu_opt_get(opts, "name");
> +    }
> +
> +    hostdev_device_add(mon, opts, (char *)name, NULL);
> +
> +    return 0;
> +}
> +
>  static int net_host_check_device(const char *device)
>  {
>     int i;
> @@ -1188,7 +1237,7 @@ static int net_init_client(QemuOpts *opts, void *dummy)
>
>  static int net_init_netdev(QemuOpts *opts, void *dummy)
>  {
> -    return net_client_init(NULL, opts, 1);
> +    return net_client_netdev_init(NULL, opts, 1);
>  }
>
>  int net_init_clients(void)
> @@ -1205,8 +1254,9 @@ int net_init_clients(void)
>
>     QTAILQ_INIT(&net_clients);
>
> -    if (qemu_opts_foreach(qemu_find_opts("netdev"), net_init_netdev, NULL, 1) == -1)
> +    if (qemu_opts_foreach(qemu_find_opts("netdev"), net_init_netdev, NULL, 1) == -1) {
>         return -1;
> +    }
>
>     if (qemu_opts_foreach(net, net_init_client, NULL, 1) == -1) {
>         return -1;
> diff --git a/net.h b/net.h
> index 60837ab..69d93b1 100644
> --- a/net.h
> +++ b/net.h
> @@ -6,7 +6,11 @@
>  #include "qdict.h"
>  #include "qemu-option.h"
>  #include "net/queue.h"
> +#include "hw/qdev.h"
>  #include "vmstate.h"
> +#include "hw/hw.h"
> +#include "hw/pci.h"
> +#include "qemu/hostdev.h"
>
>  struct MACAddr {
>     uint8_t a[6];
> @@ -61,6 +65,7 @@ typedef struct NetClientInfo {
>  } NetClientInfo;
>
>  struct NetClientState {
> +    HOSTDevice host_dev;
>     NetClientInfo *info;
>     int link_down;
>     QTAILQ_ENTRY(NetClientState) next;
> diff --git a/net/dump.c b/net/dump.c
> index 0f191d3..9152b2e 100644
> --- a/net/dump.c
> +++ b/net/dump.c
> @@ -29,12 +29,14 @@
>  #include "qemu-timer.h"
>  #include "hub.h"
>
> +/*
>  typedef struct DumpState {
>     NetClientState nc;
>     int64_t start_ts;
>     int fd;
>     int pcap_caplen;
>  } DumpState;
> +*/
>
>  #define PCAP_MAGIC 0xa1b2c3d4
>
> @@ -145,7 +147,9 @@ static int net_dump_init(NetClientState *peer, const char *device,
>     return 0;
>  }
>
> -int net_init_dump(QemuOpts *opts, Monitor *mon, const char *name,
> +int net_init_dump(QemuOpts *opts,
> +                  Monitor *mon,
> +                  const char *name,
>                   NetClientState *peer)
>  {
>     int len;
> diff --git a/net/dump.h b/net/dump.h
> index df22afe..9066ff7 100644
> --- a/net/dump.h
> +++ b/net/dump.h
> @@ -26,8 +26,18 @@
>
>  #include "net.h"
>  #include "qemu-common.h"
> +#include "qemu/hostdev.h"
>
> -int net_init_dump(QemuOpts *opts, Monitor *mon,
> -                  const char *name, NetClientState *peer);
> +typedef struct DumpState {
> +    NetClientState nc;
> +    int64_t start_ts;
> +    int fd;
> +    int pcap_caplen;
> +} DumpState;
> +
> +int net_init_dump(QemuOpts *opts,
> +                  Monitor *mon,
> +                  const char *name,
> +                  NetClientState *peer);
>
>  #endif /* QEMU_NET_DUMP_H */
> diff --git a/net/slirp.c b/net/slirp.c
> index d3e56fc..0838fd5 100644
> --- a/net/slirp.c
> +++ b/net/slirp.c
> @@ -66,6 +66,7 @@ struct slirp_config_str {
>     int legacy_format;
>  };
>
> +/*
>  typedef struct SlirpState {
>     NetClientState nc;
>     QTAILQ_ENTRY(SlirpState) entry;
> @@ -74,6 +75,7 @@ typedef struct SlirpState {
>     char smb_dir[128];
>  #endif
>  } SlirpState;
> +*/
>
>  static struct slirp_config_str *slirp_configs;
>  const char *legacy_tftp_prefix;
> @@ -777,3 +779,36 @@ int net_slirp_parse_legacy(QemuOptsList *opts_list, const char *optarg, int *ret
>     return 1;
>  }
>
> +static hostdevProperty net_user_properties[] = {
> +    //DEFINE_PROP_STRING("type", NetClientState, info->type),
> +    DEFINE_HOSTDEV_PROP_INT32("link_down", NetClientState,link_down, 0),
> +    DEFINE_HOSTDEV_PROP_PEER("peer", NetClientState, peer),
> +    //DEFINE_PROP_STRING("model", NetClientState, model),
> +    DEFINE_HOSTDEV_PROP_STRING("name", NetClientState, name),
> +    //DEFINE_PROP_BIT("receive_disabled", NetClientState, receive_disabled, 0, true),
> +    DEFINE_PROP_END_OF_LIST(),
> +};
> +
> +static void net_user_class_init(ObjectClass *klass, void *data)
> +{
> +    HOSTDeviceClass *k = HOSTDEV_CLASS(klass);
> +
> +    k->init = net_init_slirp;
> +    k->props = net_user_properties;
> +}
> +
> +static TypeInfo net_user_type = {
> +    .name          = "user",
> +    .parent        = TYPE_HOSTDEV,
> +    .instance_size = sizeof(NetClientState),
> +    .class_init    = net_user_class_init,
> +};
> +
> +static void net_user_register_types(void)
> +{
> +#ifdef CONFIG_SLIRP
> +    type_register_static(&net_user_type);
> +#endif
> +}
> +
> +type_init(net_user_register_types)
> diff --git a/net/slirp.h b/net/slirp.h
> index e6000af..8a7622e 100644
> --- a/net/slirp.h
> +++ b/net/slirp.h
> @@ -27,6 +27,19 @@
>  #include "qemu-common.h"
>  #include "qdict.h"
>  #include "qemu-option.h"
> +#include "qemu_socket.h"
> +#include "slirp/libslirp.h"
> +#include "net.h"
> +#include "qemu/hostdev.h"
> +
> +typedef struct SlirpState {
> +    NetClientState nc;
> +    QTAILQ_ENTRY(SlirpState) entry;
> +    Slirp *slirp;
> +#ifndef _WIN32
> +    char smb_dir[128];
> +#endif
> +} SlirpState;
>
>  #ifdef CONFIG_SLIRP
>
> diff --git a/net/socket.c b/net/socket.c
> index 55d9820..4ea3e07 100644
> --- a/net/socket.c
> +++ b/net/socket.c
> @@ -31,16 +31,17 @@
>  #include "qemu-error.h"
>  #include "qemu-option.h"
>  #include "qemu_socket.h"
> -
> -typedef struct NetSocketState {
> -    NetClientState nc;
> -    int fd;
> -    int state; /* 0 = getting length, 1 = getting data */
> -    unsigned int index;
> -    unsigned int packet_len;
> -    uint8_t buf[4096];
> -    struct sockaddr_in dgram_dst; /* contains inet host and port destination iff connectionless (SOCK_DGRAM) */
> -} NetSocketState;
> +#include "qemu/hostdev.h"
> +
> +//typedef struct NetSocketState {
> +//    NetClientState nc;
> +//    int fd;
> +//    int state; /* 0 = getting length, 1 = getting data */
> +//    unsigned int index;
> +//    unsigned int packet_len;
> +//    uint8_t buf[4096];
> +//    struct sockaddr_in dgram_dst; /* contains inet host and port destination iff connectionless (SOCK_DGRAM) */
> +//} NetSocketState;
>
>  typedef struct NetSocketListenState {
>     NetClientState *peer;
> @@ -592,6 +593,12 @@ int net_init_socket(QemuOpts *opts,
>                     const char *name,
>                     NetClientState *peer)
>  {
> +/*
> +    QemuOpts *opts = host_dev->opts;
> +    Monitor *mon = host_dev->mon;
> +    const char *name = strdup(host_dev->name);
> +    NetClientState *peer = host_dev->peer;
> +*/
>     if (qemu_opt_get(opts, "fd")) {
>         int fd;
>
> @@ -690,3 +697,29 @@ int net_init_socket(QemuOpts *opts,
>     }
>     return 0;
>  }
> +
> +static hostdevProperty net_socket_properties[] = {
> +    DEFINE_PROP_END_OF_LIST(),
> +};
> +
> +static void net_socket_class_init(ObjectClass *klass, void *data)
> +{
> +    HOSTDeviceClass *k = HOSTDEV_CLASS(klass);
> +
> +    k->init = net_init_socket;
> +    k->props = net_socket_properties;
> +}
> +
> +static TypeInfo net_socket_type = {
> +    .name          = "socket",
> +    .parent        = TYPE_HOSTDEV,
> +    .instance_size = sizeof(NetClientState),
> +    .class_init    = net_socket_class_init,
> +};
> +
> +static void net_socket_register_types(void)
> +{
> +    type_register_static(&net_socket_type);
> +}
> +
> +type_init(net_socket_register_types)
> diff --git a/net/socket.h b/net/socket.h
> index 5edf17c..128af01 100644
> --- a/net/socket.h
> +++ b/net/socket.h
> @@ -26,8 +26,22 @@
>
>  #include "net.h"
>  #include "qemu-common.h"
> +#include "qemu_socket.h"
> +#include "qemu/hostdev.h"
>
> -int net_init_socket(QemuOpts *opts, Monitor *mon,
> -                    const char *name, NetClientState *peer);
> +typedef struct NetSocketState {
> +    NetClientState nc;
> +    int fd;
> +    int state; /* 0 = getting length, 1 = getting data */
> +    unsigned int index;
> +    unsigned int packet_len;
> +    uint8_t buf[4096];
> +    struct sockaddr_in dgram_dst; /* contains inet host and port destination iff connectionless (SOCK_DGRAM) */
> +} NetSocketState;
> +
> +int net_init_socket(QemuOpts *opts,
> +                    Monitor *mon,
> +                    const char *name,
> +                    NetClientState *peer);
>
>  #endif /* QEMU_NET_SOCKET_H */
> diff --git a/net/tap-win32.c b/net/tap-win32.c
> index 3406717..fa17239 100644
> --- a/net/tap-win32.c
> +++ b/net/tap-win32.c
> @@ -699,11 +699,15 @@ static int tap_win32_init(NetClientState *peer, const char *model,
>     return 0;
>  }
>
> -int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name,
> -                 NetClientState *peer)
> +int net_init_tap(HOSTDevice *host_dev)
>  {
>     const char *ifname;
>
> +    QemuOpts *opts = host_dev->opts;
> +    Monitor *mon = host_dev->mon;
> +    const char *name = strdup(host_dev->name);
> +    NetClientState *peer = host_dev->peer;
> +
>     ifname = qemu_opt_get(opts, "ifname");
>
>     if (!ifname) {
> diff --git a/net/tap.c b/net/tap.c
> index 65f45b8..f568c50 100644
> --- a/net/tap.c
> +++ b/net/tap.c
> @@ -46,6 +46,7 @@
>  /* Maximum GSO packet size (64k) plus plenty of room for
>  * the ethernet and virtio_net headers
>  */
> +/*
>  #define TAP_BUFSIZE (4096 + 65536)
>
>  typedef struct TAPState {
> @@ -61,6 +62,7 @@ typedef struct TAPState {
>     VHostNetState *vhost_net;
>     unsigned host_vnet_hdr_len;
>  } TAPState;
> +*/
>
>  static int launch_script(const char *setup_script, const char *ifname, int fd);
>
> @@ -512,7 +514,9 @@ static int net_bridge_run_helper(const char *helper, const char *bridge)
>     return -1;
>  }
>
> -int net_init_bridge(QemuOpts *opts, Monitor *mon, const char *name,
> +int net_init_bridge(QemuOpts *opts,
> +                    Monitor *mon,
> +                    const char *name,
>                     NetClientState *peer)
>  {
>     TAPState *s;
> @@ -583,7 +587,9 @@ static int net_tap_init(QemuOpts *opts, int *vnet_hdr)
>     return fd;
>  }
>
> -int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name,
> +int net_init_tap(QemuOpts *opts,
> +                 Monitor *mon,
> +                 const char *name,
>                  NetClientState *peer)
>  {
>     TAPState *s;
> @@ -715,3 +721,49 @@ VHostNetState *tap_get_vhost_net(NetClientState *nc)
>     assert(nc->info->type == NET_CLIENT_TYPE_TAP);
>     return s->vhost_net;
>  }
> +
> +static hostdevProperty net_tap_properties[] = {
> +    DEFINE_PROP_END_OF_LIST(),
> +};
> +
> +static void net_tap_class_init(ObjectClass *klass, void *data)
> +{
> +    HOSTDeviceClass *k = HOSTDEV_CLASS(klass);
> +
> +    k->init = net_init_tap;
> +    k->props = net_tap_properties;
> +}
> +
> +static TypeInfo net_tap_type = {
> +    .name          = "tap",
> +    .parent        = TYPE_HOSTDEV,
> +    .instance_size = sizeof(NetClientState),
> +    .class_init    = net_tap_class_init,
> +};
> +
> +static hostdevProperty net_bridge_properties[] = {
> +    DEFINE_PROP_END_OF_LIST(),
> +};
> +
> +static void net_bridge_class_init(ObjectClass *klass, void *data)
> +{
> +    HOSTDeviceClass *k = HOSTDEV_CLASS(klass);
> +
> +    k->init = net_init_bridge;
> +    k->props = net_bridge_properties;
> +}
> +
> +static TypeInfo net_bridge_type = {
> +    .name          = "bridge",
> +    .parent        = TYPE_HOSTDEV,
> +    .instance_size = sizeof(NetClientState),
> +    .class_init    = net_bridge_class_init,
> +};
> +
> +static void net_tap_register_types(void)
> +{
> +    type_register_static(&net_tap_type);
> +    type_register_static(&net_bridge_type);
> +}
> +
> +type_init(net_tap_register_types)
> diff --git a/net/tap.h b/net/tap.h
> index 0e35e81..a687d9a 100644
> --- a/net/tap.h
> +++ b/net/tap.h
> @@ -28,11 +28,31 @@
>
>  #include "qemu-common.h"
>  #include "qemu-option.h"
> +#include "hw/vhost_net.h"
> +#include "qemu/hostdev.h"
>
>  #define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"
>  #define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown"
>
> -int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name,
> +#define TAP_BUFSIZE (4096 + 65536)
> +
> +typedef struct TAPState {
> +    NetClientState nc;
> +    int fd;
> +    char down_script[1024];
> +    char down_script_arg[128];
> +    uint8_t buf[TAP_BUFSIZE];
> +    unsigned int read_poll : 1;
> +    unsigned int write_poll : 1;
> +    unsigned int using_vnet_hdr : 1;
> +    unsigned int has_ufo: 1;
> +    VHostNetState *vhost_net;
> +    unsigned host_vnet_hdr_len;
> +} TAPState;
> +
> +int net_init_tap(QemuOpts *opts,
> +                 Monitor *mon,
> +                 const char *name,
>                  NetClientState *peer);
>
>  int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required);
> @@ -58,7 +78,9 @@ int tap_get_fd(NetClientState *nc);
>  struct vhost_net;
>  struct vhost_net *tap_get_vhost_net(NetClientState *nc);
>
> -int net_init_bridge(QemuOpts *opts, Monitor *mon, const char *name,
> +int net_init_bridge(QemuOpts *opts,
> +                    Monitor *mon,
> +                    const char *name,
>                     NetClientState *peer);
>
>  #endif /* QEMU_NET_TAP_H */
> diff --git a/net/vde.c b/net/vde.c
> index 8d9e1c6..5b06f67 100644
> --- a/net/vde.c
> +++ b/net/vde.c
> @@ -110,7 +110,9 @@ static int net_vde_init(NetClientState *peer, const char *model,
>     return 0;
>  }
>
> -int net_init_vde(QemuOpts *opts, Monitor *mon, const char *name,
> +int net_init_vde(QemuOpts *opts,
> +                 Monitor *mon,
> +                 const char *name,
>                  NetClientState *peer)
>  {
>     const char *sock;
> diff --git a/net/vde.h b/net/vde.h
> index 276e1ff..4400fa5 100644
> --- a/net/vde.h
> +++ b/net/vde.h
> @@ -29,8 +29,7 @@
>
>  #ifdef CONFIG_VDE
>
> -int net_init_vde(QemuOpts *opts, Monitor *mon, const char *name,
> -                 NetClientState *peer);
> +int net_init_vde(HOSTDevice *host_dev);
>
>  #endif /* CONFIG_VDE */
>
> diff --git a/qemu-log.h b/qemu-log.h
> index fccfb110..611f796 100644
> --- a/qemu-log.h
> +++ b/qemu-log.h
> @@ -51,9 +51,9 @@ extern int loglevel;
>  /* Special cases: */
>
>  /* cpu_dump_state() logging functions: */
> -#define log_cpu_state(env, f) cpu_dump_state((env), logfile, fprintf, (f));
> -#define log_cpu_state_mask(b, env, f) do {           \
> -      if (loglevel & (b)) log_cpu_state((env), (f)); \
> +#define log_cpu_state(env1, f) cpu_dump_state((env1), logfile, fprintf, (f));
> +#define log_cpu_state_mask(b, env1, f) do {           \
> +      if (loglevel & (b)) log_cpu_state((env1), (f)); \
>   } while (0)
>
>  /* disas() and target_disas() to logfile: */
> diff --git a/qemu-timer.c b/qemu-timer.c
> index d7f56e5..8e48483 100644
> --- a/qemu-timer.c
> +++ b/qemu-timer.c
> @@ -23,7 +23,7 @@
>  */
>
>  #include "sysemu.h"
> -#include "net.h"
> +//#include "net.h"
>  #include "monitor.h"
>  #include "console.h"
>
> diff --git a/qom/Makefile b/qom/Makefile
> index 34c6de5..4731fb9 100644
> --- a/qom/Makefile
> +++ b/qom/Makefile
> @@ -1,2 +1,2 @@
>  qom-y = object.o container.o qom-qobject.o
> -qom-twice-y = cpu.o
> +qom-twice-y = cpu.o hostdev.o
> diff --git a/qom/object.c b/qom/object.c
> index 9cd9506..6f60426 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -101,7 +101,6 @@ TypeImpl *type_register(const TypeInfo *info)
>     g_assert(info->name != NULL);
>
>     if (type_table_lookup(info->name) != NULL) {
> -        fprintf(stderr, "Registering `%s' which already exists\n", info->name);
>         abort();
>     }
>
> diff --git a/vl.c b/vl.c
> index 112b0e0..5a3f425 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -2299,8 +2299,6 @@ int main(int argc, char **argv, char **envp)
>  #endif
>     }
>
> -    module_call_init(MODULE_INIT_QOM);
> -
>     runstate_init();
>
>     init_clocks();
> @@ -3381,10 +3379,6 @@ int main(int argc, char **argv, char **envp)
>     }
>     configure_icount(icount_option);
>
> -    if (net_init_clients() < 0) {
> -        exit(1);
> -    }
> -
>     /* init the bluetooth world */
>     if (foreach_device_config(DEV_BT, bt_parse))
>         exit(1);
> @@ -3474,6 +3468,8 @@ int main(int argc, char **argv, char **envp)
>     if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0)
>         exit(1);
>
> +    module_call_init(MODULE_INIT_QOM);
> +
>     /* must be after qdev registration but before machine init */
>     if (vga_model) {
>         select_vgahw(vga_model);
> @@ -3514,9 +3510,16 @@ int main(int argc, char **argv, char **envp)
>             exit(1);
>     }
>
> +    if (net_init_clients() < 0) {
> +printf("%s: net_init_clients failed\n", __func__);
> +        exit(1);
> +    }
> +
>     /* init generic devices */
> -    if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, 1) != 0)
> +    if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, 1) != 0) {
> +printf("%s: device_init_func failed\n", __func__);
>         exit(1);
> +    }
>
>     net_check_clients();
>
> --
> 1.7.6
>



-- 
Regards,

Zhi Yong Wu

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

* Re: [Qemu-devel] [RFC 1/9] hostdev: introduce the infrastructure for host device model
  2012-03-26  5:40 ` [Qemu-devel] [RFC 1/9] hostdev: introduce the infrastructure for host device model zwu.kernel
@ 2012-03-26  5:54   ` Zhi Yong Wu
  2012-03-27  8:23   ` Paolo Bonzini
  1 sibling, 0 replies; 38+ messages in thread
From: Zhi Yong Wu @ 2012-03-26  5:54 UTC (permalink / raw)
  To: qemu-devel; +Cc: zwu.kernel, pbonzini, Zhi Yong Wu, stefanha

A lot of property get/set functions in qdev-properties.c are related
to DeviceState. So i have to copy and modify some of them here to
apply our host device model. In the future, we should make those
functions more generic.

On Mon, Mar 26, 2012 at 1:40 PM,  <zwu.kernel@gmail.com> wrote:
> From: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
>
> Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
> ---
>  include/qemu/hostdev.h |  128 ++++++++++++++++++
>  qom/Makefile           |    2 +-
>  qom/hostdev.c          |  333 ++++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 462 insertions(+), 1 deletions(-)
>  create mode 100644 include/qemu/hostdev.h
>  create mode 100644 qom/hostdev.c
>
> diff --git a/include/qemu/hostdev.h b/include/qemu/hostdev.h
> new file mode 100644
> index 0000000..a291761
> --- /dev/null
> +++ b/include/qemu/hostdev.h
> @@ -0,0 +1,128 @@
> +/*
> + * QEMU host device model
> + *
> + * Copyright IBM, Corp. 2012
> + *
> + * Authors:
> + *  Zhi Yong Wu   <wuzhy@linux.vnet.ibm.com>
> + *
> + * This work is licensed under the terms of the GNU LGPL, version 2 or later.
> + * See the COPYING.LIB file in the top-level directory.
> + *
> + */
> +
> +#ifndef QEMU_HOSTDEV_H
> +#define QEMU_HOSTDEV_H
> +
> +#include "qemu-queue.h"
> +#include "qemu-char.h"
> +#include "qemu-option.h"
> +#include "qapi/qapi-visit-core.h"
> +#include "qemu/object.h"
> +
> +typedef struct hostdevProperty hostdevProperty;
> +typedef struct hostdevPropertyInfo hostdevPropertyInfo;
> +
> +/**
> + * SECTION: hostdev
> + * @section_id: QEMU-hostdev
> + * @title: hostdev Class
> + * @short_description: Base class for all host devices
> + */
> +
> +typedef struct HOSTDevice HOSTDevice;
> +
> +#define TYPE_HOSTDEV "host-dev"
> +#define HOST_DEVICE(obj) \
> +     OBJECT_CHECK(HOSTDevice, (obj), TYPE_HOSTDEV)
> +#define HOSTDEV_CLASS(klass) \
> +     OBJECT_CLASS_CHECK(HOSTDeviceClass, (klass), TYPE_HOSTDEV)
> +#define HOSTDEV_GET_CLASS(obj) \
> +     OBJECT_GET_CLASS(HOSTDeviceClass, (obj), TYPE_HOSTDEV)
> +
> +/**
> + * HOSTDeviceClass:
> + *
> + * Represents a host device model.
> + */
> +typedef struct HOSTDeviceClass {
> +    ObjectClass parent_class;
> +    hostdevProperty *props;
> +
> +    int (*init)(HOSTDevice *host_dv);
> +} HOSTDeviceClass;
> +
> +/**
> + * HOSTDevice:
> + *
> + * State of one host device.
> + */
> +struct HOSTDevice {
> +    /*< private >*/
> +    Object parent_obj;
> +
> +    /*< public >*/
> +};
> +
> +struct hostdevProperty {
> +    const char   *name;
> +    hostdevPropertyInfo *info;
> +    int          offset;
> +    uint8_t      bitnr;
> +    uint8_t      qtype;
> +    int64_t      defval;
> +};
> +
> +struct hostdevPropertyInfo {
> +    const char *name;
> +    const char *legacy_name;
> +    const char **enum_table;
> +    int64_t min;
> +    int64_t max;
> +    int (*parse)(HOSTDevice *dev,
> +                 hostdevProperty *prop,
> +                 const char *str);
> +    int (*print)(HOSTDevice *dev,
> +                 hostdevProperty *prop,
> +                 char *dest,
> +                 size_t len);
> +    ObjectPropertyAccessor *get;
> +    ObjectPropertyAccessor *set;
> +    ObjectPropertyRelease *release;
> +};
> +
> +extern hostdevPropertyInfo hostdev_prop_int32;
> +extern hostdevPropertyInfo hostdev_prop_string;
> +extern hostdevPropertyInfo hostdev_prop_netdev;
> +
> +#define DEFINE_HOSTDEV_PROP(_name, _state, _field, _prop, _type) { \
> +        .name      = (_name),                                    \
> +        .info      = &(_prop),                                   \
> +        .offset    = offsetof(_state, _field)                    \
> +            + type_check(_type,typeof_field(_state, _field)),    \
> +        }
> +#define DEFINE_HOSTDEV_PROP_DEFAULT(_name, _state, _field, _defval, _prop, _type) { \
> +        .name      = (_name),                                           \
> +        .info      = &(_prop),                                          \
> +        .offset    = offsetof(_state, _field)                           \
> +            + type_check(_type,typeof_field(_state, _field)),           \
> +        .qtype     = QTYPE_QINT,                                        \
> +        .defval    = (_type)_defval,                                    \
> +        }
> +#define DEFINE_HOSTDEV_PROP_END_OF_LIST()               \
> +    {}
> +#define DEFINE_HOSTDEV_PROP_INT32(_n, _s, _f, _d)              \
> +    DEFINE_HOSTDEV_PROP_DEFAULT(_n, _s, _f, _d, hostdev_prop_int32, int32_t)
> +#define DEFINE_HOSTDEV_PROP_PEER(_n, _s, _f)             \
> +    DEFINE_HOSTDEV_PROP(_n, _s, _f, hostdev_prop_netdev, NetClientState*)
> +#define DEFINE_HOSTDEV_PROP_STRING(_n, _s, _f)             \
> +    DEFINE_HOSTDEV_PROP(_n, _s, _f, hostdev_prop_string, char*)
> +
> +HOSTDevice *hostdev_device_create(const char *type);
> +int hostdev_device_init(HOSTDevice *dev, const char *type, const char *id);
> +void hostdev_prop_set_string(HOSTDevice *dev,
> +                             const char *name, char *value);
> +void hostdev_prop_set_peer(HOSTDevice *dev,
> +                           const char *name, NetClientState *value);
> +
> +#endif
> diff --git a/qom/Makefile b/qom/Makefile
> index 34c6de5..4731fb9 100644
> --- a/qom/Makefile
> +++ b/qom/Makefile
> @@ -1,2 +1,2 @@
>  qom-y = object.o container.o qom-qobject.o
> -qom-twice-y = cpu.o
> +qom-twice-y = cpu.o hostdev.o
> diff --git a/qom/hostdev.c b/qom/hostdev.c
> new file mode 100644
> index 0000000..867e869
> --- /dev/null
> +++ b/qom/hostdev.c
> @@ -0,0 +1,333 @@
> +/*
> + * QEMU host device model
> + *
> + * Copyright IBM, Corp. 2012
> + *
> + * Authors:
> + *  Zhi Yong Wu   <wuzhy@linux.vnet.ibm.com>
> + *
> + * This work is licensed under the terms of the GNU LGPL, version 2 or later.
> + * See the COPYING.LIB file in the top-level directory.
> + *
> + */
> +
> +#include "qemu/hostdev.h"
> +#include "qemu-common.h"
> +#include "net.h"
> +
> +void hostdev_prop_set_string(HOSTDevice *dev,
> +                             const char *name, char *value)
> +{
> +    Error *errp = NULL;
> +    object_property_set_str(OBJECT(dev), value, name, &errp);
> +    assert_no_error(errp);
> +}
> +
> +void hostdev_prop_set_peer(HOSTDevice *dev,
> +                           const char *name, NetClientState *value)
> +{
> +    Error *errp = NULL;
> +    assert(!value || value->name);
> +    object_property_set_str(OBJECT(dev),
> +                            value ? value->name : "", name, &errp);
> +    assert_no_error(errp);
> +}
> +
> +static Object *hostdev_get_hostdev(void)
> +{
> +    static Object *dev;
> +
> +    if (dev == NULL) {
> +        dev = object_new("container");
> +        object_property_add_child(object_get_root(), "hostdev",
> +                                  OBJECT(dev), NULL);
> +    }
> +
> +    return dev;
> +}
> +
> +HOSTDevice *hostdev_device_create(const char *type)
> +{
> +    HOSTDevice *hostdev;
> +
> +    hostdev = HOST_DEVICE(object_new(type));
> +    if (!hostdev) {
> +        return NULL;
> +    }
> +
> +    return hostdev;
> +}
> +
> +int hostdev_device_init(HOSTDevice *dev, const char *type, const char *id)
> +{
> +    HOSTDeviceClass *dc = HOSTDEV_GET_CLASS(dev);
> +    gchar *dev_id;
> +    int rc;
> +
> +    rc = dc->init(dev);
> +    if (rc < 0) {
> +        object_delete(OBJECT(dev));
> +        return rc;
> +    }
> +
> +    if (id) {
> +        dev_id = g_strdup(id);
> +    } else {
> +        static int anon_count;
> +        dev_id = g_strdup_printf("%s[%d]", (char *)type, anon_count++);
> +    }
> +
> +    object_property_add_child(hostdev_get_hostdev(), dev_id,
> +                              OBJECT(dev), NULL);
> +    g_free(dev_id);
> +
> +    return 0;
> +}
> +
> +static void *hostdev_get_prop_ptr(HOSTDevice *dev, hostdevProperty *prop)
> +{
> +    void *ptr = dev;
> +    ptr += prop->offset;
> +    return ptr;
> +}
> +
> +static void error_set_from_hostdev_prop_error(Error **errp, int ret,
> +                                              HOSTDevice *dev, hostdevProperty *prop,
> +                                              const char *value)
> +{
> +    switch (ret) {
> +    case -EEXIST:
> +        error_set(errp, QERR_PROPERTY_VALUE_IN_USE,
> +                  object_get_typename(OBJECT(dev)), prop->name, value);
> +        break;
> +    default:
> +    case -EINVAL:
> +        error_set(errp, QERR_PROPERTY_VALUE_BAD,
> +                  object_get_typename(OBJECT(dev)), prop->name, value);
> +        break;
> +    case -ENOENT:
> +        error_set(errp, QERR_PROPERTY_VALUE_NOT_FOUND,
> +                  object_get_typename(OBJECT(dev)), prop->name, value);
> +        break;
> +    case 0:
> +        break;
> +    }
> +}
> +
> +/* --- netdev device --- */
> +static void get_pointer(Object *obj, Visitor *v, hostdevProperty *prop,
> +                        const char *(*print)(void *ptr),
> +                        const char *name, Error **errp)
> +{
> +    HOSTDevice *dev = HOST_DEVICE(obj);
> +    void **ptr = hostdev_get_prop_ptr(dev, prop);
> +    char *p;
> +
> +    p = (char *) (*ptr ? print(*ptr) : "");
> +    visit_type_str(v, &p, name, errp);
> +}
> +
> +static void set_pointer(Object *obj, Visitor *v, hostdevProperty *prop,
> +                        int (*parse)(HOSTDevice *dev, const char *str, void **ptr),
> +                        const char *name, Error **errp)
> +{
> +    HOSTDevice *dev = HOST_DEVICE(obj);
> +    Error *local_err = NULL;
> +    void **ptr = hostdev_get_prop_ptr(dev, prop);
> +    char *str;
> +    int ret;
> +
> +    visit_type_str(v, &str, name, &local_err);
> +    if (local_err) {
> +        error_propagate(errp, local_err);
> +        return;
> +    }
> +    if (!*str) {
> +        g_free(str);
> +        *ptr = NULL;
> +        return;
> +    }
> +    ret = parse(dev, str, ptr);
> +    error_set_from_hostdev_prop_error(errp, ret, dev, prop, str);
> +    g_free(str);
> +}
> +
> +/* --- 32bit integer --- */
> +static void get_int32(Object *obj, Visitor *v, void *opaque,
> +                      const char *name, Error **errp)
> +{
> +    HOSTDevice *dev = HOST_DEVICE(obj);
> +    hostdevProperty *prop = opaque;
> +    int32_t *ptr = hostdev_get_prop_ptr(dev, prop);
> +    int64_t value;
> +
> +    value = *ptr;
> +    visit_type_int(v, &value, name, errp);
> +}
> +
> +static void set_int32(Object *obj, Visitor *v, void *opaque,
> +                      const char *name, Error **errp)
> +{
> +    HOSTDevice *dev = HOST_DEVICE(obj);
> +    hostdevProperty *prop = opaque;
> +    int32_t *ptr = hostdev_get_prop_ptr(dev, prop);
> +    Error *local_err = NULL;
> +    int64_t value;
> +
> +    visit_type_int(v, &value, name, &local_err);
> +    if (local_err) {
> +        error_propagate(errp, local_err);
> +        return;
> +    }
> +    if (value >= prop->info->min && value <= prop->info->max) {
> +        *ptr = value;
> +    } else {
> +        error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE,
> +                  "", name, value, prop->info->min,
> +                  prop->info->max);
> +    }
> +}
> +
> +hostdevPropertyInfo hostdev_prop_int32 = {
> +    .name  = "int32",
> +    .get   = get_int32,
> +    .set   = set_int32,
> +    .min   = -0x80000000LL,
> +    .max   = 0x7FFFFFFFLL,
> +};
> +
> +/* --- netdev --- */
> +static int parse_netdev(HOSTDevice *dev, const char *str, void **ptr)
> +{
> +    NetClientState *netdev = qemu_find_netdev(str);
> +
> +    if (netdev == NULL) {
> +        return -ENOENT;
> +    }
> +    if (netdev->peer) {
> +        return -EEXIST;
> +    }
> +    *ptr = netdev;
> +    return 0;
> +}
> +
> +static const char *print_netdev(void *ptr)
> +{
> +    NetClientState *netdev = ptr;
> +
> +    return netdev->name ? netdev->name : "";
> +}
> +
> +static void get_netdev(Object *obj, Visitor *v, void *opaque,
> +                       const char *name, Error **errp)
> +{
> +    get_pointer(obj, v, opaque, print_netdev, name, errp);
> +}
> +
> +static void set_netdev(Object *obj, Visitor *v, void *opaque,
> +                       const char *name, Error **errp)
> +{
> +    set_pointer(obj, v, opaque, parse_netdev, name, errp);
> +}
> +
> +hostdevPropertyInfo hostdev_prop_netdev = {
> +    .name  = "peer",
> +    .get   = get_netdev,
> +    .set   = set_netdev,
> +};
> +
> +/* --- string --- */
> +static void release_string(Object *obj, const char *name, void *opaque)
> +{
> +    hostdevProperty *prop = opaque;
> +    g_free(*(char **)hostdev_get_prop_ptr(HOST_DEVICE(obj), prop));
> +}
> +
> +static void get_string(Object *obj, Visitor *v, void *opaque,
> +                       const char *name, Error **errp)
> +{
> +    HOSTDevice *dev = HOST_DEVICE(obj);
> +    hostdevProperty *prop = opaque;
> +    char **ptr = hostdev_get_prop_ptr(dev, prop);
> +
> +    if (!*ptr) {
> +        char *str = (char *)"";
> +        visit_type_str(v, &str, name, errp);
> +    } else {
> +        visit_type_str(v, ptr, name, errp);
> +    }
> +}
> +
> +static void set_string(Object *obj, Visitor *v, void *opaque,
> +                       const char *name, Error **errp)
> +{
> +    HOSTDevice *dev = HOST_DEVICE(obj);
> +    hostdevProperty *prop = opaque;
> +    char **ptr = hostdev_get_prop_ptr(dev, prop);
> +    Error *local_err = NULL;
> +    char *str;
> +
> +    visit_type_str(v, &str, name, &local_err);
> +    if (local_err) {
> +        error_propagate(errp, local_err);
> +        return;
> +    }
> +    if (*ptr) {
> +        g_free(*ptr);
> +    }
> +    *ptr = str;
> +}
> +
> +hostdevPropertyInfo hostdev_prop_string = {
> +    .name  = "string",
> +    .release = release_string,
> +    .get   = get_string,
> +    .set   = set_string,
> +};
> +/*
> +static char *hostdev_get_type(Object *obj, Error **errp)
> +{
> +    return g_strdup(object_get_typename(obj));
> +}
> +*/
> +static void hostdev_property_add_static(HOSTDevice *dev, hostdevProperty *prop,
> +                                        Error **errp)
> +{
> +    if (!prop->info->get && !prop->info->set) {
> +        return;
> +    }
> +
> +    object_property_add(OBJECT(dev), prop->name, prop->info->name,
> +                        prop->info->get, prop->info->set,
> +                        prop->info->release,
> +                        prop, errp);
> +}
> +
> +static void hostdev_init(Object *obj)
> +{
> +    HOSTDevice *s = HOST_DEVICE(obj);
> +    HOSTDeviceClass *dc = HOSTDEV_GET_CLASS(obj);
> +    hostdevProperty *prop;
> +
> +    for (prop = dc->props; prop && prop->name; prop++) {
> +        hostdev_property_add_static(s, prop, NULL);
> +    }
> +
> +    //object_property_add_str(OBJECT(s), "type", hostdev_get_type, NULL, NULL);
> +}
> +
> +static TypeInfo hostdev_type_info = {
> +    .name          = TYPE_HOSTDEV,
> +    .parent        = TYPE_OBJECT,
> +    .instance_size = sizeof(HOSTDevice),
> +    .instance_init = hostdev_init,
> +    .abstract      = true,
> +    .class_size    = sizeof(HOSTDeviceClass),
> +};
> +
> +static void hostdev_register_types(void)
> +{
> +    type_register_static(&hostdev_type_info);
> +}
> +
> +type_init(hostdev_register_types)
> --
> 1.7.6
>



-- 
Regards,

Zhi Yong Wu

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

* Re: [Qemu-devel] [RFC 0/9] QOM: qomify -netdev
  2012-03-26  5:40 [Qemu-devel] [RFC 0/9] QOM: qomify -netdev zwu.kernel
                   ` (10 preceding siblings ...)
  2012-03-26  5:40 ` [Qemu-devel] [RFC 9/9] net: qomify -netdev tap & -netdev bridge zwu.kernel
@ 2012-03-26 11:54 ` Stefan Hajnoczi
  2012-03-26 14:20   ` Zhi Yong Wu
  2012-03-26 14:39   ` Andreas Färber
  11 siblings, 2 replies; 38+ messages in thread
From: Stefan Hajnoczi @ 2012-03-26 11:54 UTC (permalink / raw)
  To: zwu.kernel; +Cc: pbonzini, Zhi Yong Wu, qemu-devel, stefanha

On Mon, Mar 26, 2012 at 6:40 AM,  <zwu.kernel@gmail.com> wrote:
> From: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
>
> Sending the patchset is mainly intended to get some comments and void the wrong development direction.
>
> The patchset is used to qomify -netdev, but it introduce one infrastructure for host devices based on raw Class and Object, not qdev. So they are not related with DeviceClass and DeviceState.
>
> patch #1 introduce one new class and object for host devices.

A common infrastructure for host devices is useful.  The Property
mechanism in hw/qdev-properties.c is especially good.  I think host
devices will also need to 2-step creation process (init and realize).

I think the qdev-properties.c code can mostly be shared.  It currently
uses the qdev DeviceState class but I think it only really access the
Property array.

Therefore it should be possible to really share a single copy of the
code.  We don't need to duplicate Property for host devices, instead
we can extract it out of hw/.

Stefan

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

* Re: [Qemu-devel] [RFC 0/9] QOM: qomify -netdev
  2012-03-26 11:54 ` [Qemu-devel] [RFC 0/9] QOM: qomify -netdev Stefan Hajnoczi
@ 2012-03-26 14:20   ` Zhi Yong Wu
  2012-03-27  8:19     ` Paolo Bonzini
  2012-03-26 14:39   ` Andreas Färber
  1 sibling, 1 reply; 38+ messages in thread
From: Zhi Yong Wu @ 2012-03-26 14:20 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: pbonzini, Zhi Yong Wu, qemu-devel, stefanha

On Mon, Mar 26, 2012 at 7:54 PM, Stefan Hajnoczi <stefanha@gmail.com> wrote:
> On Mon, Mar 26, 2012 at 6:40 AM,  <zwu.kernel@gmail.com> wrote:
>> From: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
>>
>> Sending the patchset is mainly intended to get some comments and void the wrong development direction.
>>
>> The patchset is used to qomify -netdev, but it introduce one infrastructure for host devices based on raw Class and Object, not qdev. So they are not related with DeviceClass and DeviceState.
>>
>> patch #1 introduce one new class and object for host devices.
>
> A common infrastructure for host devices is useful.  The Property
> mechanism in hw/qdev-properties.c is especially good.  I think host
> devices will also need to 2-step creation process (init and realize).
Yeah.
>
> I think the qdev-properties.c code can mostly be shared.  It currently
> uses the qdev DeviceState class but I think it only really access the
> Property array.
struct Property {
    const char   *name;
    PropertyInfo *info;
    int          offset;
    uint8_t      bitnr;
    uint8_t      qtype;
    int64_t      defval;
};

struct PropertyInfo {
    const char *name;
    const char *legacy_name;
    const char **enum_table;
    int64_t min;
    int64_t max;
    int (*parse)(DeviceState *dev, Property *prop, const char *str);
    int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
    ObjectPropertyAccessor *get;
    ObjectPropertyAccessor *set;
    ObjectPropertyRelease *release;
};

Like above, its member functions pointers use DeviceState, so we will
have to consider how to make this PropertyInfo more generic and be
used by other Class and Object which are not based on DeviceState.

>
> Therefore it should be possible to really share a single copy of the
> code.  We don't need to duplicate Property for host devices, instead
> we can extract it out of hw/.
Yeah, but we need to make some effort to reach this goal.
>
> Stefan



-- 
Regards,

Zhi Yong Wu

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

* Re: [Qemu-devel] [RFC 0/9] QOM: qomify -netdev
  2012-03-26 11:54 ` [Qemu-devel] [RFC 0/9] QOM: qomify -netdev Stefan Hajnoczi
  2012-03-26 14:20   ` Zhi Yong Wu
@ 2012-03-26 14:39   ` Andreas Färber
  2012-03-26 14:57     ` Stefan Hajnoczi
  2012-03-26 15:01     ` Zhi Yong Wu
  1 sibling, 2 replies; 38+ messages in thread
From: Andreas Färber @ 2012-03-26 14:39 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: zwu.kernel, pbonzini, Zhi Yong Wu, qemu-devel, stefanha

Am 26.03.2012 13:54, schrieb Stefan Hajnoczi:
> I think host
> devices will also need to 2-step creation process (init and realize).

Series tested and sent out today. :)

Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg

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

* Re: [Qemu-devel] [RFC 0/9] QOM: qomify -netdev
  2012-03-26 14:39   ` Andreas Färber
@ 2012-03-26 14:57     ` Stefan Hajnoczi
  2012-03-26 15:01     ` Zhi Yong Wu
  1 sibling, 0 replies; 38+ messages in thread
From: Stefan Hajnoczi @ 2012-03-26 14:57 UTC (permalink / raw)
  To: Andreas Färber
  Cc: zwu.kernel, pbonzini, Zhi Yong Wu, qemu-devel, stefanha

On Mon, Mar 26, 2012 at 3:39 PM, Andreas Färber <afaerber@suse.de> wrote:
> Am 26.03.2012 13:54, schrieb Stefan Hajnoczi:
>> I think host
>> devices will also need to 2-step creation process (init and realize).
>
> Series tested and sent out today. :)

Hehe, great.  That will be very useful since it allows users to
configure the -netdev before activating it.

Stefan

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

* Re: [Qemu-devel] [RFC 0/9] QOM: qomify -netdev
  2012-03-26 14:39   ` Andreas Färber
  2012-03-26 14:57     ` Stefan Hajnoczi
@ 2012-03-26 15:01     ` Zhi Yong Wu
  1 sibling, 0 replies; 38+ messages in thread
From: Zhi Yong Wu @ 2012-03-26 15:01 UTC (permalink / raw)
  To: Andreas Färber
  Cc: Stefan Hajnoczi, Zhi Yong Wu, qemu-devel, stefanha, pbonzini

On Mon, Mar 26, 2012 at 10:39 PM, Andreas Färber <afaerber@suse.de> wrote:
> Am 26.03.2012 13:54, schrieb Stefan Hajnoczi:
>> I think host
>> devices will also need to 2-step creation process (init and realize).
>
> Series tested and sent out today. :)
As you've known, some models are not based on DeviceState and
DeviceClass, such as CPUClass and HOSTDeviceClass.
If property structure definition and their put/set functions don't
depend on DeviceState and more generic, that will be more great.
>
> Andreas
>
> --
> SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
> GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg



-- 
Regards,

Zhi Yong Wu

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

* Re: [Qemu-devel] [RFC 0/9] QOM: qomify -netdev
  2012-03-26 14:20   ` Zhi Yong Wu
@ 2012-03-27  8:19     ` Paolo Bonzini
  2012-03-27  9:03       ` Zhi Yong Wu
  0 siblings, 1 reply; 38+ messages in thread
From: Paolo Bonzini @ 2012-03-27  8:19 UTC (permalink / raw)
  To: Zhi Yong Wu; +Cc: Stefan Hajnoczi, Zhi Yong Wu, qemu-devel, stefanha

Il 26/03/2012 16:20, Zhi Yong Wu ha scritto:
> struct PropertyInfo {
>     const char *name;
>     const char *legacy_name;
>     const char **enum_table;
>     int64_t min;
>     int64_t max;
>     int (*parse)(DeviceState *dev, Property *prop, const char *str);
>     int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
>     ObjectPropertyAccessor *get;
>     ObjectPropertyAccessor *set;
>     ObjectPropertyRelease *release;
> };
> 
> Like above, its member functions pointers use DeviceState, so we will
> have to consider how to make this PropertyInfo more generic and be
> used by other Class and Object which are not based on DeviceState.

The member functions do not really do anything that is
DeviceState-specific.  You can change the argument to Object and add a
cast inside the implementations.

Besides, most property types do not have parse/print anymore.  Another
possibility would be to forbid hexNN types for non-DeviceState, since
only those have parse/print.

Paolo

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

* Re: [Qemu-devel] [RFC 1/9] hostdev: introduce the infrastructure for host device model
  2012-03-26  5:40 ` [Qemu-devel] [RFC 1/9] hostdev: introduce the infrastructure for host device model zwu.kernel
  2012-03-26  5:54   ` Zhi Yong Wu
@ 2012-03-27  8:23   ` Paolo Bonzini
  2012-03-27  9:06     ` Zhi Yong Wu
  1 sibling, 1 reply; 38+ messages in thread
From: Paolo Bonzini @ 2012-03-27  8:23 UTC (permalink / raw)
  To: zwu.kernel; +Cc: Zhi Yong Wu, qemu-devel, stefanha

Il 26/03/2012 07:40, zwu.kernel@gmail.com ha scritto:
> +#define DEFINE_HOSTDEV_PROP_PEER(_n, _s, _f)             \
> +    DEFINE_HOSTDEV_PROP(_n, _s, _f, hostdev_prop_netdev, NetClientState*)

This should be simply a link<NetDev> property.

Paolo

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

* Re: [Qemu-devel] [RFC 2/9] net: introduce one net host device class
  2012-03-26  5:40 ` [Qemu-devel] [RFC 2/9] net: introduce one net host device class zwu.kernel
@ 2012-03-27  8:30   ` Paolo Bonzini
  2012-03-27  9:13     ` Zhi Yong Wu
  0 siblings, 1 reply; 38+ messages in thread
From: Paolo Bonzini @ 2012-03-27  8:30 UTC (permalink / raw)
  To: zwu.kernel; +Cc: Zhi Yong Wu, qemu-devel, stefanha

Il 26/03/2012 07:40, zwu.kernel@gmail.com ha scritto:
> +    /*< public >*/
> +    QemuOpts *opts;
> +    Monitor *mon;
> +    const char *name;
> +    NetClientState *peer;
> +};

The QemuOpts should not be part of the struct.  You need to store them
into properties at initialization time, and forget them afterwards.

All the infrastructure to do this is already in qdev-properties.c.

Paolo

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

* Re: [Qemu-devel] [RFC 0/9] QOM: qomify -netdev
  2012-03-27  8:19     ` Paolo Bonzini
@ 2012-03-27  9:03       ` Zhi Yong Wu
  0 siblings, 0 replies; 38+ messages in thread
From: Zhi Yong Wu @ 2012-03-27  9:03 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: Stefan Hajnoczi, Zhi Yong Wu, qemu-devel, stefanha

On Tue, Mar 27, 2012 at 4:19 PM, Paolo Bonzini <pbonzini@redhat.com> wrote:
> Il 26/03/2012 16:20, Zhi Yong Wu ha scritto:
>> struct PropertyInfo {
>>     const char *name;
>>     const char *legacy_name;
>>     const char **enum_table;
>>     int64_t min;
>>     int64_t max;
>>     int (*parse)(DeviceState *dev, Property *prop, const char *str);
>>     int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
>>     ObjectPropertyAccessor *get;
>>     ObjectPropertyAccessor *set;
>>     ObjectPropertyRelease *release;
>> };
>>
>> Like above, its member functions pointers use DeviceState, so we will
>> have to consider how to make this PropertyInfo more generic and be
>> used by other Class and Object which are not based on DeviceState.
>
> The member functions do not really do anything that is
> DeviceState-specific.  You can change the argument to Object and add a
> cast inside the implementations.
good.
>
> Besides, most property types do not have parse/print anymore.  Another
> possibility would be to forbid hexNN types for non-DeviceState, since
> only those have parse/print.

By the way, you mentioned that you are working on QemuOpts QOM, it
mean that it will convert all qemu command line options to QOM? We are
very interested in this feature and want to know if it is helpful to
our -netdev QOM.

>
> Paolo



-- 
Regards,

Zhi Yong Wu

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

* Re: [Qemu-devel] [RFC 1/9] hostdev: introduce the infrastructure for host device model
  2012-03-27  8:23   ` Paolo Bonzini
@ 2012-03-27  9:06     ` Zhi Yong Wu
  2012-03-27 10:15       ` Paolo Bonzini
  0 siblings, 1 reply; 38+ messages in thread
From: Zhi Yong Wu @ 2012-03-27  9:06 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: Zhi Yong Wu, qemu-devel, stefanha

On Tue, Mar 27, 2012 at 4:23 PM, Paolo Bonzini <pbonzini@redhat.com> wrote:
> Il 26/03/2012 07:40, zwu.kernel@gmail.com ha scritto:
>> +#define DEFINE_HOSTDEV_PROP_PEER(_n, _s, _f)             \
>> +    DEFINE_HOSTDEV_PROP(_n, _s, _f, hostdev_prop_netdev, NetClientState*)
>
> This should be simply a link<NetDev> property.
IMHO, i don't fully understand what link<NetDev> mean. What is the
difference between it and Child<NetDev>. Can you elaborate this?

>
> Paolo



-- 
Regards,

Zhi Yong Wu

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

* Re: [Qemu-devel] [RFC 2/9] net: introduce one net host device class
  2012-03-27  8:30   ` Paolo Bonzini
@ 2012-03-27  9:13     ` Zhi Yong Wu
  0 siblings, 0 replies; 38+ messages in thread
From: Zhi Yong Wu @ 2012-03-27  9:13 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: Zhi Yong Wu, qemu-devel, stefanha

On Tue, Mar 27, 2012 at 4:30 PM, Paolo Bonzini <pbonzini@redhat.com> wrote:
> Il 26/03/2012 07:40, zwu.kernel@gmail.com ha scritto:
>> +    /*< public >*/
>> +    QemuOpts *opts;
>> +    Monitor *mon;
>> +    const char *name;
>> +    NetClientState *peer;
>> +};
>
> The QemuOpts should not be part of the struct.  You need to store them
> into properties at initialization time, and forget them afterwards.
This should be done in your QemuOpts QOM feature, right?:)
>
> All the infrastructure to do this is already in qdev-properties.c.
>
> Paolo



-- 
Regards,

Zhi Yong Wu

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

* Re: [Qemu-devel] [RFC 1/9] hostdev: introduce the infrastructure for host device model
  2012-03-27  9:06     ` Zhi Yong Wu
@ 2012-03-27 10:15       ` Paolo Bonzini
  2012-03-27 11:59         ` Zhi Yong Wu
  0 siblings, 1 reply; 38+ messages in thread
From: Paolo Bonzini @ 2012-03-27 10:15 UTC (permalink / raw)
  To: Zhi Yong Wu; +Cc: Zhi Yong Wu, qemu-devel, stefanha

Il 27/03/2012 11:06, Zhi Yong Wu ha scritto:
>>> >> +#define DEFINE_HOSTDEV_PROP_PEER(_n, _s, _f)             \
>>> >> +    DEFINE_HOSTDEV_PROP(_n, _s, _f, hostdev_prop_netdev, NetClientState*)
>> >
>> > This should be simply a link<NetDev> property.
> IMHO, i don't fully understand what link<NetDev> mean. What is the
> difference between it and Child<NetDev>. Can you elaborate this?

link<NetDev> is a pointer to another object.  child<NetDev> means that
you effectively embed the other object.  You die, the other object dies.

Your QOMification should also convert NICState to QOM.  The NICState
will be a child of the NIC device, and similar for all other
NetClientStates.  I'm not sure why you are not converting qemu_new_nic
to QOM, since NICState is-a NetClientState.

I think this conversion is extremely premature, for multiple reasons.

1) together with each conversion, we should make sure that each object
has a canonical path.  Without a canonical path you cannot use
object_property_set_link, for example.  So far, not even board-level
devices have a canonical path.  I'll bump this towards the top of my list.

2) the network devices subsystem is among the most complicated.  There
is already a pending refactoring for hubs; you are making these changes
on top of hubs but didn't even state this anywhere.  Let's concentrate
on one thing at a time, please.

3) the network devices already support hotplug very well, so it's also
not too useful to do them first.  Let's first do chardevs.

Paolo

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

* Re: [Qemu-devel] [RFC 1/9] hostdev: introduce the infrastructure for host device model
  2012-03-27 10:15       ` Paolo Bonzini
@ 2012-03-27 11:59         ` Zhi Yong Wu
  2012-03-27 13:58           ` Paolo Bonzini
  0 siblings, 1 reply; 38+ messages in thread
From: Zhi Yong Wu @ 2012-03-27 11:59 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: Zhi Yong Wu, qemu-devel, stefanha

On Tue, Mar 27, 2012 at 6:15 PM, Paolo Bonzini <pbonzini@redhat.com> wrote:
> Il 27/03/2012 11:06, Zhi Yong Wu ha scritto:
>>>> >> +#define DEFINE_HOSTDEV_PROP_PEER(_n, _s, _f)             \
>>>> >> +    DEFINE_HOSTDEV_PROP(_n, _s, _f, hostdev_prop_netdev, NetClientState*)
>>> >
>>> > This should be simply a link<NetDev> property.
>> IMHO, i don't fully understand what link<NetDev> mean. What is the
>> difference between it and Child<NetDev>. Can you elaborate this?
>
> link<NetDev> is a pointer to another object.  child<NetDev> means that
Where are link<NetDev> used? what is relationship between the two
objects? it represent the relation between bus object and device
object?

> you effectively embed the other object.  You die, the other object dies.
>
> Your QOMification should also convert NICState to QOM.  The NICState
> will be a child of the NIC device, and similar for all other
> NetClientStates.  I'm not sure why you are not converting qemu_new_nic
We will not convert -net to QOM, that is, we don't care -net nic.
Moreover, -device has exposed network card info.
> to QOM, since NICState is-a NetClientState.
>
> I think this conversion is extremely premature, for multiple reasons.
>
> 1) together with each conversion, we should make sure that each object
> has a canonical path.  Without a canonical path you cannot use
> object_property_set_link, for example.  So far, not even board-level
> devices have a canonical path.  I'll bump this towards the top of my list.
>
> 2) the network devices subsystem is among the most complicated.  There
> is already a pending refactoring for hubs; you are making these changes
> on top of hubs but didn't even state this anywhere.  Let's concentrate
> on one thing at a time, please.
good advice. thanks
>
> 3) the network devices already support hotplug very well, so it's also
> not too useful to do them first.  Let's first do chardevs.
We hope that -netdev options info can be configurated or changed
purely via QOM, not command line.
>
> Paolo



-- 
Regards,

Zhi Yong Wu

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

* Re: [Qemu-devel] [RFC 1/9] hostdev: introduce the infrastructure for host device model
  2012-03-27 11:59         ` Zhi Yong Wu
@ 2012-03-27 13:58           ` Paolo Bonzini
  2012-03-27 14:18             ` Zhi Yong Wu
  0 siblings, 1 reply; 38+ messages in thread
From: Paolo Bonzini @ 2012-03-27 13:58 UTC (permalink / raw)
  To: Zhi Yong Wu; +Cc: Zhi Yong Wu, qemu-devel, stefanha

Il 27/03/2012 13:59, Zhi Yong Wu ha scritto:
> On Tue, Mar 27, 2012 at 6:15 PM, Paolo Bonzini <pbonzini@redhat.com> wrote:
>> Il 27/03/2012 11:06, Zhi Yong Wu ha scritto:
>>>>>>> +#define DEFINE_HOSTDEV_PROP_PEER(_n, _s, _f)             \
>>>>>>> +    DEFINE_HOSTDEV_PROP(_n, _s, _f, hostdev_prop_netdev, NetClientState*)
>>>>>
>>>>> This should be simply a link<NetDev> property.
>>> IMHO, i don't fully understand what link<NetDev> mean. What is the
>>> difference between it and Child<NetDev>. Can you elaborate this?
>>
>> link<NetDev> is a pointer to another object.  child<NetDev> means that
> Where are link<NetDev> used?

The peer property needs to be one.

> what is relationship between the two objects?

A has a pointer to B.

> it represent the relation between bus object and device object?

We're talking about netdevs, bus and object does not matter here no?

> We will not convert -net to QOM, that is, we don't care -net nic.

As long as it works that's fine but...

> Moreover, -device has exposed network card info.

... this is extremely confused.  Each NIC device has a NIC-type
NetClientState.  If NetClientState is converted to QOM, all of its
instances should be QOM objects, including those owned by NICs.

>> 3) the network devices already support hotplug very well, so it's also
>> not too useful to do them first.  Let's first do chardevs.
> 
> We hope that -netdev options info can be configurated or changed
> purely via QOM, not command line.

Yes, but does it buy anything or it is just a nice exercise?

Paolo

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

* Re: [Qemu-devel] [RFC 1/9] hostdev: introduce the infrastructure for host device model
  2012-03-27 13:58           ` Paolo Bonzini
@ 2012-03-27 14:18             ` Zhi Yong Wu
  2012-03-27 14:50               ` Paolo Bonzini
  0 siblings, 1 reply; 38+ messages in thread
From: Zhi Yong Wu @ 2012-03-27 14:18 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: Zhi Yong Wu, qemu-devel, stefanha

On Tue, Mar 27, 2012 at 9:58 PM, Paolo Bonzini <pbonzini@redhat.com> wrote:
> Il 27/03/2012 13:59, Zhi Yong Wu ha scritto:
>> On Tue, Mar 27, 2012 at 6:15 PM, Paolo Bonzini <pbonzini@redhat.com> wrote:
>>> Il 27/03/2012 11:06, Zhi Yong Wu ha scritto:
>>>>>>>> +#define DEFINE_HOSTDEV_PROP_PEER(_n, _s, _f)             \
>>>>>>>> +    DEFINE_HOSTDEV_PROP(_n, _s, _f, hostdev_prop_netdev, NetClientState*)
>>>>>>
>>>>>> This should be simply a link<NetDev> property.
>>>> IMHO, i don't fully understand what link<NetDev> mean. What is the
>>>> difference between it and Child<NetDev>. Can you elaborate this?
>>>
>>> link<NetDev> is a pointer to another object.  child<NetDev> means that
>> Where are link<NetDev> used?
>
> The peer property needs to be one.
sorry, i don't get what it means.
>
>> what is relationship between the two objects?
>
> A has a pointer to B.
I knew this, but can you say one example in QEMU device model? I
checked QEMU code, and found that those link functions in object.c are
not currently used. right?
>
>> it represent the relation between bus object and device object?
>
> We're talking about netdevs, bus and object does not matter here no?
yeah.
>
>> We will not convert -net to QOM, that is, we don't care -net nic.
>
> As long as it works that's fine but...
>
>> Moreover, -device has exposed network card info.
>
> ... this is extremely confused.  Each NIC device has a NIC-type
> NetClientState.  If NetClientState is converted to QOM, all of its
The original idea about -netdev QOM is to convert NetClientState to
QOM, but now this idea seems to be changed.
> instances should be QOM objects, including those owned by NICs.
>
>>> 3) the network devices already support hotplug very well, so it's also
>>> not too useful to do them first.  Let's first do chardevs.
>>
>> We hope that -netdev options info can be configurated or changed
>> purely via QOM, not command line.
>
> Yes, but does it buy anything or it is just a nice exercise?
buy anything? sorry, i don't understand this.
>
> Paolo



-- 
Regards,

Zhi Yong Wu

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

* Re: [Qemu-devel] [RFC 1/9] hostdev: introduce the infrastructure for host device model
  2012-03-27 14:18             ` Zhi Yong Wu
@ 2012-03-27 14:50               ` Paolo Bonzini
  2012-03-27 21:21                 ` Zhi Yong Wu
  0 siblings, 1 reply; 38+ messages in thread
From: Paolo Bonzini @ 2012-03-27 14:50 UTC (permalink / raw)
  To: Zhi Yong Wu; +Cc: Zhi Yong Wu, qemu-devel, stefanha

Il 27/03/2012 16:18, Zhi Yong Wu ha scritto:
> On Tue, Mar 27, 2012 at 9:58 PM, Paolo Bonzini <pbonzini@redhat.com> wrote:
>> Il 27/03/2012 13:59, Zhi Yong Wu ha scritto:
>>> On Tue, Mar 27, 2012 at 6:15 PM, Paolo Bonzini <pbonzini@redhat.com> wrote:
>>>> Il 27/03/2012 11:06, Zhi Yong Wu ha scritto:
>>>>>>>>> +#define DEFINE_HOSTDEV_PROP_PEER(_n, _s, _f)             \
>>>>>>>>> +    DEFINE_HOSTDEV_PROP(_n, _s, _f, hostdev_prop_netdev, NetClientState*)
>>>>>>>
>>>>>>> This should be simply a link<NetDev> property.
>>>>> IMHO, i don't fully understand what link<NetDev> mean. What is the
>>>>> difference between it and Child<NetDev>. Can you elaborate this?
>>>>
>>>> link<NetDev> is a pointer to another object.  child<NetDev> means that
>>> Where are link<NetDev> used?
>>
>> The peer property needs to be one.
> sorry, i don't get what it means.

Links are pointers.  As you convert host devices to QOM, pointer
properties such as drive or chardev need to become links.  Peer is
another pointer property that needs to become a link.

>>> what is relationship between the two objects?
>>
>> A has a pointer to B.
>
> I knew this, but can you say one example in QEMU device model? I
> checked QEMU code, and found that those link functions in object.c are
> not currently used. right?

Yes, that's correct.  Everything that uses PROP_PTR needs to become a
link.  We cannot do that yet because devices do not yet have a canonical
path.

>>> Moreover, -device has exposed network card info.
>>
>> ... this is extremely confused.  Each NIC device has a NIC-type
>> NetClientState.  If NetClientState is converted to QOM, all of its
> The original idea about -netdev QOM is to convert NetClientState to
> QOM, but now this idea seems to be changed.

I cannot parse this at all.  You have not converted all of
NetClientState to QOM, have you?

>>> We hope that -netdev options info can be configurated or changed
>>> purely via QOM, not command line.
>>
>> Yes, but does it buy anything or it is just a nice exercise?
> 
> buy anything? sorry, i don't understand this.

What's the advantage?  Converting chardev would give hotplug.  What can
we do with a QOMified netdev that we cannot do now?

Paolo

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

* Re: [Qemu-devel] [RFC 1/9] hostdev: introduce the infrastructure for host device model
  2012-03-27 14:50               ` Paolo Bonzini
@ 2012-03-27 21:21                 ` Zhi Yong Wu
  2012-03-28  6:41                   ` Paolo Bonzini
  0 siblings, 1 reply; 38+ messages in thread
From: Zhi Yong Wu @ 2012-03-27 21:21 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: Zhi Yong Wu, qemu-devel, stefanha

On Tue, Mar 27, 2012 at 10:50 PM, Paolo Bonzini <pbonzini@redhat.com> wrote:
> Il 27/03/2012 16:18, Zhi Yong Wu ha scritto:
>> On Tue, Mar 27, 2012 at 9:58 PM, Paolo Bonzini <pbonzini@redhat.com> wrote:
>>> Il 27/03/2012 13:59, Zhi Yong Wu ha scritto:
>>>> On Tue, Mar 27, 2012 at 6:15 PM, Paolo Bonzini <pbonzini@redhat.com> wrote:
>>>>> Il 27/03/2012 11:06, Zhi Yong Wu ha scritto:
>>>>>>>>>> +#define DEFINE_HOSTDEV_PROP_PEER(_n, _s, _f)             \
>>>>>>>>>> +    DEFINE_HOSTDEV_PROP(_n, _s, _f, hostdev_prop_netdev, NetClientState*)
>>>>>>>>
>>>>>>>> This should be simply a link<NetDev> property.
>>>>>> IMHO, i don't fully understand what link<NetDev> mean. What is the
>>>>>> difference between it and Child<NetDev>. Can you elaborate this?
>>>>>
>>>>> link<NetDev> is a pointer to another object.  child<NetDev> means that
>>>> Where are link<NetDev> used?
>>>
>>> The peer property needs to be one.
>> sorry, i don't get what it means.
>
> Links are pointers.  As you convert host devices to QOM, pointer
> properties such as drive or chardev need to become links.  Peer is
> another pointer property that needs to become a link.
It makes sense to me, thanks.
>
>>>> what is relationship between the two objects?
>>>
>>> A has a pointer to B.
>>
>> I knew this, but can you say one example in QEMU device model? I
>> checked QEMU code, and found that those link functions in object.c are
>> not currently used. right?
>
> Yes, that's correct.  Everything that uses PROP_PTR needs to become a
But i didn't see that that stuff which uses PROP_PTR become a link in
current QEMU code.
For example:
static Property apic_properties_common[] = {
  ......
    DEFINE_PROP_PTR("cpu_env", APICCommonState, cpu_env),
  .....
    DEFINE_PROP_END_OF_LIST(),
};

It define one PROP_PTR cpu_env, but i didn't see stuff which made it
become one link. Did i miss anything?

> link.  We cannot do that yet because devices do not yet have a canonical
> path.
Cannonical path means that it is one absolute path or partial path?
>
>>>> Moreover, -device has exposed network card info.
>>>
>>> ... this is extremely confused.  Each NIC device has a NIC-type
>>> NetClientState.  If NetClientState is converted to QOM, all of its
>> The original idea about -netdev QOM is to convert NetClientState to
>> QOM, but now this idea seems to be changed.
>
> I cannot parse this at all.  You have not converted all of
> NetClientState to QOM, have you?
No. I am not sure if we need to convert all and we need to know what
the benefit is.
>
>>>> We hope that -netdev options info can be configurated or changed
>>>> purely via QOM, not command line.
>>>
>>> Yes, but does it buy anything or it is just a nice exercise?
>>
>> buy anything? sorry, i don't understand this.
>
> What's the advantage?  Converting chardev would give hotplug.  What can
> we do with a QOMified netdev that we cannot do now?
It can be configurated or changed purely via QOM, this is one of the
advantages by itself. And I think that it should also give hotplug.
>
> Paolo



-- 
Regards,

Zhi Yong Wu

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

* Re: [Qemu-devel] [RFC 1/9] hostdev: introduce the infrastructure for host device model
  2012-03-27 21:21                 ` Zhi Yong Wu
@ 2012-03-28  6:41                   ` Paolo Bonzini
  2012-03-28  7:50                     ` Zhi Yong Wu
  2012-03-28  7:53                     ` Zhi Yong Wu
  0 siblings, 2 replies; 38+ messages in thread
From: Paolo Bonzini @ 2012-03-28  6:41 UTC (permalink / raw)
  To: Zhi Yong Wu; +Cc: Zhi Yong Wu, qemu-devel, stefanha

Il 27/03/2012 23:21, Zhi Yong Wu ha scritto:
>> Yes, that's correct.  Everything that uses PROP_PTR needs to become a
> But i didn't see that that stuff which uses PROP_PTR become a link in
> current QEMU code.

Yes, that's why I wrote "needs to become".  In order to use links, you
need two things:

* the target needs to have a canonical path (more on this below);

* the target needs to be QOMified.

Most PTR properties are pointers to devices, but devices so far don't
always have a canonical path so the conversion could not happen.  Others
are to CPUs, which are not yet QOMified.

>> link.  We cannot do that yet because devices do not yet have a canonical
>> path.
> Cannonical path means that it is one absolute path or partial path?

Canonical path means it consists exclusively of child<> properties.
Unlike the links, which form a graph, children form a tree so it's easy
to define a canonical naming of all objects.

>>>>> Moreover, -device has exposed network card info.
>>>>
>>>> ... this is extremely confused.  Each NIC device has a NIC-type
>>>> NetClientState.  If NetClientState is converted to QOM, all of its
>>> The original idea about -netdev QOM is to convert NetClientState to
>>> QOM, but now this idea seems to be changed.
>>
>> I cannot parse this at all.  You have not converted all of
>> NetClientState to QOM, have you?
> No. I am not sure if we need to convert all and we need to know what
> the benefit is.

We do.  You just cannot convert the same object half to QOM and half
not.  It leads to insanity.

>>>>> We hope that -netdev options info can be configurated or changed
>>>>> purely via QOM, not command line.
>>>>
>>>> Yes, but does it buy anything or it is just a nice exercise?
>>>
>>> buy anything? sorry, i don't understand this.
>>
>> What's the advantage?  Converting chardev would give hotplug.  What can
>> we do with a QOMified netdev that we cannot do now?
> It can be configurated or changed purely via QOM, this is one of the
> advantages by itself.

Sure, but what does it do better than netdev_add?

Note that the same holds for devices.  Anthony converted them as the
proof that QOM could deal with them, and that conversions could be done
in small steps.  But strictly speaking it was not necessary to convert
them to QOM; so far, conversion brought no substantial improvement.

> And I think that it should also give hotplug.

Hotplug of -netdev is already supported.

Paolo

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

* Re: [Qemu-devel] [RFC 1/9] hostdev: introduce the infrastructure for host device model
  2012-03-28  6:41                   ` Paolo Bonzini
@ 2012-03-28  7:50                     ` Zhi Yong Wu
  2012-03-28  7:53                     ` Zhi Yong Wu
  1 sibling, 0 replies; 38+ messages in thread
From: Zhi Yong Wu @ 2012-03-28  7:50 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: Zhi Yong Wu, qemu-devel, stefanha

On Wed, Mar 28, 2012 at 2:41 PM, Paolo Bonzini <pbonzini@redhat.com> wrote:
> Il 27/03/2012 23:21, Zhi Yong Wu ha scritto:
>>> Yes, that's correct.  Everything that uses PROP_PTR needs to become a
>> But i didn't see that that stuff which uses PROP_PTR become a link in
>> current QEMU code.
>
> Yes, that's why I wrote "needs to become".  In order to use links, you
> need two things:
>
> * the target needs to have a canonical path (more on this below);
>
> * the target needs to be QOMified.
>
> Most PTR properties are pointers to devices, but devices so far don't
> always have a canonical path so the conversion could not happen.  Others
> are to CPUs, which are not yet QOMified.
nice, got it. link is next step for PROP_PTR, thanks
>
>>> link.  We cannot do that yet because devices do not yet have a canonical
>>> path.
>> Cannonical path means that it is one absolute path or partial path?
>
> Canonical path means it consists exclusively of child<> properties.
> Unlike the links, which form a graph, children form a tree so it's easy
> to define a canonical naming of all objects.
>
>>>>>> Moreover, -device has exposed network card info.
>>>>>
>>>>> ... this is extremely confused.  Each NIC device has a NIC-type
>>>>> NetClientState.  If NetClientState is converted to QOM, all of its
>>>> The original idea about -netdev QOM is to convert NetClientState to
>>>> QOM, but now this idea seems to be changed.
>>>
>>> I cannot parse this at all.  You have not converted all of
>>> NetClientState to QOM, have you?
>> No. I am not sure if we need to convert all and we need to know what
>> the benefit is.
>
> We do.  You just cannot convert the same object half to QOM and half
> not.  It leads to insanity.
OK, i will convert all.
>
>>>>>> We hope that -netdev options info can be configurated or changed
>>>>>> purely via QOM, not command line.
>>>>>
>>>>> Yes, but does it buy anything or it is just a nice exercise?
>>>>
>>>> buy anything? sorry, i don't understand this.
>>>
>>> What's the advantage?  Converting chardev would give hotplug.  What can
>>> we do with a QOMified netdev that we cannot do now?
>> It can be configurated or changed purely via QOM, this is one of the
>> advantages by itself.
>
> Sure, but what does it do better than netdev_add?
If -netdev QOM is supported, libvirt can use non-root account to get
some service from QEMU. this will enforce security, right?
>
> Note that the same holds for devices.  Anthony converted them as the
> proof that QOM could deal with them, and that conversions could be done
> in small steps.  But strictly speaking it was not necessary to convert
> them to QOM; so far, conversion brought no substantial improvement.
>
>> And I think that it should also give hotplug.
>
> Hotplug of -netdev is already supported.
ah? IHMO, i have limited knowledge about QOM, and don't know why you
said that chardev QOM can provide hotplug, how to play with it?

>
> Paolo



-- 
Regards,

Zhi Yong Wu

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

* Re: [Qemu-devel] [RFC 1/9] hostdev: introduce the infrastructure for host device model
  2012-03-28  6:41                   ` Paolo Bonzini
  2012-03-28  7:50                     ` Zhi Yong Wu
@ 2012-03-28  7:53                     ` Zhi Yong Wu
  2012-03-28  8:02                       ` Paolo Bonzini
  1 sibling, 1 reply; 38+ messages in thread
From: Zhi Yong Wu @ 2012-03-28  7:53 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: Zhi Yong Wu, qemu-devel, stefanha

By the way, why have we not add one QOM cookbook to docs? It is very
useful for us newbiew to learn.

On Wed, Mar 28, 2012 at 2:41 PM, Paolo Bonzini <pbonzini@redhat.com> wrote:
> Il 27/03/2012 23:21, Zhi Yong Wu ha scritto:
>>> Yes, that's correct.  Everything that uses PROP_PTR needs to become a
>> But i didn't see that that stuff which uses PROP_PTR become a link in
>> current QEMU code.
>
> Yes, that's why I wrote "needs to become".  In order to use links, you
> need two things:
>
> * the target needs to have a canonical path (more on this below);
>
> * the target needs to be QOMified.
>
> Most PTR properties are pointers to devices, but devices so far don't
> always have a canonical path so the conversion could not happen.  Others
> are to CPUs, which are not yet QOMified.
>
>>> link.  We cannot do that yet because devices do not yet have a canonical
>>> path.
>> Cannonical path means that it is one absolute path or partial path?
>
> Canonical path means it consists exclusively of child<> properties.
> Unlike the links, which form a graph, children form a tree so it's easy
> to define a canonical naming of all objects.
>
>>>>>> Moreover, -device has exposed network card info.
>>>>>
>>>>> ... this is extremely confused.  Each NIC device has a NIC-type
>>>>> NetClientState.  If NetClientState is converted to QOM, all of its
>>>> The original idea about -netdev QOM is to convert NetClientState to
>>>> QOM, but now this idea seems to be changed.
>>>
>>> I cannot parse this at all.  You have not converted all of
>>> NetClientState to QOM, have you?
>> No. I am not sure if we need to convert all and we need to know what
>> the benefit is.
>
> We do.  You just cannot convert the same object half to QOM and half
> not.  It leads to insanity.
>
>>>>>> We hope that -netdev options info can be configurated or changed
>>>>>> purely via QOM, not command line.
>>>>>
>>>>> Yes, but does it buy anything or it is just a nice exercise?
>>>>
>>>> buy anything? sorry, i don't understand this.
>>>
>>> What's the advantage?  Converting chardev would give hotplug.  What can
>>> we do with a QOMified netdev that we cannot do now?
>> It can be configurated or changed purely via QOM, this is one of the
>> advantages by itself.
>
> Sure, but what does it do better than netdev_add?
>
> Note that the same holds for devices.  Anthony converted them as the
> proof that QOM could deal with them, and that conversions could be done
> in small steps.  But strictly speaking it was not necessary to convert
> them to QOM; so far, conversion brought no substantial improvement.
>
>> And I think that it should also give hotplug.
>
> Hotplug of -netdev is already supported.
>
> Paolo



-- 
Regards,

Zhi Yong Wu

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

* Re: [Qemu-devel] [RFC 1/9] hostdev: introduce the infrastructure for host device model
  2012-03-28  7:53                     ` Zhi Yong Wu
@ 2012-03-28  8:02                       ` Paolo Bonzini
  2012-03-28  8:05                         ` 陳韋任
  0 siblings, 1 reply; 38+ messages in thread
From: Paolo Bonzini @ 2012-03-28  8:02 UTC (permalink / raw)
  To: Zhi Yong Wu; +Cc: Zhi Yong Wu, qemu-devel, stefanha

Il 28/03/2012 09:53, Zhi Yong Wu ha scritto:
> By the way, why have we not add one QOM cookbook to docs? It is very
> useful for us newbiew to learn.

Yes, that would be useful.  It takes time to write docs unfortunately. :(

Paolo

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

* Re: [Qemu-devel] [RFC 1/9] hostdev: introduce the infrastructure for host device model
  2012-03-28  8:02                       ` Paolo Bonzini
@ 2012-03-28  8:05                         ` 陳韋任
  2012-03-28  8:25                           ` Zhi Yong Wu
  0 siblings, 1 reply; 38+ messages in thread
From: 陳韋任 @ 2012-03-28  8:05 UTC (permalink / raw)
  To: Zhi Yong Wu, Zhi Yong Wu, qemu-devel, stefanha

> Il 28/03/2012 09:53, Zhi Yong Wu ha scritto:
> > By the way, why have we not add one QOM cookbook to docs? It is very
> > useful for us newbiew to learn.

  You can write what you learn during this work. This should be a good
start! :)

Regards,
chenwj

-- 
Wei-Ren Chen (陳韋任)
Computer Systems Lab, Institute of Information Science,
Academia Sinica, Taiwan (R.O.C.)
Tel:886-2-2788-3799 #1667
Homepage: http://people.cs.nctu.edu.tw/~chenwj

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

* Re: [Qemu-devel] [RFC 1/9] hostdev: introduce the infrastructure for host device model
  2012-03-28  8:05                         ` 陳韋任
@ 2012-03-28  8:25                           ` Zhi Yong Wu
  2012-03-28  8:29                             ` 陳韋任
  0 siblings, 1 reply; 38+ messages in thread
From: Zhi Yong Wu @ 2012-03-28  8:25 UTC (permalink / raw)
  To: 陳韋任; +Cc: Zhi Yong Wu, qemu-devel, stefanha

On Wed, Mar 28, 2012 at 4:05 PM, 陳韋任 <chenwj@iis.sinica.edu.tw> wrote:
>> Il 28/03/2012 09:53, Zhi Yong Wu ha scritto:
>> > By the way, why have we not add one QOM cookbook to docs? It is very
>> > useful for us newbiew to learn.
>
>  You can write what you learn during this work. This should be a good
> start! :)
You know, i need to get enough skills now. :)
>
> Regards,
> chenwj
>
> --
> Wei-Ren Chen (陳韋任)
> Computer Systems Lab, Institute of Information Science,
> Academia Sinica, Taiwan (R.O.C.)
> Tel:886-2-2788-3799 #1667
> Homepage: http://people.cs.nctu.edu.tw/~chenwj



-- 
Regards,

Zhi Yong Wu

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

* Re: [Qemu-devel] [RFC 1/9] hostdev: introduce the infrastructure for host device model
  2012-03-28  8:25                           ` Zhi Yong Wu
@ 2012-03-28  8:29                             ` 陳韋任
  0 siblings, 0 replies; 38+ messages in thread
From: 陳韋任 @ 2012-03-28  8:29 UTC (permalink / raw)
  To: Zhi Yong Wu; +Cc: Zhi Yong Wu, qemu-devel, 陳韋任, stefanha

On Wed, Mar 28, 2012 at 04:25:54PM +0800, Zhi Yong Wu wrote:
> On Wed, Mar 28, 2012 at 4:05 PM, 陳韋任 <chenwj@iis.sinica.edu.tw> wrote:
> >> Il 28/03/2012 09:53, Zhi Yong Wu ha scritto:
> >> > By the way, why have we not add one QOM cookbook to docs? It is very
> >> > useful for us newbiew to learn.
> >
> >  You can write what you learn during this work. This should be a good
> > start! :)
> You know, i need to get enough skills now. :)

  I mean make some notes during the work. Good luck!

Regards,
chenwj

-- 
Wei-Ren Chen (陳韋任)
Computer Systems Lab, Institute of Information Science,
Academia Sinica, Taiwan (R.O.C.)
Tel:886-2-2788-3799 #1667
Homepage: http://people.cs.nctu.edu.tw/~chenwj

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

end of thread, other threads:[~2012-03-28  8:29 UTC | newest]

Thread overview: 38+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-26  5:40 [Qemu-devel] [RFC 0/9] QOM: qomify -netdev zwu.kernel
2012-03-26  5:40 ` [Qemu-devel] [RFC 1/9] hostdev: introduce the infrastructure for host device model zwu.kernel
2012-03-26  5:54   ` Zhi Yong Wu
2012-03-27  8:23   ` Paolo Bonzini
2012-03-27  9:06     ` Zhi Yong Wu
2012-03-27 10:15       ` Paolo Bonzini
2012-03-27 11:59         ` Zhi Yong Wu
2012-03-27 13:58           ` Paolo Bonzini
2012-03-27 14:18             ` Zhi Yong Wu
2012-03-27 14:50               ` Paolo Bonzini
2012-03-27 21:21                 ` Zhi Yong Wu
2012-03-28  6:41                   ` Paolo Bonzini
2012-03-28  7:50                     ` Zhi Yong Wu
2012-03-28  7:53                     ` Zhi Yong Wu
2012-03-28  8:02                       ` Paolo Bonzini
2012-03-28  8:05                         ` 陳韋任
2012-03-28  8:25                           ` Zhi Yong Wu
2012-03-28  8:29                             ` 陳韋任
2012-03-26  5:40 ` [Qemu-devel] [PATCH] net: qomify -netdev zwu.kernel
2012-03-26  5:40 ` zwu.kernel
2012-03-26  5:44   ` Zhi Yong Wu
2012-03-26  5:40 ` [Qemu-devel] [RFC 2/9] net: introduce one net host device class zwu.kernel
2012-03-27  8:30   ` Paolo Bonzini
2012-03-27  9:13     ` Zhi Yong Wu
2012-03-26  5:40 ` [Qemu-devel] [RFC 3/9] net: adjust net common part for qomify -netdev zwu.kernel
2012-03-26  5:40 ` [Qemu-devel] [RFC 4/9] net: adjust nic init API zwu.kernel
2012-03-26  5:40 ` [Qemu-devel] [RFC 5/9] net: adjust dump " zwu.kernel
2012-03-26  5:40 ` [Qemu-devel] [RFC 6/9] net: qomify -netdev user zwu.kernel
2012-03-26  5:40 ` [Qemu-devel] [RFC 7/9] net: qomify -netdev socket zwu.kernel
2012-03-26  5:40 ` [Qemu-devel] [RFC 8/9] net: qomify -netdev vde zwu.kernel
2012-03-26  5:40 ` [Qemu-devel] [RFC 9/9] net: qomify -netdev tap & -netdev bridge zwu.kernel
2012-03-26 11:54 ` [Qemu-devel] [RFC 0/9] QOM: qomify -netdev Stefan Hajnoczi
2012-03-26 14:20   ` Zhi Yong Wu
2012-03-27  8:19     ` Paolo Bonzini
2012-03-27  9:03       ` Zhi Yong Wu
2012-03-26 14:39   ` Andreas Färber
2012-03-26 14:57     ` Stefan Hajnoczi
2012-03-26 15:01     ` Zhi Yong Wu

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.