Skip to contentSkip to conversation

qapi-flattening and preparation of -audiodev option

PATCH Superseded Kővágó, Zoltán 4 participants 18 messages Sep 7, 2015 – Sep 18, 2015

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#1 lore raw

PATCH 1/7 qapi: support implicit structs in OptsVisitor

In reply to Kővágó, Zoltán

They are required for flat unions (you still have to allocate the structs).

---
 qapi/opts-visitor.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
qapi/opts-visitor.c +15 -0
index 7ae33b3..aa68814 100644
@@ -149,6 +149,12 @@ opts_start_struct(Visitor *v, void **obj, const char *kind,
     }
 }
 
+static void
+opts_start_implicit_struct(Visitor *v, void **obj, size_t size, Error **errp)
+{
+    opts_start_struct(v, obj, NULL, NULL, size, errp);
+}
+
 
 static gboolean
 ghr_true(gpointer ign_key, gpointer ign_value, gpointer ign_user_data)
@@ -185,6 +191,12 @@ opts_end_struct(Visitor *v, Error **errp)
     ov->fake_id_opt = NULL;
 }
 
+static void
+opts_end_implicit_struct(Visitor *v, Error **errp)
+{
+    opts_end_struct(v, errp);
+}
+
 
 static GQueue *
 lookup_distinct(const OptsVisitor *ov, const char *name, Error **errp)
@@ -508,6 +520,9 @@ opts_visitor_new(const QemuOpts *opts)
     ov->visitor.start_struct = &opts_start_struct;
     ov->visitor.end_struct   = &opts_end_struct;
 
+    ov->visitor.start_implicit_struct = &opts_start_implicit_struct;
+    ov->visitor.end_implicit_struct = &opts_end_implicit_struct;
+
     ov->visitor.start_list = &opts_start_list;
     ov->visitor.next_list  = &opts_next_list;
     ov->visitor.end_list   = &opts_end_list;
Signature · 1 line
2.5.1
#0 lore raw

cover qapi-flattening and preparation of -audiodev option

As discussed here[1], I'm splitting the qapi related patches from my previous -audiodev patch series. These are patches 2--7 and 9 from my previous patches. (Patch 1 was merged into -trivial in the meanwhile.)

Please review.

[1]: http://lists.nongnu.org/archive/html/qemu-devel/2015-09/msg01505.html

Kővágó, Zoltán (7):
qapi: support implicit structs in OptsVisitor
qapi: convert NumaOptions into a flat union
net: remove NetLegacy struct
net: use Netdev instead of NetClientOptions in client init
qapi: change Netdev into a flat union
qapi: reorder NetdevBase and Netdev
qapi: support nested structs in OptsVisitor

 hw/arm/musicpal.c                       |   2 +-
 hw/core/qdev-properties-system.c        |   2 +-
 hw/net/allwinner_emac.c                 |   2 +-
 hw/net/cadence_gem.c                    |   2 +-
 hw/net/dp8393x.c                        |   2 +-
 hw/net/e1000.c                          |   2 +-
 hw/net/eepro100.c                       |   2 +-
 hw/net/etraxfs_eth.c                    |   2 +-
 hw/net/fsl_etsec/etsec.c                |   2 +-
 hw/net/lan9118.c                        |   2 +-
 hw/net/lance.c                          |   2 +-
 hw/net/mcf_fec.c                        |   2 +-
 hw/net/milkymist-minimac2.c             |   2 +-
 hw/net/mipsnet.c                        |   2 +-
 hw/net/ne2000-isa.c                     |   2 +-
 hw/net/ne2000.c                         |   2 +-
 hw/net/opencores_eth.c                  |   2 +-
 hw/net/pcnet-pci.c                      |   2 +-
 hw/net/rocker/rocker_fp.c               |   2 +-
 hw/net/rtl8139.c                        |   2 +-
 hw/net/smc91c111.c                      |   2 +-
 hw/net/spapr_llan.c                     |   2 +-
 hw/net/stellaris_enet.c                 |   2 +-
 hw/net/vhost_net.c                      |  18 ++---
 hw/net/virtio-net.c                     |   6 +-
 hw/net/vmxnet3.c                        |   2 +-
 hw/net/xen_nic.c                        |   2 +-
 hw/net/xgmac.c                          |   2 +-
 hw/net/xilinx_axienet.c                 |   2 +-
 hw/net/xilinx_ethlite.c                 |   2 +-
 hw/usb/dev-network.c                    |   2 +-
 include/net/net.h                       |   4 +-
 monitor.c                               |  14 ++--
 net/clients.h                           |  20 ++---
 net/dump.c                              |   8 +-
 net/hub.c                               |  24 +++---
 net/l2tpv3.c                            |   8 +-
 net/net.c                               | 129 ++++++++++++++++---------------
 net/netmap.c                            |   6 +-
 net/slirp.c                             |   8 +-
 net/socket.c                            |  10 +--
 net/tap-win32.c                         |   8 +-
 net/tap.c                               |  28 +++----
 net/vde.c                               |   8 +-
 net/vhost-user.c                        |  14 ++--
 numa.c                                  |   4 +-
 qapi-schema.json                        | 131 +++++++++++++++++++-------------
 qapi/opts-visitor.c                     | 131 +++++++++++++++++++++++++++-----
 tests/qapi-schema/qapi-schema-test.json |   9 ++-
 tests/qapi-schema/qapi-schema-test.out  |   6 +-
 tests/test-opts-visitor.c               |  34 +++++++++
 51 files changed, 421 insertions(+), 265 deletions(-)
Signature · 1 line
2.5.1
#4 lore raw

PATCH 2/7 qapi: convert NumaOptions into a flat union

Changes the NumaOptions to flat union from a simple one. This is required by my later OptsVisitor patch to preserve backward compatibility.

Strictly speaking this would break QMP compatibility (as specified in docs/qapi-code-gen.txt), but since no QMP command use this structure, it's not an issue. The -numa option syntax doesn't change. There are some changes in the C api, but this patch fixes them.

---

Changes from v2:
* renamed NumaDriver to NumaOptionType

 numa.c           |  4 ++--
 qapi-schema.json | 47 ++++++++++++++++++++++++++++++++++++-----------
 2 files changed, 38 insertions(+), 13 deletions(-)
numa.c +2 -2
index 402804b..e79620f 100644
@@ -226,8 +226,8 @@ static int parse_numa(void *opaque, QemuOpts *opts, Error **errp)
         goto error;
     }
 
-    switch (object->kind) {
-    case NUMA_OPTIONS_KIND_NODE:
+    switch (object->type) {
+    case NUMA_OPTION_TYPE_NODE:
         numa_node_parse(object->node, opts, &err);
         if (err) {
             goto error;
qapi-schema.json +36 -11

59 lines not on this page · raw message

Signature · 1 line
2.5.1
#6 lore raw

PATCH 3/7 net: remove NetLegacy struct

In reply to Kővágó, Zoltán

NetLegacy is just Netdev with some extra fields (name, vlan) and an optional id. This patch merges the two structs, and net_client_init1 got some extra checks to make sure only accept valid -netdev command lines. This is some extra work, but allows us to uniformly manage both legacy -net and non-legacy -netdev in code.

---
 net/net.c        | 42 +++++++++++++++++++++---------------------
 qapi-schema.json | 30 +++++++++---------------------
 2 files changed, 30 insertions(+), 42 deletions(-)
net/net.c +21 -21
index 28a5597..10fbaca 100644
@@ -911,17 +911,29 @@ static int (* const net_client_init_fun[NET_CLIENT_OPTIONS_KIND_MAX])(
 };
 
 
-static int net_client_init1(const void *object, int is_netdev, Error **errp)
+static int net_client_init1(const Netdev *netdev, int is_netdev, Error **errp)
 {
-    const NetClientOptions *opts;
+    const NetClientOptions *opts = netdev->opts;
     const char *name;
     NetClientState *peer = NULL;
 
     if (is_netdev) {
-        const Netdev *netdev = object;
-        opts = netdev->opts;
         name = netdev->id;
 
+        /* validate -netdev option: has id, no vlan or name */
+        if (!netdev->has_id) {
+            error_setg(errp, QERR_MISSING_PARAMETER, "id");
+            return -1;
+        }
+        if (netdev->has_name) {
+            error_setg(errp, QERR_INVALID_PARAMETER, "name");
+            return -1;
+        }
+        if (netdev->has_vlan) {
+            error_setg(errp, QERR_INVALID_PARAMETER, "vlan");
+            return -1;
+        }
+
         if (opts->kind == NET_CLIENT_OPTIONS_KIND_DUMP ||
             opts->kind == NET_CLIENT_OPTIONS_KIND_NIC ||
             !net_client_init_fun[opts->kind]) {
@@ -930,10 +942,8 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp)
             return -1;
         }
     } else {
-        const NetLegacy *net = object;
-        opts = net->opts;
         /* missing optional values have been initialized to "all bits zero" */
-        name = net->has_id ? net->id : net->name;
+        name = netdev->has_id ? netdev->id : netdev->name;
 
         if (opts->kind == NET_CLIENT_OPTIONS_KIND_NONE) {
             return 0; /* nothing to do */
@@ -954,7 +964,7 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp)
         /* Do not add to a vlan if it's a nic with a netdev= parameter. */
         if (opts->kind != NET_CLIENT_OPTIONS_KIND_NIC ||
             !opts->nic->has_netdev) {
-            peer = net_hub_add_port(net->has_vlan ? net->vlan : 0, NULL);
+            peer = net_hub_add_port(netdev->has_vlan ? netdev->vlan : 0, NULL);
         }
     }
 
@@ -970,26 +980,16 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp)
 }
 
 
-static void net_visit(Visitor *v, int is_netdev, void **object, Error **errp)
-{
-    if (is_netdev) {
-        visit_type_Netdev(v, (Netdev **)object, NULL, errp);
-    } else {
-        visit_type_NetLegacy(v, (NetLegacy **)object, NULL, errp);
-    }
-}
-
-
 int net_client_init(QemuOpts *opts, int is_netdev, Error **errp)
 {
-    void *object = NULL;
+    Netdev *object = NULL;
     Error *err = NULL;
     int ret = -1;
 
     {
         OptsVisitor *ov = opts_visitor_new(opts);
 
-        net_visit(opts_get_visitor(ov), is_netdev, &object, &err);
+        visit_type_Netdev(opts_get_visitor(ov), &object, NULL, &err);
         opts_visitor_cleanup(ov);
     }
 
@@ -1000,7 +1000,7 @@ int net_client_init(QemuOpts *opts, int is_netdev, Error **errp)
     if (object) {
         QapiDeallocVisitor *dv = qapi_dealloc_visitor_new();
 
-        net_visit(qapi_dealloc_get_visitor(dv), is_netdev, &object, NULL);
+        visit_type_Netdev(qapi_dealloc_get_visitor(dv), &object, NULL, NULL);
         qapi_dealloc_visitor_cleanup(dv);
     }
 
qapi-schema.json +9 -21
index 9e4fe5d..d85b55b 100644
@@ -2513,21 +2513,25 @@
     'vhost-user': 'NetdevVhostUserOptions' } }
 
 ##
-# @NetLegacy
+# @Netdev
 #
-# Captures the configuration of a network device; legacy.
+# Captures the configuration of a network device.
 #
-# @vlan: #optional vlan number
+# @vlan: #optional vlan number (legacy, forbidden with -netdev)
 #
-# @id: #optional identifier for monitor commands
+# @id: #optional identifier for monitor commands (required with -netdev)
 #
 # @name: #optional identifier for monitor commands, ignored if @id is present
+#        (legacy, forbidden with -netdev)
 #
 # @opts: device type specific properties (legacy)
 #
 # Since 1.2
+#
+# @id #optional - since 2.5
+# @vlan, @name - since 2.5
 ##
-{ 'struct': 'NetLegacy',
+{ 'struct': 'Netdev',
   'data': {
     '*vlan': 'int32',
     '*id':   'str',
@@ -2535,22 +2539,6 @@
     'opts':  'NetClientOptions' } }
 
 ##
-# @Netdev
-#
-# Captures the configuration of a network device.
-#
-# @id: identifier for monitor commands.
-#
-# @opts: device type specific properties
-#
-# Since 1.2
-##
-{ 'struct': 'Netdev',
-  'data': {
-    'id':   'str',
-    'opts': 'NetClientOptions' } }
-
-##
 # @InetSocketAddress
 #
 # Captures a socket address or address range in the Internet namespace.
Signature · 1 line
2.5.1
#8 lore raw

PATCH 4/7 net: use Netdev instead of NetClientOptions in client init

In reply to Kővágó, Zoltán

This way we no longer need NetClientOptions and can convert Netdev into a flat union.

---
 net/clients.h    | 20 ++++++++++----------
 net/dump.c       |  6 +++---
 net/hub.c        |  6 +++---
 net/l2tpv3.c     |  6 +++---
 net/net.c        | 29 ++++++++++++++---------------
 net/netmap.c     |  4 ++--
 net/slirp.c      |  6 +++---
 net/socket.c     |  6 +++---
 net/tap-win32.c  |  6 +++---
 net/tap.c        | 12 ++++++------
 net/vde.c        |  6 +++---
 net/vhost-user.c |  6 +++---
 12 files changed, 56 insertions(+), 57 deletions(-)
net/clients.h +10 -10
index d47530e..5cae479 100644
@@ -27,39 +27,39 @@
 #include "net/net.h"
 #include "qapi-types.h"
 
-int net_init_dump(const NetClientOptions *opts, const char *name,
+int net_init_dump(const Netdev *netdev, const char *name,
                   NetClientState *peer, Error **errp);
 
 #ifdef CONFIG_SLIRP
-int net_init_slirp(const NetClientOptions *opts, const char *name,
+int net_init_slirp(const Netdev *netdev, const char *name,
                    NetClientState *peer, Error **errp);
 #endif
 
-int net_init_hubport(const NetClientOptions *opts, const char *name,
+int net_init_hubport(const Netdev *netdev, const char *name,
                      NetClientState *peer, Error **errp);
 
-int net_init_socket(const NetClientOptions *opts, const char *name,
+int net_init_socket(const Netdev *netdev, const char *name,
                     NetClientState *peer, Error **errp);
 
-int net_init_tap(const NetClientOptions *opts, const char *name,
+int net_init_tap(const Netdev *netdev, const char *name,
                  NetClientState *peer, Error **errp);
 
-int net_init_bridge(const NetClientOptions *opts, const char *name,
+int net_init_bridge(const Netdev *netdev, const char *name,
                     NetClientState *peer, Error **errp);
 
-int net_init_l2tpv3(const NetClientOptions *opts, const char *name,
+int net_init_l2tpv3(const Netdev *netdev, const char *name,
                     NetClientState *peer, Error **errp);
 #ifdef CONFIG_VDE
-int net_init_vde(const NetClientOptions *opts, const char *name,
+int net_init_vde(const Netdev *netdev, const char *name,
                  NetClientState *peer, Error **errp);
 #endif
 
 #ifdef CONFIG_NETMAP
-int net_init_netmap(const NetClientOptions *opts, const char *name,
+int net_init_netmap(const Netdev *netdev, const char *name,
                     NetClientState *peer, Error **errp);
 #endif
 
-int net_init_vhost_user(const NetClientOptions *opts, const char *name,
+int net_init_vhost_user(const Netdev *netdev, const char *name,
                         NetClientState *peer, Error **errp);
 
 #endif /* QEMU_NET_CLIENTS_H */
net/dump.c +3 -3
index 02c8064..d80fa94 100644
@@ -146,7 +146,7 @@ static int net_dump_init(NetClientState *peer, const char *device,
     return 0;
 }
 
-int net_init_dump(const NetClientOptions *opts, const char *name,
+int net_init_dump(const Netdev *netdev, const char *name,
                   NetClientState *peer, Error **errp)
 {
     int len;
@@ -154,8 +154,8 @@ int net_init_dump(const NetClientOptions *opts, const char *name,
     char def_file[128];
     const NetdevDumpOptions *dump;
 
-    assert(opts->kind == NET_CLIENT_OPTIONS_KIND_DUMP);
-    dump = opts->dump;
+    assert(netdev->opts->kind == NET_CLIENT_OPTIONS_KIND_DUMP);
+    dump = netdev->opts->dump;
 
     assert(peer);
 
net/hub.c +3 -3
index 3047f12..29f65b2 100644
@@ -280,14 +280,14 @@ int net_hub_id_for_client(NetClientState *nc, int *id)
     return 0;
 }
 
-int net_init_hubport(const NetClientOptions *opts, const char *name,
+int net_init_hubport(const Netdev *netdev, const char *name,
                      NetClientState *peer, Error **errp)
 {
     const NetdevHubPortOptions *hubport;
 
-    assert(opts->kind == NET_CLIENT_OPTIONS_KIND_HUBPORT);
+    assert(netdev->opts->kind == NET_CLIENT_OPTIONS_KIND_HUBPORT);
     assert(!peer);
-    hubport = opts->hubport;
+    hubport = netdev->opts->hubport;
 
     net_hub_add_port(hubport->hubid, name);
     return 0;
net/l2tpv3.c +3 -3
index 4f9bcee..d2f8431 100644
@@ -524,7 +524,7 @@ static NetClientInfo net_l2tpv3_info = {
     .cleanup = net_l2tpv3_cleanup,
 };
 
-int net_init_l2tpv3(const NetClientOptions *opts,
+int net_init_l2tpv3(const Netdev *netdev,
                     const char *name,
                     NetClientState *peer, Error **errp)
 {
@@ -545,8 +545,8 @@ int net_init_l2tpv3(const NetClientOptions *opts,
     s->queue_tail = 0;
     s->header_mismatch = false;
 
-    assert(opts->kind == NET_CLIENT_OPTIONS_KIND_L2TPV3);
-    l2tpv3 = opts->l2tpv3;
+    assert(netdev->opts->kind == NET_CLIENT_OPTIONS_KIND_L2TPV3);
+    l2tpv3 = netdev->opts->l2tpv3;
 
     if (l2tpv3->has_ipv6 && l2tpv3->ipv6) {
         s->ipv6 = l2tpv3->ipv6;
net/net.c +14 -15
index 10fbaca..339f188 100644
@@ -813,15 +813,15 @@ int qemu_find_nic_model(NICInfo *nd, const char * const *models,
     return -1;
 }
 
-static int net_init_nic(const NetClientOptions *opts, const char *name,
+static int net_init_nic(const Netdev *netdev, const char *name,
                         NetClientState *peer, Error **errp)
 {
     int idx;
     NICInfo *nd;
     const NetLegacyNicOptions *nic;
 
-    assert(opts->kind == NET_CLIENT_OPTIONS_KIND_NIC);
-    nic = opts->nic;
+    assert(netdev->opts->kind == NET_CLIENT_OPTIONS_KIND_NIC);
+    nic = netdev->opts->nic;
 
     idx = nic_get_free_idx();
     if (idx == -1 || nb_nics >= MAX_NICS) {
@@ -882,7 +882,7 @@ static int net_init_nic(const NetClientOptions *opts, const char *name,
 
 
 static int (* const net_client_init_fun[NET_CLIENT_OPTIONS_KIND_MAX])(
-    const NetClientOptions *opts,
+    const Netdev *netdev,
     const char *name,
     NetClientState *peer, Error **errp) = {
         [NET_CLIENT_OPTIONS_KIND_NIC]       = net_init_nic,
@@ -913,7 +913,6 @@ static int (* const net_client_init_fun[NET_CLIENT_OPTIONS_KIND_MAX])(
 
 static int net_client_init1(const Netdev *netdev, int is_netdev, Error **errp)
 {
-    const NetClientOptions *opts = netdev->opts;
     const char *name;
     NetClientState *peer = NULL;
 
@@ -934,9 +933,9 @@ static int net_client_init1(const Netdev *netdev, int is_netdev, Error **errp)
             return -1;
         }
 
-        if (opts->kind == NET_CLIENT_OPTIONS_KIND_DUMP ||
-            opts->kind == NET_CLIENT_OPTIONS_KIND_NIC ||
-            !net_client_init_fun[opts->kind]) {
+        if (netdev->opts->kind == NET_CLIENT_OPTIONS_KIND_DUMP ||
+            netdev->opts->kind == NET_CLIENT_OPTIONS_KIND_NIC ||
+            !net_client_init_fun[netdev->opts->kind]) {
             error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "type",
                        "a netdev backend type");
             return -1;
@@ -945,16 +944,16 @@ static int net_client_init1(const Netdev *netdev, int is_netdev, Error **errp)
         /* missing optional values have been initialized to "all bits zero" */
         name = netdev->has_id ? netdev->id : netdev->name;
 
-        if (opts->kind == NET_CLIENT_OPTIONS_KIND_NONE) {
+        if (netdev->opts->kind == NET_CLIENT_OPTIONS_KIND_NONE) {
             return 0; /* nothing to do */
         }
-        if (opts->kind == NET_CLIENT_OPTIONS_KIND_HUBPORT) {
+        if (netdev->opts->kind == NET_CLIENT_OPTIONS_KIND_HUBPORT) {
             error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "type",
                        "a net type");
             return -1;
         }
 
-        if (!net_client_init_fun[opts->kind]) {
+        if (!net_client_init_fun[netdev->opts->kind]) {
             error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "type",
                        "a net backend type (maybe it is not compiled "
                        "into this binary)");
@@ -962,17 +961,17 @@ static int net_client_init1(const Netdev *netdev, int is_netdev, Error **errp)
         }
 
         /* Do not add to a vlan if it's a nic with a netdev= parameter. */
-        if (opts->kind != NET_CLIENT_OPTIONS_KIND_NIC ||
-            !opts->nic->has_netdev) {
+        if (netdev->opts->kind != NET_CLIENT_OPTIONS_KIND_NIC ||
+            !netdev->opts->nic->has_netdev) {
             peer = net_hub_add_port(netdev->has_vlan ? netdev->vlan : 0, NULL);
         }
     }
 
-    if (net_client_init_fun[opts->kind](opts, name, peer, errp) < 0) {
+    if (net_client_init_fun[netdev->opts->kind](netdev, name, peer, errp) < 0) {
         /* FIXME drop when all init functions store an Error */
         if (errp && !*errp) {
             error_setg(errp, QERR_DEVICE_INIT_FAILED,
-                       NetClientOptionsKind_lookup[opts->kind]);
+                       NetClientOptionsKind_lookup[netdev->opts->kind]);
         }
         return -1;
     }
net/netmap.c +2 -2
index 508b829..a464618 100644
@@ -435,11 +435,11 @@ static NetClientInfo net_netmap_info = {
  *
  * ... -net netmap,ifname="..."
  */
-int net_init_netmap(const NetClientOptions *opts,
+int net_init_netmap(const Netdev *netdev,
                     const char *name, NetClientState *peer, Error **errp)
 {
     /* FIXME error_setg(errp, ...) on failure */
-    const NetdevNetmapOptions *netmap_opts = opts->netmap;
+    const NetdevNetmapOptions *netmap_opts = netdev->opts->netmap;
     NetClientState *nc;
     NetmapPriv me;
     NetmapState *s;
net/slirp.c +3 -3
index 7657b38..0fc2c52 100644
@@ -736,7 +736,7 @@ static const char **slirp_dnssearch(const StringList *dnsname)
     return ret;
 }
 
-int net_init_slirp(const NetClientOptions *opts, const char *name,
+int net_init_slirp(const Netdev *netdev, const char *name,
                    NetClientState *peer, Error **errp)
 {
     /* FIXME error_setg(errp, ...) on failure */
@@ -746,8 +746,8 @@ int net_init_slirp(const NetClientOptions *opts, const char *name,
     const NetdevUserOptions *user;
     const char **dnssearch;
 
-    assert(opts->kind == NET_CLIENT_OPTIONS_KIND_USER);
-    user = opts->user;
+    assert(netdev->opts->kind == NET_CLIENT_OPTIONS_KIND_USER);
+    user = netdev->opts->user;
 
     vnet = user->has_net ? g_strdup(user->net) :
            user->has_ip  ? g_strdup_printf("%s/24", user->ip) :
net/socket.c +3 -3
index b1e3b1c..75f693c 100644
@@ -699,15 +699,15 @@ static int net_socket_udp_init(NetClientState *peer,
     return 0;
 }
 
-int net_init_socket(const NetClientOptions *opts, const char *name,
+int net_init_socket(const Netdev *netdev, const char *name,
                     NetClientState *peer, Error **errp)
 {
     /* FIXME error_setg(errp, ...) on failure */
     Error *err = NULL;
     const NetdevSocketOptions *sock;
 
-    assert(opts->kind == NET_CLIENT_OPTIONS_KIND_SOCKET);
-    sock = opts->socket;
+    assert(netdev->opts->kind == NET_CLIENT_OPTIONS_KIND_SOCKET);
+    sock = netdev->opts->socket;
 
     if (sock->has_fd + sock->has_listen + sock->has_connect + sock->has_mcast +
         sock->has_udp != 1) {
net/tap-win32.c +3 -3
index 625d53c..acce480 100644
@@ -761,14 +761,14 @@ static int tap_win32_init(NetClientState *peer, const char *model,
     return 0;
 }
 
-int net_init_tap(const NetClientOptions *opts, const char *name,
+int net_init_tap(const Netdev *netdev, const char *name,
                  NetClientState *peer, Error **errp)
 {
     /* FIXME error_setg(errp, ...) on failure */
     const NetdevTapOptions *tap;
 
-    assert(opts->kind == NET_CLIENT_OPTIONS_KIND_TAP);
-    tap = opts->tap;
+    assert(netdev->opts->kind == NET_CLIENT_OPTIONS_KIND_TAP);
+    tap = netdev->opts->tap;
 
     if (!tap->has_ifname) {
         error_report("tap: no interface name");
net/tap.c +6 -6
index bd01590..263f807 100644
@@ -557,7 +557,7 @@ static int net_bridge_run_helper(const char *helper, const char *bridge,
     }
 }
 
-int net_init_bridge(const NetClientOptions *opts, const char *name,
+int net_init_bridge(const Netdev *netdev, const char *name,
                     NetClientState *peer, Error **errp)
 {
     const NetdevBridgeOptions *bridge;
@@ -565,8 +565,8 @@ int net_init_bridge(const NetClientOptions *opts, const char *name,
     TAPState *s;
     int fd, vnet_hdr;
 
-    assert(opts->kind == NET_CLIENT_OPTIONS_KIND_BRIDGE);
-    bridge = opts->bridge;
+    assert(netdev->opts->kind == NET_CLIENT_OPTIONS_KIND_BRIDGE);
+    bridge = netdev->opts->bridge;
 
     helper = bridge->has_helper ? bridge->helper : DEFAULT_BRIDGE_HELPER;
     br     = bridge->has_br     ? bridge->br     : DEFAULT_BRIDGE_INTERFACE;
@@ -716,7 +716,7 @@ static int get_fds(char *str, char *fds[], int max)
     return i;
 }
 
-int net_init_tap(const NetClientOptions *opts, const char *name,
+int net_init_tap(const Netdev *netdev, const char *name,
                  NetClientState *peer, Error **errp)
 {
     const NetdevTapOptions *tap;
@@ -728,8 +728,8 @@ int net_init_tap(const NetClientOptions *opts, const char *name,
     const char *vhostfdname;
     char ifname[128];
 
-    assert(opts->kind == NET_CLIENT_OPTIONS_KIND_TAP);
-    tap = opts->tap;
+    assert(netdev->opts->kind == NET_CLIENT_OPTIONS_KIND_TAP);
+    tap = netdev->opts->tap;
     queues = tap->has_queues ? tap->queues : 1;
     vhostfdname = tap->has_vhostfd ? tap->vhostfd : NULL;
 
net/vde.c +3 -3
index dacaa64..0ac2525 100644
@@ -109,14 +109,14 @@ static int net_vde_init(NetClientState *peer, const char *model,
     return 0;
 }
 
-int net_init_vde(const NetClientOptions *opts, const char *name,
+int net_init_vde(const Netdev *netdev, const char *name,
                  NetClientState *peer, Error **errp)
 {
     /* FIXME error_setg(errp, ...) on failure */
     const NetdevVdeOptions *vde;
 
-    assert(opts->kind == NET_CLIENT_OPTIONS_KIND_VDE);
-    vde = opts->vde;
+    assert(netdev->opts->kind == NET_CLIENT_OPTIONS_KIND_VDE);
+    vde = netdev->opts->vde;
 
     /* missing optional values have been initialized to "all bits zero" */
     if (net_vde_init(peer, "vde", name, vde->sock, vde->port, vde->group,
net/vhost-user.c +3 -3
index 93dcecd..20981a9 100644
@@ -223,14 +223,14 @@ static int net_vhost_check_net(void *opaque, QemuOpts *opts, Error **errp)
     return 0;
 }
 
-int net_init_vhost_user(const NetClientOptions *opts, const char *name,
+int net_init_vhost_user(const Netdev *netdev, const char *name,
                         NetClientState *peer, Error **errp)
 {
     const NetdevVhostUserOptions *vhost_user_opts;
     CharDriverState *chr;
 
-    assert(opts->kind == NET_CLIENT_OPTIONS_KIND_VHOST_USER);
-    vhost_user_opts = opts->vhost_user;
+    assert(netdev->opts->kind == NET_CLIENT_OPTIONS_KIND_VHOST_USER);
+    vhost_user_opts = netdev->opts->vhost_user;
 
     chr = net_vhost_parse_chardev(vhost_user_opts, errp);
     if (!chr) {
Signature · 1 line
2.5.1
#12 lore raw

PATCH 6/7 qapi: reorder NetdevBase and Netdev

In reply to Kővágó, Zoltán

Probably more logical if NetdevBase comes before Netdev. No semantic changes.

---
 qapi-schema.json | 46 +++++++++++++++++++++++-----------------------
 1 file changed, 23 insertions(+), 23 deletions(-)
qapi-schema.json +23 -23
index 1b828e8..d52b8c6 100644
@@ -2499,6 +2499,29 @@
             'bridge', 'hubport', 'netmap', 'vhost-user' ] }
 
 ##
+# @NetdevBase
+#
+# Captures the commopn configuration of a network device.
+#
+# @vlan: #optional vlan number (legacy, forbidden with -netdev)
+#
+# @id: #optional identifier for monitor commands (required with -netdev)
+#
+# @name: #optional identifier for monitor commands, ignored if @id is present
+#        (legacy, forbidden with -netdev)
+#
+# @type: the netdev driver to use
+#
+# Since 2.5
+##
+{ 'struct': 'NetdevBase',
+  'data': {
+    '*vlan': 'int32',
+    '*id':   'str',
+    '*name': 'str',
+    'type':  'NetClientDriver' } }
+
+##
 # @Netdev
 #
 # Captures the configuration of a network device.
@@ -2528,29 +2551,6 @@
     'vhost-user': 'NetdevVhostUserOptions' } }
 
 ##
-# @NetdevBase
-#
-# Captures the common configuration of a network device.
-#
-# @vlan: #optional vlan number (legacy, forbidden with -netdev)
-#
-# @id: #optional identifier for monitor commands (required with -netdev)
-#
-# @name: #optional identifier for monitor commands, ignored if @id is present
-#        (legacy, forbidden with -netdev)
-#
-# @type: the netdev driver to use
-#
-# Since 2.5
-##
-{ 'struct': 'NetdevBase',
-  'data': {
-    '*vlan': 'int32',
-    '*id':   'str',
-    '*name': 'str',
-    'type':  'NetClientDriver' } }
-
-##
 # @InetSocketAddress
 #
 # Captures a socket address or address range in the Internet namespace.
Signature · 1 line
2.5.1
#14 lore raw

PATCH 7/7 qapi: support nested structs in OptsVisitor

In reply to Kővágó, Zoltán

The current OptsVisitor flattens the whole structure, if there are same named fields under different paths (like in' and out' in Audiodev'), the current visitor can't cope with them (for example setting frequency=44100' will set the in's frequency to 44100 and leave out's frequency unspecified).

This patch fixes it, by always requiring a complete path in case of nested structs. Fields in the path are separated by dots, similar to C structs (without pointers), like in.frequency' or out.frequency'.

You must provide a full path even in non-ambiguous cases. The qapi flattening commits hopefully ensures that this change doesn't create backward compatibility problems.

---
 qapi/opts-visitor.c                     | 116 ++++++++++++++++++++++++++------
 tests/qapi-schema/qapi-schema-test.json |   9 ++-
 tests/qapi-schema/qapi-schema-test.out  |   6 +-
 tests/test-opts-visitor.c               |  34 ++++++++++
 4 files changed, 141 insertions(+), 24 deletions(-)
qapi/opts-visitor.c +95 -21
index aa68814..2c2710b 100644
@@ -71,6 +71,7 @@ struct OptsVisitor
      * schema, with a single mandatory scalar member. */
     ListMode list_mode;
     GQueue *repeated_opts;
+    char *repeated_name;
 
     /* When parsing a list of repeating options as integers, values of the form
      * "a-b", representing a closed interval, are allowed. Elements in the
@@ -86,6 +87,9 @@ struct OptsVisitor
      * not survive or escape the OptsVisitor object.
      */
     QemuOpt *fake_id_opt;
+
+    /* List of field names leading to the current structure. */
+    GQueue *nested_names;
 };
 
 
@@ -100,6 +104,7 @@ static void
 opts_visitor_insert(GHashTable *unprocessed_opts, const QemuOpt *opt)
 {
     GQueue *list;
+    assert(opt);
 
     list = g_hash_table_lookup(unprocessed_opts, opt->name);
     if (list == NULL) {
@@ -127,6 +132,9 @@ opts_start_struct(Visitor *v, void **obj, const char *kind,
     if (obj) {
         *obj = g_malloc0(size > 0 ? size : 1);
     }
+
+    g_queue_push_tail(ov->nested_names, (gpointer) name);
+
     if (ov->depth++ > 0) {
         return;
     }
@@ -169,6 +177,8 @@ opts_end_struct(Visitor *v, Error **errp)
     OptsVisitor *ov = DO_UPCAST(OptsVisitor, visitor, v);
     GQueue *any;
 
+    g_queue_pop_tail(ov->nested_names);
+
     if (--ov->depth > 0) {
         return;
     }
@@ -198,15 +208,55 @@ opts_end_implicit_struct(Visitor *v, Error **errp)
 }
 
 
+static void
+sum_strlen(gpointer data, gpointer user_data)
+{
+    const char *str = data;
+    size_t *sum_len = user_data;
+
+    if (str) { /* skip NULLs */
+        *sum_len += strlen(str) + 1;
+    }
+}
+
+static void
+append_str(gpointer data, gpointer user_data)
+{
+    const char *str = data;
+    char *concat_str = user_data;
+
+    if (str) {
+        strcat(concat_str, str);
+        strcat(concat_str, ".");
+    }
+}
+
+/* lookup a name, using a fully qualified version */
 static GQueue *
-lookup_distinct(const OptsVisitor *ov, const char *name, Error **errp)
+lookup_distinct(const OptsVisitor *ov, const char *name, char **out_key,
+                Error **errp)
 {
-    GQueue *list;
+    GQueue *list = NULL;
+    char *key;
+    size_t sum_len = strlen(name);
+
+    g_queue_foreach(ov->nested_names, sum_strlen, &sum_len);
+    key = g_malloc(sum_len+1);
+    key[0] = 0;
+    g_queue_foreach(ov->nested_names, append_str, key);
+    strcat(key, name);
+
+    list = g_hash_table_lookup(ov->unprocessed_opts, key);
+    if (list && out_key) {
+        *out_key = key;
+        key = NULL;
+    }
 
-    list = g_hash_table_lookup(ov->unprocessed_opts, name);
     if (!list) {
         error_setg(errp, QERR_MISSING_PARAMETER, name);
     }
+
+    g_free(key);
     return list;
 }
 
@@ -218,7 +268,8 @@ opts_start_list(Visitor *v, const char *name, Error **errp)
 
     /* we can't traverse a list in a list */
     assert(ov->list_mode == LM_NONE);
-    ov->repeated_opts = lookup_distinct(ov, name, errp);
+    assert(ov->repeated_opts == NULL && ov->repeated_name == NULL);
+    ov->repeated_opts = lookup_distinct(ov, name, &ov->repeated_name, errp);
     if (ov->repeated_opts != NULL) {
         ov->list_mode = LM_STARTED;
     }
@@ -254,11 +305,9 @@ opts_next_list(Visitor *v, GenericList **list, Error **errp)
         /* range has been completed, fall through in order to pop option */
 
     case LM_IN_PROGRESS: {
-        const QemuOpt *opt;
-
-        opt = g_queue_pop_head(ov->repeated_opts);
+        g_queue_pop_head(ov->repeated_opts);
         if (g_queue_is_empty(ov->repeated_opts)) {
-            g_hash_table_remove(ov->unprocessed_opts, opt->name);
+            g_hash_table_remove(ov->unprocessed_opts, ov->repeated_name);
             return NULL;
         }
         link = &(*list)->next;
@@ -284,22 +333,28 @@ opts_end_list(Visitor *v, Error **errp)
            ov->list_mode == LM_SIGNED_INTERVAL ||
            ov->list_mode == LM_UNSIGNED_INTERVAL);
     ov->repeated_opts = NULL;
+
+    g_free(ov->repeated_name);
+    ov->repeated_name = NULL;
+
     ov->list_mode = LM_NONE;
 }
 
 
 static const QemuOpt *
-lookup_scalar(const OptsVisitor *ov, const char *name, Error **errp)
+lookup_scalar(const OptsVisitor *ov, const char *name, char** out_key,
+              Error **errp)
 {
     if (ov->list_mode == LM_NONE) {
         GQueue *list;
 
         /* the last occurrence of any QemuOpt takes effect when queried by name
          */
-        list = lookup_distinct(ov, name, errp);
+        list = lookup_distinct(ov, name, out_key, errp);
         return list ? g_queue_peek_tail(list) : NULL;
     }
     assert(ov->list_mode == LM_IN_PROGRESS);
+    assert(out_key == NULL || *out_key == NULL);
     return g_queue_peek_head(ov->repeated_opts);
 }
 
@@ -321,13 +376,15 @@ opts_type_str(Visitor *v, char **obj, const char *name, Error **errp)
 {
     OptsVisitor *ov = DO_UPCAST(OptsVisitor, visitor, v);
     const QemuOpt *opt;
+    char *key = NULL;
 
-    opt = lookup_scalar(ov, name, errp);
+    opt = lookup_scalar(ov, name, &key, errp);
     if (!opt) {
         return;
     }
     *obj = g_strdup(opt->str ? opt->str : "");
-    processed(ov, name);
+    processed(ov, key);
+    g_free(key);
 }
 
 
@@ -337,8 +394,9 @@ opts_type_bool(Visitor *v, bool *obj, const char *name, Error **errp)
 {
     OptsVisitor *ov = DO_UPCAST(OptsVisitor, visitor, v);
     const QemuOpt *opt;
+    char *key = NULL;
 
-    opt = lookup_scalar(ov, name, errp);
+    opt = lookup_scalar(ov, name, &key, errp);
     if (!opt) {
         return;
     }
@@ -355,13 +413,15 @@ opts_type_bool(Visitor *v, bool *obj, const char *name, Error **errp)
         } else {
             error_setg(errp, QERR_INVALID_PARAMETER_VALUE, opt->name,
                        "on|yes|y|off|no|n");
+            g_free(key);
             return;
         }
     } else {
         *obj = true;
     }
 
-    processed(ov, name);
+    processed(ov, key);
+    g_free(key);
 }
 
 
@@ -373,13 +433,14 @@ opts_type_int(Visitor *v, int64_t *obj, const char *name, Error **errp)
     const char *str;
     long long val;
     char *endptr;
+    char *key = NULL;
 
     if (ov->list_mode == LM_SIGNED_INTERVAL) {
         *obj = ov->range_next.s;
         return;
     }
 
-    opt = lookup_scalar(ov, name, errp);
+    opt = lookup_scalar(ov, name, &key, errp);
     if (!opt) {
         return;
     }
@@ -393,11 +454,13 @@ opts_type_int(Visitor *v, int64_t *obj, const char *name, Error **errp)
     if (errno == 0 && endptr > str && INT64_MIN <= val && val <= INT64_MAX) {
         if (*endptr == '\0') {
             *obj = val;
-            processed(ov, name);
+            processed(ov, key);
+            g_free(key);
             return;
         }
         if (*endptr == '-' && ov->list_mode == LM_IN_PROGRESS) {
             long long val2;
+            assert(key == NULL);
 
             str = endptr + 1;
             val2 = strtoll(str, &endptr, 0);
@@ -418,6 +481,7 @@ opts_type_int(Visitor *v, int64_t *obj, const char *name, Error **errp)
     error_setg(errp, QERR_INVALID_PARAMETER_VALUE, opt->name,
                (ov->list_mode == LM_NONE) ? "an int64 value" :
                                             "an int64 value or range");
+    g_free(key);
 }
 
 
@@ -429,13 +493,14 @@ opts_type_uint64(Visitor *v, uint64_t *obj, const char *name, Error **errp)
     const char *str;
     unsigned long long val;
     char *endptr;
+    char *key = NULL;
 
     if (ov->list_mode == LM_UNSIGNED_INTERVAL) {
         *obj = ov->range_next.u;
         return;
     }
 
-    opt = lookup_scalar(ov, name, errp);
+    opt = lookup_scalar(ov, name, &key, errp);
     if (!opt) {
         return;
     }
@@ -447,11 +512,13 @@ opts_type_uint64(Visitor *v, uint64_t *obj, const char *name, Error **errp)
     if (parse_uint(str, &val, &endptr, 0) == 0 && val <= UINT64_MAX) {
         if (*endptr == '\0') {
             *obj = val;
-            processed(ov, name);
+            processed(ov, key);
+            g_free(key);
             return;
         }
         if (*endptr == '-' && ov->list_mode == LM_IN_PROGRESS) {
             unsigned long long val2;
+            assert(key == NULL);
 
             str = endptr + 1;
             if (parse_uint_full(str, &val2, 0) == 0 &&
@@ -470,6 +537,7 @@ opts_type_uint64(Visitor *v, uint64_t *obj, const char *name, Error **errp)
     error_setg(errp, QERR_INVALID_PARAMETER_VALUE, opt->name,
                (ov->list_mode == LM_NONE) ? "a uint64 value" :
                                             "a uint64 value or range");
+    g_free(key);
 }
 
 
@@ -480,8 +548,9 @@ opts_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp)
     const QemuOpt *opt;
     int64_t val;
     char *endptr;
+    char *key = NULL;
 
-    opt = lookup_scalar(ov, name, errp);
+    opt = lookup_scalar(ov, name, &key, errp);
     if (!opt) {
         return;
     }
@@ -491,11 +560,13 @@ opts_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp)
     if (val < 0 || *endptr) {
         error_setg(errp, QERR_INVALID_PARAMETER_VALUE, opt->name,
                    "a size value representible as a non-negative int64");
+        g_free(key);
         return;
     }
 
     *obj = val;
-    processed(ov, name);
+    processed(ov, key);
+    g_free(key);
 }
 
 
@@ -506,7 +577,7 @@ opts_optional(Visitor *v, bool *present, const char *name, Error **errp)
 
     /* we only support a single mandatory scalar field in a list node */
     assert(ov->list_mode == LM_NONE);
-    *present = (lookup_distinct(ov, name, NULL) != NULL);
+    *present = (lookup_distinct(ov, name, NULL, NULL) != NULL);
 }
 
 
@@ -517,6 +588,8 @@ opts_visitor_new(const QemuOpts *opts)
 
     ov = g_malloc0(sizeof *ov);
 
+    ov->nested_names = g_queue_new();
+
     ov->visitor.start_struct = &opts_start_struct;
     ov->visitor.end_struct   = &opts_end_struct;
 
@@ -560,6 +633,7 @@ opts_visitor_cleanup(OptsVisitor *ov)
     if (ov->unprocessed_opts != NULL) {
         g_hash_table_destroy(ov->unprocessed_opts);
     }
+    g_queue_free(ov->nested_names);
     g_free(ov->fake_id_opt);
     g_free(ov);
 }
tests/qapi-schema/qapi-schema-test.json +8 -1
index a9e5aab..c4ab8b9 100644
@@ -87,6 +87,11 @@
 { 'command': 'user_def_cmd3', 'data': {'a': 'int', '*b': 'int' },
   'returns': 'int' }
 
+# For testing hierarchy support in opts-visitor
+{ 'struct': 'UserDefOptionsSub',
+  'data': {
+    '*nint': 'int' } }
+
 # For testing integer range flattening in opts-visitor. The following schema
 # corresponds to the option format:
 #
@@ -100,7 +105,9 @@
     '*u64' : [ 'uint64' ],
     '*u16' : [ 'uint16' ],
     '*i64x':   'int'     ,
-    '*u64x':   'uint64'  } }
+    '*u64x':   'uint64'  ,
+    'sub0':    'UserDefOptionsSub',
+    'sub1':    'UserDefOptionsSub' } }
 
 # testing event
 { 'struct': 'EventStructOne',
tests/qapi-schema/qapi-schema-test.out +4 -2
index b0b7187..0e8baca 100644
@@ -17,7 +17,8 @@
  OrderedDict([('command', 'user_def_cmd1'), ('data', OrderedDict([('ud1a', 'UserDefOne')]))]),
  OrderedDict([('command', 'user_def_cmd2'), ('data', OrderedDict([('ud1a', 'UserDefOne'), ('*ud1b', 'UserDefOne')])), ('returns', 'UserDefTwo')]),
  OrderedDict([('command', 'user_def_cmd3'), ('data', OrderedDict([('a', 'int'), ('*b', 'int')])), ('returns', 'int')]),
- OrderedDict([('struct', 'UserDefOptions'), ('data', OrderedDict([('*i64', ['int']), ('*u64', ['uint64']), ('*u16', ['uint16']), ('*i64x', 'int'), ('*u64x', 'uint64')]))]),
+ OrderedDict([('struct', 'UserDefOptionsSub'), ('data', OrderedDict([('*nint', 'int')]))]),
+ OrderedDict([('struct', 'UserDefOptions'), ('data', OrderedDict([('*i64', ['int']), ('*u64', ['uint64']), ('*u16', ['uint16']), ('*i64x', 'int'), ('*u64x', 'uint64'), ('sub0', 'UserDefOptionsSub'), ('sub1', 'UserDefOptionsSub')]))]),
  OrderedDict([('struct', 'EventStructOne'), ('data', OrderedDict([('struct1', 'UserDefOne'), ('string', 'str'), ('*enum2', 'EnumOne')]))]),
  OrderedDict([('event', 'EVENT_A')]),
  OrderedDict([('event', 'EVENT_B'), ('data', OrderedDict())]),
@@ -48,7 +49,8 @@
  OrderedDict([('struct', 'UserDefB'), ('data', OrderedDict([('intb', 'int')]))]),
  OrderedDict([('struct', 'UserDefUnionBase'), ('base', 'UserDefZero'), ('data', OrderedDict([('string', 'str'), ('enum1', 'EnumOne')]))]),
  OrderedDict([('struct', 'UserDefC'), ('data', OrderedDict([('string1', 'str'), ('string2', 'str')]))]),
- OrderedDict([('struct', 'UserDefOptions'), ('data', OrderedDict([('*i64', ['int']), ('*u64', ['uint64']), ('*u16', ['uint16']), ('*i64x', 'int'), ('*u64x', 'uint64')]))]),
+ OrderedDict([('struct', 'UserDefOptionsSub'), ('data', OrderedDict([('*nint', 'int')]))]),
+ OrderedDict([('struct', 'UserDefOptions'), ('data', OrderedDict([('*i64', ['int']), ('*u64', ['uint64']), ('*u16', ['uint16']), ('*i64x', 'int'), ('*u64x', 'uint64'), ('sub0', 'UserDefOptionsSub'), ('sub1', 'UserDefOptionsSub')]))]),
  OrderedDict([('struct', 'EventStructOne'), ('data', OrderedDict([('struct1', 'UserDefOne'), ('string', 'str'), ('*enum2', 'EnumOne')]))]),
  OrderedDict([('struct', '__org.qemu_x-Base'), ('data', OrderedDict([('__org.qemu_x-member1', '__org.qemu_x-Enum')]))]),
  OrderedDict([('struct', '__org.qemu_x-Struct'), ('base', '__org.qemu_x-Base'), ('data', OrderedDict([('__org.qemu_x-member2', 'str')]))]),
tests/test-opts-visitor.c +34 -0
index 1c753d9..4393266 100644
@@ -178,6 +178,34 @@ expect_u64_max(OptsVisitorFixture *f, gconstpointer test_data)
     g_assert(f->userdef->u64->value == UINT64_MAX);
 }
 
+static void
+expect_both(OptsVisitorFixture *f, gconstpointer test_data)
+{
+    expect_ok(f, test_data);
+    g_assert(f->userdef->sub0->has_nint);
+    g_assert(f->userdef->sub0->nint == 13);
+    g_assert(f->userdef->sub1->has_nint);
+    g_assert(f->userdef->sub1->nint == 17);
+}
+
+static void
+expect_sub0(OptsVisitorFixture *f, gconstpointer test_data)
+{
+    expect_ok(f, test_data);
+    g_assert(f->userdef->sub0->has_nint);
+    g_assert(f->userdef->sub0->nint == 13);
+    g_assert(!f->userdef->sub1->has_nint);
+}
+
+static void
+expect_sub1(OptsVisitorFixture *f, gconstpointer test_data)
+{
+    expect_ok(f, test_data);
+    g_assert(!f->userdef->sub0->has_nint);
+    g_assert(f->userdef->sub1->has_nint);
+    g_assert(f->userdef->sub1->nint == 13);
+}
+
 /* test cases */
 
 int
@@ -271,6 +299,12 @@ main(int argc, char **argv)
     add_test("/visitor/opts/i64/range/2big/full", &expect_fail,
              "i64=-0x8000000000000000-0x7fffffffffffffff");
 
+    /* Test nested structs support */
+    add_test("/visitor/opts/nested/unqualified", &expect_fail, "nint=13");
+    add_test("/visitor/opts/nested/both",        &expect_both,
+             "sub0.nint=13,sub1.nint=17");
+    add_test("/visitor/opts/nested/sub0",        &expect_sub0, "sub0.nint=13");
+    add_test("/visitor/opts/nested/sub1",        &expect_sub1, "sub1.nint=13");
     g_test_run();
     return 0;
 }
Signature · 1 line
2.5.1
#10 lore raw

PATCH 5/7 qapi: change Netdev into a flat union

In reply to Kővágó, Zoltán

Except qapi-schema.json, this patch was generated by:

find . -name .git -prune -o -type f \! -name '*~' -print0 | \

  xargs -0 sed -i \
    -e 's/NetClientOptionsKind/NetClientDriver/g' \
    -e 's/NET_CLIENT_OPTIONS_KIND_/NET_CLIENT_DRIVER_/g' \
    -e 's/netdev->opts/netdev/g' \
    -e 's/netdev->kind/netdev->type/g'
---
 hw/arm/musicpal.c                |  2 +-
 hw/core/qdev-properties-system.c |  2 +-
 hw/net/allwinner_emac.c          |  2 +-
 hw/net/cadence_gem.c             |  2 +-
 hw/net/dp8393x.c                 |  2 +-
 hw/net/e1000.c                   |  2 +-
 hw/net/eepro100.c                |  2 +-
 hw/net/etraxfs_eth.c             |  2 +-
 hw/net/fsl_etsec/etsec.c         |  2 +-
 hw/net/lan9118.c                 |  2 +-
 hw/net/lance.c                   |  2 +-
 hw/net/mcf_fec.c                 |  2 +-
 hw/net/milkymist-minimac2.c      |  2 +-
 hw/net/mipsnet.c                 |  2 +-
 hw/net/ne2000-isa.c              |  2 +-
 hw/net/ne2000.c                  |  2 +-
 hw/net/opencores_eth.c           |  2 +-
 hw/net/pcnet-pci.c               |  2 +-
 hw/net/rocker/rocker_fp.c        |  2 +-
 hw/net/rtl8139.c                 |  2 +-
 hw/net/smc91c111.c               |  2 +-
 hw/net/spapr_llan.c              |  2 +-
 hw/net/stellaris_enet.c          |  2 +-
 hw/net/vhost_net.c               | 18 ++++-----
 hw/net/virtio-net.c              |  6 +--
 hw/net/vmxnet3.c                 |  2 +-
 hw/net/xen_nic.c                 |  2 +-
 hw/net/xgmac.c                   |  2 +-
 hw/net/xilinx_axienet.c          |  2 +-
 hw/net/xilinx_ethlite.c          |  2 +-
 hw/usb/dev-network.c             |  2 +-
 include/net/net.h                |  4 +-
 monitor.c                        | 14 +++----
 net/dump.c                       |  6 +--
 net/hub.c                        | 22 +++++------
 net/l2tpv3.c                     |  6 +--
 net/net.c                        | 84 ++++++++++++++++++++--------------------
 net/netmap.c                     |  4 +-
 net/slirp.c                      |  6 +--
 net/socket.c                     |  8 ++--
 net/tap-win32.c                  |  6 +--
 net/tap.c                        | 24 ++++++------
 net/vde.c                        |  6 +--
 net/vhost-user.c                 | 12 +++---
 qapi-schema.json                 | 38 +++++++++++-------
 45 files changed, 167 insertions(+), 155 deletions(-)
hw/arm/musicpal.c +1 -1
index 42f66b3..94bdf5f 100644
@@ -374,7 +374,7 @@ static void eth_cleanup(NetClientState *nc)
 }
 
 static NetClientInfo net_mv88w8618_info = {
-    .type = NET_CLIENT_OPTIONS_KIND_NIC,
+    .type = NET_CLIENT_DRIVER_NIC,
     .size = sizeof(NICState),
     .receive = eth_receive,
     .cleanup = eth_cleanup,
hw/core/qdev-properties-system.c +1 -1
index 921e799..249976e 100644
@@ -229,7 +229,7 @@ static void set_netdev(Object *obj, Visitor *v, void *opaque,
     }
 
     queues = qemu_find_net_clients_except(str, peers,
-                                          NET_CLIENT_OPTIONS_KIND_NIC,
+                                          NET_CLIENT_DRIVER_NIC,
                                           MAX_QUEUE_NUM);
     if (queues == 0) {
         err = -ENOENT;
hw/net/allwinner_emac.c +1 -1
index 0407dee..4fdf824 100644
@@ -422,7 +422,7 @@ static const MemoryRegionOps aw_emac_mem_ops = {
 };
 
 static NetClientInfo net_aw_emac_info = {
-    .type = NET_CLIENT_OPTIONS_KIND_NIC,
+    .type = NET_CLIENT_DRIVER_NIC,
     .size = sizeof(NICState),
     .can_receive = aw_emac_can_receive,
     .receive = aw_emac_receive,
hw/net/cadence_gem.c +1 -1
index 494a346..d74136a 100644
@@ -1175,7 +1175,7 @@ static void gem_set_link(NetClientState *nc)
 }
 
 static NetClientInfo net_gem_info = {
-    .type = NET_CLIENT_OPTIONS_KIND_NIC,
+    .type = NET_CLIENT_DRIVER_NIC,
     .size = sizeof(NICState),
     .can_receive = gem_can_receive,
     .receive = gem_receive,
hw/net/dp8393x.c +1 -1
index ab607e4..fb57900 100644
@@ -810,7 +810,7 @@ static void dp8393x_reset(DeviceState *dev)
 }
 
 static NetClientInfo net_dp83932_info = {
-    .type = NET_CLIENT_OPTIONS_KIND_NIC,
+    .type = NET_CLIENT_DRIVER_NIC,
     .size = sizeof(NICState),
     .can_receive = dp8393x_can_receive,
     .receive = dp8393x_receive,
hw/net/e1000.c +1 -1
index 5c6bcd0..06b5a52 100644
@@ -1515,7 +1515,7 @@ pci_e1000_uninit(PCIDevice *dev)
 }
 
 static NetClientInfo net_e1000_info = {
-    .type = NET_CLIENT_OPTIONS_KIND_NIC,
+    .type = NET_CLIENT_DRIVER_NIC,
     .size = sizeof(NICState),
     .can_receive = e1000_can_receive,
     .receive = e1000_receive,
hw/net/eepro100.c +1 -1
index 60333b7..28552f7 100644
@@ -1832,7 +1832,7 @@ static void pci_nic_uninit(PCIDevice *pci_dev)
 }
 
 static NetClientInfo net_eepro100_info = {
-    .type = NET_CLIENT_OPTIONS_KIND_NIC,
+    .type = NET_CLIENT_DRIVER_NIC,
     .size = sizeof(NICState),
     .receive = nic_receive,
 };
hw/net/etraxfs_eth.c +1 -1
index d600275..f43a170 100644
@@ -577,7 +577,7 @@ static const MemoryRegionOps eth_ops = {
 };
 
 static NetClientInfo net_etraxfs_info = {
-    .type = NET_CLIENT_OPTIONS_KIND_NIC,
+    .type = NET_CLIENT_DRIVER_NIC,
     .size = sizeof(NICState),
     .receive = eth_receive,
     .link_status_changed = eth_set_link,
hw/net/fsl_etsec/etsec.c +1 -1
index 0f5cf44..c936b3b 100644
@@ -369,7 +369,7 @@ static void etsec_set_link_status(NetClientState *nc)
 }
 
 static NetClientInfo net_etsec_info = {
-    .type = NET_CLIENT_OPTIONS_KIND_NIC,
+    .type = NET_CLIENT_DRIVER_NIC,
     .size = sizeof(NICState),
     .receive = etsec_receive,
     .link_status_changed = etsec_set_link_status,
hw/net/lan9118.c +1 -1
index 4f0e840..11bfd23 100644
@@ -1305,7 +1305,7 @@ static const MemoryRegionOps lan9118_16bit_mem_ops = {
 };
 
 static NetClientInfo net_lan9118_info = {
-    .type = NET_CLIENT_OPTIONS_KIND_NIC,
+    .type = NET_CLIENT_DRIVER_NIC,
     .size = sizeof(NICState),
     .receive = lan9118_receive,
     .link_status_changed = lan9118_set_link,
hw/net/lance.c +1 -1
index 780b39d..7940c05 100644
@@ -92,7 +92,7 @@ static const MemoryRegionOps lance_mem_ops = {
 };
 
 static NetClientInfo net_lance_info = {
-    .type = NET_CLIENT_OPTIONS_KIND_NIC,
+    .type = NET_CLIENT_DRIVER_NIC,
     .size = sizeof(NICState),
     .receive = pcnet_receive,
     .link_status_changed = pcnet_set_link_status,
hw/net/mcf_fec.c +1 -1
index 21928f9..5386597 100644
@@ -506,7 +506,7 @@ static const MemoryRegionOps mcf_fec_ops = {
 };
 
 static NetClientInfo net_mcf_fec_info = {
-    .type = NET_CLIENT_OPTIONS_KIND_NIC,
+    .type = NET_CLIENT_DRIVER_NIC,
     .size = sizeof(NICState),
     .receive = mcf_fec_receive,
 };
hw/net/milkymist-minimac2.c +1 -1
index 5d1cf08..aff0c9f 100644
@@ -443,7 +443,7 @@ static void milkymist_minimac2_reset(DeviceState *d)
 }
 
 static NetClientInfo net_milkymist_minimac2_info = {
-    .type = NET_CLIENT_OPTIONS_KIND_NIC,
+    .type = NET_CLIENT_DRIVER_NIC,
     .size = sizeof(NICState),
     .receive = minimac2_rx,
 };
hw/net/mipsnet.c +1 -1
index f261011..b9bf03f 100644
@@ -218,7 +218,7 @@ static const VMStateDescription vmstate_mipsnet = {
 };
 
 static NetClientInfo net_mipsnet_info = {
-    .type = NET_CLIENT_OPTIONS_KIND_NIC,
+    .type = NET_CLIENT_DRIVER_NIC,
     .size = sizeof(NICState),
     .receive = mipsnet_receive,
 };
hw/net/ne2000-isa.c +1 -1
index 18b0644..7894fab 100644
@@ -42,7 +42,7 @@ typedef struct ISANE2000State {
 } ISANE2000State;
 
 static NetClientInfo net_ne2000_isa_info = {
-    .type = NET_CLIENT_OPTIONS_KIND_NIC,
+    .type = NET_CLIENT_DRIVER_NIC,
     .size = sizeof(NICState),
     .receive = ne2000_receive,
 };
hw/net/ne2000.c +1 -1
index 53c704a..3c5a322 100644
@@ -694,7 +694,7 @@ void ne2000_setup_io(NE2000State *s, DeviceState *dev, unsigned size)
 }
 
 static NetClientInfo net_ne2000_info = {
-    .type = NET_CLIENT_OPTIONS_KIND_NIC,
+    .type = NET_CLIENT_DRIVER_NIC,
     .size = sizeof(NICState),
     .receive = ne2000_receive,
 };
hw/net/opencores_eth.c +1 -1
index 3642046..4b6407b 100644
@@ -473,7 +473,7 @@ static ssize_t open_eth_receive(NetClientState *nc,
 }
 
 static NetClientInfo net_open_eth_info = {
-    .type = NET_CLIENT_OPTIONS_KIND_NIC,
+    .type = NET_CLIENT_DRIVER_NIC,
     .size = sizeof(NICState),
     .can_receive = open_eth_can_receive,
     .receive = open_eth_receive,
hw/net/pcnet-pci.c +1 -1
index b4d60b8..c04c3a2 100644
@@ -271,7 +271,7 @@ static void pci_pcnet_uninit(PCIDevice *dev)
 }
 
 static NetClientInfo net_pci_pcnet_info = {
-    .type = NET_CLIENT_OPTIONS_KIND_NIC,
+    .type = NET_CLIENT_DRIVER_NIC,
     .size = sizeof(NICState),
     .receive = pcnet_receive,
     .link_status_changed = pcnet_set_link_status,
hw/net/rocker/rocker_fp.c +1 -1
index c693ae5..3f82e30 100644
@@ -166,7 +166,7 @@ static void fp_port_set_link_status(NetClientState *nc)
 }
 
 static NetClientInfo fp_port_info = {
-    .type = NET_CLIENT_OPTIONS_KIND_NIC,
+    .type = NET_CLIENT_DRIVER_NIC,
     .size = sizeof(NICState),
     .receive = fp_port_receive,
     .receive_iov = fp_port_receive_iov,
hw/net/rtl8139.c +1 -1
index fb2c55c..0f1d405 100644
@@ -3415,7 +3415,7 @@ static void rtl8139_set_link_status(NetClientState *nc)
 }
 
 static NetClientInfo net_rtl8139_info = {
-    .type = NET_CLIENT_OPTIONS_KIND_NIC,
+    .type = NET_CLIENT_DRIVER_NIC,
     .size = sizeof(NICState),
     .can_receive = rtl8139_can_receive,
     .receive = rtl8139_receive,
hw/net/smc91c111.c +1 -1
index 74e06e6..4c85eb5 100644
@@ -737,7 +737,7 @@ static const MemoryRegionOps smc91c111_mem_ops = {
 };
 
 static NetClientInfo net_smc91c111_info = {
-    .type = NET_CLIENT_OPTIONS_KIND_NIC,
+    .type = NET_CLIENT_DRIVER_NIC,
     .size = sizeof(NICState),
     .can_receive = smc91c111_can_receive,
     .receive = smc91c111_receive,
hw/net/spapr_llan.c +1 -1
index 1ca5e9c..4ee4b92 100644
@@ -188,7 +188,7 @@ static ssize_t spapr_vlan_receive(NetClientState *nc, const uint8_t *buf,
 }
 
 static NetClientInfo net_spapr_vlan_info = {
-    .type = NET_CLIENT_OPTIONS_KIND_NIC,
+    .type = NET_CLIENT_DRIVER_NIC,
     .size = sizeof(NICState),
     .can_receive = spapr_vlan_can_receive,
     .receive = spapr_vlan_receive,
hw/net/stellaris_enet.c +1 -1
index 21a4773..10290fe 100644
@@ -449,7 +449,7 @@ static void stellaris_enet_reset(stellaris_enet_state *s)
 }
 
 static NetClientInfo net_stellaris_enet_info = {
-    .type = NET_CLIENT_OPTIONS_KIND_NIC,
+    .type = NET_CLIENT_DRIVER_NIC,
     .size = sizeof(NICState),
     .receive = stellaris_enet_receive,
 };
hw/net/vhost_net.c +9 -9
index 5c1d11f..5d24c29 100644
@@ -95,10 +95,10 @@ static const int *vhost_net_get_feature_bits(struct vhost_net *net)
     const int *feature_bits = 0;
 
     switch (net->nc->info->type) {
-    case NET_CLIENT_OPTIONS_KIND_TAP:
+    case NET_CLIENT_DRIVER_TAP:
         feature_bits = kernel_feature_bits;
         break;
-    case NET_CLIENT_OPTIONS_KIND_VHOST_USER:
+    case NET_CLIENT_DRIVER_VHOST_USER:
         feature_bits = user_feature_bits;
         break;
     default:
@@ -125,7 +125,7 @@ void vhost_net_ack_features(struct vhost_net *net, uint64_t features)
 static int vhost_net_get_fd(NetClientState *backend)
 {
     switch (backend->info->type) {
-    case NET_CLIENT_OPTIONS_KIND_TAP:
+    case NET_CLIENT_DRIVER_TAP:
         return tap_get_fd(backend);
     default:
         fprintf(stderr, "vhost-net requires tap backend\n");
@@ -236,7 +236,7 @@ static int vhost_net_start_one(struct vhost_net *net,
         net->nc->info->poll(net->nc, false);
     }
 
-    if (net->nc->info->type == NET_CLIENT_OPTIONS_KIND_TAP) {
+    if (net->nc->info->type == NET_CLIENT_DRIVER_TAP) {
         qemu_set_fd_handler(net->backend, NULL, NULL, NULL);
         file.fd = net->backend;
         for (file.index = 0; file.index < net->dev.nvqs; ++file.index) {
@@ -252,7 +252,7 @@ static int vhost_net_start_one(struct vhost_net *net,
     return 0;
 fail:
     file.fd = -1;
-    if (net->nc->info->type == NET_CLIENT_OPTIONS_KIND_TAP) {
+    if (net->nc->info->type == NET_CLIENT_DRIVER_TAP) {
         while (file.index-- > 0) {
             const VhostOps *vhost_ops = net->dev.vhost_ops;
             int r = vhost_ops->vhost_call(&net->dev, VHOST_NET_SET_BACKEND,
@@ -275,14 +275,14 @@ static void vhost_net_stop_one(struct vhost_net *net,
 {
     struct vhost_vring_file file = { .fd = -1 };
 
-    if (net->nc->info->type == NET_CLIENT_OPTIONS_KIND_TAP) {
+    if (net->nc->info->type == NET_CLIENT_DRIVER_TAP) {
         for (file.index = 0; file.index < net->dev.nvqs; ++file.index) {
             const VhostOps *vhost_ops = net->dev.vhost_ops;
             int r = vhost_ops->vhost_call(&net->dev, VHOST_NET_SET_BACKEND,
                                           &file);
             assert(r >= 0);
         }
-    } else if (net->nc->info->type == NET_CLIENT_OPTIONS_KIND_VHOST_USER) {
+    } else if (net->nc->info->type == NET_CLIENT_DRIVER_VHOST_USER) {
         for (file.index = 0; file.index < net->dev.nvqs; ++file.index) {
             const VhostOps *vhost_ops = net->dev.vhost_ops;
             int r = vhost_ops->vhost_call(&net->dev, VHOST_RESET_OWNER,
@@ -399,10 +399,10 @@ VHostNetState *get_vhost_net(NetClientState *nc)
     }
 
     switch (nc->info->type) {
-    case NET_CLIENT_OPTIONS_KIND_TAP:
+    case NET_CLIENT_DRIVER_TAP:
         vhost_net = tap_get_vhost_net(nc);
         break;
-    case NET_CLIENT_OPTIONS_KIND_VHOST_USER:
+    case NET_CLIENT_DRIVER_VHOST_USER:
         vhost_net = vhost_user_get_vhost_net(nc);
         break;
     default:
hw/net/virtio-net.c +3 -3
index 8d28e45..ee76e29 100644
@@ -406,7 +406,7 @@ static int peer_attach(VirtIONet *n, int index)
         return 0;
     }
 
-    if (nc->peer->info->type != NET_CLIENT_OPTIONS_KIND_TAP) {
+    if (nc->peer->info->type != NET_CLIENT_DRIVER_TAP) {
         return 0;
     }
 
@@ -421,7 +421,7 @@ static int peer_detach(VirtIONet *n, int index)
         return 0;
     }
 
-    if (nc->peer->info->type !=  NET_CLIENT_OPTIONS_KIND_TAP) {
+    if (nc->peer->info->type !=  NET_CLIENT_DRIVER_TAP) {
         return 0;
     }
 
@@ -1595,7 +1595,7 @@ static int virtio_net_load_device(VirtIODevice *vdev, QEMUFile *f,
 }
 
 static NetClientInfo net_virtio_info = {
-    .type = NET_CLIENT_OPTIONS_KIND_NIC,
+    .type = NET_CLIENT_DRIVER_NIC,
     .size = sizeof(NICState),
     .can_receive = virtio_net_can_receive,
     .receive = virtio_net_receive,
hw/net/vmxnet3.c +1 -1
index 04159c8..ae465bd 100644
@@ -1986,7 +1986,7 @@ static void vmxnet3_set_link_status(NetClientState *nc)
 }
 
 static NetClientInfo net_vmxnet3_info = {
-        .type = NET_CLIENT_OPTIONS_KIND_NIC,
+        .type = NET_CLIENT_DRIVER_NIC,
         .size = sizeof(NICState),
         .receive = vmxnet3_receive,
         .link_status_changed = vmxnet3_set_link_status,
hw/net/xen_nic.c +1 -1
index d7cbfc1..fd2da6a 100644
@@ -280,7 +280,7 @@ static ssize_t net_rx_packet(NetClientState *nc, const uint8_t *buf, size_t size
 /* ------------------------------------------------------------- */
 
 static NetClientInfo net_xen_info = {
-    .type = NET_CLIENT_OPTIONS_KIND_NIC,
+    .type = NET_CLIENT_DRIVER_NIC,
     .size = sizeof(NICState),
     .receive = net_rx_packet,
 };
hw/net/xgmac.c +1 -1
index 15fb681..ccf8a77 100644
@@ -370,7 +370,7 @@ out:
 }
 
 static NetClientInfo net_xgmac_enet_info = {
-    .type = NET_CLIENT_OPTIONS_KIND_NIC,
+    .type = NET_CLIENT_DRIVER_NIC,
     .size = sizeof(NICState),
     .receive = eth_rx,
 };
hw/net/xilinx_axienet.c +1 -1
index d63c423..cc464c9 100644
@@ -933,7 +933,7 @@ xilinx_axienet_data_stream_push(StreamSlave *obj, uint8_t *buf, size_t size)
 }
 
 static NetClientInfo net_xilinx_enet_info = {
-    .type = NET_CLIENT_OPTIONS_KIND_NIC,
+    .type = NET_CLIENT_DRIVER_NIC,
     .size = sizeof(NICState),
     .receive = eth_rx,
 };
hw/net/xilinx_ethlite.c +1 -1
index ad6b553..ab555f6 100644
@@ -214,7 +214,7 @@ static void xilinx_ethlite_reset(DeviceState *dev)
 }
 
 static NetClientInfo net_xilinx_ethlite_info = {
-    .type = NET_CLIENT_OPTIONS_KIND_NIC,
+    .type = NET_CLIENT_DRIVER_NIC,
     .size = sizeof(NICState),
     .can_receive = eth_can_rx,
     .receive = eth_rx,
hw/usb/dev-network.c +1 -1
index 7800cee..97b2c2a 100644
@@ -1330,7 +1330,7 @@ static void usb_net_handle_destroy(USBDevice *dev)
 }
 
 static NetClientInfo net_usbnet_info = {
-    .type = NET_CLIENT_OPTIONS_KIND_NIC,
+    .type = NET_CLIENT_DRIVER_NIC,
     .size = sizeof(NICState),
     .receive = usbnet_receive,
     .cleanup = usbnet_cleanup,
include/net/net.h +2 -2
index 6a6cbef..c0e00ef 100644
@@ -59,7 +59,7 @@ typedef int (SetVnetLE)(NetClientState *, bool);
 typedef int (SetVnetBE)(NetClientState *, bool);
 
 typedef struct NetClientInfo {
-    NetClientOptionsKind type;
+    NetClientDriver type;
     size_t size;
     NetReceive *receive;
     NetReceive *receive_raw;
@@ -104,7 +104,7 @@ typedef struct NICState {
 char *qemu_mac_strdup_printf(const uint8_t *macaddr);
 NetClientState *qemu_find_netdev(const char *id);
 int qemu_find_net_clients_except(const char *id, NetClientState **ncs,
-                                 NetClientOptionsKind type, int max);
+                                 NetClientDriver type, int max);
 NetClientState *qemu_new_net_client(NetClientInfo *info,
                                     NetClientState *peer,
                                     const char *model,
monitor.c +7 -7
index 5455ab9..69d60ca 100644
@@ -4208,8 +4208,8 @@ void netdev_add_completion(ReadLineState *rs, int nb_args, const char *str)
     }
     len = strlen(str);
     readline_set_completion_index(rs, len);
-    for (i = 0; NetClientOptionsKind_lookup[i]; i++) {
-        add_completion_option(rs, str, NetClientOptionsKind_lookup[i]);
+    for (i = 0; NetClientDriver_lookup[i]; i++) {
+        add_completion_option(rs, str, NetClientDriver_lookup[i]);
     }
 }
 
@@ -4409,7 +4409,7 @@ void set_link_completion(ReadLineState *rs, int nb_args, const char *str)
         NetClientState *ncs[MAX_QUEUE_NUM];
         int count, i;
         count = qemu_find_net_clients_except(NULL, ncs,
-                                             NET_CLIENT_OPTIONS_KIND_NONE,
+                                             NET_CLIENT_DRIVER_NONE,
                                              MAX_QUEUE_NUM);
         for (i = 0; i < MIN(count, MAX_QUEUE_NUM); i++) {
             const char *name = ncs[i]->name;
@@ -4434,7 +4434,7 @@ void netdev_del_completion(ReadLineState *rs, int nb_args, const char *str)
 
     len = strlen(str);
     readline_set_completion_index(rs, len);
-    count = qemu_find_net_clients_except(NULL, ncs, NET_CLIENT_OPTIONS_KIND_NIC,
+    count = qemu_find_net_clients_except(NULL, ncs, NET_CLIENT_DRIVER_NIC,
                                          MAX_QUEUE_NUM);
     for (i = 0; i < MIN(count, MAX_QUEUE_NUM); i++) {
         QemuOpts *opts;
@@ -4546,7 +4546,7 @@ void host_net_remove_completion(ReadLineState *rs, int nb_args, const char *str)
     readline_set_completion_index(rs, len);
     if (nb_args == 2) {
         count = qemu_find_net_clients_except(NULL, ncs,
-                                             NET_CLIENT_OPTIONS_KIND_NONE,
+                                             NET_CLIENT_DRIVER_NONE,
                                              MAX_QUEUE_NUM);
         for (i = 0; i < MIN(count, MAX_QUEUE_NUM); i++) {
             int id;
@@ -4563,13 +4563,13 @@ void host_net_remove_completion(ReadLineState *rs, int nb_args, const char *str)
         return;
     } else if (nb_args == 3) {
         count = qemu_find_net_clients_except(NULL, ncs,
-                                             NET_CLIENT_OPTIONS_KIND_NIC,
+                                             NET_CLIENT_DRIVER_NIC,
                                              MAX_QUEUE_NUM);
         for (i = 0; i < MIN(count, MAX_QUEUE_NUM); i++) {
             int id;
             const char *name;
 
-            if (ncs[i]->info->type == NET_CLIENT_OPTIONS_KIND_HUBPORT ||
+            if (ncs[i]->info->type == NET_CLIENT_DRIVER_HUBPORT ||
                 net_hub_id_for_client(ncs[i], &id)) {
                 continue;
             }
net/dump.c +3 -3
index d80fa94..d2c68f8 100644
@@ -94,7 +94,7 @@ static void dump_cleanup(NetClientState *nc)
 }
 
 static NetClientInfo net_dump_info = {
-    .type = NET_CLIENT_OPTIONS_KIND_DUMP,
+    .type = NET_CLIENT_DRIVER_DUMP,
     .size = sizeof(DumpState),
     .receive = dump_receive,
     .cleanup = dump_cleanup,
@@ -154,8 +154,8 @@ int net_init_dump(const Netdev *netdev, const char *name,
     char def_file[128];
     const NetdevDumpOptions *dump;
 
-    assert(netdev->opts->kind == NET_CLIENT_OPTIONS_KIND_DUMP);
-    dump = netdev->opts->dump;
+    assert(netdev->type == NET_CLIENT_DRIVER_DUMP);
+    dump = netdev->dump;
 
     assert(peer);
 
net/hub.c +11 -11
index 29f65b2..11e6450 100644
@@ -130,7 +130,7 @@ static void net_hub_port_cleanup(NetClientState *nc)
 }
 
 static NetClientInfo net_hub_port_info = {
-    .type = NET_CLIENT_OPTIONS_KIND_HUBPORT,
+    .type = NET_CLIENT_DRIVER_HUBPORT,
     .size = sizeof(NetHubPort),
     .can_receive = net_hub_port_can_receive,
     .receive = net_hub_port_receive,
@@ -265,10 +265,10 @@ int net_hub_id_for_client(NetClientState *nc, int *id)
 {
     NetHubPort *port;
 
-    if (nc->info->type == NET_CLIENT_OPTIONS_KIND_HUBPORT) {
+    if (nc->info->type == NET_CLIENT_DRIVER_HUBPORT) {
         port = DO_UPCAST(NetHubPort, nc, nc);
     } else if (nc->peer != NULL && nc->peer->info->type ==
-            NET_CLIENT_OPTIONS_KIND_HUBPORT) {
+            NET_CLIENT_DRIVER_HUBPORT) {
         port = DO_UPCAST(NetHubPort, nc, nc->peer);
     } else {
         return -ENOENT;
@@ -285,9 +285,9 @@ int net_init_hubport(const Netdev *netdev, const char *name,
 {
     const NetdevHubPortOptions *hubport;
 
-    assert(netdev->opts->kind == NET_CLIENT_OPTIONS_KIND_HUBPORT);
+    assert(netdev->type == NET_CLIENT_DRIVER_HUBPORT);
     assert(!peer);
-    hubport = netdev->opts->hubport;
+    hubport = netdev->hubport;
 
     net_hub_add_port(hubport->hubid, name);
     return 0;
@@ -314,14 +314,14 @@ void net_hub_check_clients(void)
             }
 
             switch (peer->info->type) {
-            case NET_CLIENT_OPTIONS_KIND_NIC:
+            case NET_CLIENT_DRIVER_NIC:
                 has_nic = 1;
                 break;
-            case NET_CLIENT_OPTIONS_KIND_USER:
-            case NET_CLIENT_OPTIONS_KIND_TAP:
-            case NET_CLIENT_OPTIONS_KIND_SOCKET:
-            case NET_CLIENT_OPTIONS_KIND_VDE:
-            case NET_CLIENT_OPTIONS_KIND_VHOST_USER:
+            case NET_CLIENT_DRIVER_USER:
+            case NET_CLIENT_DRIVER_TAP:
+            case NET_CLIENT_DRIVER_SOCKET:
+            case NET_CLIENT_DRIVER_VDE:
+            case NET_CLIENT_DRIVER_VHOST_USER:
                 has_host_dev = 1;
                 break;
             default:
net/l2tpv3.c +3 -3
index d2f8431..aa2c020 100644
@@ -516,7 +516,7 @@ static void net_l2tpv3_cleanup(NetClientState *nc)
 }
 
 static NetClientInfo net_l2tpv3_info = {
-    .type = NET_CLIENT_OPTIONS_KIND_L2TPV3,
+    .type = NET_CLIENT_DRIVER_L2TPV3,
     .size = sizeof(NetL2TPV3State),
     .receive = net_l2tpv3_receive_dgram,
     .receive_iov = net_l2tpv3_receive_dgram_iov,
@@ -545,8 +545,8 @@ int net_init_l2tpv3(const Netdev *netdev,
     s->queue_tail = 0;
     s->header_mismatch = false;
 
-    assert(netdev->opts->kind == NET_CLIENT_OPTIONS_KIND_L2TPV3);
-    l2tpv3 = netdev->opts->l2tpv3;
+    assert(netdev->type == NET_CLIENT_DRIVER_L2TPV3);
+    l2tpv3 = netdev->l2tpv3;
 
     if (l2tpv3->has_ipv6 && l2tpv3->ipv6) {
         s->ipv6 = l2tpv3->ipv6;
net/net.c +42 -42

243 lines not on this page · raw message

net/netmap.c +2 -2
index a464618..eff9b8c 100644
@@ -417,7 +417,7 @@ static void netmap_set_offload(NetClientState *nc, int csum, int tso4, int tso6,
 
 /* NetClientInfo methods */
 static NetClientInfo net_netmap_info = {
-    .type = NET_CLIENT_OPTIONS_KIND_NETMAP,
+    .type = NET_CLIENT_DRIVER_NETMAP,
     .size = sizeof(NetmapState),
     .receive = netmap_receive,
     .receive_iov = netmap_receive_iov,
@@ -439,7 +439,7 @@ int net_init_netmap(const Netdev *netdev,
                     const char *name, NetClientState *peer, Error **errp)
 {
     /* FIXME error_setg(errp, ...) on failure */
-    const NetdevNetmapOptions *netmap_opts = netdev->opts->netmap;
+    const NetdevNetmapOptions *netmap_opts = netdev->netmap;
     NetClientState *nc;
     NetmapPriv me;
     NetmapState *s;
net/slirp.c +3 -3
index 0fc2c52..055c9de 100644
@@ -126,7 +126,7 @@ static void net_slirp_cleanup(NetClientState *nc)
 }
 
 static NetClientInfo net_slirp_info = {
-    .type = NET_CLIENT_OPTIONS_KIND_USER,
+    .type = NET_CLIENT_DRIVER_USER,
     .size = sizeof(SlirpState),
     .receive = net_slirp_receive,
     .cleanup = net_slirp_cleanup,
@@ -746,8 +746,8 @@ int net_init_slirp(const Netdev *netdev, const char *name,
     const NetdevUserOptions *user;
     const char **dnssearch;
 
-    assert(netdev->opts->kind == NET_CLIENT_OPTIONS_KIND_USER);
-    user = netdev->opts->user;
+    assert(netdev->type == NET_CLIENT_DRIVER_USER);
+    user = netdev->user;
 
     vnet = user->has_net ? g_strdup(user->net) :
            user->has_ip  ? g_strdup_printf("%s/24", user->ip) :
net/socket.c +4 -4
index 75f693c..915bed2 100644
@@ -346,7 +346,7 @@ static void net_socket_cleanup(NetClientState *nc)
 }
 
 static NetClientInfo net_dgram_socket_info = {
-    .type = NET_CLIENT_OPTIONS_KIND_SOCKET,
+    .type = NET_CLIENT_DRIVER_SOCKET,
     .size = sizeof(NetSocketState),
     .receive = net_socket_receive_dgram,
     .cleanup = net_socket_cleanup,
@@ -429,7 +429,7 @@ static void net_socket_connect(void *opaque)
 }
 
 static NetClientInfo net_socket_info = {
-    .type = NET_CLIENT_OPTIONS_KIND_SOCKET,
+    .type = NET_CLIENT_DRIVER_SOCKET,
     .size = sizeof(NetSocketState),
     .receive = net_socket_receive,
     .cleanup = net_socket_cleanup,
@@ -706,8 +706,8 @@ int net_init_socket(const Netdev *netdev, const char *name,
     Error *err = NULL;
     const NetdevSocketOptions *sock;
 
-    assert(netdev->opts->kind == NET_CLIENT_OPTIONS_KIND_SOCKET);
-    sock = netdev->opts->socket;
+    assert(netdev->type == NET_CLIENT_DRIVER_SOCKET);
+    sock = netdev->socket;
 
     if (sock->has_fd + sock->has_listen + sock->has_connect + sock->has_mcast +
         sock->has_udp != 1) {
net/tap-win32.c +3 -3
index acce480..32be2a0 100644
@@ -723,7 +723,7 @@ static void tap_set_vnet_hdr_len(NetClientState *nc, int len)
 }
 
 static NetClientInfo net_tap_win32_info = {
-    .type = NET_CLIENT_OPTIONS_KIND_TAP,
+    .type = NET_CLIENT_DRIVER_TAP,
     .size = sizeof(TAPState),
     .receive = tap_receive,
     .cleanup = tap_cleanup,
@@ -767,8 +767,8 @@ int net_init_tap(const Netdev *netdev, const char *name,
     /* FIXME error_setg(errp, ...) on failure */
     const NetdevTapOptions *tap;
 
-    assert(netdev->opts->kind == NET_CLIENT_OPTIONS_KIND_TAP);
-    tap = netdev->opts->tap;
+    assert(netdev->type == NET_CLIENT_DRIVER_TAP);
+    tap = netdev->tap;
 
     if (!tap->has_ifname) {
         error_report("tap: no interface name");
net/tap.c +12 -12
index 263f807..626dfca 100644
@@ -221,7 +221,7 @@ static bool tap_has_ufo(NetClientState *nc)
 {
     TAPState *s = DO_UPCAST(TAPState, nc, nc);
 
-    assert(nc->info->type == NET_CLIENT_OPTIONS_KIND_TAP);
+    assert(nc->info->type == NET_CLIENT_DRIVER_TAP);
 
     return s->has_ufo;
 }
@@ -230,7 +230,7 @@ static bool tap_has_vnet_hdr(NetClientState *nc)
 {
     TAPState *s = DO_UPCAST(TAPState, nc, nc);
 
-    assert(nc->info->type == NET_CLIENT_OPTIONS_KIND_TAP);
+    assert(nc->info->type == NET_CLIENT_DRIVER_TAP);
 
     return !!s->host_vnet_hdr_len;
 }
@@ -239,7 +239,7 @@ static bool tap_has_vnet_hdr_len(NetClientState *nc, int len)
 {
     TAPState *s = DO_UPCAST(TAPState, nc, nc);
 
-    assert(nc->info->type == NET_CLIENT_OPTIONS_KIND_TAP);
+    assert(nc->info->type == NET_CLIENT_DRIVER_TAP);
 
     return !!tap_probe_vnet_hdr_len(s->fd, len);
 }
@@ -248,7 +248,7 @@ static void tap_set_vnet_hdr_len(NetClientState *nc, int len)
 {
     TAPState *s = DO_UPCAST(TAPState, nc, nc);
 
-    assert(nc->info->type == NET_CLIENT_OPTIONS_KIND_TAP);
+    assert(nc->info->type == NET_CLIENT_DRIVER_TAP);
     assert(len == sizeof(struct virtio_net_hdr_mrg_rxbuf) ||
            len == sizeof(struct virtio_net_hdr));
 
@@ -260,7 +260,7 @@ static void tap_using_vnet_hdr(NetClientState *nc, bool using_vnet_hdr)
 {
     TAPState *s = DO_UPCAST(TAPState, nc, nc);
 
-    assert(nc->info->type == NET_CLIENT_OPTIONS_KIND_TAP);
+    assert(nc->info->type == NET_CLIENT_DRIVER_TAP);
     assert(!!s->host_vnet_hdr_len == using_vnet_hdr);
 
     s->using_vnet_hdr = using_vnet_hdr;
@@ -326,14 +326,14 @@ static void tap_poll(NetClientState *nc, bool enable)
 int tap_get_fd(NetClientState *nc)
 {
     TAPState *s = DO_UPCAST(TAPState, nc, nc);
-    assert(nc->info->type == NET_CLIENT_OPTIONS_KIND_TAP);
+    assert(nc->info->type == NET_CLIENT_DRIVER_TAP);
     return s->fd;
 }
 
 /* fd support */
 
 static NetClientInfo net_tap_info = {
-    .type = NET_CLIENT_OPTIONS_KIND_TAP,
+    .type = NET_CLIENT_DRIVER_TAP,
     .size = sizeof(TAPState),
     .receive = tap_receive,
     .receive_raw = tap_receive_raw,
@@ -565,8 +565,8 @@ int net_init_bridge(const Netdev *netdev, const char *name,
     TAPState *s;
     int fd, vnet_hdr;
 
-    assert(netdev->opts->kind == NET_CLIENT_OPTIONS_KIND_BRIDGE);
-    bridge = netdev->opts->bridge;
+    assert(netdev->type == NET_CLIENT_DRIVER_BRIDGE);
+    bridge = netdev->bridge;
 
     helper = bridge->has_helper ? bridge->helper : DEFAULT_BRIDGE_HELPER;
     br     = bridge->has_br     ? bridge->br     : DEFAULT_BRIDGE_INTERFACE;
@@ -728,8 +728,8 @@ int net_init_tap(const Netdev *netdev, const char *name,
     const char *vhostfdname;
     char ifname[128];
 
-    assert(netdev->opts->kind == NET_CLIENT_OPTIONS_KIND_TAP);
-    tap = netdev->opts->tap;
+    assert(netdev->type == NET_CLIENT_DRIVER_TAP);
+    tap = netdev->tap;
     queues = tap->has_queues ? tap->queues : 1;
     vhostfdname = tap->has_vhostfd ? tap->vhostfd : NULL;
 
@@ -890,7 +890,7 @@ int net_init_tap(const Netdev *netdev, const char *name,
 VHostNetState *tap_get_vhost_net(NetClientState *nc)
 {
     TAPState *s = DO_UPCAST(TAPState, nc, nc);
-    assert(nc->info->type == NET_CLIENT_OPTIONS_KIND_TAP);
+    assert(nc->info->type == NET_CLIENT_DRIVER_TAP);
     return s->vhost_net;
 }
 
net/vde.c +3 -3
index 0ac2525..7a6d4f0 100644
@@ -68,7 +68,7 @@ static void vde_cleanup(NetClientState *nc)
 }
 
 static NetClientInfo net_vde_info = {
-    .type = NET_CLIENT_OPTIONS_KIND_VDE,
+    .type = NET_CLIENT_DRIVER_VDE,
     .size = sizeof(VDEState),
     .receive = vde_receive,
     .cleanup = vde_cleanup,
@@ -115,8 +115,8 @@ int net_init_vde(const Netdev *netdev, const char *name,
     /* FIXME error_setg(errp, ...) on failure */
     const NetdevVdeOptions *vde;
 
-    assert(netdev->opts->kind == NET_CLIENT_OPTIONS_KIND_VDE);
-    vde = netdev->opts->vde;
+    assert(netdev->type == NET_CLIENT_DRIVER_VDE);
+    vde = netdev->vde;
 
     /* missing optional values have been initialized to "all bits zero" */
     if (net_vde_init(peer, "vde", name, vde->sock, vde->port, vde->group,
net/vhost-user.c +6 -6
index 20981a9..fef89ca 100644
@@ -30,7 +30,7 @@ typedef struct VhostUserChardevProps {
 VHostNetState *vhost_user_get_vhost_net(NetClientState *nc)
 {
     VhostUserState *s = DO_UPCAST(VhostUserState, nc, nc);
-    assert(nc->info->type == NET_CLIENT_OPTIONS_KIND_VHOST_USER);
+    assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_USER);
     return s->vhost_net;
 }
 
@@ -75,20 +75,20 @@ static void vhost_user_cleanup(NetClientState *nc)
 
 static bool vhost_user_has_vnet_hdr(NetClientState *nc)
 {
-    assert(nc->info->type == NET_CLIENT_OPTIONS_KIND_VHOST_USER);
+    assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_USER);
 
     return true;
 }
 
 static bool vhost_user_has_ufo(NetClientState *nc)
 {
-    assert(nc->info->type == NET_CLIENT_OPTIONS_KIND_VHOST_USER);
+    assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_USER);
 
     return true;
 }
 
 static NetClientInfo net_vhost_user_info = {
-        .type = NET_CLIENT_OPTIONS_KIND_VHOST_USER,
+        .type = NET_CLIENT_DRIVER_VHOST_USER,
         .size = sizeof(VhostUserState),
         .cleanup = vhost_user_cleanup,
         .has_vnet_hdr = vhost_user_has_vnet_hdr,
@@ -229,8 +229,8 @@ int net_init_vhost_user(const Netdev *netdev, const char *name,
     const NetdevVhostUserOptions *vhost_user_opts;
     CharDriverState *chr;
 
-    assert(netdev->opts->kind == NET_CLIENT_OPTIONS_KIND_VHOST_USER);
-    vhost_user_opts = netdev->opts->vhost_user;
+    assert(netdev->type == NET_CLIENT_DRIVER_VHOST_USER);
+    vhost_user_opts = netdev->vhost_user;
 
     chr = net_vhost_parse_chardev(vhost_user_opts, errp);
     if (!chr) {
qapi-schema.json +25 -13
index d85b55b..1b828e8 100644
@@ -2488,16 +2488,31 @@
     '*vhostforce':    'bool' } }
 
 ##
-# @NetClientOptions
+# @NetClientDriver
 #
-# A discriminated record of network device traits.
+# Available netdev drivers.
+#
+# Since 2.5
+##
+{ 'enum': 'NetClientDriver',
+  'data': [ 'none', 'nic', 'user', 'tap', 'l2tpv3', 'socket', 'vde', 'dump',
+            'bridge', 'hubport', 'netmap', 'vhost-user' ] }
+
+##
+# @Netdev
+#
+# Captures the configuration of a network device.
+#
+# @id #optional - since 2.5
+# @vlan, @name - since 2.5
 #
 # Since 1.2
 #
 # 'l2tpv3' - since 2.1
-#
 ##
-{ 'union': 'NetClientOptions',
+{ 'union': 'Netdev',
+  'base': 'NetdevBase',
+  'discriminator': 'type',
   'data': {
     'none':     'NetdevNoneOptions',
     'nic':      'NetLegacyNicOptions',
@@ -2513,9 +2528,9 @@
     'vhost-user': 'NetdevVhostUserOptions' } }
 
 ##
-# @Netdev
+# @NetdevBase
 #
-# Captures the configuration of a network device.
+# Captures the common configuration of a network device.
 #
 # @vlan: #optional vlan number (legacy, forbidden with -netdev)
 #
@@ -2524,19 +2539,16 @@
 # @name: #optional identifier for monitor commands, ignored if @id is present
 #        (legacy, forbidden with -netdev)
 #
-# @opts: device type specific properties (legacy)
+# @type: the netdev driver to use
 #
-# Since 1.2
-#
-# @id #optional - since 2.5
-# @vlan, @name - since 2.5
+# Since 2.5
 ##
-{ 'struct': 'Netdev',
+{ 'struct': 'NetdevBase',
   'data': {
     '*vlan': 'int32',
     '*id':   'str',
     '*name': 'str',
-    'opts':  'NetClientOptions' } }
+    'type':  'NetClientDriver' } }
 
 ##
 # @InetSocketAddress
Signature · 1 line
2.5.1
#5 lore raw

Re: [Qemu-devel] [PATCH 2/7] qapi: convert NumaOptions into a flat union

In reply to Kővágó, Zoltán

On Mon, Sep 07, 2015 at 02:08:07PM +0200, Kővágó, Zoltán wrote:
[...]

Quoted 23 lines
qapi-schema.json +0 -11
index 67fef37..9e4fe5d 100644
@@ -3550,17 +3550,6 @@
   'data': { '*console':'int', 'events': [ 'InputEvent' ] } }
 
 ##
-# @NumaOptions
-#
-# A discriminated record of NUMA options. (for OptsVisitor)
-#
-# Since 2.1
-##
-{ 'union': 'NumaOptions',
-  'data': {
-    'node': 'NumaNodeOptions' }}
-
-##
 # @NumaNodeOptions
 #
 # Create a guest NUMA node. (for OptsVisitor)

qapi-schema.json line 3581

Quoted 6 lines
qapi-schema.json +3 -0
@@ -3587,6 +3576,42 @@
    '*memdev': 'str' }}
 
 ##
+# @NumaOptionType
+#
+# List of possible numa drivers.

There's no such thing as a "numa driver". The type name was fixed but the documentation still doesn't make sense.

I suggest:

# NUMA command-line option type.
#
# @node: Create a guest NUMA node. See @NumaNodeOptions.

qapi-schema.json line 3593

Quoted 12 lines
qapi-schema.json +12 -0
+#
+# Since: 2.5
+##
+{ 'enum': 'NumaOptionType',
+  'data': [ 'node' ] }
+
+##
+# @NumaCommonOptions
+#
+# Common set of numa options.
+#
+# @type: the numa driver to use

Suggestion:

# @type: NUMA command-line option type.

Signature · 1 line
Eduardo
#9 lore raw

Re: [Qemu-devel] [PATCH 4/7] net: use Netdev instead of NetClientOptions in client init

In reply to Kővágó, Zoltán
Quoted 5 lines · Zoltán

This way we no longer need NetClientOptions and can convert Netdev into a flat union.

I may have reviewed this one, but I'm still not a fan of 3/7. Give me a chance to post my introspection followup patches that cherry-pick pieces of your work and make QMP netdev_add a full-fledged qapi-fied command; I'll keep you on cc when I post.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#17 lore raw
In reply to Kővágó, Zoltán
Quoted 7 lines · Zoltán

As discussed here[1], I'm splitting the qapi related patches from my previous -audiodev patch series. These are patches 2--7 and 9 from my previous patches. (Patch 1 was merged into -trivial in the meanwhile.)

Please review.

[1]: http://lists.nongnu.org/archive/html/qemu-devel/2015-09/msg01505.html

Ongoing QAPI work has shown that the visitors code is brittle, and we need to retrofit a proper contract[*].

As discussed before, you're proposing dropping a design assumption of OptsVisitor. Messing with design assumptions is always scary, but it's even scarier when the whole edifice built on it has been found brittle already.

I'm afraid we need retrofit a contract *first*, both to build understanding on how this sucker is supposed to work (right now nobody knows), and to hopefully make it more robust.

Your series adds urgency to the job.

[*] http://lists.nongnu.org/archive/html/qemu-devel/2015-09/msg03363.html

#7 lore raw

Re: [Qemu-devel] [PATCH 3/7] net: remove NetLegacy struct

In reply to Kővágó, Zoltán
Quoted 11 lines · Zoltán

NetLegacy is just Netdev with some extra fields (name, vlan) and an optional id. This patch merges the two structs, and net_client_init1 got some extra checks to make sure only accept valid -netdev command lines. This is some extra work, but allows us to uniformly manage both legacy -net and non-legacy -netdev in code.

---
 net/net.c        | 42 +++++++++++++++++++++---------------------
 qapi-schema.json | 30 +++++++++---------------------
 2 files changed, 30 insertions(+), 42 deletions(-)

I'm still not a fan of this one. See my counter-proposal that rewrites patches 4/7 and 5/7 of this series to keep NetdevLegacy a separate type for command line usage, while exposing only Netdev through QMP (in particular, patch 2/29 and 27/29 are my rewrites, and 29/29 turns on Netdev use in QMP)

https://lists.gnu.org/archive/html/qemu-devel/2015-09/msg02580.html

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Reviewed-by Tested-by on v1 1/7
#2 lore raw

Re: [Qemu-devel] [PATCH 1/7] qapi: support implicit structs in OptsVisitor

In reply to Kővágó, Zoltán
Quoted 7 lines · Zoltán

They are required for flat unions (you still have to allocate the structs).

---
 qapi/opts-visitor.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

and required for 'make check' to pass when 4/7 is applied, so:

qapi/opts-visitor.c opts_start_struct(Visitor *v, void **obj, const char *kind, · line 155

Quoted 13 lines
qapi/opts-visitor.c +4 -0
index 7ae33b3..aa68814 100644
@@ -149,6 +149,12 @@ opts_start_struct(Visitor *v, void **obj, const char *kind,
     }
 }
 
+static void
+opts_start_implicit_struct(Visitor *v, void **obj, size_t size, Error **errp)
+{
+    opts_start_struct(v, obj, NULL, NULL, size, errp);

Works because ov->depth is always non-zero by the time any visitor reaches this callback, triggering the early return in opts_start_struct(). Might be slightly safer if you just did the g_malloc0() here, to make sure no caller ever ends up re-initializing ov->unprocessed_opts, but what you have works.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Reviewed-by on v1 5/7
#11 lore raw

Re: [Qemu-devel] [PATCH 5/7] qapi: change Netdev into a flat union

In reply to Kővágó, Zoltán
Quoted 8 lines · Zoltán

Except qapi-schema.json, this patch was generated by:

find . -name .git -prune -o -type f \! -name '*~' -print0 | \

  xargs -0 sed -i \
    -e 's/NetClientOptionsKind/NetClientDriver/g' \
    -e 's/NET_CLIENT_OPTIONS_KIND_/NET_CLIENT_DRIVER_/g' \
    -e 's/netdev->opts/netdev/g' \
    -e 's/netdev->kind/netdev->type/g'

This last line goes away if my patch goes in first:
https://lists.gnu.org/archive/html/qemu-devel/2015-09/msg02598.html

Quoted 7 lines
---
 hw/arm/musicpal.c                |  2 +-
 qapi-schema.json                 | 38 +++++++++++-------
 45 files changed, 167 insertions(+), 155 deletions(-)

See my counterproposal that preserves NetdevLegacy for use by the command line (that is, with 3/7 unapplied):
https://lists.gnu.org/archive/html/qemu-devel/2015-09/msg02604.html

The differences (other than rebase conflict resolution) are limited to qapi-schema.json and to net_client_init1().

But since I'm proposing to reuse your patch in my series, you can add this if you need to respin before my patches land:

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#13 lore raw

Re: [Qemu-devel] [PATCH 6/7] qapi: reorder NetdevBase and Netdev

In reply to Kővágó, Zoltán
Quoted 8 lines · Zoltán

Probably more logical if NetdevBase comes before Netdev. No semantic changes.

---
 qapi-schema.json | 46 +++++++++++++++++++++++-----------------------
 1 file changed, 23 insertions(+), 23 deletions(-)

May be different depending on what happens to the earlier patches in the series; and may even be worth squashing this into 5/7 directly.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#15 lore raw

Re: [Qemu-devel] [PATCH 7/7] qapi: support nested structs in OptsVisitor

In reply to Kővágó, Zoltán
Quoted 6 lines · Zoltán

The current OptsVisitor flattens the whole structure, if there are same named fields under different paths (like in' and out' in Audiodev'), the current visitor can't cope with them (for example setting frequency=44100' will set the in's frequency to 44100 and leave out's frequency unspecified).

Quoted 7 lines

This patch fixes it, by always requiring a complete path in case of nested structs. Fields in the path are separated by dots, similar to C structs (without pointers), like in.frequency' or out.frequency'.

You must provide a full path even in non-ambiguous cases. The qapi flattening commits hopefully ensures that this change doesn't create backward compatibility problems.

It's the "hopefully" that worries me.

If I understand correctly, prior to this series, we have several instances of qapi simple unions, where a member is a substruct when converting to QObject. Conceptually:

{ 'struct':'Sub', 'data':{ 'c':'int' } }
{ 'union':'Main', 'data':{ 'X':'Sub' } }

would accept the following QDict:

{ "type":"X", "data":{ "c":1 } }

and directly translating that to QemuOpts would be spelled:

-opt type=X,data.c=1

but we wanted shorthand:

-opt type=X,c=1

So, the "flattening" that opts-visitor does is what allows "c" instead of "data.c" to refer to a nested member of a union. It worked as long as 'c' appeared only once per visit of the overall qapi type (multiple branches of the union may have 'c', but for a given union branch, 'c' appears only once no matter what depth of substructs it is reached through).

Question: do we actually ALLOW the user to specify data.c, or do we ONLY accept the shorthand?

This series then proceeds to teach opts-visitor how to handle flat unions. Converting the above example to a flat union is done by:

{ 'enum':'Foo', 'data':['X'] }
{ 'struct':'Base', 'data':{ 'type':'Foo' } }
{ 'struct':'Sub', 'data':{ 'c':'int' } }
{ 'union':'Main', 'base':'Base', 'discriminator':'type',
'data':{ 'X':'Sub' } }

which now accepts the following QDict:

{ "type":"X", "c":1" }

(note the loss of the nested 'data' struct), and directly translating that to QemuOpts would be spelled:

-opt type=X,c=1

which exactly matches the shorthand that we previously accepted. It completely gets rid of the data.c longhand, but I don't know if we accepted that in the first place.

So, the next question is whether we still need flattening. If we no longer have any simple unions parsed by QemuOpts, then the flattening no longer helps us. Furthermore, you have a case in audio where flattening hurts; the QDict:

{ "in":{ "frequency":4400 }, "out":{ "frequency":4400 } }

has unambiguous paths 'in.frequency' and 'out.frequency', but the shorthand 'frequency' could now match two separate places in the struct.

Now, let's look at what your testsuite changes say about this patch:

tests/test-opts-visitor.c main(int argc, char **argv) · line 303

Quoted 6 lines
tests/test-opts-visitor.c +2 -0
@@ -271,6 +299,12 @@ main(int argc, char **argv)
     add_test("/visitor/opts/i64/range/2big/full", &expect_fail,
              "i64=-0x8000000000000000-0x7fffffffffffffff");
 
+    /* Test nested structs support */
+    add_test("/visitor/opts/nested/unqualified", &expect_fail, "nint=13");

You are saying that an unqualified member no longer resolves (that is, when nesting is in place, we MUST spell it by the long name);

tests/test-opts-visitor.c main(int argc, char **argv) · line 307

Quoted 4 lines
tests/test-opts-visitor.c +4 -0
+    add_test("/visitor/opts/nested/both",        &expect_both,
+             "sub0.nint=13,sub1.nint=17");
+    add_test("/visitor/opts/nested/sub0",        &expect_sub0, "sub0.nint=13");
+    add_test("/visitor/opts/nested/sub1",        &expect_sub1, "sub1.nint=13");

and that using qualified names gets at the nested struct members as desired. Furthermore, if we truly have converted ALL qapi unions to flat unions, and if qapi unions were the ONLY reason that we had flattening in the first place, and if we did NOT accept longhand 'data.c=1' for the flattened shorthand of 'c=1' within a simple union branch, then it looks like you are 100% backwards-compatible. But that's quite a few things to verify. Also, I'm not sure if your visitor approaches the change of no longer flattening things in the most efficient manner (I still haven't studied the rest of the patch closely).

I'd like to defer reviewing this until the qapi patch queue is not quite so long, but the premise behind it is appealing. However, I strongly recommend that the commit message be improved to cover some of the background that I spelled out here, as well as offering more proof than just "hopefully", and an analysis of whether we are breaking any longhand data.c=1 option spellings.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#16 lore raw

Re: [Qemu-devel] [PATCH 7/7] qapi: support nested structs in OptsVisitor

2015-09-17 23:24 keltezéssel, Eric Blake írta:

Quoted 36 lines · Zoltán
Quoted 6 lines

The current OptsVisitor flattens the whole structure, if there are same named fields under different paths (like in' and out' in Audiodev'), the current visitor can't cope with them (for example setting frequency=44100' will set the in's frequency to 44100 and leave out's frequency unspecified).

Quoted 7 lines

This patch fixes it, by always requiring a complete path in case of nested structs. Fields in the path are separated by dots, similar to C structs (without pointers), like in.frequency' or out.frequency'.

You must provide a full path even in non-ambiguous cases. The qapi flattening commits hopefully ensures that this change doesn't create backward compatibility problems.

It's the "hopefully" that worries me.

If I understand correctly, prior to this series, we have several instances of qapi simple unions, where a member is a substruct when converting to QObject. Conceptually:

{ 'struct':'Sub', 'data':{ 'c':'int' } }
{ 'union':'Main', 'data':{ 'X':'Sub' } }

would accept the following QDict:

{ "type":"X", "data":{ "c":1 } }

and directly translating that to QemuOpts would be spelled:

-opt type=X,data.c=1

but we wanted shorthand:

-opt type=X,c=1

Quoted 8 lines

So, the "flattening" that opts-visitor does is what allows "c" instead of "data.c" to refer to a nested member of a union. It worked as long as 'c' appeared only once per visit of the overall qapi type (multiple branches of the union may have 'c', but for a given union branch, 'c' appears only once no matter what depth of substructs it is reached through).

Question: do we actually ALLOW the user to specify data.c, or do we ONLY accept the shorthand?

The current implementation in qemu only allows the shorthand version, in fact it doesn't even care about the name of the parent struct/union. Neither Main nor Sub has a field names 'data.c', so the data.c=1 version is currently invalid. But the problem is, as you noted, it only works if each field name is unique in the whole visited type (excluding non-visited union branches).

Quoted 13 lines

This series then proceeds to teach opts-visitor how to handle flat unions. Converting the above example to a flat union is done by:

{ 'enum':'Foo', 'data':['X'] }
{ 'struct':'Base', 'data':{ 'type':'Foo' } }
{ 'struct':'Sub', 'data':{ 'c':'int' } }
{ 'union':'Main', 'base':'Base', 'discriminator':'type',
'data':{ 'X':'Sub' } }

which now accepts the following QDict:

{ "type":"X", "c":1" }

Quoted 8 lines

(note the loss of the nested 'data' struct), and directly translating that to QemuOpts would be spelled:

-opt type=X,c=1

which exactly matches the shorthand that we previously accepted. It completely gets rid of the data.c longhand, but I don't know if we accepted that in the first place.

No, data.c was never valid.

Quoted 9 lines

So, the next question is whether we still need flattening. If we no longer have any simple unions parsed by QemuOpts, then the flattening no longer helps us. Furthermore, you have a case in audio where flattening hurts; the QDict:

{ "in":{ "frequency":4400 }, "out":{ "frequency":4400 } }

has unambiguous paths 'in.frequency' and 'out.frequency', but the shorthand 'frequency' could now match two separate places in the struct.

This is why exactly the flattening needs to be moved from OptsVisitor to somewhere else. If the qapi structs are flattened, old options (-net, -numa) continue to work as before, while at allows -audiodev to specify in.frequency and out.frequency. Of course, this isn't the only possible approach, but my previous attempt where I modified OptsVisitor instead to allow both shorthand and full paths were also problematic:

http://lists.nongnu.org/archive/html/qemu-devel/2015-06/msg04189.html

Quoted 35 lines

Now, let's look at what your testsuite changes say about this patch:

tests/test-opts-visitor.c main(int argc, char **argv) · line 303

Quoted 6 lines
tests/test-opts-visitor.c +2 -0
@@ -271,6 +299,12 @@ main(int argc, char **argv)
      add_test("/visitor/opts/i64/range/2big/full", &expect_fail,
               "i64=-0x8000000000000000-0x7fffffffffffffff");
 
+    /* Test nested structs support */
+    add_test("/visitor/opts/nested/unqualified", &expect_fail, "nint=13");

You are saying that an unqualified member no longer resolves (that is, when nesting is in place, we MUST spell it by the long name);

tests/test-opts-visitor.c main(int argc, char **argv) · line 307

Quoted 4 lines
tests/test-opts-visitor.c +4 -0
+    add_test("/visitor/opts/nested/both",        &expect_both,
+             "sub0.nint=13,sub1.nint=17");
+    add_test("/visitor/opts/nested/sub0",        &expect_sub0, "sub0.nint=13");
+    add_test("/visitor/opts/nested/sub1",        &expect_sub1, "sub1.nint=13");

and that using qualified names gets at the nested struct members as desired. Furthermore, if we truly have converted ALL qapi unions to flat unions, and if qapi unions were the ONLY reason that we had flattening in the first place, and if we did NOT accept longhand 'data.c=1' for the flattened shorthand of 'c=1' within a simple union branch, then it looks like you are 100% backwards-compatible. But that's quite a few things to verify. Also, I'm not sure if your visitor approaches the change of no longer flattening things in the most efficient manner (I still haven't studied the rest of the patch closely).

I'd like to defer reviewing this until the qapi patch queue is not quite so long, but the premise behind it is appealing. However, I strongly recommend that the commit message be improved to cover some of the background that I spelled out here, as well as offering more proof than just "hopefully", and an analysis of whether we are breaking any longhand data.c=1 option spellings.

#3 lore raw

Re: [Qemu-devel] [PATCH 1/7] qapi: support implicit structs in OptsVisitor

In reply to Eric Blake
Quoted 24 lines · Eric Blake
Quoted 7 lines · Zoltán

They are required for flat unions (you still have to allocate the structs).

---
 qapi/opts-visitor.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

and required for 'make check' to pass when 4/7 is applied, so:

Quoted 9 lines
qapi/opts-visitor.c +0 -0
index 7ae33b3..aa68814 100644
@@ -149,6 +149,12 @@ opts_start_struct(Visitor *v, void **obj, const char *kind,
     }
 }
 
Quoted 11 lines

qapi/opts-visitor.c opts_start_struct(Visitor *v, void **obj, const char *kind, · line 155

Quoted 4 lines
qapi/opts-visitor.c +4 -0
+static void
+opts_start_implicit_struct(Visitor *v, void **obj, size_t size, Error **errp)
+{
+    opts_start_struct(v, obj, NULL, NULL, size, errp);

Works because ov->depth is always non-zero by the time any visitor reaches this callback, triggering the early return in opts_start_struct(). Might be slightly safer if you just did the g_malloc0() here, to make sure no caller ever ends up re-initializing ov->unprocessed_opts, but what you have works.

In fact, the alternative that just does a local malloc was proposed here:
https://lists.gnu.org/archive/html/qemu-devel/2015-09/msg04746.html

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org