post-introspection cleanups, and qapi-ify netdev_add
Subsystems (6)
PATCH v5 31/46 qapi: use 'type' in generated C code to match QMP union wire form
In reply to Eric BlakeWhen dealing with simple qapi unions, the code was generating a discriminator field of 'kind' even though the discriminator is sent as 'type' over QMP. Renaming things to match gets us one step closer to reusing common generator code for both simple and flat unions, without having to special case the naming choice for simple unions. It also gets rid of some TODO markers in using the raw QAPISchemaObjectTypeVariants.tag_name field, although we can't yet convert that field to private until later fixes to alternate types also quit using it.
However, this patch does not rename the generated enum, which is still 'unionnameKind'; if we wanted, a further patch could generate implicit enums as 'unionnameType', with even more churn to C code to react, and probably update the qapi generator to reserve the 'fooType' namespace instead of 'fooKind', or better yet ensure that generated names do not conflict with user names. But that is a lot harder, as we already have existing qapi usage of types that end in 'Type'.
--- block/qcow2.c | 2 +- block/vmdk.c | 2 +- blockdev.c | 16 ++++++++-------- hmp.c | 12 ++++++------ hw/input/hid.c | 2 +- hw/input/ps2.c | 2 +- hw/input/virtio-input-hid.c | 2 +- hw/mem/pc-dimm.c | 2 +- net/dump.c | 2 +- net/hub.c | 2 +- net/l2tpv3.c | 2 +- net/net.c | 20 ++++++++++---------- net/slirp.c | 2 +- net/socket.c | 2 +- net/tap.c | 4 ++-- net/vhost-user.c | 2 +- numa.c | 4 ++-- qemu-char.c | 24 ++++++++++++------------ scripts/qapi-types.py | 7 ++----- scripts/qapi-visit.py | 9 +-------- tests/test-qmp-commands.c | 2 +- tests/test-qmp-input-visitor.c | 8 ++++---- tests/test-qmp-output-visitor.c | 6 +++--- tpm.c | 2 +- ui/input-keymap.c | 10 +++++----- ui/input-legacy.c | 2 +- ui/input.c | 22 +++++++++++----------- util/qemu-sockets.c | 12 ++++++------ 28 files changed, 87 insertions(+), 97 deletions(-)
block/qcow2.c +1 -1
@@ -2736,7 +2736,7 @@ static ImageInfoSpecific *qcow2_get_specific_info(BlockDriverState *bs)ImageInfoSpecific *spec_info =g_new (ImageInfoSpecific,1 ); *spec_info = (ImageInfoSpecific ){ - .kind =IMAGE_INFO_SPECIFIC_KIND_QCOW2 , + .type =IMAGE_INFO_SPECIFIC_KIND_QCOW2 , { .qcow2 =g_new (ImageInfoSpecificQCow2,1 ), },
block/vmdk.c +1 -1
@@ -2156,7 +2156,7 @@ static ImageInfoSpecific *vmdk_get_specific_info(BlockDriverState *bs)ImageInfoList **next; *spec_info = (ImageInfoSpecific ){ - .kind =IMAGE_INFO_SPECIFIC_KIND_VMDK , + .type =IMAGE_INFO_SPECIFIC_KIND_VMDK , { .vmdk =g_new0 (ImageInfoSpecificVmdk,1 ), },
blockdev.c +8 -8
@@ -1052,12 +1052,12 @@ void hmp_commit(Monitor *mon, const QDict *qdict) } } -static void blockdev_do_action (int kind,void *data,Error **errp) +static void blockdev_do_action (int type,void *data,Error **errp) {TransactionAction action;TransactionActionList list; - action.kind = kind; + action.type = type; action.data = data; list.value = &action; list.next =NULL ;
@@ -1297,7 +1297,7 @@ static void internal_snapshot_prepare(BlkTransactionState *common,InternalSnapshotState *state;int ret1; -g_assert (common->action->kind == +g_assert (common->action->type ==TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_INTERNAL_SYNC ); internal = common->action->blockdev_snapshot_internal_sync; state =DO_UPCAST (InternalSnapshotState, common, common);
@@ -1439,7 +1439,7 @@ static void external_snapshot_prepare(BlkTransactionState *common,TransactionAction *action = common->action;/* get parameters */ -g_assert (action->kind ==TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC ); +g_assert (action->type ==TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC ); has_device = action->blockdev_snapshot_sync->has_device; device = action->blockdev_snapshot_sync->device;
@@ -1579,7 +1579,7 @@ static void drive_backup_prepare(BlkTransactionState *common, Error **errp)DriveBackup *backup;Error *local_err =NULL ; -assert (common->action->kind ==TRANSACTION_ACTION_KIND_DRIVE_BACKUP ); +assert (common->action->type ==TRANSACTION_ACTION_KIND_DRIVE_BACKUP ); backup = common->action->drive_backup; blk =blk_by_name (backup->device);
@@ -1647,7 +1647,7 @@ static void blockdev_backup_prepare(BlkTransactionState *common, Error **errp)BlockBackend *blk;Error *local_err =NULL ; -assert (common->action->kind ==TRANSACTION_ACTION_KIND_BLOCKDEV_BACKUP ); +assert (common->action->type ==TRANSACTION_ACTION_KIND_BLOCKDEV_BACKUP ); backup = common->action->blockdev_backup; blk =blk_by_name (backup->device);
@@ -1774,9 +1774,9 @@ void qmp_transaction(TransactionActionList *dev_list, Error **errp) dev_info = dev_entry->value; dev_entry = dev_entry->next; -assert (dev_info->kind <ARRAY_SIZE (actions)); +assert (dev_info->type <ARRAY_SIZE (actions)); - ops = &actions[dev_info->kind]; + ops = &actions[dev_info->type];assert (ops->instance_size >0 ); state =g_malloc0 (ops->instance_size);
hmp.c +6 -6
@@ -830,9 +830,9 @@ void hmp_info_tpm(Monitor *mon, const QDict *qdict) c, TpmModel_lookup[ti->model]);monitor_printf (mon," \\ %s: type=%s" , - ti->id, TpmTypeOptionsKind_lookup[ti->options->kind]); + ti->id, TpmTypeOptionsKind_lookup[ti->options->type]); -switch (ti->options->kind) { +switch (ti->options->type) {case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH : tpo = ti->options->passthrough; monitor_printf(mon, "%s%s%s%s",
@@ -1714,14 +1714,14 @@ void hmp_sendkey(Monitor *mon, const QDict *qdict)if (*endp !='\0' ) { goto err_out; } - keylist->value->kind =KEY_VALUE_KIND_NUMBER ; + keylist->value->type =KEY_VALUE_KIND_NUMBER ; keylist->value->number = value; }else {int idx =index_from_key (keyname_buf);if (idx ==Q_KEY_CODE_MAX ) { goto err_out; } - keylist->value->kind =KEY_VALUE_KIND_QCODE ; + keylist->value->type =KEY_VALUE_KIND_QCODE ; keylist->value->qcode = idx; }
@@ -1937,12 +1937,12 @@ void hmp_info_memory_devices(Monitor *mon, const QDict *qdict) value = info->value;if (value) { -switch (value->kind) { +switch (value->type) {case MEMORY_DEVICE_INFO_KIND_DIMM : di = value->dimm;monitor_printf (mon,"Memory device [%s]: \"%s\"\n" , - MemoryDeviceInfoKind_lookup[value->kind], + MemoryDeviceInfoKind_lookup[value->type], di->id ? di->id :"" );monitor_printf (mon," addr: 0x%" PRIx64"\n" , di->addr);monitor_printf (mon," slot: %" PRId64"\n" , di->slot);
hw/input/hid.c +1 -1
@@ -119,7 +119,7 @@ static void hid_pointer_event(DeviceState *dev, QemuConsole *src,assert (hs->n <QUEUE_LENGTH ); e = &hs->ptr.queue[(hs->head + hs->n) &QUEUE_MASK ]; -switch (evt->kind) { +switch (evt->type) {case INPUT_EVENT_KIND_REL :if (evt->rel->axis ==INPUT_AXIS_X ) { e->xdx += evt->rel->value;
hw/input/ps2.c +1 -1
@@ -393,7 +393,7 @@ static void ps2_mouse_event(DeviceState *dev, QemuConsole *src,if (!(s->mouse_status &MOUSE_STATUS_ENABLED ))return ; -switch (evt->kind) { +switch (evt->type) {case INPUT_EVENT_KIND_REL :if (evt->rel->axis ==INPUT_AXIS_X ) { s->mouse_dx += evt->rel->value;
hw/input/virtio-input-hid.c +1 -1
@@ -191,7 +191,7 @@ static void virtio_input_handle_event(DeviceState *dev, QemuConsole *src,virtio_input_event event;int qcode; -switch (evt->kind) { +switch (evt->type) {case INPUT_EVENT_KIND_KEY : qcode =qemu_input_key_value_to_qcode (evt->key->key);if (qcode && keymap_qcode[qcode]) {
hw/mem/pc-dimm.c +1 -1
@@ -196,7 +196,7 @@ ram_addr_t get_current_ram_size(void)MemoryDeviceInfo *value = info->value;if (value) { -switch (value->kind) { +switch (value->type) {case MEMORY_DEVICE_INFO_KIND_DIMM : size += value->dimm->size;break ;
net/dump.c +1 -1
@@ -154,7 +154,7 @@ 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 ); +assert (netdev->opts->type ==NET_CLIENT_OPTIONS_KIND_DUMP ); dump = netdev->opts->dump;assert (peer);
net/hub.c +1 -1
@@ -285,7 +285,7 @@ int net_init_hubport(const Netdev *netdev, const char *name, {const NetdevHubPortOptions *hubport; -assert (netdev->opts->kind ==NET_CLIENT_OPTIONS_KIND_HUBPORT ); +assert (netdev->opts->type ==NET_CLIENT_OPTIONS_KIND_HUBPORT );assert (!peer); hubport = netdev->opts->hubport;
net/l2tpv3.c +1 -1
@@ -545,7 +545,7 @@ int net_init_l2tpv3(const Netdev *netdev, s->queue_tail =0 ; s->header_mismatch = false; -assert (netdev->opts->kind ==NET_CLIENT_OPTIONS_KIND_L2TPV3 ); +assert (netdev->opts->type ==NET_CLIENT_OPTIONS_KIND_L2TPV3 ); l2tpv3 = netdev->opts->l2tpv3;if (l2tpv3->has_ipv6 && l2tpv3->ipv6) {
net/net.c +10 -10
@@ -820,7 +820,7 @@ static int net_init_nic(const Netdev *netdev, const char *name,NICInfo *nd;const NetLegacyNicOptions *nic; -assert (netdev->opts->kind ==NET_CLIENT_OPTIONS_KIND_NIC ); +assert (netdev->opts->type ==NET_CLIENT_OPTIONS_KIND_NIC ); nic = netdev->opts->nic; idx =nic_get_free_idx ();
@@ -924,9 +924,9 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp) opts = netdev->opts; name = netdev->id; -if (opts->kind ==NET_CLIENT_OPTIONS_KIND_DUMP || - opts->kind ==NET_CLIENT_OPTIONS_KIND_NIC || - !net_client_init_fun[opts->kind]) { +if (opts->type ==NET_CLIENT_OPTIONS_KIND_DUMP || + opts->type ==NET_CLIENT_OPTIONS_KIND_NIC || + !net_client_init_fun[opts->type]) {error_setg (errp,QERR_INVALID_PARAMETER_VALUE ,"type" ,"a netdev backend type" );return -1 ;
@@ -939,16 +939,16 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp)/* missing optional values have been initialized to "all bits zero" */ name = net->has_id ? net->id : net->name; -if (opts->kind ==NET_CLIENT_OPTIONS_KIND_NONE ) { +if (opts->type ==NET_CLIENT_OPTIONS_KIND_NONE ) {return 0 ;/* nothing to do */ } -if (opts->kind ==NET_CLIENT_OPTIONS_KIND_HUBPORT ) { +if (opts->type ==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[opts->type]) {error_setg (errp,QERR_INVALID_PARAMETER_VALUE ,"type" ,"a net backend type (maybe it is not compiled " "into this binary)" );
@@ -956,17 +956,17 @@ 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 || +if (opts->type !=NET_CLIENT_OPTIONS_KIND_NIC || !opts->nic->has_netdev) { peer =net_hub_add_port (net->has_vlan ? net->vlan :0 ,NULL ); } } -if (net_client_init_fun[opts->kind](netdev, name, peer, errp) <0 ) { +if (net_client_init_fun[opts->type](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[opts->type]); }return -1 ; }
net/slirp.c +1 -1
@@ -746,7 +746,7 @@ 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 ); +assert (netdev->opts->type ==NET_CLIENT_OPTIONS_KIND_USER ); user = netdev->opts->user; vnet = user->has_net ? g_strdup(user->net) :
net/socket.c +1 -1
@@ -706,7 +706,7 @@ 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 ); +assert (netdev->opts->type ==NET_CLIENT_OPTIONS_KIND_SOCKET ); sock = netdev->opts->socket; if (sock->has_fd + sock->has_listen + sock->has_connect + sock->has_mcast +
net/tap.c +2 -2
@@ -565,7 +565,7 @@ 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 ); +assert (netdev->opts->type ==NET_CLIENT_OPTIONS_KIND_BRIDGE ); bridge = netdev->opts->bridge; helper = bridge->has_helper ? bridge->helper :DEFAULT_BRIDGE_HELPER ;
@@ -728,7 +728,7 @@ 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 ); +assert (netdev->opts->type ==NET_CLIENT_OPTIONS_KIND_TAP ); tap = netdev->opts->tap; queues = tap->has_queues ? tap->queues :1 ; vhostfdname = tap->has_vhostfd ? tap->vhostfd :NULL ;
net/vhost-user.c +1 -1
@@ -229,7 +229,7 @@ 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 ); +assert (netdev->opts->type ==NET_CLIENT_OPTIONS_KIND_VHOST_USER ); vhost_user_opts = netdev->opts->vhost_user; chr =net_vhost_parse_chardev (vhost_user_opts, errp);
numa.c +2 -2
@@ -226,7 +226,7 @@ static int parse_numa(void *opaque, QemuOpts *opts, Error **errp) goto error; } -switch (object->kind) { +switch (object->type) {case NUMA_OPTIONS_KIND_NODE :numa_node_parse (object->node, opts, &err);if (err) {
@@ -487,7 +487,7 @@ static void numa_stat_memory_devices(uint64_t node_mem[])MemoryDeviceInfo *value = info->value;if (value) { -switch (value->kind) { +switch (value->type) {case MEMORY_DEVICE_INFO_KIND_DIMM : node_mem[value->dimm->node] += value->dimm->size;break ;
qemu-char.c +12 -12
@@ -122,7 +122,7 @@ static int SocketAddress_to_str(char *dest, int max_len, const char *prefix, SocketAddress *addr, bool is_listen, bool is_telnet) { - switch (addr->kind) { + switch (addr->type) { case SOCKET_ADDRESS_KIND_INET: return snprintf(dest, max_len, "%s%s:%s:%s%s", prefix, is_telnet ? "telnet" : "tcp", addr->inet->host,
@@ -3567,11 +3567,11 @@ static void qemu_chr_parse_socket(QemuOpts *opts, ChardevBackend *backend, addr =g_new0 (SocketAddress,1 );if (path) { - addr->kind =SOCKET_ADDRESS_KIND_UNIX ; + addr->type =SOCKET_ADDRESS_KIND_UNIX ; addr->q_unix =g_new0 (UnixSocketAddress,1 ); addr->q_unix->path =g_strdup (path); }else { - addr->kind =SOCKET_ADDRESS_KIND_INET ; + addr->type =SOCKET_ADDRESS_KIND_INET ; addr->inet =g_new0 (InetSocketAddress,1 ); addr->inet->host =g_strdup (host); addr->inet->port =g_strdup (port);
@@ -3616,7 +3616,7 @@ static void qemu_chr_parse_udp(QemuOpts *opts, ChardevBackend *backend, backend->udp =g_new0 (ChardevUdp,1 ); addr =g_new0 (SocketAddress,1 ); - addr->kind =SOCKET_ADDRESS_KIND_INET ; + addr->type =SOCKET_ADDRESS_KIND_INET ; addr->inet =g_new0 (InetSocketAddress,1 ); addr->inet->host =g_strdup (host); addr->inet->port =g_strdup (port);
@@ -3629,7 +3629,7 @@ static void qemu_chr_parse_udp(QemuOpts *opts, ChardevBackend *backend,if (has_local) { backend->udp->has_local = true; addr =g_new0 (SocketAddress,1 ); - addr->kind =SOCKET_ADDRESS_KIND_INET ; + addr->type =SOCKET_ADDRESS_KIND_INET ; addr->inet =g_new0 (InetSocketAddress,1 ); addr->inet->host =g_strdup (localaddr); addr->inet->port =g_strdup (localport);
@@ -3701,7 +3701,7 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts, } chr =NULL ; - backend->kind = cd->kind; + backend->type = cd->kind;if (cd->parse) { cd->parse (opts, backend, &local_err);if (local_err) {
@@ -3719,7 +3719,7 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,qapi_free_ChardevReturn (ret); backend =g_new0 (ChardevBackend,1 ); backend->mux =g_new0 (ChardevMux,1 ); - backend->kind =CHARDEV_BACKEND_KIND_MUX ; + backend->type =CHARDEV_BACKEND_KIND_MUX ; backend->mux->chardev =g_strdup (bid); ret =qmp_chardev_add (id, backend, errp);if (!ret) {
@@ -4148,7 +4148,7 @@ static CharDriverState *qmp_chardev_open_socket(ChardevSocket *sock, s->fd =-1 ; s->listen_fd =-1 ; - s->is_unix = addr->kind ==SOCKET_ADDRESS_KIND_UNIX ; + s->is_unix = addr->type ==SOCKET_ADDRESS_KIND_UNIX ; s->is_listen = is_listen; s->is_telnet = is_telnet; s->do_nodelay = do_nodelay;
@@ -4222,7 +4222,7 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend,return NULL ; } -switch (backend->kind) { +switch (backend->type) {case CHARDEV_BACKEND_KIND_FILE : chr =qmp_chardev_open_file (backend->file, errp);break ;
@@ -4293,7 +4293,7 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend, chr =qemu_chr_open_ringbuf (backend->ringbuf, errp);break ;default : -error_setg (errp,"unknown chardev backend (%d)" , backend->kind); +error_setg (errp,"unknown chardev backend (%d)" , backend->type);break ; }
@@ -4309,9 +4309,9 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend,if (chr) { chr->label =g_strdup (id); chr->avail_connections = - (backend->kind ==CHARDEV_BACKEND_KIND_MUX ) ?MAX_MUX :1 ; + (backend->type ==CHARDEV_BACKEND_KIND_MUX ) ?MAX_MUX :1 ;if (!chr->filename) { - chr->filename =g_strdup (ChardevBackendKind_lookup[backend->kind]); + chr->filename =g_strdup (ChardevBackendKind_lookup[backend->type]); }if (!chr->explicit_be_open) {qemu_chr_be_event (chr,CHR_EVENT_OPENED );
scripts/qapi-types.py +2 -5
@@ -110,13 +110,10 @@ struct %(c_name)s { tag_name = 'type' else: ret += mcgen(''' - %(c_type)s kind; + %(c_type)s type; ''', c_type=c_name(variants.tag_member.type.name)) - # TODO ugly special case for simple union - # Use same tag name in C as on the wire to get rid of - # it, then: tag_name = variants.tag_member.name - tag_name = 'kind' + tag_name = variants.tag_member.name # FIXME: What purpose does data serve, besides preventing a union that # has a branch named 'data'? We use it in qapi-visit.py to decide
scripts/qapi-visit.py +1 -8
@@ -277,9 +277,6 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error c_name=c_name(name)) tag_key = variants.tag_member.name - if not variants.tag_name: - # we pointlessly use a different key for simple unions - tag_key = 'type' ret += mcgen(''' visit_type_%(c_type)s(v, &(*obj)->%(c_name)s, "%(name)s", &err); if (err) {
@@ -288,11 +285,7 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error switch ((*obj)->%(c_name)s) { ''', c_type=variants.tag_member.type.c_name(), - # TODO ugly special case for simple union - # Use same tag name in C as on the wire to get rid of - # it, then: c_name=c_name(variants.tag_member.name) - c_name=c_name(variants.tag_name or 'kind'), - name=tag_key) + c_name=c_name(tag_key), name=tag_key) for var in variants.variants: # TODO ugly special case for simple union
tests/test-qmp-commands.c +1 -1
@@ -64,7 +64,7 @@ __org_qemu_x_Union1 *qmp___org_qemu_x_command(__org_qemu_x_EnumList *a, {__org_qemu_x_Union1 *ret =g_new0 (__org_qemu_x_Union1,1 ); - ret->kind =ORG_QEMU_X_UNION1_KIND___ORG_QEMU_X_BRANCH ; + ret->type =ORG_QEMU_X_UNION1_KIND___ORG_QEMU_X_BRANCH ; ret->__org_qemu_x_branch =strdup ("blah1" );return ret;
tests/test-qmp-input-visitor.c +4 -4
@@ -549,7 +549,7 @@ static void test_native_list_integer_helper(TestInputVisitorData *data,visit_type_UserDefNativeListUnion (v, &cvalue,NULL , &err);g_assert (err ==NULL );g_assert (cvalue !=NULL ); - g_assert_cmpint(cvalue->kind, ==, kind); + g_assert_cmpint(cvalue->type, ==, kind);switch (kind) {case USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER : {
@@ -713,7 +713,7 @@ static void test_visitor_in_native_list_bool(TestInputVisitorData *data,visit_type_UserDefNativeListUnion (v, &cvalue,NULL , &err);g_assert (err ==NULL );g_assert (cvalue !=NULL ); - g_assert_cmpint(cvalue->kind, ==, USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN); + g_assert_cmpint(cvalue->type, ==, USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN);for (i =0 , elem = cvalue->boolean; elem; elem = elem->next, i++) { g_assert_cmpint(elem->value, ==, (i % 3 == 0) ? 1 : 0);
@@ -749,7 +749,7 @@ static void test_visitor_in_native_list_string(TestInputVisitorData *data,visit_type_UserDefNativeListUnion (v, &cvalue,NULL , &err);g_assert (err ==NULL );g_assert (cvalue !=NULL ); - g_assert_cmpint(cvalue->kind, ==, USER_DEF_NATIVE_LIST_UNION_KIND_STRING); + g_assert_cmpint(cvalue->type, ==, USER_DEF_NATIVE_LIST_UNION_KIND_STRING);for (i =0 , elem = cvalue->string; elem; elem = elem->next, i++) {gchar str[8 ];
@@ -789,7 +789,7 @@ static void test_visitor_in_native_list_number(TestInputVisitorData *data,visit_type_UserDefNativeListUnion (v, &cvalue,NULL , &err);g_assert (err ==NULL );g_assert (cvalue !=NULL ); - g_assert_cmpint(cvalue->kind, ==, USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER); + g_assert_cmpint(cvalue->type, ==, USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER);for (i =0 , elem = cvalue->number; elem; elem = elem->next, i++) {GString *double_expected =g_string_new ("" );
tests/test-qmp-output-visitor.c +3 -3
@@ -556,7 +556,7 @@ static void test_visitor_out_empty(TestOutputVisitorData *data,static void init_native_list (UserDefNativeListUnion *cvalue) {int i; -switch (cvalue->kind) { +switch (cvalue->type) {case USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER : {intList **list = &cvalue->integer;for (i =0 ; i <32 ; i++) {
@@ -777,14 +777,14 @@ static void test_native_list(TestOutputVisitorData *data,Error *err =NULL ;QObject *obj; - cvalue->kind = kind; + cvalue->type = kind;init_native_list (cvalue);visit_type_UserDefNativeListUnion (data->ov, &cvalue,NULL , &err);g_assert (err ==NULL ); obj =qmp_output_get_qobject (data->qov); -check_native_list (obj, cvalue->kind); +check_native_list (obj, cvalue->type);qapi_free_UserDefNativeListUnion (cvalue);qobject_decref (obj); }
tpm.c +1 -1
@@ -260,7 +260,7 @@ static TPMInfo *qmp_query_tpm_inst(TPMBackend *drv)switch (drv->ops->type) {case TPM_TYPE_PASSTHROUGH : - res->options->kind =TPM_TYPE_OPTIONS_KIND_PASSTHROUGH ; + res->options->type =TPM_TYPE_OPTIONS_KIND_PASSTHROUGH ; tpo =g_new0 (TPMPassthroughOptions,1 ); res->options->passthrough = tpo;if (drv->path) {
ui/input-keymap.c +5 -5
@@ -139,10 +139,10 @@ static int number_to_qcode[0x100];int qemu_input_key_value_to_number (const KeyValue *value) { -if (value->kind ==KEY_VALUE_KIND_QCODE ) { +if (value->type ==KEY_VALUE_KIND_QCODE ) {return qcode_to_number[value->qcode]; }else { -assert (value->kind ==KEY_VALUE_KIND_NUMBER ); +assert (value->type ==KEY_VALUE_KIND_NUMBER );return value->number; } }
@@ -166,10 +166,10 @@ int qemu_input_key_number_to_qcode(uint8_t nr)int qemu_input_key_value_to_qcode (const KeyValue *value) { -if (value->kind ==KEY_VALUE_KIND_QCODE ) { +if (value->type ==KEY_VALUE_KIND_QCODE ) {return value->qcode; }else { -assert (value->kind ==KEY_VALUE_KIND_NUMBER ); +assert (value->type ==KEY_VALUE_KIND_NUMBER );return qemu_input_key_number_to_qcode (value->number); } }
@@ -180,7 +180,7 @@ int qemu_input_key_value_to_scancode(const KeyValue *value, bool down,int keycode =qemu_input_key_value_to_number (value);int count =0 ; -if (value->kind ==KEY_VALUE_KIND_QCODE && +if (value->type ==KEY_VALUE_KIND_QCODE && value->qcode ==Q_KEY_CODE_PAUSE ) {/* specific case */ int v = down ?0 :0x80 ;
ui/input-legacy.c +1 -1
@@ -150,7 +150,7 @@ static void legacy_mouse_event(DeviceState *dev, QemuConsole *src, };QEMUPutMouseEntry *s = (QEMUPutMouseEntry *)dev; -switch (evt->kind) { +switch (evt->type) {case INPUT_EVENT_KIND_BTN :if (evt->btn->down) { s->buttons |= bmap[evt->btn->button];
ui/input.c +11 -11
@@ -147,10 +147,10 @@ void qmp_x_input_send_event(bool has_console, int64_t console,for (e = events; e !=NULL ; e = e->next) {InputEvent *event = e->value; -if (!qemu_input_find_handler (1 << event->kind, con)) { +if (!qemu_input_find_handler (1 << event->type, con)) {error_setg (errp,"Input handler not found for " "event type %s" , - InputEventKind_lookup[event->kind]); + InputEventKind_lookup[event->type]);return ; } }
@@ -197,9 +197,9 @@ static void qemu_input_event_trace(QemuConsole *src, InputEvent *evt)if (src) { idx =qemu_console_get_index (src); } -switch (evt->kind) { +switch (evt->type) {case INPUT_EVENT_KIND_KEY : -switch (evt->key->key->kind) { +switch (evt->key->key->type) {case KEY_VALUE_KIND_NUMBER : qcode =qemu_input_key_number_to_qcode (evt->key->key->number); name = QKeyCode_lookup[qcode];
@@ -311,12 +311,12 @@ void qemu_input_event_send(QemuConsole *src, InputEvent *evt)qemu_input_event_trace (src, evt);/* pre processing */ -if (graphic_rotate && (evt->kind ==INPUT_EVENT_KIND_ABS )) { +if (graphic_rotate && (evt->type ==INPUT_EVENT_KIND_ABS )) {qemu_input_transform_abs_rotate (evt); }/* send event */ - s =qemu_input_find_handler (1 << evt->kind, src); + s =qemu_input_find_handler (1 << evt->type, src);if (!s) {return ; }
@@ -349,7 +349,7 @@ InputEvent *qemu_input_event_new_key(KeyValue *key, bool down) {InputEvent *evt =g_new0 (InputEvent,1 ); evt->key =g_new0 (InputKeyEvent,1 ); - evt->kind =INPUT_EVENT_KIND_KEY ; + evt->type =INPUT_EVENT_KIND_KEY ; evt->key->key = key; evt->key->down = down;return evt;
@@ -372,7 +372,7 @@ void qemu_input_event_send_key(QemuConsole *src, KeyValue *key, bool down)void qemu_input_event_send_key_number (QemuConsole *src,int num,bool down) {KeyValue *key =g_new0 (KeyValue,1 ); - key->kind =KEY_VALUE_KIND_NUMBER ; + key->type =KEY_VALUE_KIND_NUMBER ; key->number = num;qemu_input_event_send_key (src, key, down); }
@@ -380,7 +380,7 @@ void qemu_input_event_send_key_number(QemuConsole *src, int num, bool down)void qemu_input_event_send_key_qcode (QemuConsole *src,QKeyCode q,bool down) {KeyValue *key =g_new0 (KeyValue,1 ); - key->kind =KEY_VALUE_KIND_QCODE ; + key->type =KEY_VALUE_KIND_QCODE ; key->qcode = q;qemu_input_event_send_key (src, key, down); }
@@ -399,7 +399,7 @@ InputEvent *qemu_input_event_new_btn(InputButton btn, bool down) {InputEvent *evt =g_new0 (InputEvent,1 ); evt->btn =g_new0 (InputBtnEvent,1 ); - evt->kind =INPUT_EVENT_KIND_BTN ; + evt->type =INPUT_EVENT_KIND_BTN ; evt->btn->button = btn; evt->btn->down = down;return evt;
@@ -451,7 +451,7 @@ InputEvent *qemu_input_event_new_move(InputEventKind kind,InputEvent *evt =g_new0 (InputEvent,1 );InputMoveEvent *move =g_new0 (InputMoveEvent,1 ); - evt->kind = kind; + evt->type = kind; evt->data = move; move->axis = axis; move->value = value;
util/qemu-sockets.c +6 -6
@@ -904,7 +904,7 @@ SocketAddress *socket_parse(const char *str, Error **errp)error_setg (errp,"invalid Unix socket address" ); goto fail; }else { - addr->kind =SOCKET_ADDRESS_KIND_UNIX ; + addr->type =SOCKET_ADDRESS_KIND_UNIX ; addr->q_unix =g_new (UnixSocketAddress,1 ); addr->q_unix->path =g_strdup (str +5 ); }
@@ -913,12 +913,12 @@ SocketAddress *socket_parse(const char *str, Error **errp)error_setg (errp,"invalid file descriptor address" ); goto fail; }else { - addr->kind =SOCKET_ADDRESS_KIND_FD ; + addr->type =SOCKET_ADDRESS_KIND_FD ; addr->fd =g_new (String,1 ); addr->fd->str =g_strdup (str +3 ); } }else { - addr->kind =SOCKET_ADDRESS_KIND_INET ; + addr->type =SOCKET_ADDRESS_KIND_INET ; addr->inet =inet_parse (str, errp);if (addr->inet ==NULL ) { goto fail;
@@ -938,7 +938,7 @@ int socket_connect(SocketAddress *addr, Error **errp,int fd; opts =qemu_opts_create (&socket_optslist,NULL ,0 , &error_abort); -switch (addr->kind) { +switch (addr->type) {case SOCKET_ADDRESS_KIND_INET :inet_addr_to_opts (opts, addr->inet); fd =inet_connect_opts (opts, errp, callback, opaque);
@@ -970,7 +970,7 @@ int socket_listen(SocketAddress *addr, Error **errp)int fd; opts =qemu_opts_create (&socket_optslist,NULL ,0 , &error_abort); -switch (addr->kind) { +switch (addr->type) {case SOCKET_ADDRESS_KIND_INET :inet_addr_to_opts (opts, addr->inet); fd =inet_listen_opts (opts,0 , errp);
@@ -998,7 +998,7 @@ int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp)int fd; opts =qemu_opts_create (&socket_optslist,NULL ,0 , &error_abort); -switch (remote->kind) { +switch (remote->type) {case SOCKET_ADDRESS_KIND_INET :inet_addr_to_opts (opts, remote->inet);if (local) {
Signature · 1 line
2.4.3
PATCH v5 32/46 qapi: Hide tag_name data member of variants
In reply to Eric BlakeClean up the only remaining external use of the tag_name field of QAPISchemaObjectTypeVariants, by explicitly listing the generated 'type' tag for simple unions in the testsuite. Since alternate types no longer use the tag_member field, we can now mark the tag_name field as private by adding a leading underscore to prevent any further use.
--- scripts/qapi.py | 8 ++++---- tests/qapi-schema/qapi-schema-test.out | 2 ++ tests/qapi-schema/test-qapi.py | 4 ++-- tests/qapi-schema/union-clash2.out | 1 + tests/qapi-schema/union-empty.out | 1 + 5 files changed, 10 insertions(+), 6 deletions(-)
scripts/qapi.py +4 -4
@@ -1015,7 +1015,7 @@ class QAPISchemaObjectTypeVariants(object): assert tag_enum is None or isinstance(tag_enum, str) for v in variants: assert isinstance(v, QAPISchemaObjectTypeVariant) - self.tag_name = tag_name + self._tag_name = tag_name if tag_name: # flat union assert not tag_enum self.tag_member = None
@@ -1028,9 +1028,9 @@ class QAPISchemaObjectTypeVariants(object): self.variants = variants def check(self, schema, info, members, seen): - if self.tag_name: - self.tag_member = seen[c_name(self.tag_name)] - assert self.tag_name == self.tag_member.name + if self._tag_name: + self.tag_member = seen[c_name(self._tag_name)] + assert self._tag_name == self.tag_member.name elif self.tag_member: self.tag_member.check(schema, info, members, seen) typ = None
tests/qapi-schema/qapi-schema-test.out +2 -0
@@ -113,6 +113,7 @@ object UserDefFlatUnion2 case value2: UserDefB case value3: UserDefA object UserDefNativeListUnion + tag type case integer: :obj-intList-wrapper case s8: :obj-int8List-wrapper case s16: :obj-int16List-wrapper
@@ -167,6 +168,7 @@ object __org.qemu_x-Struct object __org.qemu_x-Struct2 member array: __org.qemu_x-Union1List optional=False object __org.qemu_x-Union1 + tag type case __org.qemu_x-branch: :obj-str-wrapper enum __org.qemu_x-Union1Kind ['__org.qemu_x-branch'] object __org.qemu_x-Union2
tests/qapi-schema/test-qapi.py +2 -2
@@ -47,8 +47,8 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): @staticmethod def _print_variants(variants): if variants: - if variants.tag_name: - print ' tag %s' % variants.tag_name + if variants.tag_member: + print ' tag %s' % variants.tag_member.name for v in variants.variants: print ' case %s: %s' % (v.name, v.type.name)
tests/qapi-schema/union-clash2.out +1 -0
@@ -2,5 +2,6 @@ object :empty object :obj-int-wrapper member data: int optional=False object TestUnion + tag type case data: :obj-int-wrapper enum TestUnionKind ['data']
tests/qapi-schema/union-empty.out +1 -0
@@ -1,3 +1,4 @@ object :empty object Union + tag type enum UnionKind []
Signature · 1 line
2.4.3
PATCH v5 33/46 vnc: hoist allocation of VncBasicInfo to callers
In reply to Eric BlakeA future qapi patch will rework generated structs with a base class to be unboxed. In preparation for that, change the code that allocates then populates an info struct to instead merely populate the fields of an info field passed in as a parameter. Add rudimentary Error handling for cases where the old code returned NULL; but as before, callers merely ignore errors for now.
--- ui/vnc.c | 52 ++++++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 24 deletions(-)
ui/vnc.c +28 -24
@@ -156,10 +156,11 @@ char *vnc_socket_remote_addr(const char *format, int fd) {return addr_to_string (format, &sa, salen); } -static VncBasicInfo *vnc_basic_info_get (struct sockaddr_storage *sa, -socklen_t salen) +static void vnc_basic_info_get (struct sockaddr_storage *sa, +socklen_t salen, +VncBasicInfo *info, +Error **errp) { -VncBasicInfo *info;char host[NI_MAXHOST ];char serv[NI_MAXSERV ];int err;
@@ -168,42 +169,44 @@ static VncBasicInfo *vnc_basic_info_get(struct sockaddr_storage *sa, host, sizeof(host), serv, sizeof(serv), NI_NUMERICHOST | NI_NUMERICSERV)) != 0) { -VNC_DEBUG ("Cannot resolve address %d: %s\n" , - err,gai_strerror (err)); -return NULL ; +error_setg (errp,"Cannot resolve address %d: %s" , + err,gai_strerror (err)); +return ; } - info =g_malloc0 (sizeof (VncBasicInfo)); info->host =g_strdup (host); info->service =g_strdup (serv); info->family =inet_netfamily (sa->ss_family); -return info; } -static VncBasicInfo *vnc_basic_info_get_from_server_addr (int fd) +static void vnc_basic_info_get_from_server_addr (int fd,VncBasicInfo *info, +Error **errp) {struct sockaddr_storage sa;socklen_t salen; salen =sizeof (sa);if (getsockname (fd, (struct sockaddr *)&sa, &salen) <0 ) { -return NULL ; +error_setg_errno (errp, errno,"getsockname failed" ); +return ; } -return vnc_basic_info_get (&sa, salen); +vnc_basic_info_get (&sa, salen, info, errp); } -static VncBasicInfo *vnc_basic_info_get_from_remote_addr (int fd) +static void vnc_basic_info_get_from_remote_addr (int fd,VncBasicInfo *info, +Error **errp) {struct sockaddr_storage sa;socklen_t salen; salen =sizeof (sa);if (getpeername (fd, (struct sockaddr *)&sa, &salen) <0 ) { -return NULL ; +error_setg_errno (errp, errno,"getpeername failed" ); +return ; } -return vnc_basic_info_get (&sa, salen); +vnc_basic_info_get (&sa, salen, info, errp); }static const char *vnc_auth_name (VncDisplay *vd) {
@@ -256,13 +259,10 @@ static const char *vnc_auth_name(VncDisplay *vd) {static VncServerInfo *vnc_server_info_get (VncDisplay *vd) {VncServerInfo *info; -VncBasicInfo *bi =vnc_basic_info_get_from_server_addr (vd->lsock); -if (!bi) { -return NULL ; - } info =g_malloc (sizeof (*info)); - info->base = bi; + info->base =g_malloc (sizeof (*info->base)); +vnc_basic_info_get_from_server_addr (vd->lsock, info->base,NULL ); info->has_auth = true; info->auth =g_strdup (vnc_auth_name (vd));return info;
@@ -291,11 +291,15 @@ static void vnc_client_cache_auth(VncState *client)static void vnc_client_cache_addr (VncState *client) { -VncBasicInfo *bi =vnc_basic_info_get_from_remote_addr (client->csock); - -if (bi) { - client->info =g_malloc0 (sizeof (*client->info)); - client->info->base = bi; +Error *err =NULL ; + client->info =g_malloc0 (sizeof (*client->info)); + client->info->base =g_malloc0 (sizeof (*client->info->base)); +vnc_basic_info_get_from_remote_addr (client->csock, client->info->base, + &err); +if (err) { +qapi_free_VncClientInfo (client->info); + client->info =NULL ; +error_free (err); } }
Signature · 1 line
2.4.3
PATCH v5 34/46 qapi: Unbox base members
In reply to Eric BlakeRather than storing a base class as a pointer to a box, just store the fields of that base class in the same order, so that a child struct can be safely cast to its parent. This gives less malloc overhead, less pointer dereferencing, and even less generated code.
Without boxing, the corner case of one empty struct having another empty struct as its base type now requires inserting a dummy member (previously, the pointer to the base would have sufficed).
And now that we no longer consume a 'base' member in the generated C struct, we can delete the former negative test struct-base-clash2 and replace it with a positive test in qapi-schema-test that ensures we don't reintroduce the naming collision.
Compare to the earlier commit 1e6c1616a "qapi: Generate a nicer struct for flat unions".
--- hmp.c | 6 +++--- scripts/qapi-types.py | 29 +++++++++++++++-------------- scripts/qapi-visit.py | 9 ++++++--- tests/Makefile | 1 - tests/qapi-schema/qapi-schema-test.json | 3 +++ tests/qapi-schema/qapi-schema-test.out | 3 +++ tests/qapi-schema/struct-base-clash2.err | 0 tests/qapi-schema/struct-base-clash2.exit | 1 - tests/qapi-schema/struct-base-clash2.json | 5 ----- tests/qapi-schema/struct-base-clash2.out | 5 ----- tests/test-qmp-commands.c | 15 +++++---------- tests/test-qmp-event.c | 8 ++------ tests/test-qmp-input-visitor.c | 4 ++-- tests/test-qmp-output-visitor.c | 12 ++++-------- tests/test-visitor-serialization.c | 14 ++++++-------- ui/spice-core.c | 23 +++++++++++++---------- ui/vnc.c | 20 +++++++++----------- 17 files changed, 71 insertions(+), 87 deletions(-) delete mode 100644 tests/qapi-schema/struct-base-clash2.err delete mode 100644 tests/qapi-schema/struct-base-clash2.exit delete mode 100644 tests/qapi-schema/struct-base-clash2.json delete mode 100644 tests/qapi-schema/struct-base-clash2.out
hmp.c +3 -3
@@ -558,8 +558,8 @@ void hmp_info_vnc(Monitor *mon, const QDict *qdict)for (client = info->clients; client; client = client->next) {monitor_printf (mon,"Client:\n" );monitor_printf (mon," address: %s:%s\n" , - client->value->base->host, - client->value->base->service); + client->value->host, + client->value->service);monitor_printf (mon," x509_dname: %s\n" , client->value->x509_dname ? client->value->x509_dname :"none" );
@@ -627,7 +627,7 @@ void hmp_info_spice(Monitor *mon, const QDict *qdict)for (chan = info->channels; chan; chan = chan->next) {monitor_printf (mon,"Channel:\n" );monitor_printf (mon," address: %s:%s%s\n" , - chan->value->base->host, chan->value->base->port, + chan->value->host, chan->value->port, chan->value->tls ?" [tls]" :"" );monitor_printf (mon," session: %" PRId64"\n" , chan->value->connection_id);
scripts/qapi-types.py +15 -14
@@ -51,8 +51,19 @@ def gen_struct_field(name, typ, optional): return ret -def gen_struct_fields(members): +def gen_struct_fields(members, base, nested=False): ret = '' + if base: + if not nested: + ret += mcgen(''' + /* Members inherited from %(c_name)s: */ +''', + c_name=base.c_name()) + ret += gen_struct_fields(base.local_members, base.base, True) + if not nested: + ret += mcgen(''' + /* Own members: */ +''') for memb in members: ret += gen_struct_field(memb.name, memb.type, memb.optional)
@@ -66,16 +77,13 @@ struct %(c_name)s { ''', c_name=c_name(name)) - if base: - ret += gen_struct_field('base', base, False) - - ret += gen_struct_fields(members) + ret += gen_struct_fields(members, base) # Make sure that all structs have at least one field; this avoids # potential issues with attempting to malloc space for zero-length # structs in C, and also incompatibility with C++ (where an empty # struct is size 1). - if not base and not members: + if not (base and base.members) and not members: ret += mcgen(''' char qapi_dummy_field_for_empty_struct; ''')
@@ -94,14 +102,7 @@ struct %(c_name)s { ''', c_name=c_name(name)) if base: - ret += mcgen(''' - /* Members inherited from %(c_name)s: */ -''', - c_name=c_name(base.name)) - ret += gen_struct_fields(base.members) - ret += mcgen(''' - /* Own members: */ -''') + ret += gen_struct_fields([], base) tag_name = variants.tag_member.name elif not variants.tag_member: ret += mcgen('''
scripts/qapi-visit.py +6 -3
@@ -69,12 +69,15 @@ static void visit_type_implicit_%(c_type)s(Visitor *v, %(c_type)s **obj, Error * def gen_visit_struct_fields(name, base, members): + if name in struct_fields_seen: + return '' struct_fields_seen.add(name) ret = '' if base: - ret += gen_visit_implicit_struct(base) + ret += gen_visit_struct_fields(base.name, base.base, + base.local_members) ret += mcgen('''
@@ -88,12 +91,12 @@ static void visit_type_%(c_name)s_fields(Visitor *v, %(c_name)s **obj, Error **e if base: ret += mcgen(''' -visit_type_implicit_%(c_type)s(v, &(*obj)->%(c_name)s, &err); +visit_type_%(c_type)s_fields(v, (%(c_type)s **)obj, &err); if (err) { goto out; } ''', - c_type=base.c_name(), c_name=c_name('base')) + c_type=base.c_name()) ret += gen_visit_fields(members, '(*obj)->', False, 'err')
tests/Makefile +0 -1
@@ -323,7 +323,6 @@ qapi-schema += returns-unknown.json qapi-schema += returns-whitelist.json qapi-schema += struct-base-clash-deep.json qapi-schema += struct-base-clash.json -qapi-schema += struct-base-clash2.json qapi-schema += struct-data-invalid.json qapi-schema += struct-member-invalid.json qapi-schema += trailing-comma-list.json
tests/qapi-schema/qapi-schema-test.json +3 -0
@@ -31,6 +31,9 @@ 'data': { 'string0': 'str', 'dict1': 'UserDefTwoDict' } } +{ 'struct': 'UserDefThree', + 'base': 'UserDefOne', 'data': { 'base': 'str' } } + # for testing unions # name collisions between branches should not clash { 'struct': 'UserDefA',
tests/qapi-schema/qapi-schema-test.out +3 -0
@@ -139,6 +139,9 @@ object UserDefOptions member u16: uint16List optional=True member i64x: int optional=True member u64x: uint64 optional=True +object UserDefThree + base UserDefOne + member base: str optional=False object UserDefTwo member string0: str optional=False member dict1: UserDefTwoDict optional=False
tests/qapi-schema/struct-base-clash2.err deleted +0 -0
tests/qapi-schema/struct-base-clash2.exit deleted +0 -1
@@ -1 +0,0 @@ -0
tests/qapi-schema/struct-base-clash2.json deleted +0 -5
@@ -1,5 +0,0 @@ -# FIXME - a base class collides with a member named base -{ 'struct': 'Base', 'data': {} } -{ 'struct': 'Sub', - 'base': 'Base', - 'data': { 'base': 'str' } }
tests/qapi-schema/struct-base-clash2.out deleted +0 -5
@@ -1,5 +0,0 @@ -object :empty -object Base -object Sub - base Base - member base: str optional=False
tests/test-qmp-commands.c +5 -10
@@ -25,11 +25,9 @@ UserDefTwo *qmp_user_def_cmd2(UserDefOne *ud1a,UserDefOne *ud1d =g_malloc0 (sizeof (UserDefOne)); ud1c->string =strdup (ud1a->string); - ud1c->base =g_new0 (UserDefZero,1 ); - ud1c->base->integer = ud1a->base->integer; + ud1c->integer = ud1a->integer; ud1d->string =strdup (has_udb1 ? ud1b->string :"blah0" ); - ud1d->base =g_new0 (UserDefZero,1 ); - ud1d->base->integer = has_udb1 ? ud1b->base->integer :0 ; + ud1d->integer = has_udb1 ? ud1b->integer :0 ; ret =g_new0 (UserDefTwo,1 ); ret->string0 =strdup ("blah1" );
@@ -176,20 +174,17 @@ static void test_dealloc_types(void)UserDefOneList *ud1list; ud1test =g_malloc0 (sizeof (UserDefOne)); - ud1test->base =g_new0 (UserDefZero,1 ); - ud1test->base->integer =42 ; + ud1test->integer =42 ; ud1test->string =g_strdup ("hi there 42" );qapi_free_UserDefOne (ud1test); ud1a =g_malloc0 (sizeof (UserDefOne)); - ud1a->base =g_new0 (UserDefZero,1 ); - ud1a->base->integer =43 ; + ud1a->integer =43 ; ud1a->string =g_strdup ("hi there 43" ); ud1b =g_malloc0 (sizeof (UserDefOne)); - ud1b->base =g_new0 (UserDefZero,1 ); - ud1b->base->integer =44 ; + ud1b->integer =44 ; ud1b->string =g_strdup ("hi there 44" ); ud1list =g_malloc0 (sizeof (UserDefOneList));
tests/test-qmp-event.c +2 -6
@@ -179,9 +179,7 @@ static void test_event_c(TestEventData *data,QDict *d, *d_data, *d_b;UserDefOne b; -UserDefZero z; - z.integer =2 ; - b.base = &z; + b.integer =2 ; b.string =g_strdup ("test1" ); b.has_enum1 = false;
@@ -209,11 +207,9 @@ static void test_event_d(TestEventData *data, {UserDefOne struct1;EventStructOne a; -UserDefZero z;QDict *d, *d_data, *d_a, *d_struct1; - z.integer =2 ; - struct1.base = &z; + struct1.integer =2 ; struct1.string =g_strdup ("test1" ); struct1.has_enum1 = true; struct1.enum1 =ENUM_ONE_VALUE1 ;
tests/test-qmp-input-visitor.c +2 -2
@@ -272,7 +272,7 @@ static void test_visitor_in_struct_nested(TestInputVisitorData *data,check_and_free_str (udp->string0,"string0" );check_and_free_str (udp->dict1->string1,"string1" ); - g_assert_cmpint(udp->dict1->dict2->userdef->base->integer, ==, 42); + g_assert_cmpint(udp->dict1->dict2->userdef->integer, ==, 42);check_and_free_str (udp->dict1->dict2->userdef->string,"string" );check_and_free_str (udp->dict1->dict2->string,"string2" );g_assert (udp->dict1->has_dict3 == false);
@@ -303,7 +303,7 @@ static void test_visitor_in_list(TestInputVisitorData *data,snprintf (string,sizeof (string),"string%d" , i); g_assert_cmpstr(item->value->string, ==, string); - g_assert_cmpint(item->value->base->integer, ==, 42 + i); + g_assert_cmpint(item->value->integer, ==, 42 + i); }qapi_free_UserDefOneList (head);
tests/test-qmp-output-visitor.c +4 -8
@@ -250,16 +250,14 @@ static void test_visitor_out_struct_nested(TestOutputVisitorData *data, ud2->dict1->dict2 =g_malloc0 (sizeof (*ud2->dict1->dict2)); ud2->dict1->dict2->userdef =g_new0 (UserDefOne,1 ); ud2->dict1->dict2->userdef->string =g_strdup (string); - ud2->dict1->dict2->userdef->base =g_new0 (UserDefZero,1 ); - ud2->dict1->dict2->userdef->base->integer = value; + ud2->dict1->dict2->userdef->integer = value; ud2->dict1->dict2->string =g_strdup (strings[2 ]); ud2->dict1->dict3 =g_malloc0 (sizeof (*ud2->dict1->dict3)); ud2->dict1->has_dict3 = true; ud2->dict1->dict3->userdef =g_new0 (UserDefOne,1 ); ud2->dict1->dict3->userdef->string =g_strdup (string); - ud2->dict1->dict3->userdef->base =g_new0 (UserDefZero,1 ); - ud2->dict1->dict3->userdef->base->integer = value; + ud2->dict1->dict3->userdef->integer = value; ud2->dict1->dict3->string =g_strdup (strings[3 ]);visit_type_UserDefTwo (data->ov, &ud2,"unused" , &err);
@@ -301,8 +299,7 @@ static void test_visitor_out_struct_errors(TestOutputVisitorData *data, const void *unused) {EnumOne bad_values[] = {ENUM_ONE_MAX ,-1 }; -UserDefZero b; -UserDefOne u = { .base = &b }, *pu = &u; +UserDefOne u, *pu = &u;Error *err;int i;
@@ -416,8 +413,7 @@ static void test_visitor_out_list_qapi_free(TestOutputVisitorData *data, p->value->dict1->dict2 =g_new0 (UserDefTwoDictDict,1 ); p->value->dict1->dict2->userdef =g_new0 (UserDefOne,1 ); p->value->dict1->dict2->userdef->string =g_strdup (string); - p->value->dict1->dict2->userdef->base =g_new0 (UserDefZero,1 ); - p->value->dict1->dict2->userdef->base->integer =42 ; + p->value->dict1->dict2->userdef->integer =42 ; p->value->dict1->dict2->string =g_strdup (string); p->value->dict1->has_dict3 = false;
tests/test-visitor-serialization.c +6 -8
@@ -258,15 +258,13 @@ static UserDefTwo *nested_struct_create(void) udnp->dict1->string1 =strdup ("test_string1" ); udnp->dict1->dict2 =g_malloc0 (sizeof (*udnp->dict1->dict2)); udnp->dict1->dict2->userdef =g_new0 (UserDefOne,1 ); - udnp->dict1->dict2->userdef->base =g_new0 (UserDefZero,1 ); - udnp->dict1->dict2->userdef->base->integer =42 ; + udnp->dict1->dict2->userdef->integer =42 ; udnp->dict1->dict2->userdef->string =strdup ("test_string" ); udnp->dict1->dict2->string =strdup ("test_string2" ); udnp->dict1->dict3 =g_malloc0 (sizeof (*udnp->dict1->dict3)); udnp->dict1->has_dict3 = true; udnp->dict1->dict3->userdef =g_new0 (UserDefOne,1 ); - udnp->dict1->dict3->userdef->base =g_new0 (UserDefZero,1 ); - udnp->dict1->dict3->userdef->base->integer =43 ; + udnp->dict1->dict3->userdef->integer =43 ; udnp->dict1->dict3->userdef->string =strdup ("test_string" ); udnp->dict1->dict3->string =strdup ("test_string3" );return udnp;
@@ -278,15 +276,15 @@ static void nested_struct_compare(UserDefTwo *udnp1, UserDefTwo *udnp2)g_assert (udnp2); g_assert_cmpstr(udnp1->string0, ==, udnp2->string0); g_assert_cmpstr(udnp1->dict1->string1, ==, udnp2->dict1->string1); - g_assert_cmpint(udnp1->dict1->dict2->userdef->base->integer, ==, - udnp2->dict1->dict2->userdef->base->integer); + g_assert_cmpint(udnp1->dict1->dict2->userdef->integer, ==, + udnp2->dict1->dict2->userdef->integer); g_assert_cmpstr(udnp1->dict1->dict2->userdef->string, ==, udnp2->dict1->dict2->userdef->string); g_assert_cmpstr(udnp1->dict1->dict2->string, ==, udnp2->dict1->dict2->string);g_assert (udnp1->dict1->has_dict3 == udnp2->dict1->has_dict3); - g_assert_cmpint(udnp1->dict1->dict3->userdef->base->integer, ==, - udnp2->dict1->dict3->userdef->base->integer); + g_assert_cmpint(udnp1->dict1->dict3->userdef->integer, ==, + udnp2->dict1->dict3->userdef->integer); g_assert_cmpstr(udnp1->dict1->dict3->userdef->string, ==, udnp2->dict1->dict3->userdef->string); g_assert_cmpstr(udnp1->dict1->dict3->string, ==,
ui/spice-core.c +13 -10
@@ -200,8 +200,6 @@ static void channel_event(int event, SpiceChannelEventInfo *info) {SpiceServerInfo *server =g_malloc0 (sizeof (*server));SpiceChannel *client =g_malloc0 (sizeof (*client)); - server->base =g_malloc0 (sizeof (*server->base)); - client->base =g_malloc0 (sizeof (*client->base));/* * Spice server might have called us from spice worker thread
@@ -218,9 +216,11 @@ static void channel_event(int event, SpiceChannelEventInfo *info) }if (info->flags &SPICE_CHANNEL_EVENT_FLAG_ADDR_EXT ) { -add_addr_info (client->base, (struct sockaddr *)&info->paddr_ext, +add_addr_info ((SpiceBasicInfo *)client, + (struct sockaddr *)&info->paddr_ext, info->plen_ext); -add_addr_info (server->base, (struct sockaddr *)&info->laddr_ext, +add_addr_info ((SpiceBasicInfo *)server, + (struct sockaddr *)&info->laddr_ext, info->llen_ext); }else { error_report("spice: %s, extended address is expected",
@@ -229,7 +229,9 @@ static void channel_event(int event, SpiceChannelEventInfo *info)switch (event) {case SPICE_CHANNEL_EVENT_CONNECTED : -qapi_event_send_spice_connected (server->base, client->base, &error_abort); +qapi_event_send_spice_connected ((SpiceBasicInfo *)server, + (SpiceBasicInfo *)client, + &error_abort);break ;case SPICE_CHANNEL_EVENT_INITIALIZED :if (auth) {
@@ -242,7 +244,9 @@ static void channel_event(int event, SpiceChannelEventInfo *info)break ;case SPICE_CHANNEL_EVENT_DISCONNECTED :channel_list_del (info); -qapi_event_send_spice_disconnected (server->base, client->base, &error_abort); +qapi_event_send_spice_disconnected ((SpiceBasicInfo *)server, + (SpiceBasicInfo *)client, + &error_abort);break ;default :break ;
@@ -378,16 +382,15 @@ static SpiceChannelList *qmp_query_spice_channels(void) chan =g_malloc0 (sizeof (*chan)); chan->value =g_malloc0 (sizeof (*chan->value)); - chan->value->base =g_malloc0 (sizeof (*chan->value->base)); paddr = (struct sockaddr *)&item->info->paddr_ext; plen = item->info->plen_ext;getnameinfo (paddr, plen, host,sizeof (host), port,sizeof (port),NI_NUMERICHOST |NI_NUMERICSERV ); - chan->value->base->host =g_strdup (host); - chan->value->base->port =g_strdup (port); - chan->value->base->family =inet_netfamily (paddr->sa_family); + chan->value->host =g_strdup (host); + chan->value->port =g_strdup (port); + chan->value->family =inet_netfamily (paddr->sa_family); chan->value->connection_id = item->info->connection_id; chan->value->channel_type = item->info->type;
ui/vnc.c +9 -11
@@ -261,8 +261,7 @@ static VncServerInfo *vnc_server_info_get(VncDisplay *vd)VncServerInfo *info; info =g_malloc (sizeof (*info)); - info->base =g_malloc (sizeof (*info->base)); -vnc_basic_info_get_from_server_addr (vd->lsock, info->base,NULL ); +vnc_basic_info_get_from_server_addr (vd->lsock, (VncBasicInfo *)info,NULL ); info->has_auth = true; info->auth =g_strdup (vnc_auth_name (vd));return info;
@@ -293,8 +292,8 @@ static void vnc_client_cache_addr(VncState *client) {Error *err =NULL ; client->info =g_malloc0 (sizeof (*client->info)); - client->info->base =g_malloc0 (sizeof (*client->info->base)); -vnc_basic_info_get_from_remote_addr (client->csock, client->info->base, +vnc_basic_info_get_from_remote_addr (client->csock, + (VncBasicInfo *)client->info, &err);if (err) {qapi_free_VncClientInfo (client->info);
@@ -310,7 +309,6 @@ static void vnc_qmp_event(VncState *vs, QAPIEvent event)if (!vs->info) {return ; } -g_assert (vs->info->base); si =vnc_server_info_get (vs->vd);if (!si) {
@@ -319,7 +317,8 @@ static void vnc_qmp_event(VncState *vs, QAPIEvent event)switch (event) {case QAPI_EVENT_VNC_CONNECTED : -qapi_event_send_vnc_connected (si, vs->info->base, &error_abort); +qapi_event_send_vnc_connected (si, (VncBasicInfo *)vs->info, + &error_abort);break ;case QAPI_EVENT_VNC_INITIALIZED :qapi_event_send_vnc_initialized (si, vs->info, &error_abort);
@@ -354,11 +353,10 @@ static VncClientInfo *qmp_query_vnc_client(const VncState *client) } info =g_malloc0 (sizeof (*info)); - info->base =g_malloc0 (sizeof (*info->base)); - info->base->host =g_strdup (host); - info->base->service =g_strdup (serv); - info->base->family =inet_netfamily (sa.ss_family); - info->base->websocket = client->websocket; + info->host =g_strdup (host); + info->service =g_strdup (serv); + info->family =inet_netfamily (sa.ss_family); + info->websocket = client->websocket;if (client->tls) { info->x509_dname =qcrypto_tls_session_get_peer_name (client->tls);
Signature · 1 line
2.4.3
PATCH v5 35/46 qapi-visit: Remove redundant functions for flat union base
In reply to Eric BlakeThe code for visiting the base class of a child struct created visit_type_Base_fields(); the code for visiting the base class of a flat union created visit_type_Union_fields(). If the same type is shared between a struct and a union, the two functions differed only by whether they visited the discriminator used by the union. But if the base class always visits all its fields, then we don't need to revisit the discriminator specially for a union. By consistently visiting the base class fields under the name of the base class, we can eliminate some redundant code.
Now that gen_visit_struct_fields() can potentially collect more than one function into 'ret', a regular expression searching for whether a label was used may hit a false positive within the body of the first function. But using a regex was overkill, since we can easily determine when we jumped to a label.
--- scripts/qapi-visit.py | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-)
scripts/qapi-visit.py +19 -19
@@ -101,7 +101,7 @@ if (err) { ret += gen_visit_fields(members, '(*obj)->', False, 'err') pop_indent() - if re.search('^ *goto out;', ret, re.MULTILINE): + if base or members: ret += mcgen(''' out:
@@ -245,8 +245,8 @@ def gen_visit_union(name, base, variants): ret = '' if base: - members = [m for m in base.members if m != variants.tag_member] - ret += gen_visit_struct_fields(name, None, members) + ret += gen_visit_struct_fields(base.name, base.base, + base.local_members) for var in variants.variants: # Ugly special case for simple union TODO get rid of it
@@ -270,25 +270,25 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error ''', c_name=c_name(name), name=name) - if base: - ret += mcgen(''' - visit_type_%(c_name)s_fields(v, obj, &err); - if (err) { - goto out_obj; - } -''', - c_name=c_name(name)) - tag_key = variants.tag_member.name - ret += mcgen(''' + if base: + ret += mcgen(''' + visit_type_%(c_name)s_fields(v, (%(c_name)s **)obj, &err); +''', + c_name=c_name(base.name)) + else: + ret += mcgen(''' visit_type_%(c_type)s(v, &(*obj)->%(c_name)s, "%(name)s", &err); - if (err) { - goto out_obj; - } - switch ((*obj)->%(c_name)s) { ''', - c_type=variants.tag_member.type.c_name(), - c_name=c_name(tag_key), name=tag_key) + c_type=variants.tag_member.type.c_name(), + c_name=c_name(tag_key), name=tag_key) + ret += mcgen(''' + if (err) { + goto out_obj; + } + switch ((*obj)->%(c_name)s) { +''', + c_name=c_name(tag_key)) for var in variants.variants: # TODO ugly special case for simple union
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v5 35/46] qapi-visit: Remove redundant functions for flat union base
Quoted 23 lines · Eric Blake
The code for visiting the base class of a child struct created
visit_type_Base_fields(); the code for visiting the base class of a flat union createdvisit_type_Union_fields(). If the same type is shared between a struct and a union, the two functions differed only by whether they visited the discriminator used by the union. But if the base class always visits all its fields, then we don't need to revisit the discriminator specially for a union. By consistently visiting the base class fields under the name of the base class, we can eliminate some redundant code.Now that
gen_visit_struct_fields()can potentially collect more than one function into 'ret', a regular expression searching for whether a label was used may hit a false positive within the body of the first function. But using a regex was overkill, since we can easily determine when we jumped to a label.visit_type_%(c_type)s(v, &(*obj)->%(c_name)s, "%(name)s", &err);scripts/qapi-visit.py +0
-4- if (err) { - goto out_obj; - } - switch ((*obj)->%(c_name)s) {
scripts/qapi-visit.py void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error · line 289
Quoted 10 lines
scripts/qapi-visit.py +7
-2''', - c_type=variants.tag_member.type.c_name(), - c_name=c_name(tag_key), name=tag_key) + c_type=variants.tag_member.type.c_name(), + c_name=c_name(tag_key), name=tag_key) + ret += mcgen(''' + if (err) { + goto out_obj; + } + switch ((*obj)->%(c_name)s) {
Rebase snafu - I botched the generated indentation within this mcgen() by 4 spaces. Shouldn't affect a technical review, and I will fix it up for v6.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH v5 36/46 qapi: Avoid use of 'data' member of qapi unions
In reply to Eric Blakeqapi code generators currently create a 'void *data' member as part of the anonymous union embedded in the C struct corresponding to a qapi union. However, directly assigning to this member of the union feels a bit fishy, when we can directly use the rest of the struct instead.
--- blockdev.c | 22 ++++++++++++---------- ui/input.c | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-)
blockdev.c +12 -10
@@ -1052,14 +1052,11 @@ void hmp_commit(Monitor *mon, const QDict *qdict) } } -static void blockdev_do_action (int type,void *data,Error **errp) +static void blockdev_do_action (TransactionAction *action,Error **errp) { -TransactionAction action;TransactionActionList list; - action.type = type; - action.data = data; - list.value = &action; + list.value = action; list.next =NULL ;qmp_transaction (&list, errp); }
@@ -1085,8 +1082,11 @@ void qmp_blockdev_snapshot_sync(bool has_device, const char *device, .has_mode = has_mode, .mode = mode, }; -blockdev_do_action (TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC , - &snapshot, errp); +TransactionAction action = { + .type =TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC , + .blockdev_snapshot_sync = &snapshot, + }; +blockdev_do_action (&action, errp); } void qmp_blockdev_snapshot_internal_sync(const char *device,
@@ -1097,9 +1097,11 @@ void qmp_blockdev_snapshot_internal_sync(const char *device, .device = (char *) device, .name = (char *) name }; - -blockdev_do_action (TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_INTERNAL_SYNC , - &snapshot, errp); +TransactionAction action = { + .type =TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_INTERNAL_SYNC , + .blockdev_snapshot_internal_sync = &snapshot, + }; +blockdev_do_action (&action, errp); } SnapshotInfo *qmp_blockdev_snapshot_delete_internal_sync(const char *device,
ui/input.c +1 -1
@@ -452,7 +452,7 @@ InputEvent *qemu_input_event_new_move(InputEventKind kind,InputMoveEvent *move =g_new0 (InputMoveEvent,1 ); evt->type = kind; - evt->data = move; + evt->rel = move;/* also would work as evt->abs */ move->axis = axis; move->value = value;return evt;
Signature · 1 line
2.4.3
PATCH v5 37/46 qapi: Forbid empty unions and useless alternates
In reply to Eric BlakeEmpty unions serve no purpose, and while we compile with gcc which permits them, strict C99 forbids them. We could inject a dummy member (and in fact, we do for empty structs), but while empty structs make sense in qapi, empty unions don't add any expressiveness to the QMP language. So prohibit them at parse time. Update the documentation and testsuite to match.
--- docs/qapi-code-gen.txt | 15 ++++++++------- scripts/qapi.py | 12 ++++++++++-- tests/qapi-schema/alternate-empty.err | 1 + tests/qapi-schema/alternate-empty.exit | 2 +- tests/qapi-schema/alternate-empty.json | 2 +- tests/qapi-schema/alternate-empty.out | 3 --- tests/qapi-schema/flat-union-empty.err | 1 + tests/qapi-schema/flat-union-empty.exit | 2 +- tests/qapi-schema/flat-union-empty.json | 2 +- tests/qapi-schema/flat-union-empty.out | 7 ------- tests/qapi-schema/union-empty.err | 1 + tests/qapi-schema/union-empty.exit | 2 +- tests/qapi-schema/union-empty.json | 2 +- tests/qapi-schema/union-empty.out | 4 ---- 14 files changed, 27 insertions(+), 29 deletions(-)
docs/qapi-code-gen.txt +8 -7
@@ -182,11 +182,11 @@ prevent incomplete include files. Usage: { 'struct': STRING, 'data': DICT, '*base': STRUCT-NAME } -A struct is a dictionary containing a single 'data' key whose -value is a dictionary. This corresponds to a struct in C or an Object -in JSON. Each value of the 'data' dictionary must be the name of a -type, or a one-element array containing a type name. An example of a -struct is: +A struct is a dictionary containing a single 'data' key whose value is +a dictionary; the dictionary may be empty. This corresponds to a +struct in C or an Object in JSON. Each value of the 'data' dictionary +must be the name of a type, or a one-element array containing a type +name. An example of a struct is: { 'struct': 'MyType', 'data': { 'member1': 'str', 'member2': 'int', '*member3': 'str' } }
@@ -283,9 +283,10 @@ or: { 'union': STRING, 'data': DICT, 'base': STRUCT-NAME, Union types are used to let the user choose between several different variants for an object. There are two flavors: simple (no -discriminator or base), flat (both discriminator and base). A union +discriminator or base), and flat (both discriminator and base). A union type is defined using a data dictionary as explained in the following -paragraphs. +paragraphs. The data dictionary for either type of union must not +be empty. A simple union type defines a mapping from automatic discriminator values to data types like in this example:
scripts/qapi.py +10 -2
@@ -573,7 +573,10 @@ def check_union(expr, expr_info): "Discriminator '%s' must be of enumeration " "type" % discriminator) - # Check every branch + # Check every branch; don't allow an empty union + if len(members) == 0: + raise QAPIExprError(expr_info, + "Union '%s' cannot have empty 'data'" % name) for (key, value) in members.items(): check_name(expr_info, "Member of union '%s'" % name, key)
@@ -606,7 +609,11 @@ def check_alternate(expr, expr_info): values = {'MAX': '(automatic)'} types_seen = {} - # Check every branch + # Check every branch; require at least two branches + if len(members) < 2: + raise QAPIExprError(expr_info, + "Alternate '%s' should have at least two branches " + "in 'data'" % name) for (key, value) in members.items(): check_name(expr_info, "Member of alternate '%s'" % name, key)
@@ -1013,6 +1020,7 @@ class QAPISchemaObjectTypeVariants(object): def __init__(self, tag_name, tag_enum, variants): assert tag_name is None or isinstance(tag_name, str) assert tag_enum is None or isinstance(tag_enum, str) + assert len(variants) > 0 for v in variants: assert isinstance(v, QAPISchemaObjectTypeVariant) self._tag_name = tag_name
tests/qapi-schema/alternate-empty.err +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/alternate-empty.json:2: Alternate 'Alt' should have at least two branches in 'data'
tests/qapi-schema/alternate-empty.exit +1 -1
@@ -1 +1 @@ -0 +1
tests/qapi-schema/alternate-empty.json +1 -1
@@ -1,2 +1,2 @@ -# FIXME - alternates should list at least two types to be useful +# alternates must list at least two types to be useful { 'alternate': 'Alt', 'data': { 'i': 'int' } }
tests/qapi-schema/alternate-empty.out +0 -3
@@ -1,3 +0,0 @@ -object :empty -alternate Alt - case i: int
tests/qapi-schema/flat-union-empty.err +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/flat-union-empty.json:4: Union 'Union' cannot have empty 'data'
tests/qapi-schema/flat-union-empty.exit +1 -1
@@ -1 +1 @@ -0 +1
tests/qapi-schema/flat-union-empty.json +1 -1
@@ -1,4 +1,4 @@ -# FIXME - flat unions should not be empty +# flat unions cannot be empty { 'enum': 'Empty', 'data': [ ] } { 'struct': 'Base', 'data': { 'type': 'Empty' } } { 'union': 'Union', 'base': 'Base', 'discriminator': 'type', 'data': { } }
tests/qapi-schema/flat-union-empty.out +0 -7
@@ -1,7 +0,0 @@ -object :empty -object Base - member type: Empty optional=False -enum Empty [] -object Union - base Base - tag type
tests/qapi-schema/union-empty.err +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/union-empty.json:2: Union 'Union' cannot have empty 'data'
tests/qapi-schema/union-empty.exit +1 -1
@@ -1 +1 @@ -0 +1
tests/qapi-schema/union-empty.json +1 -1
@@ -1,2 +1,2 @@ -# FIXME - unions should not be empty +# unions cannot be empty { 'union': 'Union', 'data': { } }
tests/qapi-schema/union-empty.out +0 -4
@@ -1,4 +0,0 @@ -object :empty -object Union - tag type -enum UnionKind []
Signature · 1 line
2.4.3
PATCH v5 38/46 qapi: Drop useless 'data' member of unions
In reply to Eric BlakeNow that we no longer have any clients of the 'void *data' member injected into unions, we can drop it. Update the testsuite to drop the negative test union-clash2, and replace it with a positive test in qapi-schema-test that proves that we no longer have a name collision.
--- scripts/qapi-types.py | 9 --------- tests/Makefile | 1 - tests/qapi-schema/qapi-schema-test.json | 2 +- tests/qapi-schema/qapi-schema-test.out | 4 ++-- tests/qapi-schema/union-clash2.err | 0 tests/qapi-schema/union-clash2.exit | 1 - tests/qapi-schema/union-clash2.json | 3 --- tests/qapi-schema/union-clash2.out | 7 ------- 8 files changed, 3 insertions(+), 24 deletions(-) delete mode 100644 tests/qapi-schema/union-clash2.err delete mode 100644 tests/qapi-schema/union-clash2.exit delete mode 100644 tests/qapi-schema/union-clash2.json delete mode 100644 tests/qapi-schema/union-clash2.out
scripts/qapi-types.py +0 -9
@@ -116,17 +116,8 @@ struct %(c_name)s { c_type=c_name(variants.tag_member.type.name)) tag_name = variants.tag_member.name - # FIXME: What purpose does data serve, besides preventing a union that - # has a branch named 'data'? We use it in qapi-visit.py to decide - # whether to bypass the switch statement if visiting the discriminator - # failed; but since we 0-initialize structs, and cannot tell what - # branch of the union is in use if the discriminator is invalid, there - # should not be any data leaks even without a data pointer. Or, if - # 'data' is merely added to guarantee we don't have an empty union, - # shouldn't we enforce that at .json parse time? ret += mcgen(''' union { /* union tag is @%(c_name)s */ - void *data; ''', c_name=c_name(tag_name))
tests/Makefile +0 -1
@@ -335,7 +335,6 @@ qapi-schema += unicode-str.json qapi-schema += union-bad-branch.json qapi-schema += union-base-no-discriminator.json qapi-schema += union-clash.json -qapi-schema += union-clash2.json qapi-schema += union-empty.json qapi-schema += union-invalid-base.json qapi-schema += union-max.json
tests/qapi-schema/qapi-schema-test.json +1 -1
@@ -90,7 +90,7 @@ 'number': ['number'], 'boolean': ['bool'], 'string': ['str'], - 'sizes': ['size'], + 'data': ['size'], 'any': ['any'] } } # testing commands
tests/qapi-schema/qapi-schema-test.out +2 -2
@@ -126,9 +126,9 @@ object UserDefNativeListUnion case number: :obj-numberList-wrapper case boolean: :obj-boolList-wrapper case string: :obj-strList-wrapper - case sizes: :obj-sizeList-wrapper + case data: :obj-sizeList-wrapper case any: :obj-anyList-wrapper -enum UserDefNativeListUnionKind ['integer', 's8', 's16', 's32', 's64', 'u8', 'u16', 'u32', 'u64', 'number', 'boolean', 'string', 'sizes', 'any'] +enum UserDefNativeListUnionKind ['integer', 's8', 's16', 's32', 's64', 'u8', 'u16', 'u32', 'u64', 'number', 'boolean', 'string', 'data', 'any'] object UserDefOne base UserDefZero member string: str optional=False
tests/qapi-schema/union-clash2.err deleted +0 -0
tests/qapi-schema/union-clash2.exit deleted +0 -1
@@ -1 +0,0 @@ -0
tests/qapi-schema/union-clash2.json deleted +0 -3
@@ -1,3 +0,0 @@ -# FIXME - a union branch named 'data' collides with generated C code -{ 'union': 'TestUnion', - 'data': { 'data': 'int' } }
tests/qapi-schema/union-clash2.out deleted +0 -7
@@ -1,7 +0,0 @@ -object :empty -object :obj-int-wrapper - member data: int optional=False -object TestUnion - tag type - case data: :obj-int-wrapper -enum TestUnionKind ['data']
Signature · 1 line
2.4.3
PATCH v5 39/46 qapi: Plumb in 'box' to qapi generator lower levels
In reply to Eric BlakeA future patch will add support for passing a qapi union type as the 'data' of a command. But to do that, the user function for implementing the command, as called by the generated marshal command, must take the corresponding C struct as a single boxed pointer, rather than a breakdown into one parameter per member. This patch adds the internal plubming of a 'box' flag associated with each command and event. For this patch, no behavior changes, other than the testsuite outputting the value of the new flag (always False for now).
--- scripts/qapi-commands.py | 63 +++++++++++++++++++-------------- scripts/qapi-event.py | 34 ++++++++++-------- scripts/qapi-introspect.py | 4 +-- scripts/qapi.py | 51 +++++++++++++++----------- tests/qapi-schema/args-member-array.out | 2 +- tests/qapi-schema/event-case.out | 1 + tests/qapi-schema/ident-with-escape.out | 2 +- tests/qapi-schema/indented-expr.out | 4 +-- tests/qapi-schema/qapi-schema-test.out | 17 +++++---- tests/qapi-schema/returns-int.out | 2 +- tests/qapi-schema/test-qapi.py | 8 +++-- 11 files changed, 111 insertions(+), 77 deletions(-)
scripts/qapi-commands.py +36 -27
@@ -16,24 +16,27 @@ from qapi import * import re -def gen_command_decl(name, arg_type, ret_type): +def gen_command_decl(name, arg_type, box, ret_type): return mcgen(''' %(c_type)s qmp_%(c_name)s(%(params)s); ''', c_type=(ret_type and ret_type.c_type()) or 'void', c_name=c_name(name), - params=gen_params(arg_type, 'Error **errp')) + params=gen_params(arg_type, box, 'Error **errp')) -def gen_call(name, arg_type, ret_type): +def gen_call(name, arg_type, box, ret_type): ret = '' argstr = '' - if arg_type: - for memb in arg_type.members: - if memb.optional: - argstr += 'has_%s, ' % c_name(memb.name) - argstr += '%s, ' % c_name(memb.name) + if box: + assert False # not implemented + else: + if arg_type: + for memb in arg_type.members: + if memb.optional: + argstr += 'has_%s, ' % c_name(memb.name) + argstr += '%s, ' % c_name(memb.name) lhs = '' if ret_type:
@@ -56,7 +59,7 @@ qmp_marshal_output_%(c_name)s(retval, ret, &err); return ret -def gen_marshal_vars(arg_type, ret_type): +def gen_marshal_vars(arg_type, box, ret_type): ret = mcgen(''' Error *err = NULL; ''')
@@ -76,18 +79,21 @@ QapiDeallocVisitor *md; Visitor *v; ''') - for memb in arg_type.members: - if memb.optional: - ret += mcgen(''' + if box: + assert False # not implemented + else: + for memb in arg_type.members: + if memb.optional: + ret += mcgen(''' bool has_%(c_name)s = false; ''', - c_name=c_name(memb.name)) - ret += mcgen(''' + c_name=c_name(memb.name)) + ret += mcgen(''' %(c_type)s %(c_name)s = %(c_null)s; ''', - c_name=c_name(memb.name), - c_type=memb.type.c_type(), - c_null=memb.type.c_null()) + c_name=c_name(memb.name), + c_type=memb.type.c_type(), + c_null=memb.type.c_null()) ret += '\n' else: ret += mcgen('''
@@ -99,7 +105,7 @@ bool has_%(c_name)s = false; return ret -def gen_marshal_input_visit(arg_type, dealloc=False): +def gen_marshal_input_visit(arg_type, box, dealloc=False): ret = '' if not arg_type:
@@ -120,7 +126,10 @@ v = qapi_dealloc_get_visitor(md); v = qmp_input_get_visitor(mi); ''') - ret += gen_visit_fields(arg_type.members, '', False, errarg) + if box: + assert False # not implemented + else: + ret += gen_visit_fields(arg_type.members, '', False, errarg) if dealloc: ret += mcgen('''
@@ -173,7 +182,7 @@ def gen_marshal_decl(name): proto=gen_marshal_proto(name)) -def gen_marshal(name, arg_type, ret_type): +def gen_marshal(name, arg_type, box, ret_type): ret = mcgen(''' %(proto)s
@@ -181,9 +190,9 @@ def gen_marshal(name, arg_type, ret_type): ''', proto=gen_marshal_proto(name)) - ret += gen_marshal_vars(arg_type, ret_type) - ret += gen_marshal_input_visit(arg_type) - ret += gen_call(name, arg_type, ret_type) + ret += gen_marshal_vars(arg_type, box, ret_type) + ret += gen_marshal_input_visit(arg_type, box) + ret += gen_call(name, arg_type, box, ret_type) if re.search('^ *goto out;', ret, re.MULTILINE): ret += mcgen('''
@@ -193,7 +202,7 @@ out: ret += mcgen(''' error_propagate(errp, err); ''') - ret += gen_marshal_input_visit(arg_type, dealloc=True) + ret += gen_marshal_input_visit(arg_type, box, dealloc=True) ret += mcgen(''' } ''')
@@ -250,16 +259,16 @@ class QAPISchemaGenCommandVisitor(QAPISchemaVisitor): self._visited_ret_types = None def visit_command(self, name, info, arg_type, ret_type, - gen, success_response): + gen, success_response, box): if not gen: return - self.decl += gen_command_decl(name, arg_type, ret_type) + self.decl += gen_command_decl(name, arg_type, box, ret_type) if ret_type and ret_type not in self._visited_ret_types: self._visited_ret_types.add(ret_type) self.defn += gen_marshal_output(ret_type) if middle_mode: self.decl += gen_marshal_decl(name) - self.defn += gen_marshal(name, arg_type, ret_type) + self.defn += gen_marshal(name, arg_type, box, ret_type) if not middle_mode: self._regy += gen_register_command(name, success_response)
scripts/qapi-event.py +20 -14
@@ -14,21 +14,21 @@ from qapi import * -def gen_event_send_proto(name, arg_type): +def gen_event_send_proto(name, arg_type, box): return 'void qapi_event_send_%(c_name)s(%(param)s)' % { 'c_name': c_name(name.lower()), - 'param': gen_params(arg_type, 'Error **errp')} + 'param': gen_params(arg_type, box, 'Error **errp')} -def gen_event_send_decl(name, arg_type): +def gen_event_send_decl(name, arg_type, box): return mcgen(''' %(proto)s; ''', - proto=gen_event_send_proto(name, arg_type)) + proto=gen_event_send_proto(name, arg_type, box)) -def gen_event_send(name, arg_type): +def gen_event_send(name, arg_type, box): ret = mcgen(''' %(proto)s
@@ -37,7 +37,7 @@ def gen_event_send(name, arg_type): Error *err = NULL; QMPEventFuncEmit emit; ''', - proto=gen_event_send_proto(name, arg_type)) + proto=gen_event_send_proto(name, arg_type, box)) if arg_type and arg_type.members: ret += mcgen('''
@@ -66,6 +66,12 @@ def gen_event_send(name, arg_type): v = qmp_output_get_visitor(qov); g_assert(v); +''') + + if box: + assert False # not implemented + else: + ret += mcgen(''' /* Fake visit, as if all members are under a structure */ visit_start_struct(v, NULL, "", "%(name)s", 0, &err); if (err) {
@@ -73,11 +79,11 @@ def gen_event_send(name, arg_type): } ''', - name=name) - push_indent() - ret += gen_visit_fields(arg_type.members, '', True, 'err') - pop_indent() - ret += mcgen(''' + name=name) + push_indent() + ret += gen_visit_fields(arg_type.members, '', True, 'err') + pop_indent() + ret += mcgen(''' visit_end_struct(v, &err); if (err) {
@@ -125,9 +131,9 @@ class QAPISchemaGenEventVisitor(QAPISchemaVisitor): self.defn += gen_enum_lookup(event_enum_name, self._event_names) self._event_names = None - def visit_event(self, name, info, arg_type): - self.decl += gen_event_send_decl(name, arg_type) - self.defn += gen_event_send(name, arg_type) + def visit_event(self, name, info, arg_type, box): + self.decl += gen_event_send_decl(name, arg_type, box) + self.defn += gen_event_send(name, arg_type, box) self._event_names.append(name)
scripts/qapi-introspect.py +2 -2
@@ -154,14 +154,14 @@ const char %(c_name)s[] = %(c_string)s; for m in variants.variants]}) def visit_command(self, name, info, arg_type, ret_type, - gen, success_response): + gen, success_response, box): arg_type = arg_type or self._schema.the_empty_object_type ret_type = ret_type or self._schema.the_empty_object_type self._gen_json(name, 'command', {'arg-type': self._use_type(arg_type), 'ret-type': self._use_type(ret_type)}) - def visit_event(self, name, info, arg_type): + def visit_event(self, name, info, arg_type, box): arg_type = arg_type or self._schema.the_empty_object_type self._gen_json(name, 'event', {'arg-type': self._use_type(arg_type)})
scripts/qapi.py +31 -20
126 lines not on this page · raw message
tests/qapi-schema/args-member-array.out +1 -1
@@ -6,4 +6,4 @@ enum abc ['a', 'b', 'c'] object def member array: abcList optional=False command okay :obj-okay-arg -> None - gen=True success_response=True + gen=True success_response=True box=False
tests/qapi-schema/event-case.out +1 -0
@@ -1,2 +1,3 @@ object :empty event oops None + box=False
tests/qapi-schema/ident-with-escape.out +1 -1
@@ -2,4 +2,4 @@ object :empty object :obj-fooA-arg member bar1: str optional=False command fooA :obj-fooA-arg -> None - gen=True success_response=True + gen=True success_response=True box=False
tests/qapi-schema/indented-expr.out +2 -2
@@ -1,5 +1,5 @@ object :empty command eins None -> None - gen=True success_response=True + gen=True success_response=True box=False command zwei None -> None - gen=True success_response=True + gen=True success_response=True box=False
tests/qapi-schema/qapi-schema-test.out +11 -6
@@ -72,9 +72,13 @@ alternate AltTwo case s: str case n: number event EVENT_A None + box=False event EVENT_B None + box=False event EVENT_C :obj-EVENT_C-arg + box=False event EVENT_D :obj-EVENT_D-arg + box=False enum EnumOne ['value1', 'value2', 'value3'] object EventStructOne member struct1: UserDefOne optional=False
@@ -159,6 +163,7 @@ object UserDefUnionBase object UserDefZero member integer: int optional=False event __ORG.QEMU_X-EVENT __org.qemu_x-Struct + box=False alternate __org.qemu_x-Alt case __org.qemu_x-branch: str case b: __org.qemu_x-Base
@@ -179,14 +184,14 @@ object __org.qemu_x-Union2 tag __org.qemu_x-member1 case __org.qemu_x-value: __org.qemu_x-Struct2 command __org.qemu_x-command :obj-__org.qemu_x-command-arg -> __org.qemu_x-Union1 - gen=True success_response=True + gen=True success_response=True box=False command guest-sync :obj-guest-sync-arg -> any - gen=True success_response=True + gen=True success_response=True box=False command user_def_cmd None -> None - gen=True success_response=True + gen=True success_response=True box=False command user_def_cmd1 :obj-user_def_cmd1-arg -> None - gen=True success_response=True + gen=True success_response=True box=False command user_def_cmd2 :obj-user_def_cmd2-arg -> UserDefTwo - gen=True success_response=True + gen=True success_response=True box=False command user_def_cmd3 :obj-user_def_cmd3-arg -> int - gen=True success_response=True + gen=True success_response=True box=False
tests/qapi-schema/returns-int.out +1 -1
@@ -1,3 +1,3 @@ object :empty command guest-get-time None -> int - gen=True success_response=True + gen=True success_response=True box=False
tests/qapi-schema/test-qapi.py +5 -3
@@ -36,13 +36,15 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): self._print_variants(variants) def visit_command(self, name, info, arg_type, ret_type, - gen, success_response): + gen, success_response, box): print 'command %s %s -> %s' % \ (name, arg_type and arg_type.name, ret_type and ret_type.name) - print ' gen=%s success_response=%s' % (gen, success_response) + print ' gen=%s success_response=%s box=%s' % (gen, success_response, + box) - def visit_event(self, name, info, arg_type): + def visit_event(self, name, info, arg_type, box): print 'event %s %s' % (name, arg_type and arg_type.name) + print ' box=%s' % box @staticmethod def _print_variants(variants):
Signature · 1 line
2.4.3
PATCH v5 40/46 qapi: Implement boxed structs for commands/events
In reply to Eric BlakeTurn on the ability to pass command and event arguments in a single boxed parameter. This patch merely tests the use of the feature on structs. With this patch, we still reject union types, and crash on { 'command':'foo', 'data': { anonymous...}, 'box':true }; that will be addressed in the next patch.
While this does not alter any QMP commands, it opens the door for clients to turn on boxing to receive a single pointer parameter of the overall struct instead of a series of parameters for each member of the struct; which will be useful for commands whose argument struct has lots of members. The generated code is slightly reorganized for convenience.
--- docs/qapi-code-gen.txt | 24 ++++++++++++++++++++++-- scripts/qapi-commands.py | 16 +++++++++++++--- scripts/qapi-event.py | 13 +++++++++++-- scripts/qapi.py | 11 ++++++++--- tests/qapi-schema/qapi-schema-test.json | 2 ++ tests/qapi-schema/qapi-schema-test.out | 4 ++++ tests/test-qmp-commands.c | 4 ++++ 7 files changed, 64 insertions(+), 10 deletions(-)
docs/qapi-code-gen.txt +22 -2
@@ -404,7 +404,7 @@ following example objects: === Commands === Usage: { 'command': STRING, '*data': COMPLEX-TYPE-NAME-OR-DICT, - '*returns': TYPE-NAME, + '*returns': TYPE-NAME, '*box': true, '*gen': false, '*success-response': false } Commands are defined by using a dictionary containing several members,
@@ -455,6 +455,17 @@ which would validate this Client JSON Protocol transaction: => { "execute": "my-second-command" } <= { "return": [ { "value": "one" }, { } ] } +By default, the generator creates a marshalling function that converts +an input QDict into a function call implemented by the user, and +declares a prototype for the user's function which has a parameter for +each member of the argument struct, including boolean arguments that +describe whether optional arguments were provided. But if the QAPI +description includes the key 'box' with the boolean value true, the +user call prototype will have only a single parameter for the overall +generated C structure. The 'box' key is required in order to use a +union as an input argument, since it is not possible to list all +members of the union as separate parameters. + In rare cases, QAPI cannot express a type-safe representation of a corresponding Client JSON Protocol command. You then have to suppress generation of a marshalling function by including a key 'gen' with
@@ -478,7 +489,8 @@ use of this field. === Events === -Usage: { 'event': STRING, '*data': COMPLEX-TYPE-NAME-OR-DICT } +Usage: { 'event': STRING, '*data': COMPLEX-TYPE-NAME-OR-DICT, + '*box': true } Events are defined with the keyword 'event'. It is not allowed to name an event 'MAX', since the generator also produces a C enumeration
@@ -499,6 +511,14 @@ Resulting in this JSON object: "data": { "b": "test string" }, "timestamp": { "seconds": 1267020223, "microseconds": 435656 } } +By default, the generator creates a C function that takes as +parameters each member of the argument struct and turns it into the +appropriate JSON Client event. But if the QAPI description includes +the key 'box' with the boolean value true, the event function will +have only a single parameter for the overall generated C structure. +The 'box' key is required in order to use a union as the data key, +since it is not possible to list all members of the union as separate +parameters. == Client JSON Protocol introspection ==
scripts/qapi-commands.py +13 -3
@@ -30,7 +30,7 @@ def gen_call(name, arg_type, box, ret_type): argstr = '' if box: - assert False # not implemented + argstr = 'arg, ' else: if arg_type: for memb in arg_type.members:
@@ -80,7 +80,10 @@ Visitor *v; ''') if box: - assert False # not implemented + ret += mcgen(''' +%(c_type)s arg = %(c_null)s; +''', + c_type=arg_type.c_type(), c_null=arg_type.c_null()) else: for memb in arg_type.members: if memb.optional:
@@ -115,6 +118,7 @@ def gen_marshal_input_visit(arg_type, box, dealloc=False): if dealloc: errarg = None + errparg = 'NULL' ret += mcgen(''' qmp_input_visitor_cleanup(mi); md = qapi_dealloc_visitor_new();
@@ -122,12 +126,18 @@ v = qapi_dealloc_get_visitor(md); ''') else: errarg = 'err' + errparg = '&err' ret += mcgen(''' v = qmp_input_get_visitor(mi); ''') if box: - assert False # not implemented + ret += mcgen(''' +visit_type_%(c_name)s(v, &arg, NULL, %(errp)s); + +''', + c_name=arg_type.c_name(), errp=errparg) + ret += gen_err_check(errarg) else: ret += gen_visit_fields(arg_type.members, '', False, errarg)
scripts/qapi-event.py +11 -2
@@ -40,10 +40,13 @@ def gen_event_send(name, arg_type, box): proto=gen_event_send_proto(name, arg_type, box)) if arg_type and arg_type.members: + if not box: + ret += mcgen(''' + QObject *obj; +''') ret += mcgen(''' QmpOutputVisitor *qov; Visitor *v; - QObject *obj; ''')
@@ -69,7 +72,13 @@ def gen_event_send(name, arg_type, box): ''') if box: - assert False # not implemented + ret += mcgen(''' + visit_type_%(c_name)s(v, &arg, NULL, &err); + if (err) { + goto out; + } +''', + c_name=arg_type.c_name(), name=arg_type.name) else: ret += mcgen(''' /* Fake visit, as if all members are under a structure */
scripts/qapi.py +8 -3
@@ -689,6 +689,10 @@ def check_keys(expr_elem, meta, required, optional=[]): raise QAPIExprError(info, "'%s' of %s '%s' should only use false value" % (key, meta, name)) + if key == 'box' and value is not True: + raise QAPIExprError(info, + "'%s' of %s '%s' should only use true value" + % (key, meta, name)) for key in required: if key not in expr: raise QAPIExprError(info,
@@ -720,10 +724,10 @@ def check_exprs(exprs): add_struct(expr, info) elif 'command' in expr: check_keys(expr_elem, 'command', [], - ['data', 'returns', 'gen', 'success-response']) + ['data', 'returns', 'gen', 'success-response', 'box']) add_name(expr['command'], info, 'command') elif 'event' in expr: - check_keys(expr_elem, 'event', [], ['data']) + check_keys(expr_elem, 'event', [], ['data', 'box']) add_name(expr['event'], info, 'event') else: raise QAPIExprError(expr_elem['info'],
@@ -1564,7 +1568,8 @@ def gen_params(arg_type, box, extra): ret = '' sep = '' if box: - assert False # not implemented + ret += '%s arg' % arg_type.c_type(is_param=True) + sep = ', ' else: assert not arg_type.variants for memb in arg_type.members:
tests/qapi-schema/qapi-schema-test.json +2 -0
@@ -103,6 +103,7 @@ 'returns': 'int' } # note: command name 'guest-sync' chosen to avoid "cannot use built-in" error { 'command': 'guest-sync', 'data': { 'arg': 'any' }, 'returns': 'any' } +{ 'command': 'boxed', 'box': true, 'data': 'UserDefZero' } # For testing integer range flattening in opts-visitor. The following schema # corresponds to the option format:
@@ -130,6 +131,7 @@ 'data': { '*a': 'int', '*b': 'UserDefOne', 'c': 'str' } } { 'event': 'EVENT_D', 'data': { 'a' : 'EventStructOne', 'b' : 'str', '*c': 'str', '*enum3': 'EnumOne' } } +{ 'event': 'EVENT_E', 'box': true, 'data': 'UserDefZero' } # test that we correctly compile downstream extensions { 'enum': '__org.qemu_x-Enum', 'data': [ '__org.qemu_x-value' ] }
tests/qapi-schema/qapi-schema-test.out +4 -0
@@ -79,6 +79,8 @@ event EVENT_C :obj-EVENT_C-arg box=False event EVENT_D :obj-EVENT_D-arg box=False +event EVENT_E UserDefZero + box=True enum EnumOne ['value1', 'value2', 'value3'] object EventStructOne member struct1: UserDefOne optional=False
@@ -185,6 +187,8 @@ object __org.qemu_x-Union2 case __org.qemu_x-value: __org.qemu_x-Struct2 command __org.qemu_x-command :obj-__org.qemu_x-command-arg -> __org.qemu_x-Union1 gen=True success_response=True box=False +command boxed UserDefZero -> None + gen=True success_response=True box=True command guest-sync :obj-guest-sync-arg -> any gen=True success_response=True box=False command user_def_cmd None -> None
tests/test-qmp-commands.c +4 -0
@@ -54,6 +54,10 @@ QObject *qmp_guest_sync(QObject *arg, Error **errp)return arg; } +void qmp_boxed (UserDefZero *arg,Error **errp) +{ +} + __org_qemu_x_Union1 *qmp___org_qemu_x_command(__org_qemu_x_EnumList *a, __org_qemu_x_StructList *b, __org_qemu_x_Union2 *c,
Signature · 1 line
2.4.3
PATCH v5 41/46 qapi: Support boxed unions
In reply to Eric BlakeThis patch completes support for boxed types, by allowing union types to be used when 'box':true is specified. It also avoids a python crash when attempting to use boxing on an anonymous type. While it was possible to support 'box':true on an empty event, it was easier to just reject missing 'data' for commands. Add some tests to cover new error messages, as well as enhancing qapi-schema-test to cover situations that are now valid.
--- scripts/qapi.py | 22 +++++++++++++++++----- tests/Makefile | 3 +++ tests/qapi-schema/args-bad-box.err | 1 + tests/qapi-schema/args-bad-box.exit | 1 + tests/qapi-schema/args-bad-box.json | 2 ++ tests/qapi-schema/args-bad-box.out | 0 tests/qapi-schema/args-box-anon.err | 1 + tests/qapi-schema/args-box-anon.exit | 1 + tests/qapi-schema/args-box-anon.json | 2 ++ tests/qapi-schema/args-box-anon.out | 0 tests/qapi-schema/args-box-empty.err | 1 + tests/qapi-schema/args-box-empty.exit | 1 + tests/qapi-schema/args-box-empty.json | 2 ++ tests/qapi-schema/args-box-empty.out | 0 tests/qapi-schema/args-union.err | 2 +- tests/qapi-schema/args-union.json | 3 +-- tests/qapi-schema/qapi-schema-test.json | 3 ++- tests/qapi-schema/qapi-schema-test.out | 4 +++- tests/test-qmp-commands.c | 4 ++++ 19 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 tests/qapi-schema/args-bad-box.err create mode 100644 tests/qapi-schema/args-bad-box.exit create mode 100644 tests/qapi-schema/args-bad-box.json create mode 100644 tests/qapi-schema/args-bad-box.out create mode 100644 tests/qapi-schema/args-box-anon.err create mode 100644 tests/qapi-schema/args-box-anon.exit create mode 100644 tests/qapi-schema/args-box-anon.json create mode 100644 tests/qapi-schema/args-box-anon.out create mode 100644 tests/qapi-schema/args-box-empty.err create mode 100644 tests/qapi-schema/args-box-empty.exit create mode 100644 tests/qapi-schema/args-box-empty.json create mode 100644 tests/qapi-schema/args-box-empty.out
scripts/qapi.py +17 -5
@@ -501,10 +501,18 @@ def check_type(expr_info, source, value, allow_array=False, def check_command(expr, expr_info): name = expr['command'] + box = expr.get('box', False) + args_meta = ['struct'] + if box: + args_meta += ['union'] + if not expr.get('data'): + raise QAPIExprError(expr_info, + "Use of 'box' requires 'data' for command '%s'" + % name) check_type(expr_info, "'data' for command '%s'" % name, - expr.get('data'), allow_dict=True, allow_optional=True, - allow_metas=['struct']) + expr.get('data'), allow_dict=not box, allow_optional=True, + allow_metas=args_meta) returns_meta = ['union', 'struct'] if name in returns_whitelist: returns_meta += ['built-in', 'alternate', 'enum']
@@ -516,13 +524,17 @@ def check_command(expr, expr_info): def check_event(expr, expr_info): global events name = expr['event'] + box = expr.get('box', False) + meta = ['struct'] + if box: + meta += ['union'] if name.upper() == 'MAX': raise QAPIExprError(expr_info, "Event name 'MAX' cannot be created") events.append(name) check_type(expr_info, "'data' for event '%s'" % name, - expr.get('data'), allow_dict=True, allow_optional=True, - allow_metas=['struct']) + expr.get('data'), allow_dict=not box, allow_optional=True, + allow_metas=meta) def check_union(expr, expr_info):
@@ -1567,7 +1579,7 @@ def gen_params(arg_type, box, extra): return extra ret = '' sep = '' - if box: + if box and arg_type.members: ret += '%s arg' % arg_type.c_type(is_param=True) sep = ', ' else:
tests/Makefile +3 -0
@@ -234,6 +234,9 @@ qapi-schema += args-alternate.json qapi-schema += args-any.json qapi-schema += args-array-empty.json qapi-schema += args-array-unknown.json +qapi-schema += args-bad-box.json +qapi-schema += args-box-anon.json +qapi-schema += args-box-empty.json qapi-schema += args-int.json qapi-schema += args-invalid.json qapi-schema += args-member-array-bad.json
tests/qapi-schema/args-bad-box.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/args-bad-box.json:2: 'box' of command 'foo' should only use true value
tests/qapi-schema/args-bad-box.exit new file +1 -0
@@ -0,0 +1 @@ +1
tests/qapi-schema/args-bad-box.json new file +2 -0
@@ -0,0 +1,2 @@ +# 'box' should only appear with value true +{ 'command': 'foo', 'box': false }
tests/qapi-schema/args-bad-box.out new file +0 -0
tests/qapi-schema/args-box-anon.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/args-box-anon.json:2: 'data' for command 'foo' should be a type name
tests/qapi-schema/args-box-anon.exit new file +1 -0
@@ -0,0 +1 @@ +1
tests/qapi-schema/args-box-anon.json new file +2 -0
@@ -0,0 +1,2 @@ +# 'box' can only be used with named types +{ 'command': 'foo', 'box': true, 'data': { 'string': 'str' } }
tests/qapi-schema/args-box-anon.out new file +0 -0
tests/qapi-schema/args-box-empty.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/args-box-empty.json:2: Use of 'box' requires 'data' for command 'foo'
tests/qapi-schema/args-box-empty.exit new file +1 -0
@@ -0,0 +1 @@ +1
tests/qapi-schema/args-box-empty.json new file +2 -0
@@ -0,0 +1,2 @@ +# 'box' can only be used with named types +{ 'command': 'foo', 'box': true }
tests/qapi-schema/args-box-empty.out new file +0 -0
tests/qapi-schema/args-union.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/args-union.json:4: 'data' for command 'oops' cannot use union type 'Uni' +tests/qapi-schema/args-union.json:3: 'data' for command 'oops' cannot use union type 'Uni'
tests/qapi-schema/args-union.json +1 -2
@@ -1,4 +1,3 @@ -# we do not allow union arguments -# TODO should we support this? +# use of union arguments requires 'box':true { 'union': 'Uni', 'data': { 'case1': 'int', 'case2': 'str' } } { 'command': 'oops', 'data': 'Uni' }
tests/qapi-schema/qapi-schema-test.json +2 -1
@@ -104,6 +104,7 @@ # note: command name 'guest-sync' chosen to avoid "cannot use built-in" error { 'command': 'guest-sync', 'data': { 'arg': 'any' }, 'returns': 'any' } { 'command': 'boxed', 'box': true, 'data': 'UserDefZero' } +{ 'command': 'boxed2', 'data': 'UserDefNativeListUnion', 'box': true } # For testing integer range flattening in opts-visitor. The following schema # corresponds to the option format:
@@ -124,7 +125,7 @@ { 'struct': 'EventStructOne', 'data': { 'struct1': 'UserDefOne', 'string': 'str', '*enum2': 'EnumOne' } } -{ 'event': 'EVENT_A' } +{ 'event': 'EVENT_A', 'box': true } { 'event': 'EVENT_B', 'data': { } } { 'event': 'EVENT_C',
tests/qapi-schema/qapi-schema-test.out +3 -1
@@ -72,7 +72,7 @@ alternate AltTwo case s: str case n: number event EVENT_A None - box=False + box=True event EVENT_B None box=False event EVENT_C :obj-EVENT_C-arg
@@ -189,6 +189,8 @@ command __org.qemu_x-command :obj-__org.qemu_x-command-arg -> __org.qemu_x-Union gen=True success_response=True box=False command boxed UserDefZero -> None gen=True success_response=True box=True +command boxed2 UserDefNativeListUnion -> None + gen=True success_response=True box=True command guest-sync :obj-guest-sync-arg -> any gen=True success_response=True box=False command user_def_cmd None -> None
tests/test-qmp-commands.c +4 -0
@@ -58,6 +58,10 @@ void qmp_boxed(UserDefZero *arg, Error **errp) { } +void qmp_boxed2 (UserDefNativeListUnion *arg,Error **errp) +{ +} + __org_qemu_x_Union1 *qmp___org_qemu_x_command(__org_qemu_x_EnumList *a, __org_qemu_x_StructList *b, __org_qemu_x_Union2 *c,
Signature · 1 line
2.4.3
PATCH v5 42/46 qapi: support implicit structs in OptsVisitor
In reply to Eric BlakeFrom: Kővágó, Zoltán <[email protected]>
They are required for flat unions (you still have to allocate the structs).
Message-Id: <88451f26df139c09b56b1525f3c5afeea43dd3db.1441627175.git.DirtY.iCE.hu@gmail.com>
--- qapi/opts-visitor.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
qapi/opts-visitor.c +15 -0
@@ -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.4.3
PATCH v5 43/46 qapi: Change Netdev into a flat union
In reply to Eric BlakeFrom: Kővágó, Zoltán <[email protected]>
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'Message-Id: <01a527fbf1a5de880091f98cf011616a78adeeee.1441627176.git.DirtY.iCE.hu@gmail.com>
Additional changes:
Rebase the patch on top of an earlier change from netdev->kind to netdev->type, so that tweak no longer needed here.
Rework so that NetdevLegacy doesn't pollute QMP command but is instead copied piecewise into the new Netdev, which means that NetClientOptions must still remain in qapi. Since legacy previously always rejected 'hubport', we can now make that explicit by having the two unions be slightly different; but that means we must manually map between the two structures.
--- 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/imx_fec.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 | 133 +++++++++++++++++++++++++-------------- 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 | 57 +++++++++++++---- 46 files changed, 230 insertions(+), 162 deletions(-)
hw/arm/musicpal.c +1 -1
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -1516,7 +1516,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
@@ -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
@@ -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
@@ -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/imx_fec.c +1 -1
@@ -651,7 +651,7 @@ static void imx_fec_cleanup(NetClientState *nc) }static NetClientInfo net_imx_fec_info = { - .type =NET_CLIENT_OPTIONS_KIND_NIC , + .type =NET_CLIENT_DRIVER_NIC , .size =sizeof (NICState), .can_receive = imx_fec_can_receive, .receive = imx_fec_receive,
hw/net/lan9118.c +1 -1
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -705,7 +705,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
@@ -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
@@ -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
@@ -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
@@ -3413,7 +3413,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
@@ -754,7 +754,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_nc, .receive = smc91c111_receive,
hw/net/spapr_llan.c +1 -1
@@ -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
@@ -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
@@ -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
@@ -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 ; }
@@ -1596,7 +1596,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
@@ -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
@@ -279,7 +279,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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -2994,8 +2994,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]); } }
@@ -3195,7 +3195,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;
@@ -3220,7 +3220,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;
@@ -3332,7 +3332,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;
@@ -3349,13 +3349,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
@@ -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->type ==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
@@ -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->type ==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
@@ -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->type ==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 +85 -48
302 lines not on this page · raw message
net/netmap.c +2 -2
@@ -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
@@ -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->type ==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
@@ -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->type ==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
@@ -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
@@ -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->type ==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->type ==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
@@ -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
@@ -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->type ==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 +44 -13
80 lines not on this page · raw message
Signature · 1 line
2.4.3
PATCH v5 44/46 net: Use correct type for bool flag
In reply to Eric Blakeis_netdev is only used as a bool, so make it one.
--- hw/usb/dev-network.c | 2 +- include/net/net.h | 2 +- net/net.c | 12 ++++++------ 3 files changed, 8 insertions(+), 8 deletions(-)
hw/usb/dev-network.c +1 -1
@@ -1392,7 +1392,7 @@ static USBDevice *usb_net_init(USBBus *bus, const char *cmdline)qemu_opt_set (opts,"type" ,"nic" , &error_abort);qemu_opt_set (opts,"model" ,"usb" , &error_abort); - idx =net_client_init (opts,0 , &local_err); + idx =net_client_init (opts, false, &local_err);if (local_err) {error_report_err (local_err);return NULL ;
include/net/net.h +1 -1
@@ -189,7 +189,7 @@ extern const char *host_net_devices[];extern const char *legacy_tftp_prefix;extern const char *legacy_bootp_filename; -int net_client_init (QemuOpts *opts,int is_netdev,Error **errp); +int net_client_init (QemuOpts *opts,bool is_netdev,Error **errp);int net_client_parse (QemuOptsList *opts_list,const char *str);int net_init_clients (void );void net_check_clients (void );
net/net.c +6 -6
@@ -911,7 +911,7 @@ static int (* const net_client_init_fun[NET_CLIENT_DRIVER_MAX])( }; -static int net_client_init1 (const void *object,int is_netdev,Error **errp) +static int net_client_init1 (const void *object,bool is_netdev,Error **errp) {Netdev legacy = {0 };const Netdev *netdev;
@@ -1021,7 +1021,7 @@ static void net_visit(Visitor *v, int is_netdev, void **object, Error **errp) } -int net_client_init (QemuOpts *opts,int is_netdev,Error **errp) +int net_client_init (QemuOpts *opts,bool is_netdev,Error **errp) {void *object =NULL ;Error *err =NULL ;
@@ -1083,7 +1083,7 @@ void hmp_host_net_add(Monitor *mon, const QDict *qdict)qemu_opt_set (opts,"type" , device, &error_abort); -net_client_init (opts,0 , &local_err); +net_client_init (opts, false, &local_err);if (local_err) {error_report_err (local_err);monitor_printf (mon,"adding host network device %s failed\n" , device);
@@ -1113,7 +1113,7 @@ void hmp_host_net_remove(Monitor *mon, const QDict *qdict)void netdev_add (QemuOpts *opts,Error **errp) { -net_client_init (opts,1 , errp); +net_client_init (opts, true, errp); }void qmp_netdev_add (QDict *qdict,QObject **ret,Error **errp)
@@ -1381,7 +1381,7 @@ static int net_init_client(void *dummy, QemuOpts *opts, Error **errp) {Error *local_err =NULL ; -net_client_init (opts,0 , &local_err); +net_client_init (opts, false, &local_err);if (local_err) {error_report_err (local_err);return -1 ;
@@ -1395,7 +1395,7 @@ static int net_init_netdev(void *dummy, QemuOpts *opts, Error **errp)Error *local_err =NULL ;int ret; - ret =net_client_init (opts,1 , &local_err); + ret =net_client_init (opts, true, &local_err);if (local_err) {error_report_err (local_err);return -1 ;
Signature · 1 line
2.4.3
PATCH v5 45/46 net: Complete qapi-fication of netdev_add
In reply to Eric BlakeWe finally have all the required pieces for doing a type-safe representation of netdev_add as a flat union, where the discriminator 'type' now selects which additional members may appear in the "arguments" JSON object sent over QMP, while making no changes to the set of previously-valid QMP commands that would work, and without breaking command line parsing.
--- include/net/net.h | 1 - net/net.c | 25 ++----------------------- qapi-schema.json | 15 +++------------ qmp-commands.hx | 2 +- 4 files changed, 6 insertions(+), 37 deletions(-)
include/net/net.h +0 -1
@@ -197,7 +197,6 @@ void net_cleanup(void);void hmp_host_net_add (Monitor *mon,const QDict *qdict);void hmp_host_net_remove (Monitor *mon,const QDict *qdict);void netdev_add (QemuOpts *opts,Error **errp); -void qmp_netdev_add (QDict *qdict,QObject **ret,Error **errp);int net_hub_id_for_client (NetClientState *nc,int *id);NetClientState *net_hub_port_find (int hub_id);
net/net.c +2 -23
@@ -1116,30 +1116,9 @@ void netdev_add(QemuOpts *opts, Error **errp)net_client_init (opts, true, errp); } -void qmp_netdev_add (QDict *qdict,QObject **ret,Error **errp) +void qmp_netdev_add (Netdev *netdev,Error **errp) { -Error *local_err =NULL ; -QemuOptsList *opts_list; -QemuOpts *opts; - - opts_list =qemu_find_opts_err ("netdev" , &local_err); -if (local_err) { - goto out; - } - - opts =qemu_opts_from_qdict (opts_list, qdict, &local_err); -if (local_err) { - goto out; - } - -netdev_add (opts, &local_err); -if (local_err) { -qemu_opts_del (opts); - goto out; - } - -out: -error_propagate (errp, local_err); +net_client_init1 (netdev, true, errp); }void qmp_netdev_del (const char *id,Error **errp)
qapi-schema.json +3 -12
@@ -2077,26 +2077,17 @@ # # Add a network backend. # -# @type: the type of network backend. Current valid values are 'user', 'tap', -# 'vde', 'socket', 'dump' and 'bridge' +# @type: the type of network backend; determines which additional arguments +# are valid. See Netdev documentation for more details. # # @id: the name of the new network backend # -# Additional arguments depend on the type. -# -# TODO This command effectively bypasses QAPI completely due to its -# "additional arguments" business. It shouldn't have been added to -# the schema in this form. It should be qapified properly, or -# replaced by a properly qapified command. -# # Since: 0.14.0 # # Returns: Nothing on success # If @type is not a valid network backend, DeviceNotFound ## -{ 'command': 'netdev_add', - 'data': {'type': 'str', 'id': 'str'}, - 'gen': false } # so we can get the additional arguments +{ 'command': 'netdev_add', 'data': 'Netdev', 'box': true } ## # @netdev_del:
qmp-commands.hx +1 -1
@@ -900,7 +900,7 @@ EQMP { .name = "netdev_add", .args_type = "netdev:O", - .mhandler.cmd_new = qmp_netdev_add, + .mhandler.cmd_new = qmp_marshal_netdev_add, }, SQMP
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v5 45/46] net: Complete qapi-fication of netdev_add
Quoted 6 lines · Eric Blake
We finally have all the required pieces for doing a type-safe representation of
netdev_addas a flat union, where the discriminator 'type' now selects which additional members may appear in the "arguments" JSON object sent over QMP, while making no changes to the set of previously-valid QMP commands that would work, and without breaking command line parsing.
Is this still type-unsafe like the old netdev_add (e.g. accepts a string for an integer)?
Paolo
Re: [Qemu-devel] [PATCH v5 45/46] net: Complete qapi-fication of netdev_add
Quoted 10 lines · Paolo Bonzini
Quoted 6 lines · Eric Blake
We finally have all the required pieces for doing a type-safe representation of
netdev_addas a flat union, where the discriminator 'type' now selects which additional members may appear in the "arguments" JSON object sent over QMP, while making no changes to the set of previously-valid QMP commands that would work, and without breaking command line parsing.
Quoted 2 lines
Is this still type-unsafe like the old
netdev_add(e.g. accepts a string for an integer)?
I did not address that yet; it still needs further patches to accept an integer as a port number. I can investigate what additional patches are needed along those lines, while still preserving back-compat to previously-accepted QMP command lines (it may require the use of an 'alternate' type that accepts both int and string). The main goal here was that the command line is unchanged, and that now the QMP command is introspectable, even if what introspection shows is ugly types.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v5 45/46] net: Complete qapi-fication of netdev_add
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
Quoted 11 lines · Eric Blake
Quoted 3 lines
Quoted 3 lines
Is this still type-unsafe like the old
netdev_add(e.g. accepts a string for an integer)?I did not address that yet; it still needs further patches to accept an integer as a port number. I can investigate what additional patches are needed along those lines, while still preserving back-compat to previously-accepted QMP command lines (it may require the use of an 'alternate' type that accepts both int and string). The main goal here was that the command line is unchanged, and that now the QMP command is introspectable, even if what introspection shows is ugly types.
This in fact is a laudable goal. However, while changing the command to
{ 'command': 'netdev_add', 'data': 'Netdev', 'box': true, 'gen': false }
for better introspection, you should keep 'gen':'false' and the manual implementation based on qemu_opts_from_qdict, otherwise you break backwards-compatibility.
Paolo
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
iQEcBAEBCAAGBQJWBXr0AAoJEL/70l94x66DJNUH/24lvns9MJpLv0ycT0+jrwVd BhlCBatRwISITCX+gRSL5kmC0UNeGUWUB6AaYeCxZtY+Z40lCcOakMf2ZvDOf+Iq 0CvrtXSjEzwf3DxUawso4bcBdQKg1Za1sQsvExGd84VbnsRr+HFKNclYhJGxbiG4 UNPvIFzd+mwod+i2RHooRY/CiDqYDSinlLlp4N6DqjjMQeiTcetJqfdsm6Kke9fg ntu/YEwlqcgGFSSDOdGG1YmSmWApUOw0gAzHt+Ufyy+I/M6Mzvn9OH6E3lQtghOy ovK230/8YIoIPBkWsRxYDp1LrmxarszMTqAWMuc3ALRxJSQ6GMrtgDby1ghw1W8= =akeC
-----END PGP SIGNATURE-----
Re: [Qemu-devel] [PATCH v5 45/46] net: Complete qapi-fication of netdev_add
Quoted 13 lines · Paolo Bonzini
Quoted 11 lines · Eric Blake
Quoted 3 lines
Quoted 3 lines
Is this still type-unsafe like the old
netdev_add(e.g. accepts a string for an integer)?I did not address that yet; it still needs further patches to accept an integer as a port number. I can investigate what additional patches are needed along those lines, while still preserving back-compat to previously-accepted QMP command lines (it may require the use of an 'alternate' type that accepts both int and string). The main goal here was that the command line is unchanged, and that now the QMP command is introspectable, even if what introspection shows is ugly types.
Quoted 7 lines
This in fact is a laudable goal. However, while changing the command to
{ 'command': '
netdev_add', 'data': 'Netdev', 'box': true, 'gen': false }for better introspection, you should keep 'gen':'false' and the manual implementation based on
qemu_opts_from_qdict, otherwise you break backwards-compatibility.
Non sequitur :)
We need to stay sufficiently backwards compatible somehow. 'gen' false is one possible solution. Liberal use of alternate types could be another. A special input visitor mode could be a third.
Since my review cursor is >30 patches behind this one, I don't have an opinion, yet.
Re: [Qemu-devel] [PATCH v5 45/46] net: Complete qapi-fication of netdev_add
Quoted 4 lines · Markus Armbruster
Quoted 4 lines
However, while changing the command to
Quoted 3 lines
{ 'command': '
netdev_add', 'data': 'Netdev', 'box': true, 'gen': false }
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
for better introspection, you should keep 'gen':'false' and the manual implementation based on
qemu_opts_from_qdict, otherwise you break backwards-compatibility.Non sequitur :)
We need to stay sufficiently backwards compatible somehow. 'gen' false is one possible solution. Liberal use of alternate types could be another. A special input visitor mode could be a third.
Agreed; my suggestion is the minimal change on top of this patch, actually undoing part of it. Any other approach should be done separately.
Paolo
Quoted 2 lines
Since my review cursor is >30 patches behind this one, I don't have an opinion, yet.
PATCH v5 46/46 qapi: Allow anonymous base for flat union
In reply to Eric BlakeRather than requiring all flat unions to explicitly create a separate base struct, we want to allow the qapi schema to specify the common fields via an inline dictionary. This is similar to how commands can specify inline types for the arguments.
Now that the feature is legal, we can drop the former flat-union-bad-base negative test, and instead change the positive tests in qapi-schema-test to use it.
--- docs/qapi-code-gen.txt | 28 ++++++++++++++-------------- scripts/qapi-commands.py | 2 +- scripts/qapi-event.py | 2 +- scripts/qapi-types.py | 2 +- scripts/qapi-visit.py | 15 +++++++++++---- scripts/qapi.py | 20 +++++++++++++------- tests/Makefile | 1 - tests/qapi-schema/flat-union-bad-base.err | 1 - tests/qapi-schema/flat-union-bad-base.exit | 1 - tests/qapi-schema/flat-union-bad-base.json | 13 ------------- tests/qapi-schema/flat-union-bad-base.out | 0 tests/qapi-schema/qapi-schema-test.json | 2 +- tests/qapi-schema/qapi-schema-test.out | 5 ++++- 13 files changed, 46 insertions(+), 46 deletions(-) delete mode 100644 tests/qapi-schema/flat-union-bad-base.err delete mode 100644 tests/qapi-schema/flat-union-bad-base.exit delete mode 100644 tests/qapi-schema/flat-union-bad-base.json delete mode 100644 tests/qapi-schema/flat-union-bad-base.out
docs/qapi-code-gen.txt +14 -14
@@ -278,7 +278,7 @@ better than open-coding the field to be type 'str'. === Union types === Usage: { 'union': STRING, 'data': DICT } -or: { 'union': STRING, 'data': DICT, 'base': STRUCT-NAME, +or: { 'union': STRING, 'data': DICT, 'base': STRUCT-NAME-OR-DICT, 'discriminator': ENUM-MEMBER-OF-BASE } Union types are used to let the user choose between several different
@@ -314,13 +314,16 @@ an implicit C enum 'NameKind' is created, corresponding to the union the union can be named 'max', as this would collide with the implicit enum. The value for each branch can be of any type. -A flat union definition specifies a struct as its base, and -avoids nesting on the wire. All branches of the union must be -complex types, and the top-level fields of the union dictionary on -the wire will be combination of fields from both the base type and the -appropriate branch type (when merging two dictionaries, there must be -no keys in common). The 'discriminator' field must be the name of an -enum-typed member of the base struct. +A flat union definition avoids nesting on the wire, and specifies a +set of common fields that occur in all variants of the union. The +'base' key must specifiy either a type name (the type must be a +struct, not a union), or a dictionary representing an anonymous type. +All branches of the union must be complex types, and the top-level +fields of the union dictionary on the wire will be combination of +fields from both the base type and the appropriate branch type (when +merging two dictionaries, there must be no keys in common). The +'discriminator' field must be the name of an enum-typed member of the +base struct. The following example enhances the above simple union example by adding a common field 'readonly', renaming the discriminator to
@@ -328,10 +331,8 @@ something more applicable, and reducing the number of {} required on the wire: { 'enum': 'BlockdevDriver', 'data': [ 'file', 'qcow2' ] } - { 'struct': 'BlockdevCommonOptions', - 'data': { 'driver': 'BlockdevDriver', 'readonly': 'bool' } } { 'union': 'BlockdevOptions', - 'base': 'BlockdevCommonOptions', + 'base': { 'driver': 'BlockdevDriver', 'readonly': 'bool' }, 'discriminator': 'driver', 'data': { 'file': 'FileOptions', 'qcow2': 'Qcow2Options' } }
@@ -349,7 +350,7 @@ code generator can ensure that branches exist for all values of the enum (although the order of the keys need not match the declaration of the enum). In the resulting generated C data types, a flat union is represented as a struct with the base member fields included directly, -and then a union of structures for each branch of the struct. +and then a union of pointers to structures for each branch of the struct. A simple union can always be re-written as a flat union where the base class has a single member named 'type', and where each branch of the
@@ -360,10 +361,9 @@ union has a struct with a single member named 'data'. That is, is identical on the wire to: { 'enum': 'Enum', 'data': ['one', 'two'] } - { 'struct': 'Base', 'data': { 'type': 'Enum' } } { 'struct': 'Branch1', 'data': { 'data': 'str' } } { 'struct': 'Branch2', 'data': { 'data': 'int' } } - { 'union': 'Flat', 'base': 'Base', 'discriminator': 'type', + { 'union': 'Flat': 'base': { 'type': 'Enum' }, 'discriminator': 'type', 'data': { 'one': 'Branch1', 'two': 'Branch2' } }
scripts/qapi-commands.py +1 -1
@@ -139,7 +139,7 @@ visit_type_%(c_name)s(v, &arg, NULL, %(errp)s); c_name=arg_type.c_name(), errp=errparg) ret += gen_err_check(errarg) else: - ret += gen_visit_fields(arg_type.members, '', False, errarg) + ret += gen_visit_fields(arg_type.members, '', False, errarg, 'out') if dealloc: ret += mcgen('''
scripts/qapi-event.py +1 -1
@@ -90,7 +90,7 @@ def gen_event_send(name, arg_type, box): ''', name=name) push_indent() - ret += gen_visit_fields(arg_type.members, '', True, 'err') + ret += gen_visit_fields(arg_type.members, '', True, 'err', 'out') pop_indent() ret += mcgen('''
scripts/qapi-types.py +1 -1
@@ -102,7 +102,7 @@ struct %(c_name)s { ''', c_name=c_name(name)) if base: - ret += gen_struct_fields([], base) + ret += gen_struct_fields([], base, base.is_implicit()) tag_name = variants.tag_member.name elif not variants.tag_member: ret += mcgen('''
scripts/qapi-visit.py +11 -4
@@ -98,7 +98,7 @@ if (err) { ''', c_type=base.c_name()) - ret += gen_visit_fields(members, '(*obj)->', False, 'err') + ret += gen_visit_fields(members, '(*obj)->', False, 'err', 'out') pop_indent() if base or members:
@@ -244,7 +244,7 @@ out: def gen_visit_union(name, base, variants): ret = '' - if base: + if base and not base.is_implicit(): ret += gen_visit_struct_fields(base.name, base.base, base.local_members)
@@ -272,10 +272,17 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error tag_key = variants.tag_member.name if base: - ret += mcgen(''' + if not base.is_implicit(): + ret += mcgen(''' visit_type_%(c_name)s_fields(v, (%(c_name)s **)obj, &err); ''', - c_name=c_name(base.name)) + c_name=c_name(base.name)) + else: + push_indent() + ret += gen_visit_fields(base.members, '(*obj)->', False, + 'err', 'out_obj') + pop_indent() + tag_key = variants.tag_member.name else: ret += mcgen(''' visit_type_%(c_type)s(v, &(*obj)->%(c_name)s, "%(name)s", &err);
scripts/qapi.py +13 -7
@@ -317,6 +317,8 @@ class QAPISchemaParser(object): def find_base_fields(base): + if isinstance(base, dict): + return base base_struct_define = find_struct(base) if not base_struct_define: return None
@@ -557,9 +559,9 @@ def check_union(expr, expr_info): # Else, it's a flat union. else: - # The object must have a string member 'base'. + # The object must have a string or dictionary 'base'. check_type(expr_info, "'base' for union '%s'" % name, - base, allow_metas=['struct']) + base, allow_dict=True, allow_metas=['struct']) if not base: raise QAPIExprError(expr_info, "Flat union '%s' must have a valid base"
@@ -1277,6 +1279,10 @@ class QAPISchema(object): base = expr.get('base') tag_name = expr.get('discriminator') tag_enum = None + if isinstance(base, dict): + base = self._make_implicit_object_type(name, info, 'base', + self._make_members(base, + name)) if tag_name: variants = [self._make_variant(key, value, name) for (key, value) in data.iteritems()]
@@ -1596,18 +1602,18 @@ def gen_params(arg_type, box, extra): return ret -def gen_err_check(err): +def gen_err_check(err, label='out'): if not err: return '' return mcgen(''' if (%(err)s) { - goto out; + goto %(label)s; } ''', - err=err) + err=err, label=label) -def gen_visit_fields(members, prefix, need_cast, errarg): +def gen_visit_fields(members, prefix, need_cast, errarg, label): ret = '' if errarg: errparg = '&' + errarg
@@ -1634,7 +1640,7 @@ visit_type_%(c_type)s(v, %(cast)s&%(prefix)s%(c_name)s, "%(name)s", %(errp)s); c_type=memb.type.c_name(), prefix=prefix, cast=cast, c_name=c_name(memb.name), name=memb.name, errp=errparg) - ret += gen_err_check(errarg) + ret += gen_err_check(errarg, label) if memb.optional: pop_indent()
tests/Makefile +0 -1
@@ -275,7 +275,6 @@ qapi-schema += event-case.json qapi-schema += event-max.json qapi-schema += event-nest-struct.json qapi-schema += flat-union-array-branch.json -qapi-schema += flat-union-bad-base.json qapi-schema += flat-union-bad-discriminator.json qapi-schema += flat-union-base-any.json qapi-schema += flat-union-base-union.json
tests/qapi-schema/flat-union-bad-base.err deleted +0 -1
@@ -1 +0,0 @@ -tests/qapi-schema/flat-union-bad-base.json:9: 'base' for union 'TestUnion' should be a type name
tests/qapi-schema/flat-union-bad-base.exit deleted +0 -1
@@ -1 +0,0 @@ -1
tests/qapi-schema/flat-union-bad-base.json deleted +0 -13
@@ -1,13 +0,0 @@ -# we require the base to be an existing struct -# TODO: should we allow an anonymous inline base type? -{ 'enum': 'TestEnum', - 'data': [ 'value1', 'value2' ] } -{ 'struct': 'TestTypeA', - 'data': { 'string': 'str' } } -{ 'struct': 'TestTypeB', - 'data': { 'integer': 'int' } } -{ 'union': 'TestUnion', - 'base': { 'enum1': 'TestEnum', 'kind': 'str' }, - 'discriminator': 'enum1', - 'data': { 'value1': 'TestTypeA', - 'value2': 'TestTypeB' } }
tests/qapi-schema/flat-union-bad-base.out deleted +0 -0
tests/qapi-schema/qapi-schema-test.json +1 -1
@@ -56,7 +56,7 @@ # this variant of UserDefFlatUnion defaults to a union that uses fields with # allocated types to test corner cases in the cleanup/dealloc visitor { 'union': 'UserDefFlatUnion2', - 'base': 'UserDefUnionBase', + 'base': { 'string': 'str', 'enum1': 'EnumOne' }, 'discriminator': 'enum1', 'data': { 'value1' : 'UserDefC', # intentional forward reference 'value2' : 'UserDefB',
tests/qapi-schema/qapi-schema-test.out +4 -1
@@ -8,6 +8,9 @@ object :obj-EVENT_D-arg member b: str optional=False member c: str optional=True member enum3: EnumOne optional=True +object :obj-UserDefFlatUnion2-base + member string: str optional=False + member enum1: EnumOne optional=False object :obj-__org.qemu_x-command-arg member a: __org.qemu_x-EnumList optional=False member b: __org.qemu_x-StructList optional=False
@@ -113,7 +116,7 @@ object UserDefFlatUnion case value2: UserDefB case value3: UserDefB object UserDefFlatUnion2 - base UserDefUnionBase + base :obj-UserDefFlatUnion2-base tag enum1 case value1: UserDefC case value2: UserDefB
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v5 46/46] qapi: Allow anonymous base for flat union
Quoted 36 lines · Eric Blake
Rather than requiring all flat unions to explicitly create a separate base struct, we want to allow the qapi schema to specify the common fields via an inline dictionary. This is similar to how commands can specify inline types for the arguments.
Now that the feature is legal, we can drop the former flat-union-bad-base negative test, and instead change the positive tests in qapi-schema-test to use it.
Signed-off-by Eric Blake <[email protected]>---
+++
b/scripts/qapi-visit.pyscripts/qapi-visit.py +9
-2@@ -272,10 +272,17 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error tag_key = variants.tag_member.name if base: - ret += mcgen(''' + if not base.is_implicit(): + ret += mcgen(''' visit_type_%(c_name)s_fields(v, (%(c_name)s **)obj, &err); ''', - c_name=c_name(base.name)) + c_name=c_name(base.name)) + else: + push_indent() + ret += gen_visit_fields(base.members, '(*obj)->', False, + 'err', 'out_obj') + pop_indent() + tag_key = variants.tag_member.name else: ret += mcgen(''' visit_type_%(c_type)s(v, &(*obj)->%(c_name)s, "%(name)s", &err);''',
Quoted 6 lines
c_type=variants.tag_member.type.c_name(),
c_name=c_name(tag_key), name=tag_key)
ret += mcgen('''
if (err) {
goto out_obj;
}Whoops - this results in two back-to-back 'if (err)' clauses in the generated output when an implicit base is used (harmless, other than wasted effort). I'll avoid the duplication in v6.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
I think the first ten patches are a about as large a bite as we can chew and commit quickly. If you split them off, I can try to get them in quickly, and in parallel continue reviewing the rest of your series.
Quoted 3 lines · Markus Armbruster
I think the first ten patches are a about as large a bite as we can chew and commit quickly. If you split them off, I can try to get them in quickly, and in parallel continue reviewing the rest of your series.
Done. Well, the first 10 patches turned into 16 on the respin, but hopefully easier to chew.
http://repo.or.cz/qemu/ericb.git/shortlog/refs/tags/qapi-cleanupv6a
[I'd also post a mail archives link, but it looks like the list server is having some ugly delays in sending mail from lots of people today, so I don't have a link yet]
I guess you can continue reviewing v5 textually, even though it will be hard to actually apply many of those patches atop v6 subset A, while waiting for me to rebase patches based on comments so far. I've got enough churn locally rebasing things already that it may be the better part of a day before I post the rest of my v6 series subset B and update my public git repo (I know Marc-Andre at least is basing his patches on my public repo, so I'm trying to avoid rewinding that branch to anything that has less functionality than v5 had)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org