Skip to contentSkip to conversation

QOM: qomify -netdev

RFC In review [email protected] 5 participants 38 messages Mar 26, 2012 – Mar 28, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover QOM: qomify -netdev

From: Zhi Yong Wu <[email protected]>

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
Signature · 1 line
1.7.6
#1 lore raw

RFC 1/9 hostdev: introduce the infrastructure for host device model

From: Zhi Yong Wu <[email protected]>

---
 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
include/qemu/hostdev.h new file +128 -0
new file mode 100644
index 0000000..a291761
@@ -0,0 +1,128 @@
+/*
+ * QEMU host device model
+ *
+ * Copyright IBM, Corp. 2012
+ *
+ * Authors:
+ *  Zhi Yong Wu   <[email protected]>
+ *
+ * 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
qom/Makefile +1 -1
index 34c6de5..4731fb9 100644
@@ -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
qom/hostdev.c new file +333 -0

333 lines not on this page · raw message

Signature · 1 line
1.7.6
#18 lore raw

PATCH 1/1 net: qomify -netdev

In reply to [email protected]

From: Zhi Yong Wu <[email protected]>

---
 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(-)
net.c +53 -1
index dd67d16..ee8737c 100644
@@ -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)
net.h +2 -0
index 60837ab..0926a42 100644
@@ -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;
net/slirp.c +33 -0
index d3e56fc..a30b4f0 100644
@@ -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)
net/slirp.h +1 -0
index e6000af..c6f5079 100644
@@ -27,6 +27,7 @@
 #include "qemu-common.h"
 #include "qdict.h"
 #include "qemu-option.h"
+#include "qemu/hostdev.h"
 
 #ifdef CONFIG_SLIRP
 
net/socket.c +29 -4
index 55d9820..778a5a3 100644
@@ -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)
net/socket.h +5 -2
index 5edf17c..70d07cb 100644
@@ -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 */
net/tap.c +46 -0

49 lines not on this page · raw message

net/tap.h +1 -0
index 0e35e81..832aa08 100644
@@ -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"
qom/Makefile +1 -1
index 34c6de5..4731fb9 100644
@@ -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
vl.c +6 -6
index 112b0e0..0fa8e03 100644
@@ -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);
Signature · 1 line
1.7.6
#23 lore raw

RFC 4/9 net: adjust nic init API

In reply to [email protected]

From: Zhi Yong Wu <[email protected]>

---
 net.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
net.c +6 -4
index ff8ddaf..22ed51b 100644
@@ -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");
Signature · 1 line
1.7.6
#22 lore raw

RFC 3/9 net: adjust net common part for qomify -netdev

In reply to [email protected]

From: Zhi Yong Wu <[email protected]>

---
 net.c |  108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 net.h |    1 +
 vl.c  |   12 +++---
 3 files changed, 109 insertions(+), 12 deletions(-)
net.c +102 -6
index 608c090..ff8ddaf 100644
@@ -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)
net.h +1 -0
index 912fa2d..3de60d4 100644
@@ -88,6 +88,7 @@ typedef struct NetClientInfo {
 } NetClientInfo;
 
 struct NetClientState {
+    NETDevice net_dev;
     NetClientInfo *info;
     int link_down;
     QTAILQ_ENTRY(NetClientState) next;
vl.c +6 -6
index 112b0e0..0fa8e03 100644
@@ -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);
Signature · 1 line
1.7.6
#19 lore raw

RFC 2/9 net: introduce one net host device class

In reply to [email protected]

From: Zhi Yong Wu <[email protected]>

---
 net.c |   35 +++++++++++++++++++++++++++++++++++
 net.h |   27 +++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 0 deletions(-)
net.c +35 -0
index dd67d16..608c090 100644
@@ -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)
+
net.h +27 -0
index 60837ab..912fa2d 100644
@@ -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];
Signature · 1 line
1.7.6
#27 lore raw

RFC 6/9 net: qomify -netdev user

In reply to [email protected]

From: Zhi Yong Wu <[email protected]>

---
 net/slirp.c |   42 ++++++++++++++++++++++++++++++++++++++----
 net/slirp.h |    7 +++----
 2 files changed, 41 insertions(+), 8 deletions(-)
net/slirp.c +38 -4
index d3e56fc..62fea09 100644
@@ -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)
net/slirp.h +3 -4
index e6000af..1364347 100644
@@ -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);
Signature · 1 line
1.7.6
#25 lore raw

PATCH 1/1 net: qomify -netdev

In reply to [email protected]

From: Zhi Yong Wu <[email protected]>

---
 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(-)
cpu-common.h +11 -2
index dca5175..81279aa 100644
@@ -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);
 
hw/qdev-monitor.c +3 -1
index a310cc7..82d5c50 100644
@@ -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);
 
hw/qdev.h +2 -0
index c638b98..e0c8ffa 100644
@@ -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,
net.c +56 -6

87 lines not on this page · raw message

net.h +5 -0
index 60837ab..69d93b1 100644
@@ -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;
net/dump.c +5 -1
index 0f191d3..9152b2e 100644
@@ -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;
net/dump.h +12 -2
index df22afe..9066ff7 100644
@@ -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 */
net/slirp.c +35 -0
index d3e56fc..0838fd5 100644
@@ -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)
net/slirp.h +13 -0
index e6000af..8a7622e 100644
@@ -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
 
net/socket.c +43 -10

68 lines not on this page · raw message

net/socket.h +16 -2
index 5edf17c..128af01 100644
@@ -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 */
net/tap-win32.c +6 -2
index 3406717..fa17239 100644
@@ -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) {
net/tap.c +54 -2

83 lines not on this page · raw message

net/tap.h +24 -2
index 0e35e81..a687d9a 100644
@@ -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 */
net/vde.c +3 -1
index 8d9e1c6..5b06f67 100644
@@ -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;
net/vde.h +1 -2
index 276e1ff..4400fa5 100644
@@ -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 */
 
qemu-log.h +3 -3
index fccfb110..611f796 100644
@@ -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: */
qemu-timer.c +1 -1
index d7f56e5..8e48483 100644
@@ -23,7 +23,7 @@
  */
 
 #include "sysemu.h"
-#include "net.h"
+//#include "net.h"
 #include "monitor.h"
 #include "console.h"
 
qom/Makefile +1 -1
index 34c6de5..4731fb9 100644
@@ -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
qom/object.c +0 -1
index 9cd9506..6f60426 100644
@@ -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();
     }
 
vl.c +10 -7
index 112b0e0..5a3f425 100644
@@ -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();
 
Signature · 1 line
1.7.6
#28 lore raw

RFC 7/9 net: qomify -netdev socket

In reply to [email protected]

From: Zhi Yong Wu <[email protected]>

---
 net/socket.c |   38 ++++++++++++++++++++++++++++++++++----
 net/socket.h |    4 ++--
 2 files changed, 36 insertions(+), 6 deletions(-)
net/socket.c +34 -4
index 55d9820..fe18e87 100644
@@ -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)
net/socket.h +2 -2
index 5edf17c..1ac7c85 100644
@@ -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 */
Signature · 1 line
1.7.6
#24 lore raw

RFC 5/9 net: adjust dump init API

In reply to [email protected]

From: Zhi Yong Wu <[email protected]>

---
 net/dump.c |    8 ++++++--
 net/dump.h |    3 +--
 2 files changed, 7 insertions(+), 4 deletions(-)
net/dump.c +6 -2
index 0f191d3..16e6efc 100644
@@ -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");
net/dump.h +1 -2
index df22afe..4bccdcf 100644
@@ -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 */
Signature · 1 line
1.7.6
#29 lore raw

RFC 8/9 net: qomify -netdev vde

In reply to [email protected]

From: Zhi Yong Wu <[email protected]>

---
 net/vde.c |   34 ++++++++++++++++++++++++++++++++--
 net/vde.h |    4 ++--
 2 files changed, 34 insertions(+), 4 deletions(-)
net/vde.c +32 -2
index 8d9e1c6..c06716d 100644
@@ -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)
net/vde.h +2 -2
index 276e1ff..c99a3a9 100644
@@ -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 */
 
Signature · 1 line
1.7.6
#30 lore raw

RFC 9/9 net: qomify -netdev tap & -netdev bridge

In reply to [email protected]

From: Zhi Yong Wu <[email protected]>

---
 net/tap.c |   64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 net/tap.h |    8 +++---
 2 files changed, 64 insertions(+), 8 deletions(-)
net/tap.c +60 -4
index 65f45b8..81d022b 100644
@@ -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)
net/tap.h +4 -4
index 0e35e81..5344d24 100644
@@ -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 */
Signature · 1 line
1.7.6
#26 lore raw

Re: [Qemu-devel] [PATCH] net: qomify -netdev

In reply to [email protected]

Sorry, pls ignore this patch

Quoted 762 lines · On Mon, Mar 26, 2012 at 1:40 PM, <[email protected]> wrote:

From: Zhi Yong Wu <[email protected]>

---
 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(-)
cpu-common.h +11 -2
index dca5175..81279aa 100644
@@ -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);
 
hw/qdev-monitor.c +3 -1
index a310cc7..82d5c50 100644
@@ -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);
 
hw/qdev.h +2 -0
index c638b98..e0c8ffa 100644
@@ -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,
net.c +56 -6
index dd67d16..5e4f871 100644
@@ -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;
net.h +5 -0
index 60837ab..69d93b1 100644
@@ -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;
net/dump.c +5 -1
index 0f191d3..9152b2e 100644
@@ -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;
net/dump.h +12 -2
index df22afe..9066ff7 100644
@@ -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 */
net/slirp.c +35 -0
index d3e56fc..0838fd5 100644
@@ -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)
net/slirp.h +13 -0
index e6000af..8a7622e 100644
@@ -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
 
net/socket.c +43 -10
index 55d9820..4ea3e07 100644
@@ -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)
net/socket.h +16 -2
index 5edf17c..128af01 100644
@@ -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 */
net/tap-win32.c +6 -2
index 3406717..fa17239 100644
@@ -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) {
net/tap.c +54 -2
index 65f45b8..f568c50 100644
@@ -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)
net/tap.h +24 -2
index 0e35e81..a687d9a 100644
@@ -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 */
net/vde.c +3 -1
index 8d9e1c6..5b06f67 100644
@@ -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;
net/vde.h +1 -2
index 276e1ff..4400fa5 100644
@@ -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 */
 
qemu-log.h +3 -3
index fccfb110..611f796 100644
@@ -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: */
qemu-timer.c +1 -1
index d7f56e5..8e48483 100644
@@ -23,7 +23,7 @@
  */
 
  #include "sysemu.h"
-#include "net.h"
+//#include "net.h"
  #include "monitor.h"
  #include "console.h"
 
qom/Makefile +0 -0
index 34c6de5..4731fb9 100644
@@ -1,2 +1,2 @@

 qom-y = object.o container.o qom-qobject.o

qom/Makefile +1 -1
-qom-twice-y = cpu.o
+qom-twice-y = cpu.o hostdev.o
qom/object.c +0 -1
index 9cd9506..6f60426 100644
@@ -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();
     }
 
vl.c +10 -8
index 112b0e0..5a3f425 100644
@@ -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

Signature · 3 lines
Regards,

Zhi Yong Wu
#2 lore raw

Re: [Qemu-devel] [RFC 1/9] hostdev: introduce the infrastructure for host device model

In reply to [email protected]

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.

Quoted 495 lines · On Mon, Mar 26, 2012 at 1:40 PM, <[email protected]> wrote:

From: Zhi Yong Wu <[email protected]>

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

include/qemu/hostdev.h new file +128 -0
new file mode 100644
index 0000000..a291761
@@ -0,0 +1,128 @@
+/*
+ * QEMU host device model
+ *
+ * Copyright IBM, Corp. 2012
+ *
+ * Authors:
+ *  Zhi Yong Wu   <[email protected]>
+ *
+ * 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
qom/Makefile +0 -0
index 34c6de5..4731fb9 100644
@@ -1,2 +1,2 @@

 qom-y = object.o container.o qom-qobject.o

qom/Makefile +1 -1
-qom-twice-y = cpu.o
+qom-twice-y = cpu.o hostdev.o
qom/hostdev.c new file +333 -1
new file mode 100644
index 0000000..867e869
@@ -0,0 +1,333 @@
+/*
+ * QEMU host device model
+ *
+ * Copyright IBM, Corp. 2012
+ *
+ * Authors:
+ *  Zhi Yong Wu   <[email protected]>
+ *
+ * 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

Signature · 3 lines
Regards,

Zhi Yong Wu
#31 lore raw
In reply to [email protected]
Quoted 7 lines · On Mon, Mar 26, 2012 at 6:40 AM, <[email protected]> wrote:

From: Zhi Yong Wu <[email protected]>

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

#32 lore raw
Quoted 5 lines · Stefan Hajnoczi
Quoted 4 lines · On Mon, Mar 26, 2012 at 6:40 AM,  <[email protected]> wrote:

From: Zhi Yong Wu <[email protected]>

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

Quoted 7 lines
Quoted 3 lines

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.

Quoted 4 lines

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.

Quoted 4 lines

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.

Quoted 2 lines

Stefan

Signature · 3 lines
Regards,

Zhi Yong Wu
#35 lore raw
In reply to Stefan Hajnoczi

Am 26.03.2012 13:54, schrieb Stefan Hajnoczi:

Quoted 2 lines

I think host
devices will also need to 2-step creation process (init and realize).

Series tested and sent out today. :)

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#36 lore raw
Quoted 5 lines · Andreas Färber

Am 26.03.2012 13:54, schrieb Stefan Hajnoczi:

Quoted 2 lines

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

#37 lore raw
In reply to Andreas Färber
Quoted 5 lines · Andreas Färber

Am 26.03.2012 13:54, schrieb Stefan Hajnoczi:

Quoted 2 lines

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.

Quoted 6 lines

Andreas

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

Signature · 3 lines
Regards,

Zhi Yong Wu
#33 lore raw
In reply to Zhi Yong Wu

Il 26/03/2012 16:20, Zhi Yong Wu ha scritto:

Quoted 13 lines
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;
};
Quoted 3 lines

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

#3 lore raw

Re: [Qemu-devel] [RFC 1/9] hostdev: introduce the infrastructure for host device model

In reply to [email protected]

Il 26/03/2012 07:40, [email protected] ha scritto:

include/qemu/hostdev.h line 117

Quoted 2 lines
include/qemu/hostdev.h new file +2 -0
+#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

#34 lore raw
In reply to Paolo Bonzini
Quoted 14 lines · Paolo Bonzini

Il 26/03/2012 16:20, Zhi Yong Wu ha scritto:

Quoted 13 lines

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;
};

Quoted 7 lines
Quoted 3 lines

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.

Quoted 4 lines

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.

Quoted 2 lines

Paolo

Signature · 3 lines
Regards,

Zhi Yong Wu
#4 lore raw

Re: [Qemu-devel] [RFC 1/9] hostdev: introduce the infrastructure for host device model

In reply to Paolo Bonzini
Quoted 5 lines · Paolo Bonzini

Il 26/03/2012 07:40, [email protected] ha scritto:

Quoted 2 lines

+#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?

Quoted 2 lines

Paolo

Signature · 3 lines
Regards,

Zhi Yong Wu
#20 lore raw

Re: [Qemu-devel] [RFC 2/9] net: introduce one net host device class

In reply to [email protected]

Il 26/03/2012 07:40, [email protected] ha scritto:

net.h line 36

Quoted 6 lines
net.h +6 -0
+    /*< 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

#21 lore raw

Re: [Qemu-devel] [RFC 2/9] net: introduce one net host device class

Quoted 10 lines · Paolo Bonzini

Il 26/03/2012 07:40, [email protected] ha scritto:

Quoted 6 lines

+    /*< 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?:)

Quoted 4 lines

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

Paolo

Signature · 3 lines
Regards,

Zhi Yong Wu
#5 lore raw

Re: [Qemu-devel] [RFC 1/9] hostdev: introduce the infrastructure for host device model

In reply to Zhi Yong Wu

Il 27/03/2012 11:06, Zhi Yong Wu ha scritto:

Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

include/qemu/hostdev.h line 117

Quoted 2 lines
include/qemu/hostdev.h new file +2 -0
+#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

#6 lore raw

Re: [Qemu-devel] [RFC 1/9] hostdev: introduce the infrastructure for host device model

Quoted 9 lines · Paolo Bonzini

Il 27/03/2012 11:06, Zhi Yong Wu ha scritto:

Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines

+#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?

Quoted 5 lines

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.

Quoted 9 lines

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.

Quoted 4 lines

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

Quoted 3 lines

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.

Quoted 2 lines

Paolo

Signature · 3 lines
Regards,

Zhi Yong Wu
#7 lore raw

Re: [Qemu-devel] [RFC 1/9] hostdev: introduce the infrastructure for host device model

Il 27/03/2012 13:59, Zhi Yong Wu ha scritto:

Quoted 11 lines · Paolo Bonzini
Quoted 9 lines

Il 27/03/2012 11:06, Zhi Yong Wu ha scritto:

Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

include/qemu/hostdev.h line 117

Quoted 2 lines
include/qemu/hostdev.h new file +2 -0
+#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.

Quoted 1 line

what is relationship between the two objects?

A has a pointer to B.

Quoted 1 line

it represent the relation between bus object and device object?

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

Quoted 1 line

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

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

Quoted 1 line

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.

Quoted 5 lines
Quoted 2 lines

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

#8 lore raw

Re: [Qemu-devel] [RFC 1/9] hostdev: introduce the infrastructure for host device model

Quoted 6 lines · Paolo Bonzini

Il 27/03/2012 13:59, Zhi Yong Wu ha scritto:

Quoted 5 lines · Paolo Bonzini
Quoted 4 lines

Il 27/03/2012 11:06, Zhi Yong Wu ha scritto:

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
Quoted 2 lines

+#define DEFINE_HOSTDEV_PROP_PEER(_n, _s, _f)             \
+    DEFINE_HOSTDEV_PROP(_n, _s, _f, hostdev_prop_netdev, NetClientState*)

Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line

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.

Quoted 4 lines
Quoted 2 lines

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?

Quoted 4 lines
Quoted 2 lines

it represent the relation between bus object and device object?

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

yeah.

Quoted 9 lines
Quoted 2 lines

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

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

Quoted 1 line

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.

Quoted 9 lines

instances should be QOM objects, including those owned by NICs.

Quoted 5 lines
Quoted 2 lines

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.

Quoted 2 lines

Paolo

Signature · 3 lines
Regards,

Zhi Yong Wu
#9 lore raw

Re: [Qemu-devel] [RFC 1/9] hostdev: introduce the infrastructure for host device model

Il 27/03/2012 16:18, Zhi Yong Wu ha scritto:

Quoted 8 lines · Paolo Bonzini
Quoted 7 lines

Il 27/03/2012 13:59, Zhi Yong Wu ha scritto:

Quoted 6 lines · Paolo Bonzini
Quoted 5 lines

Il 27/03/2012 11:06, Zhi Yong Wu ha scritto:

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+#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.

Quoted 8 lines
Quoted 7 lines
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines

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.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

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.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

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?

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

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

#10 lore raw

Re: [Qemu-devel] [RFC 1/9] hostdev: introduce the infrastructure for host device model

Quoted 13 lines · Paolo Bonzini

Il 27/03/2012 16:18, Zhi Yong Wu ha scritto:

Quoted 12 lines · Paolo Bonzini
Quoted 11 lines

Il 27/03/2012 13:59, Zhi Yong Wu ha scritto:

Quoted 10 lines · Paolo Bonzini
Quoted 9 lines

Il 27/03/2012 11:06, Zhi Yong Wu ha scritto:

Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines

+#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

Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line

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.

Quoted 10 lines
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

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?

Quoted 2 lines

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?

Quoted 10 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

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.

Quoted 10 lines
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

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.

Quoted 2 lines

Paolo

Signature · 3 lines
Regards,

Zhi Yong Wu
#11 lore raw

Re: [Qemu-devel] [RFC 1/9] hostdev: introduce the infrastructure for host device model

Il 27/03/2012 23:21, Zhi Yong Wu ha scritto:

Quoted 3 lines
Quoted 1 line

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.

Quoted 3 lines
Quoted 2 lines

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.

Quoted 11 lines
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

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.

Quoted 11 lines
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

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.

Quoted 1 line

And I think that it should also give hotplug.

Hotplug of -netdev is already supported.

Paolo

#12 lore raw

Re: [Qemu-devel] [RFC 1/9] hostdev: introduce the infrastructure for host device model

Quoted 8 lines · Paolo Bonzini

Il 27/03/2012 23:21, Zhi Yong Wu ha scritto:

Quoted 3 lines
Quoted 1 line

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:

Quoted 7 lines

* 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

Quoted 16 lines
Quoted 4 lines
Quoted 3 lines

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.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

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.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

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.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines

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?

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

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?

Quoted 9 lines

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.

Quoted 1 line

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?

Quoted 2 lines

Paolo

Signature · 3 lines
Regards,

Zhi Yong Wu
#13 lore raw

Re: [Qemu-devel] [RFC 1/9] hostdev: introduce the infrastructure for host device model

In reply to Paolo Bonzini

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

Quoted 63 lines · Paolo Bonzini

Il 27/03/2012 23:21, Zhi Yong Wu ha scritto:

Quoted 3 lines
Quoted 1 line

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.

Quoted 3 lines
Quoted 2 lines

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.

Quoted 11 lines
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

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.

Quoted 11 lines
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

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.

Quoted 1 line

And I think that it should also give hotplug.

Hotplug of -netdev is already supported.

Paolo

Signature · 3 lines
Regards,

Zhi Yong Wu
#14 lore raw

Re: [Qemu-devel] [RFC 1/9] hostdev: introduce the infrastructure for host device model

Il 28/03/2012 09:53, Zhi Yong Wu ha scritto:

Quoted 2 lines

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

#15 lore raw

Re: [Qemu-devel] [RFC 1/9] hostdev: introduce the infrastructure for host device model

Quoted 3 lines

Il 28/03/2012 09:53, Zhi Yong Wu ha scritto:

Quoted 2 lines

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

Signature · 5 lines
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
#16 lore raw

Re: [Qemu-devel] [RFC 1/9] hostdev: introduce the infrastructure for host device model

Quoted 6 lines · 陳韋任
Quoted 3 lines

Il 28/03/2012 09:53, Zhi Yong Wu ha scritto:

Quoted 2 lines

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

Quoted 10 lines

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

Signature · 3 lines
Regards,

Zhi Yong Wu
#17 lore raw

Re: [Qemu-devel] [RFC 1/9] hostdev: introduce the infrastructure for host device model

Quoted 8 lines · Zhi Yong Wu
Quoted 6 lines · 陳韋任
Quoted 3 lines

Il 28/03/2012 09:53, Zhi Yong Wu ha scritto:

Quoted 2 lines

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

Signature · 5 lines
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