qapi: introduce strList and visit_type_strList()
PATCH RESEND 1/2 qapi: introduce strList and visit_type_strList()
Currently we can only use ['String'] to add string to a list, it contains some additional JSON structure.
"multicast": [
{
"str": "01:80:c2:00:00:21"
},
{
"str": "00:00:00:00:00:00"
}
]This patch introdued strList, we can use ['str']
"multicast": [
"01:00:5e:00:00:01",
"33:33:ff:12:34:57"
]---
I used an _ugly_ "#ifndef" to limit it only be defined in qapi-types.h. do you have some suggestion to fix it?
--- include/qapi/visitor.h | 2 ++ qapi/qapi-visit-core.c | 23 +++++++++++++++++++++++ scripts/qapi-types.py | 8 ++++++++ 3 files changed, 33 insertions(+), 0 deletions(-)
include/qapi/visitor.h +2 -0
@@ -50,6 +50,8 @@ void visit_type_int64(Visitor *v, int64_t *obj, const char *name, Error **errp);void visit_type_size (Visitor *v,uint64_t *obj,const char *name,Error **errp);void visit_type_bool (Visitor *v,bool *obj,const char *name,Error **errp);void visit_type_str (Visitor *v,char **obj,const char *name,Error **errp); +void visit_type_strList (Visitor *m,strList ** obj,const char *name, +Error **errp);void visit_type_number (Visitor *v,double *obj,const char *name,Error **errp);#endif
qapi/qapi-visit-core.c +23 -0
@@ -257,6 +257,29 @@ void visit_type_str(Visitor *v, char **obj, const char *name, Error **errp) } } +void visit_type_strList (Visitor *m,strList ** obj,const char *name, +Error **errp) +{ +GenericList *i, **prev = (GenericList **)obj; +Error *err =NULL ; + +if (!error_is_set (errp)) { +visit_start_list (m, name, &err); +if (!err) { +for (; (i =visit_next_list (m, prev, &err)) !=NULL ; prev = &i) { +strList *native_i = (strList *)i; +visit_type_str (m, &native_i->value,NULL , &err); + } +error_propagate (errp, err); + err =NULL ; + +/* Always call end_list if start_list succeeded. */ +visit_end_list (m, &err); + } +error_propagate (errp, err); + } +} +void visit_type_number (Visitor *v,double *obj,const char *name,Error **errp) {if (!error_is_set (errp)) {
scripts/qapi-types.py +8 -0
@@ -276,6 +276,14 @@ fdecl.write(mcgen(''' #include <stdbool.h> #include <stdint.h> +#ifndef QGA_QAPI_TYPES_H +typedef struct strList +{ + char *value; + struct strList *next; +} strList; +#endif + ''', guard=guardname(h_file)))
Signature · 1 line
1.7.1
PATCH 2/2 monitor: introduce query-config-schema command
Libvirt has no way to probe if an option or property is supported, This patch introdues a new qmp command to query configuration schema information. hmp command isn't added because it's not needed.
--- qapi-schema.json | 29 +++++++++++++++++++++++++++++ qmp-commands.hx | 40 ++++++++++++++++++++++++++++++++++++++++ util/qemu-config.c | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+), 0 deletions(-)
qapi-schema.json +29 -0
@@ -3505,3 +3505,32 @@ '*asl_compiler_rev': 'uint32', '*file': 'str', '*data': 'str' }} + +## +# @ConfigSchemaInfo: +# +# Configration schema information. +# +# @option: option name +# +# @params: parameters strList of one option +# +# Since 1.5 +## +{ 'type': 'ConfigSchemaInfo', 'data': {'option': 'str', 'params': ['str']} } + +## +# @query-config-schema +# +# Query configuration schema information of options +# +# @option: #optional option name +# +# Returns: returns @ConfigSchemaInfo if option is assigned, returns +# @ConfigSchemaInfo list if no option is assigned, returns an error +# QERR_INVALID_OPTION_GROUP if assigned option doesn't exist. +# +# Since 1.5 +## +{'command': 'query-config-schema', 'data': {'*option': 'str'}, + 'returns': ['ConfigSchemaInfo']}
qmp-commands.hx +40 -0
@@ -2414,6 +2414,46 @@ EQMP .args_type = "", .mhandler.cmd_new = qmp_marshal_input_query_uuid, }, +SQMP +query-config-schema +------------ + +Show configuration schema. + +Return configuration schema of one option if option is assigned, return +configuration schema list of all options if no option is assigned. return +an error QERR_INVALID_OPTION_GROUP if assigned option doesn't exist. + +- "option": option name +- "params": parameters string list of one option + +Example: + +-> {"execute": "query-config-schema", "arguments" : {"option": "boot-opts"}} +<- { + "return": [ + { + "params": [ + "strict", + "reboot-timeout", + "splash-time", + "splash", + "menu", + "once", + "order" + ], + "option": "boot-opts" + } + ] + } + +EQMP + + { + .name = "query-config-schema", + .args_type = "option:s?", + .mhandler.cmd_new = qmp_marshal_input_query_config_schema, + }, SQMP query-migrate
util/qemu-config.c +40 -0
@@ -5,6 +5,7 @@#include "qapi/qmp/qerror.h" #include "hw/qdev.h" #include "qapi/error.h" +#include "qmp-commands.h" static QemuOptsList *vm_config_groups[32 ];
@@ -37,6 +38,45 @@ QemuOptsList *qemu_find_opts(const char *group)return ret; } +ConfigSchemaInfoList *qmp_query_config_schema (bool has_option, +const char *option,Error **errp) +{ +ConfigSchemaInfoList *conf_list =NULL , *entry; +ConfigSchemaInfo *info; +strList *str_list =NULL , *str_entry; +int entries, i, j; + + entries =ARRAY_SIZE (vm_config_groups); + +for (i =0 ; i < entries; i++) { +if (vm_config_groups[i] !=NULL && + (!has_option || !strcmp (option, vm_config_groups[i]->name))) { + info =g_malloc0 (sizeof (*info)); + info->option =g_strdup (vm_config_groups[i]->name); + str_list =NULL ; + +for (j =0 ; vm_config_groups[i]->desc[j].name !=NULL ; j++) { + str_entry =g_malloc0 (sizeof (*str_entry)); + str_entry->value =g_strdup (vm_config_groups[i]->desc[j].name); + str_entry->next = str_list; + str_list = str_entry; + } + + info->params = str_list; + entry =g_malloc0 (sizeof (*entry)); + entry->value = info; + entry->next = conf_list; + conf_list = entry; + } + } + +if (conf_list ==NULL ) { +error_set (errp,QERR_INVALID_OPTION_GROUP , option); + } + +return conf_list; +} +QemuOptsList *qemu_find_opts_err (const char *group,Error **errp) {return find_list (vm_config_groups, group, errp);
Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH 2/2] monitor: introduce query-config-schema command
Quoted 3 lines · Amos Kong
Libvirt has no way to probe if an option or property is supported, This patch introdues a new qmp command to query configuration schema information. hmp command isn't added because it's not needed.
Agreed that no HMP counterpart is needed. However, I don't think we have quite the right interface yet.
Quoted 17 lines
Signed-off-by Amos Kong <[email protected]>CC Osier Yang <[email protected]>CC Anthony Liguori <[email protected]>--- qapi-schema.json | 29 +++++++++++++++++++++++++++++ qmp-commands.hx | 40 ++++++++++++++++++++++++++++++++++++++++ util/qemu-config.c | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+), 0 deletions(-)qapi-schema.json +0
-0@@ -3505,3 +3505,32 @@ '*asl_compiler_rev': 'uint32', '*file': 'str',
qapi-schema.json line 3516
Quoted 10 lines
qapi-schema.json +9
-0'*data': 'str' }} + +## +# @ConfigSchemaInfo: +# +# Configration schema information. +# +# @option: option name +# +# @params: parameters strList of one option
Why just a strList? That only tells me option names. But we already know so much more than that - we know the type and the help string.
qapi-schema.json line 3520
Quoted 4 lines
qapi-schema.json +4
-0+# +# Since 1.5 +## +{ 'type': 'ConfigSchemaInfo', 'data': {'option': 'str', 'params': ['str']} }
I'd rather see an array of structs, more closely mirroring what include/qemu/option.h gives us:
# JSON representation of values of QEMUOptionParType, may grow in future { 'enum': 'ConfigParamType',
'data': [ 'flag', 'number', 'size', 'string' ] }
# JSON representation of QEMUOptionParameter, may grow in future # @help is optional if no text was present
{ 'type': 'ConfigParamInfo',
'data': { 'name': 'str', 'type': 'ConfigParamType', '*help':'str' } }
# Each command line option, and its list of parameters { 'type': 'ConfigSchemaInfo',
'data': { 'option':'str', 'params': ['ConfigParamInfo'] } }
And that means we no longer have ['str'], which bypasses the need for your patch 1/2.
qapi-schema.json line 3531
Quoted 11 lines
qapi-schema.json +11
-0+ +## +# @query-config-schema +# +# Query configuration schema information of options +# +# @option: #optional option name +# +# Returns: returns @ConfigSchemaInfo if option is assigned, returns +# @ConfigSchemaInfo list if no option is assigned, returns an error +# QERR_INVALID_OPTION_GROUP if assigned option doesn't exist.
That didn't read well. Also, QERR_INVALID_OPTION_GROUP is a generic error; we don't mention any other QERR_* names in qapi-schema.json. How about:
Returns: list of @ConfigSchemaInfo for all options (or for the given
@option). Returns an error if a given @option doesn't exist.
qapi-schema.json line 3536
Quoted 5 lines
qapi-schema.json +5
-0+# +# Since 1.5 +## +{'command': 'query-config-schema', 'data': {'*option': 'str'}, + 'returns': ['ConfigSchemaInfo']}
This part looks good.
Quoted 7 lines
qmp-commands.hx +0
-0@@ -2414,6 +2414,46 @@ EQMP .args_type = "", .mhandler.cmd_new = qmp_marshal_input_query_uuid,
qmp-commands.hx EQMP · line 2425
Quoted 10 lines
qmp-commands.hx +9
-0}, +SQMP +query-config-schema +------------ + +Show configuration schema. + +Return configuration schema of one option if option is assigned, return +configuration schema list of all options if no option is assigned. return +an error QERR_INVALID_OPTION_GROUP if assigned option doesn't exist.
Again, QERR_INVALID_OPTION_GROUP is not a defined error (it is shorthand for a specific message for a GenericError class).
Quoted 13 lines
qmp-commands.hx +13
-0+ +- "option": option name +- "params": parameters string list of one option + +Example: + +-> {"execute": "query-config-schema", "arguments" : {"option": "boot-opts"}} +<- { + "return": [ + { + "params": [ + "strict", + "reboot-timeout",
qmp-commands.hx EQMP · line 2448
Quoted 10 lines
qmp-commands.hx +10
-0+ "splash-time", + "splash", + "menu", + "once", + "order" + ], + "option": "boot-opts" + } + ] + }
Back to my desire for more structure, I'd like to see:
-> {"execute": "query-config-schema", "arguments" : {"option": "boot-opts"}}
<- {
"return": [
{
"params": [
{
"name": "strict",
"type": "string"
},
{
"name": "reboot-timeout",
"type": "string"
},
...
],
"option": "boot-opts"
}
]}
Another more interesting example, showing why the "type" and optional "help" fields are useful, assuming
https://lists.gnu.org/archive/html/qemu-devel/2013-04/msg04810.html goes in:
-> {"execute": "query-config-schema", "arguments" : {"option": "drive"}}
<- {
"return": [
{
"params": [
{
"name": "bus",
"type": "number",
"help": "bus number"
},
{
"name": "if",
"type": "string",
"help": "interface (ide, scsi, sd, mtd, floppy,
pflash, virtio)"
},
...
],
"option": "drive"
}
]}
Quoted 5 lines
qmp-commands.hx +4
-0+ConfigSchemaInfoList *qmp_query_config_schema(bool has_option, + const char *option, Error **errp) +{ + ConfigSchemaInfoList *conf_list = NULL, *entry;
qmp-commands.hx EQMP
Quoted 10 lines
qmp-commands.hx +10
-0+ ConfigSchemaInfo *info; + strList *str_list = NULL, *str_entry; + int entries, i, j; + + entries = ARRAY_SIZE(vm_config_groups); + + for (i = 0; i < entries; i++) { + if (vm_config_groups[i] != NULL && + (!has_option || !strcmp(option, vm_config_groups[i]->name))) { + info = g_malloc0(sizeof(*info));
This part of the iteration looks fine.
qmp-commands.hx
Quoted 9 lines
qmp-commands.hx +9
-0+ info->option = g_strdup(vm_config_groups[i]->name); + str_list = NULL; + + for (j = 0; vm_config_groups[i]->desc[j].name != NULL; j++) { + str_entry = g_malloc0(sizeof(*str_entry)); + str_entry->value = g_strdup(vm_config_groups[i]->desc[j].name); + str_entry->next = str_list; + str_list = str_entry; + }
Here, you'd need to allocate a bit more structure, to match the JSON I proposed above.
Quoted 10 lines
qmp-commands.hx +9
-0+ + info->params = str_list; + entry = g_malloc0(sizeof(*entry)); + entry->value = info; + entry->next = conf_list; + conf_list = entry; + } + } +
qmp-commands.hx
Quoted 10 lines
qmp-commands.hx +7
-0+ if (conf_list == NULL) { + error_set(errp, QERR_INVALID_OPTION_GROUP, option); + } + + return conf_list; +} + QemuOptsList *qemu_find_opts_err(const char *group, Error **errp) { return find_list(vm_config_groups, group, errp);
Looking forward to v2.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 2/2] monitor: introduce query-config-schema command
Quoted 56 lines · Eric Blake
Quoted 3 lines · Amos Kong
Libvirt has no way to probe if an option or property is supported, This patch introdues a new qmp command to query configuration schema information. hmp command isn't added because it's not needed.
Agreed that no HMP counterpart is needed. However, I don't think we have quite the right interface yet.
Quoted 17 lines
Signed-off-by Amos Kong <[email protected]>CC Osier Yang <[email protected]>CC Anthony Liguori <[email protected]>--- qapi-schema.json | 29 +++++++++++++++++++++++++++++ qmp-commands.hx | 40 ++++++++++++++++++++++++++++++++++++++++ util/qemu-config.c | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+), 0 deletions(-)qapi-schema.json +0
-0@@ -3505,3 +3505,32 @@ '*asl_compiler_rev': 'uint32', '*file': 'str',qapi-schema.json line 3516
Quoted 10 lines
qapi-schema.json +9
-0'*data': 'str' }} + +## +# @ConfigSchemaInfo: +# +# Configration schema information. +# +# @option: option name +# +# @params: parameters strList of one optionWhy just a strList? That only tells me option names. But we already know so much more than that - we know the type and the help string.
qapi-schema.json line 3520
Quoted 4 lines
qapi-schema.json +4
-0+# +# Since 1.5 +## +{ 'type': 'ConfigSchemaInfo', 'data': {'option': 'str', 'params': ['str']} }I'd rather see an array of structs, more closely mirroring what
include/qemu/option.hgives us:# JSON representation of values of QEMUOptionParType, may grow in future { 'enum': 'ConfigParamType',
'data': [ 'flag', 'number', 'size', 'string' ] }# JSON representation of QEMUOptionParameter, may grow in future # @help is optional if no text was present
{ 'type': 'ConfigParamInfo',
'data': { 'name': 'str', 'type': 'ConfigParamType', '*help':'str' } }
Quoted 6 lines
# Each command line option, and its list of parameters { 'type': 'ConfigSchemaInfo',
'data': { 'option':'str', 'params': ['ConfigParamInfo'] } }And that means we no longer have ['str'], which bypasses the need for your patch 1/2.
Strong Ack on this schema.
Regards,
Anthony Liguori
PATCH 1/1 monitor: introduce query-config-schema command
In reply to Amos KongLibvirt has no way to probe if an option or property is supported, This patch introdues a new qmp command to query configuration schema information. hmp command isn't added because it's not needed.
V2: fix jaso schema and comments (Eric)
--- qapi-schema.json | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 43 ++++++++++++++++++++++++++++++++++++ util/qemu-config.c | 51 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 158 insertions(+)
qapi-schema.json +64 -0
@@ -3505,3 +3505,67 @@ '*asl_compiler_rev': 'uint32', '*file': 'str', '*data': 'str' }} + +## +# @ConfigParamType: +# +# JSON representation of values of QEMUOptionParType, may grow in future +# +# @flag: If no value is given, the flag is set to 1. Otherwise the value must +# be "on" (set to 1) or "off" (set to 0) +# +# @number: Simple number +# +# @size: The value is converted to an integer. Suffixes for kilobytes etc +# +# @string: Character string +# +# Since 1.5 +## +{ 'enum': 'ConfigParamType', + 'data': [ 'flag', 'number', 'size', 'string' ] } + +## +# @ConfigParamInfo: +# +# JSON representation of QEMUOptionParameter, may grow in future +# +# @name: parameter name +# +# @type: parameter type +# +# @help is optional if no text was present +# +# Since 1.5 +## +{ 'type': 'ConfigParamInfo', + 'data': { 'name': 'str', 'type': 'ConfigParamType', '*help':'str' } } + +## +# @ConfigSchemaInfo: +# +# Each command line option, and its list of parameters +# +# @option: option name +# +# @params: a list of parameters of one option +# +# Since 1.5 +## +{ 'type': 'ConfigSchemaInfo', + 'data': { 'option':'str', 'params': ['ConfigParamInfo'] } } + +## +# @query-config-schema: +# +# Query configuration schema information +# +# @option: #optional option name +# +# Returns: list of @ConfigSchemaInfo for all options (or for the given +# @option). Returns an error if a given @option doesn't exist. +# +# Since 1.5 +## +{'command': 'query-config-schema', 'data': {'*option': 'str'}, + 'returns': ['ConfigSchemaInfo']}
qmp-commands.hx +43 -0
49 lines not on this page · raw message
util/qemu-config.c +51 -0
63 lines not on this page · raw message
Signature · 1 line
1.8.1.4
PATCH v2 1/1 monitor: introduce query-config-schema command
Quoted 5 lines · Amos Kong
Libvirt has no way to probe if an option or property is supported, This patch introdues a new qmp command to query configuration schema information. hmp command isn't added because it's not needed.
V2: fix jaso schema and comments (Eric)
Fix the subject: it's the v2, Please help to review, thanks.
---
Amos.
Re: [Qemu-devel] [PATCH] monitor: introduce query-config-schema command
In reply to Amos KongQuoted 5 lines · On Thu, 25 Apr 2013 01:33:24 +0800 Amos Kong <[email protected]> wrote:
Libvirt has no way to probe if an option or property is supported, This patch introdues a new qmp command to query configuration schema information. hmp command isn't added because it's not needed.
V2: fix jaso schema and comments (Eric)
I guess this is v3, isn't it? Btw, it's better to start a new thread when submitting a new version.
More comments below.
Quoted 16 lines
Signed-off-by Amos Kong <[email protected]>CC Osier Yang <[email protected]>CC Anthony Liguori <[email protected]>Signed-off-by Amos Kong <[email protected]>--- qapi-schema.json | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 43 ++++++++++++++++++++++++++++++++++++ util/qemu-config.c | 51 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 158 insertions(+)qapi-schema.json +0
-0@@ -3505,3 +3505,67 @@ '*asl_compiler_rev': 'uint32',
qapi-schema.json line 3515
Quoted 10 lines
qapi-schema.json +8
-0'*file': 'str', '*data': 'str' }} + +## +# @ConfigParamType: +# +# JSON representation of values of QEMUOptionParType, may grow in future +# +# @flag: If no value is given, the flag is set to 1. Otherwise the value must +# be "on" (set to 1) or "off" (set to 0)
Let's call this 'boolean', because it's what it is. Also, I suggest 'Accepts "on" or "off"' as the help text.
qapi-schema.json line 3517
Quoted 2 lines
qapi-schema.json +2
-0+# +# @number: Simple number
Suggest "Accepts a number".
qapi-schema.json line 3519
Quoted 2 lines
qapi-schema.json +2
-0+# +# @size: The value is converted to an integer. Suffixes for kilobytes etc
Suggest "Accepts a number followed by an optional postfix (K)ilo, (M)ega, (G)iga, (T)era"
Quoted 8 lines
qapi-schema.json +8
-0+# +# @string: Character string +# +# Since 1.5 +## +{ 'enum': 'ConfigParamType', + 'data': [ 'flag', 'number', 'size', 'string' ] } +
qapi-schema.json line 3537
Quoted 10 lines
qapi-schema.json +10
-0+## +# @ConfigParamInfo: +# +# JSON representation of QEMUOptionParameter, may grow in future +# +# @name: parameter name +# +# @type: parameter type +# +# @help is optional if no text was present
Suggest '@help human readable text string. This text may change is not suitable for parsing #optional'
Quoted 12 lines
qapi-schema.json +12
-0+# +# Since 1.5 +## +{ 'type': 'ConfigParamInfo', + 'data': { 'name': 'str', 'type': 'ConfigParamType', '*help':'str' } } + +## +# @ConfigSchemaInfo: +# +# Each command line option, and its list of parameters +# +# @option: option name
qapi-schema.json line 3559
Quoted 10 lines
qapi-schema.json +10
-0+# +# @params: a list of parameters of one option +# +# Since 1.5 +## +{ 'type': 'ConfigSchemaInfo', + 'data': { 'option':'str', 'params': ['ConfigParamInfo'] } } + +## +# @query-config-schema:
If you allow me the bikeshed, I find query-config-schema too generic, what about query-command-line-schema? query-command-line-options?
qapi-schema.json line 3570
Quoted 11 lines
qapi-schema.json +11
-0+# +# Query configuration schema information +# +# @option: #optional option name +# +# Returns: list of @ConfigSchemaInfo for all options (or for the given +# @option). Returns an error if a given @option doesn't exist. +# +# Since 1.5 +## +{'command': 'query-config-schema', 'data': {'*option': 'str'},
Please, let's not make option optional. It makes the code slightly more complex for no good reason.
Quoted 73 lines
qapi-schema.json +1
-0+ 'returns': ['ConfigSchemaInfo']}qmp-commands.hx +43
-0@@ -2414,6 +2414,49 @@ EQMP .args_type = "", .mhandler.cmd_new = qmp_marshal_input_query_uuid, }, +SQMP +query-config-schema +------------ + +Show configuration schema. + +Return list of configuration schema of all options (or for the given option), +return an error if given option doesn't exist. + +- "option": option name +- "params": parameters infomation list of one option +- "name": parameter name +- "type": parameter type +- "help": parameter help message + +Example: + +-> {"execute": "query-config-schema", "arguments" : {"option": "option-rom"}} +<- { + "return": [ + { + "params": [ + { + "name": "romfile", + "type": "flag" + }, + { + "name": "bootindex", + "type": "size" + } + ], + "option": "option-rom" + } + ] + } + +EQMP + + { + .name = "query-config-schema", + .args_type = "option:s?", + .mhandler.cmd_new = qmp_marshal_input_query_config_schema, + }, SQMP query-migrateutil/qemu-config.c +3
-0@@ -5,6 +5,7 @@#include "qapi/qmp/qerror.h" #include "hw/qdev.h" #include "qapi/error.h" +#include "qmp-commands.h" static QemuOptsList *vm_config_groups[32 ];@@ -37,6 +38,56 @@ QemuOptsList *qemu_find_opts(const char *group)return ret; } +ConfigSchemaInfoList *qmp_query_config_schema (bool has_option, +const char *option,Error **errp)
util/qemu-config.c QemuOptsList *qemu_find_opts(const char *group) · line 52
Quoted 10 lines
util/qemu-config.c +10
-0+{ +ConfigSchemaInfoList *conf_list =NULL , *conf_entry; +ConfigSchemaInfo *schema_info; +ConfigParamInfoList *param_list =NULL , *param_entry; +ConfigParamInfo *param_info; +int entries, i, j; + + entries =ARRAY_SIZE (vm_config_groups); + +for (i =0 ; i < entries; i++) {
Can't you loop until vm_config_groups[i] is NULL?
util/qemu-config.c QemuOptsList *qemu_find_opts(const char *group) · line 62
Quoted 10 lines
util/qemu-config.c +10
-0+if (vm_config_groups[i] !=NULL && + (!has_option || !strcmp (option, vm_config_groups[i]->name))) { + schema_info =g_malloc0 (sizeof (*schema_info)); + schema_info->option =g_strdup (vm_config_groups[i]->name); + param_list =NULL ; + +for (j =0 ; vm_config_groups[i]->desc[j].name !=NULL ; j++) { + param_info =g_malloc0 (sizeof (*param_info)); + param_info->name =g_strdup (vm_config_groups[i]->desc[j].name); + param_info->type = vm_config_groups[i]->desc[j].type;
That's a bug. This would only work if QemuOptType and ConfigParamType elements ordering matched, but even then it's a bad idea to do that.
Suggest doing the type match manually via a switch().
Quoted 31 lines
util/qemu-config.c +28
-0+ +if (vm_config_groups[i]->desc[j].help) { + param_info->has_help = true; + param_info->help =g_strdup ( + vm_config_groups[i]->desc[j].help); + } + + param_entry =g_malloc0 (sizeof (*param_entry)); + param_entry->value = param_info; + param_entry->next = param_list; + param_list = param_entry; + } + + schema_info->params = param_list; + conf_entry =g_malloc0 (sizeof (*conf_entry)); + conf_entry->value = schema_info; + conf_entry->next = conf_list; + conf_list = conf_entry; + } + } + +if (conf_list ==NULL ) { +error_set (errp,QERR_INVALID_OPTION_GROUP , option); + } + +return conf_list; +} +QemuOptsList *qemu_find_opts_err (const char *group,Error **errp) {return find_list (vm_config_groups, group, errp);
Re: [Qemu-devel] [PATCH] monitor: introduce query-config-schema command
Quoted 11 lines · Luiz Capitulino
Quoted 5 lines · On Thu, 25 Apr 2013 01:33:24 +0800 Amos Kong <[email protected]> wrote:
Libvirt has no way to probe if an option or property is supported, This patch introdues a new qmp command to query configuration schema information. hmp command isn't added because it's not needed.
V2: fix jaso schema and comments (Eric)
I guess this is v3, isn't it? Btw, it's better to start a new thread when submitting a new version.
Also, move your changelog below the --- line...
Quoted 8 lines
More comments below.
Quoted 5 lines
Signed-off-by Amos Kong <[email protected]>CC Osier Yang <[email protected]>CC Anthony Liguori <[email protected]>Signed-off-by Amos Kong <[email protected]>---
...here. The changelog is essential during review, but adds nothing to the long-term git history (a year from now, we won't care if it took 1 or 20 revisions to get to the version finally committed).
http://wiki.qemu.org/Contribute/SubmitAPatch
Quoted 5 lines
Quoted 5 lines
qapi-schema.json | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 43 ++++++++++++++++++++++++++++++++++++ util/qemu-config.c | 51 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 158 insertions(+)
Quoted 13 lines
qapi-schema.json line 3512
Quoted 13 lines
qapi-schema.json +5
-0@@ -3505,3 +3505,67 @@ '*asl_compiler_rev': 'uint32', '*file': 'str', '*data': 'str' }} + +## +# @ConfigParamType: +# +# JSON representation of values of QEMUOptionParType, may grow in future
I see why you used this text (it's straight copy-and-paste from my email suggestion); but it's rather geared towards someone that cares about the internals of qemu. On the other hand, qapi-schema is the public interface that should tell you how to interact with qemu without having to open include/qemu/option.h or even know about the C type QEMUOptionParType in the first place. Also, we've never mentioned that enums are subject to future growth elsewhere - it's kind of implicit. I think the following would be better text (and sorry for leading you in the wrong direction; in my mail, I was trying to justify WHY I suggested the type, not HOW it should be documented).
# Possible types for an option parameter.
Quoted 6 lines
qapi-schema.json line 3515
Quoted 3 lines
qapi-schema.json +3
-0+# +# @flag: If no value is given, the flag is set to 1. Otherwise the value must +# be "on" (set to 1) or "off" (set to 0)Let's call this 'boolean', because it's what it is. Also, I suggest 'Accepts "on" or "off"' as the help text.
I'm fine with calling the enum value 'boolean' even where the C code called it 'flag'. As long as we have a documented name that describes the semantics of what the parameter will take, libvirt should be able to cope.
One other concern - you document that if a flag parameter is omitted, then it defaults to 1. Is that really true? For that matter, does QEMUOptionParameter even have a way of expression which parameters are mandatory vs. optional, and for those which are optional, what the default value is if omitted? If so, then we probably ought to expand the representation of ConfigParamInfo to provide additional fields exposing that information.
Quoted 12 lines
qapi-schema.json line 3517
Quoted 3 lines
qapi-schema.json +2
-0+# +# @number: Simple numberSuggest "Accepts a number".
qapi-schema.json line 3519
Quoted 2 lines
qapi-schema.json +2
-0+# +# @size: The value is converted to an integer. Suffixes for kilobytes etcSuggest "Accepts a number followed by an optional postfix (K)ilo, (M)ega, (G)iga, (T)era"
Quoted 12 lines
qapi-schema.json line 3531
Quoted 12 lines
qapi-schema.json +12
-0+# +# @string: Character string +# +# Since 1.5 +## +{ 'enum': 'ConfigParamType', + 'data': [ 'flag', 'number', 'size', 'string' ] } + +## +# @ConfigParamInfo: +# +# JSON representation of QEMUOptionParameter, may grow in future
Again, my fault for trying to point to the C code as my justification, instead of providing a user-facing documentation. I think a better wording would be:
# Details about a single parameter of a command-line option.
Quoted 9 lines
qapi-schema.json line 3537
Quoted 6 lines
qapi-schema.json +6
-0+# +# @name: parameter name +# +# @type: parameter type +# +# @help is optional if no text was presentSuggest '@help human readable text string. This text may change is not suitable for parsing #optional'
Well, with enough punctuation to read well:
@help: #optional human readable text string. Not suitable for parsing.
Quoted 11 lines
qapi-schema.json line 3547
Quoted 11 lines
qapi-schema.json +10
-0+# +# Since 1.5 +## +{ 'type': 'ConfigParamInfo', + 'data': { 'name': 'str', 'type': 'ConfigParamType', '*help':'str' } } + +## +# @ConfigSchemaInfo: +# +# Each command line option, and its list of parameters
Close. But really, a single ConfigSchemaInfo is only one command line option, not 'each'. I'd use:
Details about a command line option, including its list of parameters.
Quoted 4 lines
qapi-schema.json line 3551
Quoted 4 lines
qapi-schema.json +4
-0+# +# @option: option name +# +# @params: a list of parameters of one option
No need to abbreviate in QMP; let's call this 'parameters'.
Quoted 5 lines
qapi-schema.json line 3556
Quoted 5 lines
qapi-schema.json +5
-0+# +# Since 1.5 +## +{ 'type': 'ConfigSchemaInfo', + 'data': { 'option':'str', 'params': ['ConfigParamInfo'] } }
We aren't very consistent on whether to put space after ':' or not; I don't care enough to fix existing uses, but it would look better if you are at least self-consistent within a patch.
Quoted 6 lines
qapi-schema.json line 3559
Quoted 3 lines
qapi-schema.json +3
-0+ +## +# @query-config-schema:If you allow me the bikeshed, I find query-config-schema too generic, what about query-command-line-schema? query-command-line-options?
I like query-command-line-options, myself. And if you change that name, you should reflect the naming convention back to the other types:
s/ConfigSchemaInfo/CommandLineOptionInfo/, s/ConfigParamInfo/CommandLineParameterInfo/, s/ConfigParamType/CommandLineParameterType/
Quoted 15 lines
qapi-schema.json line 3570
Quoted 12 lines
qapi-schema.json +11
-0+# +# Query configuration schema information +# +# @option: #optional option name +# +# Returns: list of @ConfigSchemaInfo for all options (or for the given +# @option). Returns an error if a given @option doesn't exist. +# +# Since 1.5 +## +{'command': 'query-config-schema', 'data': {'*option': 'str'},Please, let's not make option optional. It makes the code slightly more complex for no good reason.
There's two possibilities:
1. Discovering which options are available. Libvirt wants to do this (a single call returns as much information as possible, and it is mandatory for an option that was added after libvirt was compiled, but where libvirt has ability to dynamically use the results of the introspection to offer the user a chance to use introspected options) - for this one, omitting 'option' is essential.
2. Querying whether a given option is available, and what it supports. Libvirt is less likely to do this (if it needs to learn about 3 different command line options, a single call to get all options and then read through the array is easier to code than making 3 separate QMP calls to query about each individual option); but it makes sense from a usability standpoint of minimizing processing time (making 3 calls that return targeted information passes less data over the wire than making 1 call that returns all information and which the receiver must then sift through).
Most existing query-* commands do NOT support filtering, but always return a full array of information. I am not opposed to filtering (I actually think the idea of filtering is quite slick), even if libvirt won't use it; but if you are going to simplify the command, then get rid of 'option' entirely. Do NOT make 'option' mandatory, as then you have hindered the ability to learn which options exist even when you didn't know their name a priori.
Quoted 13 lines
Quoted 13 lines
qapi-schema.json +1
-0+ 'returns': ['ConfigSchemaInfo']}qmp-commands.hx +3
-0@@ -2414,6 +2414,49 @@ EQMP .args_type = "", .mhandler.cmd_new = qmp_marshal_input_query_uuid, }, +SQMP +query-config-schema +------------
Quoted 8 lines
qmp-commands.hx EQMP · line 2427
Quoted 8 lines
qmp-commands.hx +8
-0+ +Show configuration schema. + +Return list of configuration schema of all options (or for the given option), +return an error if given option doesn't exist. + +- "option": option name +- "params": parameters infomation list of one option
s/infomation/information/
Quoted 3 lines
qmp-commands.hx EQMP · line 2430
Quoted 3 lines
qmp-commands.hx +3
-0+- "name": parameter name +- "type": parameter type +- "help": parameter help message
I'd format this to show the levels of structures:
Return an array of command line option schema for all options (or for the given option), returning an error if the given option doesn't exist.
Each entry contains:
- "option": option name (json-string)
- "parameters": an array of json-objects, each describing one parameter of the option:
- "name": parameter name (json-string)
- "type": parameter type (one of 'flag', 'number', 'size', or 'string')
- "help": human readable description of the parameter (json-string, optional)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH] monitor: introduce query-config-schema command
Quoted 8 lines · Eric Blake
Quoted 7 lines · Luiz Capitulino
Quoted 4 lines · On Thu, 25 Apr 2013 01:33:24 +0800 Amos Kong <[email protected]> wrote:
Libvirt has no way to probe if an option or property is supported, This patch introdues a new qmp command to query configuration schema information. hmp command isn't added because it's not needed.
Quoted 15 lines
Quoted 4 lines
qapi-schema.json line 3512
Quoted 4 lines
qapi-schema.json +4
-0+## +# @ConfigParamType: +# +# JSON representation of values of QEMUOptionParType, may grow in futureI see why you used this text (it's straight copy-and-paste from my email suggestion); but it's rather geared towards someone that cares about the internals of qemu. On the other hand, qapi-schema is the public interface that should tell you how to interact with qemu without having to open
include/qemu/option.hor even know about the C type QEMUOptionParType in the first place. Also, we've never mentioned that enums are subject to future growth elsewhere - it's kind of implicit. I think the following would be better text (and sorry for leading you in the wrong direction; in my mail, I was trying to justify WHY I suggested the type, not HOW it should be documented).
That said, while the public document need not refer to the C api, you SHOULD patch include/qemu/option.h to document that any additions to the C API should be reflected back into the public QMP type name.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH] monitor: introduce query-config-schema command
In reply to Eric BlakeQuoted 9 lines · Eric Blake
Quoted 8 lines · Luiz Capitulino
Quoted 5 lines · On Thu, 25 Apr 2013 01:33:24 +0800 Amos Kong <[email protected]> wrote:
Libvirt has no way to probe if an option or property is supported, This patch introdues a new qmp command to query configuration schema information. hmp command isn't added because it's not needed.
V2: fix jaso schema and comments (Eric)
...
Quoted 7 lines
Quoted 6 lines
qapi-schema.json line 3515
Quoted 3 lines
qapi-schema.json +3
-0+# +# @flag: If no value is given, the flag is set to 1. Otherwise the value must +# be "on" (set to 1) or "off" (set to 0)Let's call this 'boolean', because it's what it is. Also, I suggest 'Accepts "on" or "off"' as the help text.
Quoted 7 lines
I'm fine with calling the enum value 'boolean' even where the C code called it 'flag'. As long as we have a documented name that describes the semantics of what the parameter will take, libvirt should be able to cope.
One other concern - you document that if a flag parameter is omitted, then it defaults to 1. Is that really true?
I'm wrong. If it's omitted in cmdline, we will give it a default value.
example:
enable_mlock = qemu_opt_get_bool(opts, "mlock", true);
another example:
-boot strict=on
bool boot_strict; (false by default)
strict boot is disabled by default, type of strict parameter is 'QEMU_OPT_STRING' the logical default parameter is "off".
This kind of default info is only added in help descriptions right now, we can add a new item 'default_value' to option.h:QemuOptDesc & qapi-schema.json:CommandLineParameterInfo in future?
I guess the default value is useful for libvirt.
However, we live in different timezone, so I will post my latest patch to maillist (no change about default value).
Agree with other comments, thanks.
Amos.
Re: [Qemu-devel] [PATCH] monitor: introduce query-config-schema command
Quoted 30 lines · Amos Kong
Quoted 9 lines · Eric Blake
Quoted 8 lines · Luiz Capitulino
Quoted 5 lines · On Thu, 25 Apr 2013 01:33:24 +0800 Amos Kong <[email protected]> wrote:
Libvirt has no way to probe if an option or property is supported, This patch introdues a new qmp command to query configuration schema information. hmp command isn't added because it's not needed.
V2: fix jaso schema and comments (Eric)
...
Quoted 5 lines
Quoted 5 lines
qapi-schema.json line 3515
Quoted 3 lines
qapi-schema.json +3
-0+# +# @flag: If no value is given, the flag is set to 1. Otherwise the value must +# be "on" (set to 1) or "off" (set to 0)Let's call this 'boolean', because it's what it is. Also, I suggest 'Accepts "on" or "off"' as the help text.
Quoted 7 lines
I'm fine with calling the enum value 'boolean' even where the C code called it 'flag'. As long as we have a documented name that describes the semantics of what the parameter will take, libvirt should be able to cope.
One other concern - you document that if a flag parameter is omitted, then it defaults to 1. Is that really true?
I'm wrong. If it's omitted in cmdline, we will give it a default value.
example:
enable_mlock = qemu_opt_get_bool(opts, "mlock", true);
Quoted 7 lines
another example:
-boot strict=onbool
boot_strict; (false by default)strict boot is disabled by default, type of strict parameter is '
QEMU_OPT_STRING' the logical default parameter is "off".
I didn't look through all the threads, not sure if it's already clarified, but is the "flags" indicates whether the option is enabled or disabled by default?
If so, is it possible to have another "name" instead of "flag"? Or please add documentation to tell more about the meaning.
Quoted 4 lines
This kind of default info is only added in help descriptions right now, we can add a new item '
default_value' to option.h:QemuOptDesc & qapi-schema.json:CommandLineParameterInfo in future?
Sounds good to add it in the struct instead and dump as a JSON parameter.
Quoted 2 lines
I guess the default value is useful for libvirt.
Yeah, sure, it's nice if libvirt could known if the device is enabled or disabled by default.
Osier
Re: [Qemu-devel] [PATCH] monitor: introduce query-config-schema command
Quoted 36 lines · Osier Yang
Quoted 35 lines · Amos Kong
Quoted 9 lines · Eric Blake
Quoted 8 lines · Luiz Capitulino
Quoted 5 lines · On Thu, 25 Apr 2013 01:33:24 +0800 Amos Kong <[email protected]> wrote:
Libvirt has no way to probe if an option or property is supported, This patch introdues a new qmp command to query configuration schema information. hmp command isn't added because it's not needed.
V2: fix jaso schema and comments (Eric)
...
Quoted 5 lines
Quoted 5 lines
qapi-schema.json line 3515
Quoted 3 lines
qapi-schema.json +3
-0+# +# @flag: If no value is given, the flag is set to 1. Otherwise the value must +# be "on" (set to 1) or "off" (set to 0)Let's call this 'boolean', because it's what it is. Also, I suggest 'Accepts "on" or "off"' as the help text.
Quoted 7 lines
I'm fine with calling the enum value 'boolean' even where the C code called it 'flag'. As long as we have a documented name that describes the semantics of what the parameter will take, libvirt should be able to cope.
One other concern - you document that if a flag parameter is omitted, then it defaults to 1. Is that really true?
I'm wrong. If it's omitted in cmdline, we will give it a default value.
example:
enable_mlock = qemu_opt_get_bool(opts, "mlock", true);another example:
-boot strict=onbool
boot_strict; (false by default)
Quoted 7 lines
Quoted 2 lines
strict boot is disabled by default, type of strict parameter is '
QEMU_OPT_STRING' the logical default parameter is "off".I didn't look through all the threads, not sure if it's already clarified, but
is the "flags" indicates whether the option is enabled or disabled by default?
No, it used for used to enable/disable sth, not to save default value
Quoted 2 lines
If so, is it possible to have another "name" instead of "flag"? Or please add documentation to tell more about the meaning.
Signature · 1 line
Amos.
Re: [Qemu-devel] [PATCH] monitor: introduce query-config-schema command
In reply to Amos KongQuoted 37 lines · On Thu, 25 Apr 2013 11:52:58 +0800 Amos Kong <[email protected]> wrote:
Quoted 9 lines · Eric Blake
Quoted 8 lines · Luiz Capitulino
Quoted 5 lines · On Thu, 25 Apr 2013 01:33:24 +0800 Amos Kong <[email protected]> wrote:
Libvirt has no way to probe if an option or property is supported, This patch introdues a new qmp command to query configuration schema information. hmp command isn't added because it's not needed.
V2: fix jaso schema and comments (Eric)
...
Quoted 7 lines
Quoted 6 lines
qapi-schema.json line 3515
Quoted 3 lines
qapi-schema.json +3
-0+# +# @flag: If no value is given, the flag is set to 1. Otherwise the value must +# be "on" (set to 1) or "off" (set to 0)Let's call this 'boolean', because it's what it is. Also, I suggest 'Accepts "on" or "off"' as the help text.
Quoted 7 lines
I'm fine with calling the enum value 'boolean' even where the C code called it 'flag'. As long as we have a documented name that describes the semantics of what the parameter will take, libvirt should be able to cope.
One other concern - you document that if a flag parameter is omitted, then it defaults to 1. Is that really true?
I'm wrong. If it's omitted in cmdline, we will give it a default value.
example:
enable_mlock = qemu_opt_get_bool(opts, "mlock", true);another example:
-boot strict=on
Quoted 8 lines
bool
boot_strict; (false by default)strict boot is disabled by default, type of strict parameter is '
QEMU_OPT_STRING' the logical default parameter is "off".This kind of default info is only added in help descriptions right now, we can add a new item '
default_value' to option.h:QemuOptDesc & qapi-schema.json:CommandLineParameterInfo in future?
Yes. I don't think we'll have enough time to fix this now.
Quoted 11 lines
I guess the default value is useful for libvirt.
However, we live in different timezone, so I will post my latest patch to maillist (no change about default value).
Agree with other comments, thanks.
Amos.
Re: [Qemu-devel] [PATCH] monitor: introduce query-config-schema command
Quoted 4 lines · Luiz Capitulino
Quoted 4 lines
Quoted 2 lines
One other concern - you document that if a flag parameter is omitted, then it defaults to 1. Is that really true?
Quoted 8 lines
Quoted 6 lines
I'm wrong. If it's omitted in cmdline, we will give it a default value.
This kind of default info is only added in help descriptions right now, we can add a new item '
default_value' to option.h:QemuOptDesc & qapi-schema.json:CommandLineParameterInfo in future?Yes. I don't think we'll have enough time to fix this now.
Agreed - we've added additional information in the QMP types returned by query-* in the past, and it's no problem if we don't expose default values via QMP until improving the C code to track default values in 1.6. For 1.5, let's just focus on exposing the information we have readily available.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH] monitor: introduce query-config-schema command
In reply to Luiz CapitulinoQuoted 11 lines · Luiz Capitulino
Quoted 5 lines · On Thu, 25 Apr 2013 01:33:24 +0800 Amos Kong <[email protected]> wrote:
Libvirt has no way to probe if an option or property is supported, This patch introdues a new qmp command to query configuration schema information. hmp command isn't added because it's not needed.
V2: fix jaso schema and comments (Eric)
I guess this is v3, isn't it? Btw, it's better to start a new thread when submitting a new version.
I didn't count RFC patch, I will use v4 for next version. Thanks for the review.
Quoted 23 lines
More comments below.
Quoted 21 lines
Signed-off-by Amos Kong <[email protected]>CC Osier Yang <[email protected]>CC Anthony Liguori <[email protected]>Signed-off-by Amos Kong <[email protected]>--- qapi-schema.json | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 43 ++++++++++++++++++++++++++++++++++++ util/qemu-config.c | 51 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 158 insertions(+)qapi-schema.json +3
-0@@ -3505,3 +3505,67 @@ '*asl_compiler_rev': 'uint32', '*file': 'str', '*data': 'str' }} + +## +# @ConfigParamType:
Quoted 8 lines
qapi-schema.json line 3515
Quoted 5 lines
qapi-schema.json +5
-0+# +# JSON representation of values of QEMUOptionParType, may grow in future +# +# @flag: If no value is given, the flag is set to 1. Otherwise the value must +# be "on" (set to 1) or "off" (set to 0)Let's call this 'boolean', because it's what it is. Also, I suggest 'Accepts "on" or "off"' as the help text.
Ok.
btw, using 'bool' matches with 'enum QemuOptType', but it might confuse with 'bool' type in qapi-schema.json
Quoted 50 lines
qapi-schema.json line 3517
Quoted 2 lines
qapi-schema.json +2
-0+# +# @number: Simple numberSuggest "Accepts a number".
qapi-schema.json line 3519
Quoted 2 lines
qapi-schema.json +2
-0+# +# @size: The value is converted to an integer. Suffixes for kilobytes etcSuggest "Accepts a number followed by an optional postfix (K)ilo, (M)ega, (G)iga, (T)era"
Quoted 8 lines
qapi-schema.json +8
-0+# +# @string: Character string +# +# Since 1.5 +## +{ 'enum': 'ConfigParamType', + 'data': [ 'flag', 'number', 'size', 'string' ] } +qapi-schema.json line 3537
Quoted 10 lines
qapi-schema.json +10
-0+## +# @ConfigParamInfo: +# +# JSON representation of QEMUOptionParameter, may grow in future +# +# @name: parameter name +# +# @type: parameter type +# +# @help is optional if no text was presentSuggest '@help human readable text string. This text may change is not suitable for parsing #optional'
Quoted 17 lines
qapi-schema.json +17
-0+# +# Since 1.5 +## +{ 'type': 'ConfigParamInfo', + 'data': { 'name': 'str', 'type': 'ConfigParamType', '*help':'str' } } + +## +# @ConfigSchemaInfo: +# +# Each command line option, and its list of parameters +# +# @option: option name +# +# @params: a list of parameters of one option +# +# Since 1.5 +##
Quoted 8 lines
qapi-schema.json line 3559
Quoted 5 lines
qapi-schema.json +5
-0+{ 'type': 'ConfigSchemaInfo', + 'data': { 'option':'str', 'params': ['ConfigParamInfo'] } } + +## +# @query-config-schema:If you allow me the bikeshed, I find query-config-schema too generic, what about query-command-line-schema? query-command-line-options?
'query-command-line-options' is clearer.
Quoted 6 lines
Quoted 6 lines
qapi-schema.json +6
-0+# +# Query configuration schema information +# +# @option: #optional option name +# +# Returns: list of @ConfigSchemaInfo for all options (or for the given
Quoted 8 lines
qapi-schema.json line 3570
Quoted 5 lines
qapi-schema.json +5
-0+# @option). Returns an error if a given @option doesn't exist. +# +# Since 1.5 +## +{'command': 'query-config-schema', 'data': {'*option': 'str'},Please, let's not make option optional. It makes the code slightly more complex for no good reason.
For the human, if they don't know the detail name of one option, they just list all the options, then find the useful one.
Not sure the use-case of full list for libvirt. Osier?
....
Quoted 6 lines
Quoted 6 lines
qapi-schema.json +6
-0+ConfigSchemaInfoList *qmp_query_config_schema(bool has_option, + const char *option, Error **errp) +{ + ConfigSchemaInfoList *conf_list = NULL, *conf_entry; + ConfigSchemaInfo *schema_info; + ConfigParamInfoList *param_list = NULL, *param_entry;
Quoted 8 lines
qapi-schema.json
Quoted 6 lines
qapi-schema.json +6
-0+ ConfigParamInfo *param_info; + int entries, i, j; + + entries = ARRAY_SIZE(vm_config_groups); + + for (i = 0; i < entries; i++) {Can't you loop until vm_config_groups[i] is NULL?
Fixed.
Quoted 10 lines
Quoted 9 lines
qapi-schema.json +9
-0+ if (vm_config_groups[i] != NULL && + (!has_option || !strcmp(option, vm_config_groups[i]->name))) { + schema_info = g_malloc0(sizeof(*schema_info)); + schema_info->option = g_strdup(vm_config_groups[i]->name); + param_list = NULL; + + for (j = 0; vm_config_groups[i]->desc[j].name != NULL; j++) { + param_info = g_malloc0(sizeof(*param_info)); + param_info->name = g_strdup(vm_config_groups[i]->desc[j].name);
Quoted 6 lines
Quoted 1 line
+
param_info->type= vm_config_groups[i]->desc[j].type;That's a bug. This would only work if QemuOptType and ConfigParamType elements ordering matched, but even then it's a bad idea to do that.
Suggest doing the type match manually via a
switch().
Right! the order doesn't match here.
switch (vm_config_groups[i]->desc[j].type) {
case QEMU_OPT_STRING:
param_info->type = CONFIG_PARAM_TYPE_STRING;
break;
case QEMU_OPT_BOOL:
param_info->type = CONFIG_PARAM_TYPE_FLAG;
break;
case QEMU_OPT_NUMBER:
param_info->type = CONFIG_PARAM_TYPE_NUMBER;
break;
case QEMU_OPT_SIZE:
param_info->type = CONFIG_PARAM_TYPE_SIZE;
break;
} I think we don't need default here, until some add new items in enum QemuOptType without update this code.
Signature · 1 line
Amos.
Re: [Qemu-devel] [PATCH] monitor: introduce query-config-schema command
Quoted 48 lines · On Thu, 25 Apr 2013 09:14:51 +0800 Amos Kong <[email protected]> wrote:
Quoted 11 lines · Luiz Capitulino
Quoted 5 lines · On Thu, 25 Apr 2013 01:33:24 +0800 Amos Kong <[email protected]> wrote:
Libvirt has no way to probe if an option or property is supported, This patch introdues a new qmp command to query configuration schema information. hmp command isn't added because it's not needed.
V2: fix jaso schema and comments (Eric)
I guess this is v3, isn't it? Btw, it's better to start a new thread when submitting a new version.
I didn't count RFC patch, I will use v4 for next version. Thanks for the review.
Quoted 23 lines
More comments below.
Quoted 21 lines
Signed-off-by Amos Kong <[email protected]>CC Osier Yang <[email protected]>CC Anthony Liguori <[email protected]>Signed-off-by Amos Kong <[email protected]>--- qapi-schema.json | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 43 ++++++++++++++++++++++++++++++++++++ util/qemu-config.c | 51 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 158 insertions(+)qapi-schema.json +3
-0@@ -3505,3 +3505,67 @@ '*asl_compiler_rev': 'uint32', '*file': 'str', '*data': 'str' }} + +## +# @ConfigParamType:Quoted 8 lines
qapi-schema.json line 3515
Quoted 5 lines
qapi-schema.json +5
-0+# +# JSON representation of values of QEMUOptionParType, may grow in future +# +# @flag: If no value is given, the flag is set to 1. Otherwise the value must +# be "on" (set to 1) or "off" (set to 0)Let's call this 'boolean', because it's what it is. Also, I suggest 'Accepts "on" or "off"' as the help text.
Quoted 4 lines
Ok.
btw, using 'bool' matches with 'enum QemuOptType', but it might confuse with 'bool' type in qapi-schema.json
I don't think so because this won't cause a real conflict, as the enum name will always have the CONFIG_PARAM_TYPE prefix. But I 'suggested' boolean anyway.
Quoted 77 lines
Quoted 51 lines
qapi-schema.json line 3517
Quoted 3 lines
qapi-schema.json +2
-0+# +# @number: Simple numberSuggest "Accepts a number".
qapi-schema.json line 3519
Quoted 2 lines
qapi-schema.json +2
-0+# +# @size: The value is converted to an integer. Suffixes for kilobytes etcSuggest "Accepts a number followed by an optional postfix (K)ilo, (M)ega, (G)iga, (T)era"
Quoted 8 lines
qapi-schema.json +8
-0+# +# @string: Character string +# +# Since 1.5 +## +{ 'enum': 'ConfigParamType', + 'data': [ 'flag', 'number', 'size', 'string' ] } +qapi-schema.json line 3537
Quoted 10 lines
qapi-schema.json +10
-0+## +# @ConfigParamInfo: +# +# JSON representation of QEMUOptionParameter, may grow in future +# +# @name: parameter name +# +# @type: parameter type +# +# @help is optional if no text was presentSuggest '@help human readable text string. This text may change is not suitable for parsing #optional'
Quoted 17 lines
qapi-schema.json +17
-0+# +# Since 1.5 +## +{ 'type': 'ConfigParamInfo', + 'data': { 'name': 'str', 'type': 'ConfigParamType', '*help':'str' } } + +## +# @ConfigSchemaInfo: +# +# Each command line option, and its list of parameters +# +# @option: option name +# +# @params: a list of parameters of one option +# +# Since 1.5 +##Quoted 8 lines
qapi-schema.json line 3559
Quoted 5 lines
qapi-schema.json +5
-0+{ 'type': 'ConfigSchemaInfo', + 'data': { 'option':'str', 'params': ['ConfigParamInfo'] } } + +## +# @query-config-schema:If you allow me the bikeshed, I find query-config-schema too generic, what about query-command-line-schema? query-command-line-options?
'query-command-line-options' is clearer.
Quoted 6 lines
Quoted 6 lines
qapi-schema.json +6
-0+# +# Query configuration schema information +# +# @option: #optional option name +# +# Returns: list of @ConfigSchemaInfo for all options (or for the givenQuoted 8 lines
qapi-schema.json line 3570
Quoted 5 lines
qapi-schema.json +5
-0+# @option). Returns an error if a given @option doesn't exist. +# +# Since 1.5 +## +{'command': 'query-config-schema', 'data': {'*option': 'str'},Please, let's not make option optional. It makes the code slightly more complex for no good reason.
Quoted 2 lines
For the human, if they don't know the detail name of one option, they just list all the options, then find the useful one.
QMP is not concerned with human users, we can always use tools like qmp-shell to give this feature to humans.
Quoted 40 lines
Not sure the use-case of full list for libvirt. Osier?
....
Quoted 6 lines
Quoted 6 lines
qapi-schema.json +6
-0+ConfigSchemaInfoList *qmp_query_config_schema(bool has_option, + const char *option, Error **errp) +{ + ConfigSchemaInfoList *conf_list = NULL, *conf_entry; + ConfigSchemaInfo *schema_info; + ConfigParamInfoList *param_list = NULL, *param_entry;Quoted 8 lines
qapi-schema.json
Quoted 6 lines
qapi-schema.json +6
-0+ ConfigParamInfo *param_info; + int entries, i, j; + + entries = ARRAY_SIZE(vm_config_groups); + + for (i = 0; i < entries; i++) {Can't you loop until vm_config_groups[i] is NULL?
Fixed.
Quoted 10 lines
Quoted 9 lines
qapi-schema.json +9
-0+ if (vm_config_groups[i] != NULL && + (!has_option || !strcmp(option, vm_config_groups[i]->name))) { + schema_info = g_malloc0(sizeof(*schema_info)); + schema_info->option = g_strdup(vm_config_groups[i]->name); + param_list = NULL; + + for (j = 0; vm_config_groups[i]->desc[j].name != NULL; j++) { + param_info = g_malloc0(sizeof(*param_info)); + param_info->name = g_strdup(vm_config_groups[i]->desc[j].name);Quoted 6 lines
Quoted 1 line
+
param_info->type= vm_config_groups[i]->desc[j].type;That's a bug. This would only work if QemuOptType and ConfigParamType elements ordering matched, but even then it's a bad idea to do that.
Suggest doing the type match manually via a
switch().Right! the order doesn't match here.
Quoted 14 lines
switch (vm_config_groups[i]->desc[j].type) {
case QEMU_OPT_STRING:
param_info->type = CONFIG_PARAM_TYPE_STRING;
break;
case QEMU_OPT_BOOL:
param_info->type = CONFIG_PARAM_TYPE_FLAG;
break;
case QEMU_OPT_NUMBER:
param_info->type = CONFIG_PARAM_TYPE_NUMBER;
break;
case QEMU_OPT_SIZE:
param_info->type = CONFIG_PARAM_TYPE_SIZE;
break;
} Looks good.
Quoted 2 lines
I think we don't need default here, until some add new items in enum QemuOptType without update this code.
Maybe we can have:
default: abort();
So that we catch new QEmuOpts types not accompanied by a new ConfigParamType type.
Re: [Qemu-devel] [PATCH] monitor: introduce query-config-schema command
Quoted 10 lines · Luiz Capitulino
Quoted 4 lines
case QEMU_OPT_SIZE: param_info->type = CONFIG_PARAM_TYPE_SIZE; break; }Looks good.
Quoted 2 lines
I think we don't need default here, until some add new items in enum QemuOptType without update this code.
Quoted 7 lines
Maybe we can have:
default: abort();So that we catch new QEmuOpts types not accompanied by a new ConfigParamType type.
gcc is able to warn about missed options if you omit a default case (and if the switch was on an actual enum type); but does not warn about missed options if you do have a default case. Libvirt has actually been switching to default-free coding styles on any switch statement where we expect an enum will grow in the future, for that reason.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH] monitor: introduce query-config-schema command
Quoted 17 lines · Eric Blake
Quoted 15 lines · Luiz Capitulino
Quoted 4 lines
case QEMU_OPT_SIZE: param_info->type = CONFIG_PARAM_TYPE_SIZE; break; }Looks good.
Quoted 2 lines
I think we don't need default here, until some add new items in enum QemuOptType without update this code.
Maybe we can have:
default: abort();
Quoted 8 lines
Quoted 2 lines
So that we catch new QEmuOpts types not accompanied by a new ConfigParamType type.
gcc is able to warn about missed options if you omit a default case (and if the switch was on an actual enum type); but does not warn about missed options if you do have a default case. Libvirt has actually been switching to default-free coding styles on any switch statement where we expect an enum will grow in the future, for that reason.
util/qemu-config.c: In function ‘qmp_query_command_line_options’:util/qemu-config.c:60:17: error: enumeration value ‘QEMU_OPT_NEW’ not handled in switch [-Werror=switch]
cc1: all warnings being treated as errors
Good! no need default case here.
Signature · 1 line
Amos.
Re: [Qemu-devel] [PATCH] monitor: introduce query-config-schema command
In reply to Eric BlakeQuoted 17 lines · On Wed, 24 Apr 2013 19:44:37 -0600 Eric Blake <[email protected]> wrote:
Quoted 15 lines · Luiz Capitulino
Quoted 4 lines
case QEMU_OPT_SIZE: param_info->type = CONFIG_PARAM_TYPE_SIZE; break; }Looks good.
Quoted 2 lines
I think we don't need default here, until some add new items in enum QemuOptType without update this code.
Maybe we can have:
default: abort();
Quoted 8 lines
Quoted 2 lines
So that we catch new QEmuOpts types not accompanied by a new ConfigParamType type.
gcc is able to warn about missed options if you omit a default case (and if the switch was on an actual enum type); but does not warn about missed options if you do have a default case. Libvirt has actually been switching to default-free coding styles on any switch statement where we expect an enum will grow in the future, for that reason.
Ah, didn't know that. Fine with me then.
Re: [Qemu-devel] [PATCH] monitor: introduce query-config-schema command
In reply to Amos KongQuoted 10 lines · Amos Kong
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+## +{'command': 'query-config-schema', 'data': {'*option': 'str'},Please, let's not make option optional. It makes the code slightly more complex for no good reason.
For the human, if they don't know the detail name of one option, they just list all the options, then find the useful one.
Not sure the use-case of full list for libvirt. Osier?
I think I already answered that - having the whole list (single QMP call) is more efficient than calling multiple times per command we are interested in. Also, most other query-* commands do NOT filter; having the 'option' argument introduces filtering. It's up to Luiz whether we leave it as is, or omit '*option' for now and save filtering for later, but I'd rather not have mandatory 'option' as then you have to know in advance which command line options you care about.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH] monitor: introduce query-config-schema command
In reply to Amos KongQuoted 118 lines · Amos Kong
Quoted 10 lines · Luiz Capitulino
Quoted 5 lines · On Thu, 25 Apr 2013 01:33:24 +0800 Amos Kong <[email protected]> wrote:
Libvirt has no way to probe if an option or property is supported, This patch introdues a new qmp command to query configuration schema information. hmp command isn't added because it's not needed.
V2: fix jaso schema and comments (Eric)
I guess this is v3, isn't it? Btw, it's better to start a new thread when submitting a new version.
I didn't count RFC patch, I will use v4 for next version. Thanks for the review.
Quoted 22 lines
More comments below.
Quoted 20 lines
Signed-off-by Amos Kong <[email protected]>CC Osier Yang <[email protected]>CC Anthony Liguori <[email protected]>Signed-off-by Amos Kong <[email protected]>--- qapi-schema.json | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 43 ++++++++++++++++++++++++++++++++++++ util/qemu-config.c | 51 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 158 insertions(+)qapi-schema.json +2
-0@@ -3505,3 +3505,67 @@ '*asl_compiler_rev': 'uint32', '*file': 'str', '*data': 'str' }} + +##Quoted 8 lines
qapi-schema.json line 3515
Quoted 6 lines
qapi-schema.json +6
-0+# @ConfigParamType: +# +# JSON representation of values of QEMUOptionParType, may grow in future +# +# @flag: If no value is given, the flag is set to 1. Otherwise the value must +# be "on" (set to 1) or "off" (set to 0)Let's call this 'boolean', because it's what it is. Also, I suggest 'Accepts "on" or "off"' as the help text.
Ok.
btw, using 'bool' matches with 'enum QemuOptType', but it might confuse with 'bool' type in qapi-schema.json
Quoted 46 lines
qapi-schema.json line 3517
Quoted 2 lines
qapi-schema.json +2
-0+# +# @number: Simple numberSuggest "Accepts a number".
qapi-schema.json line 3519
Quoted 2 lines
qapi-schema.json +2
-0+# +# @size: The value is converted to an integer. Suffixes for kilobytes etcSuggest "Accepts a number followed by an optional postfix (K)ilo, (M)ega, (G)iga, (T)era"
Quoted 8 lines
qapi-schema.json +8
-0+# +# @string: Character string +# +# Since 1.5 +## +{ 'enum': 'ConfigParamType', + 'data': [ 'flag', 'number', 'size', 'string' ] } +qapi-schema.json line 3537
Quoted 10 lines
qapi-schema.json +10
-0+## +# @ConfigParamInfo: +# +# JSON representation of QEMUOptionParameter, may grow in future +# +# @name: parameter name +# +# @type: parameter type +# +# @help is optional if no text was presentSuggest '@help human readable text string. This text may change is not suitable for parsing #optional'
Quoted 16 lines
qapi-schema.json +16
-0+# +# Since 1.5 +## +{ 'type': 'ConfigParamInfo', + 'data': { 'name': 'str', 'type': 'ConfigParamType', '*help':'str' } } + +## +# @ConfigSchemaInfo: +# +# Each command line option, and its list of parameters +# +# @option: option name +# +# @params: a list of parameters of one option +# +# Since 1.5Quoted 8 lines
qapi-schema.json line 3559
Quoted 6 lines
qapi-schema.json +6
-0+## +{ 'type': 'ConfigSchemaInfo', + 'data': { 'option':'str', 'params': ['ConfigParamInfo'] } } + +## +# @query-config-schema:If you allow me the bikeshed, I find query-config-schema too generic, what about query-command-line-schema? query-command-line-options?
'query-command-line-options' is clearer.
Quoted 5 lines
Quoted 5 lines
qapi-schema.json +5
-0+# +# Query configuration schema information +# +# @option: #optional option name +#Quoted 8 lines
qapi-schema.json line 3570
Quoted 6 lines
qapi-schema.json +6
-0+# Returns: list of @ConfigSchemaInfo for all options (or for the given +# @option). Returns an error if a given @option doesn't exist. +# +# Since 1.5 +## +{'command': 'query-config-schema', 'data': {'*option': 'str'},Please, let's not make option optional. It makes the code slightly more complex for no good reason.
Quoted 4 lines
For the human, if they don't know the detail name of one option, they just list all the options, then find the useful one.
Not sure the use-case of full list for libvirt. Osier?
One of the use is to query what options qemu support. Changing the "option" to be mandatory is not nice? any other way for libvirt to query what options qemu support?
Quoted 49 lines
....
Quoted 5 lines
Quoted 5 lines
qapi-schema.json +5
-0+ConfigSchemaInfoList *qmp_query_config_schema(bool has_option, + const char *option, Error **errp) +{ + ConfigSchemaInfoList *conf_list = NULL, *conf_entry; + ConfigSchemaInfo *schema_info;Quoted 8 lines
qapi-schema.json
Quoted 7 lines
qapi-schema.json +7
-0+ ConfigParamInfoList *param_list = NULL, *param_entry; + ConfigParamInfo *param_info; + int entries, i, j; + + entries = ARRAY_SIZE(vm_config_groups); + + for (i = 0; i < entries; i++) {Can't you loop until vm_config_groups[i] is NULL?
Fixed.
Quoted 10 lines
qapi-schema.json
Quoted 10 lines
qapi-schema.json +10
-0+ if (vm_config_groups[i] != NULL && + (!has_option || !strcmp(option, vm_config_groups[i]->name))) { + schema_info = g_malloc0(sizeof(*schema_info)); + schema_info->option = g_strdup(vm_config_groups[i]->name); + param_list = NULL; + + for (j = 0; vm_config_groups[i]->desc[j].name != NULL; j++) { + param_info = g_malloc0(sizeof(*param_info)); + param_info->name = g_strdup(vm_config_groups[i]->desc[j].name); + param_info->type = vm_config_groups[i]->desc[j].type;Quoted 4 lines
That's a bug. This would only work if QemuOptType and ConfigParamType elements ordering matched, but even then it's a bad idea to do that.
Suggest doing the type match manually via a
switch().Right! the order doesn't match here.
switch (vm_config_groups[i]->desc[j].type) { case QEMU_OPT_STRING: param_info->type = CONFIG_PARAM_TYPE_STRING; break; case QEMU_OPT_BOOL: param_info->type = CONFIG_PARAM_TYPE_FLAG; break; case QEMU_OPT_NUMBER: param_info->type = CONFIG_PARAM_TYPE_NUMBER; break; case QEMU_OPT_SIZE: param_info->type = CONFIG_PARAM_TYPE_SIZE; break; }
Quoted 4 lines
I think we don't need default here, until some add new items in enum QemuOptType without update this code.
gcc will give warnings if the new enum member is added but not handled in the switch. From this p.o.v, not using the default is good.
Quoted 18 lines · Amos Kong
Currently we can only use ['String'] to add string to a list, it contains some additional JSON structure.
"multicast": [ { "str": "01:80:c2:00:00:21" }, { "str": "00:00:00:00:00:00" } ]This patch introdued strList, we can use ['str']
"multicast": [ "01:00:5e:00:00:01", "33:33:ff:12:34:57" ]
Quoted 4 lines
Signed-off-by Amos Kong <[email protected]>---
I used an _ugly_ "#ifndef" to limit it only be defined inqapi-types.h. do you have some suggestion to fix it?
I'm not the maintainer, so you may still want to wait for a better suggestion. But since I personally don't mind the #ifdef if that's what it takes to get this to compile, and since I'd like to see the feature added, I'm fine giving:
That said, I think the API in patch 2/2 is not quite right; and when you fix things there, you may not need this patch in the 1.5 timeframe...
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 24 lines · Eric Blake
Quoted 18 lines · Amos Kong
Currently we can only use ['String'] to add string to a list, it contains some additional JSON structure.
"multicast": [ { "str": "01:80:c2:00:00:21" }, { "str": "00:00:00:00:00:00" } ]This patch introdued strList, we can use ['str']
"multicast": [ "01:00:5e:00:00:01", "33:33:ff:12:34:57" ]Quoted 4 lines
Signed-off-by Amos Kong <[email protected]>---
I used an _ugly_ "#ifndef" to limit it only be defined inqapi-types.h. do you have some suggestion to fix it?
Quoted 4 lines
I'm not the maintainer, so you may still want to wait for a better suggestion. But since I personally don't mind the #ifdef if that's what it takes to get this to compile, and since I'd like to see the feature added, I'm fine giving:
I will send a v2 to solve this issue.
Quoted 4 lines
Reviewed-by Eric Blake <[email protected]>That said, I think the API in patch 2/2 is not quite right; and when you fix things there, you may not need this patch in the 1.5 timeframe...
I already saw your comment, will split those two patches. Thanks
Signature · 1 line
Amos.
Quoted 2 lines · Amos Kong
Currently we can only use ['String'] to add string to a list, it contains some additional JSON structure.
Side note - when sending a 2-patch series, it helps to include a 0/2 cover letter.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org