object: Add 'help' option for all available backends and properties
Subsystems (3)
v4 cover object: Add 'help' option for all available backends and properties
V3->V4:
* drop the code about manually define interface 'user-creatable' as abstract.
* add test case for the generated enum value str.
* split the code about adding descriptions to class properties into a separate patch.
* minor changes in user_creatable_help_func to ignore interface TYPE_USER_CREATABLE.
V2->v3:
* make type user-creatable abstract.
* auto generate enum value strings during qemu configuration.(Borrowwed Daniel's code)
* save the generated enum value strings into member description of ObjectProperty.
* drop the judgement logic of whether a property has an enumeration type anymore, output member description of ObjectProperty directly.
* at least, user_creatable_help_func should be put after 'object_property_add_child(object_get_root(), "machine",OBJECT(current_machine), ...)', because host_memory_backend_init needs to access an instance of type machine.
V1->V2:
* Output the acceptable values of enum types by "-object TYPE-NAME,help"
Lin Ma (5):
qom: Add interface check in object_class_is_abstract
qapi: auto generate enum value strings
qapi: add test case for the generated enum value str
backends: add description for enum class properties
object: Add 'help' option for all available backends and properties
backends/hostmem.c | 4 +++ crypto/secret.c | 4 +++ crypto/tlscreds.c | 4 +++ include/qom/object_interfaces.h | 2 ++ net/filter.c | 4 +++ qemu-options.hx | 7 +++++- qom/object.c | 6 ++++- qom/object_interfaces.c | 55 +++++++++++++++++++++++++++++++++++++++++ scripts/qapi-types.py | 2 ++ scripts/qapi.py | 9 +++++++ tests/test-qmp-commands.c | 18 ++++++++++++++ vl.c | 5 ++++ 12 files changed, 118 insertions(+), 2 deletions(-)
Signature · 1 line
2.9.2
PATCH v4 1/5 qom: Add interface check in object_class_is_abstract
--- qom/object.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
qom/object.c +5 -1
@@ -747,7 +747,11 @@ ObjectClass *object_get_class(Object *obj)bool object_class_is_abstract (ObjectClass *klass) { -return klass->type->abstract; +if (type_is_ancestor (klass->type, type_interface)) { +return true; + }else { +return klass->type->abstract; + } }const char *object_class_get_name (ObjectClass *klass)
Signature · 1 line
2.9.2
[Qemu-devel] 答复: [PATCH v4 1/5] qom: Add interface check in object_class_is_abstract
ping...
Quoted 1 line
Quoted 1 line
Quoted 1 line
Lin Ma <[email protected]> 2016/10/20 星期四 下午 7:28 >>>
---qom/object.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
qom/object.c +0 -0
@@ -747,7 +747,11 @@ ObjectClass *object_get_class(Object *obj)
bool object_class_is_abstract(ObjectClass *klass)
{
- return klass->type->abstract;
+ if (type_is_ancestor(klass->type, type_interface)) {
+ return true;
+ } else {
+ return klass->type->abstract;
+ }
}
const char *object_class_get_name(ObjectClass *klass)
Signature · 1 line
2.9.2
Re: [Qemu-devel] [PATCH v4 1/5] qom: Add interface check in object_class_is_abstract
In reply to Lin MaQuoted 12 lines · Lin Ma
Signed-off-by Lin Ma <[email protected]>--- qom/object.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)qom/object.c +0
-0@@ -747,7 +747,11 @@ ObjectClass *object_get_class(Object *obj)bool object_class_is_abstract (ObjectClass *klass)
qom/object.c ObjectClass *object_get_class(Object *obj) · line 757
Quoted 10 lines
qom/object.c +5
-1{ -return klass->type->abstract; +if (type_is_ancestor (klass->type, type_interface)) { +return true; + }else { +return klass->type->abstract; + } }const char *object_class_get_name (ObjectClass *klass)
Pardon my ignorance...
If all types derived from type_interface are abstract, why aren't we setting ->abstract right when such a type is defined?
Hmm, perhaps we do? type_initialize_interface() sets info.abstract = true...
In case we don't: what about other uses of ->abstract? Why is it okay not to check whether type_interface is an ancestore there?
[Qemu-devel] 答复: Re: [PATCH v4 1/5] qom: Add interface check in object_class_is_abstract
Quoted 26 lines
Quoted 3 lines
Quoted 3 lines
Markus Armbruster <[email protected]> 2016/11/4 星期五 上午 2:18 >>>
Quoted 21 lines · Lin Ma
Signed-off-by Lin Ma <[email protected]>--- qom/object.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)qom/object.c +5
-1@@ -747,7 +747,11 @@ ObjectClass *object_get_class(Object *obj)bool object_class_is_abstract (ObjectClass *klass) { -return klass->type->abstract; +if (type_is_ancestor (klass->type, type_interface)) { +return true; + }else { +return klass->type->abstract; + } }
Quoted 6 lines
qom/object.c ObjectClass *object_get_class(Object *obj) · line 757
Quoted 1 line
qom/object.c +0
-0const char *object_class_get_name (ObjectClass *klass)Pardon my ignorance...
If all types derived from
type_interfaceare abstract, why aren't we setting ->abstract right when such a type is defined?
For lots of interfaces, they already explicitly define abstract as true, say:
generic-pc-machine in hw/i386/pc.c, or memory-backend in backends/hostmem.c
Please refer to http://lists.nongnu.org/archive/html/qemu-devel/2016-10/msg01955.html
hope it could give you some clue.
but I see that other interfaces (I randomly picked generic-pc-machine and fw_cfg as examples) still explicitly define 'abstract = true'.
Quoted 2 lines
Hmm, perhaps we do?
type_initialize_interface()sets info.abstract = true...
For interfaces, I guess not.
Quoted 2 lines
In case we don't: what about other uses of ->abstract? Why is it okay not to check whether
type_interfaceis an ancestore there?
For lots of interfaces, they already explicitly define abstract as true, say:
generic-pc-machine in hw/i386/pc.c, or memory-backend in backends/hostmem.c So they can be checked through ->abstract, dont need to check whether type_interface is an ancestore.
Thanks,
Lin
PATCH v4 2/5 qapi: auto generate enum value strings
In reply to Lin MaAutomatically generate enum value strings that containing the acceptable values. (Borrowed Daniel's code.)
--- scripts/qapi-types.py | 2 ++ scripts/qapi.py | 9 +++++++++ 2 files changed, 11 insertions(+)
scripts/qapi-types.py +2 -0
@@ -202,9 +202,11 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): self._btin += gen_enum(name, values, prefix) if do_builtins: self.defn += gen_enum_lookup(name, values, prefix) + self._btin += gen_enum_value_str(name, values) else: self._fwdecl += gen_enum(name, values, prefix) self.defn += gen_enum_lookup(name, values, prefix) + self._fwdecl += gen_enum_value_str(name, values) def visit_array_type(self, name, info, element_type): if isinstance(element_type, QAPISchemaBuiltinType):
scripts/qapi.py +9 -0
@@ -1649,6 +1649,15 @@ const char *const %(c_name)s_lookup[] = { return ret +def gen_enum_value_str(name, values): + return mcgen(''' + +#define %(c_name)s_value_str "%(value_str)s" +''', + c_name=c_name(name), + value_str=", ".join(["'%s'" % c for c in values])) + + def gen_enum(name, values, prefix=None): # append automatically generated _MAX value enum_values = values + ['_MAX']
Signature · 1 line
2.9.2
[Qemu-devel] 答复: [PATCH v4 2/5] qapi: auto generate enum value strings
ping...
Quoted 1 line
Quoted 1 line
Quoted 1 line
Lin Ma <[email protected]> 2016/10/20 星期四 下午 7:28 >>>
Automatically generate enum value strings that containing the acceptable values. (Borrowed Daniel's code.)
---scripts/qapi-types.py | 2 ++scripts/qapi.py | 9 +++++++++
2 files changed, 11 insertions(+)
scripts/qapi-types.py +0 -0
@@ -202,9 +202,11 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor):
self._btin += gen_enum(name, values, prefix) if do_builtins: self.defn += gen_enum_lookup(name, values, prefix) + self._btin += gen_enum_value_str(name, values) else: self._fwdecl += gen_enum(name, values, prefix) self.defn += gen_enum_lookup(name, values, prefix)
+ self._fwdecl += gen_enum_value_str(name, values)
def visit_array_type(self, name, info, element_type):
if isinstance(element_type, QAPISchemaBuiltinType):
scripts/qapi.py +0 -0
@@ -1649,6 +1649,15 @@ const char *const %(c_name)s_lookup[] = {
return ret
+def gen_enum_value_str(name, values):
+ return mcgen('''
+
+#define %(c_name)s_value_str "%(value_str)s"
+''',
+ c_name=c_name(name),
+ value_str=", ".join(["'%s'" % c for c in values]))
+
+
def gen_enum(name, values, prefix=None):
# append automatically generated _MAX value enum_values = values + ['_MAX']
Signature · 1 line
2.9.2
Re: [Qemu-devel] [PATCH v4 2/5] qapi: auto generate enum value strings
In reply to Lin MaQuoted 35 lines · Lin Ma
Automatically generate enum value strings that containing the acceptable values. (Borrowed Daniel's code.)
Signed-off-by Lin Ma <[email protected]>--- scripts/qapi-types.py | 2 ++ scripts/qapi.py | 9 +++++++++ 2 files changed, 11 insertions(+)scripts/qapi-types.py +2
-0@@ -202,9 +202,11 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): self._btin += gen_enum(name, values, prefix) if do_builtins: self.defn += gen_enum_lookup(name, values, prefix) + self._btin += gen_enum_value_str(name, values) else: self._fwdecl += gen_enum(name, values, prefix) self.defn += gen_enum_lookup(name, values, prefix) + self._fwdecl += gen_enum_value_str(name, values) def visit_array_type(self, name, info, element_type): if isinstance(element_type, QAPISchemaBuiltinType):scripts/qapi.py +2
-0@@ -1649,6 +1649,15 @@ const char *const %(c_name)s_lookup[] = { return ret +def gen_enum_value_str(name, values): + return mcgen('''
scripts/qapi.py const char *const %(c_name)s_lookup[] = { · line 1663
Quoted 10 lines
scripts/qapi.py +7
-0+ +#define %(c_name)s_value_str "%(value_str)s" +''', + c_name=c_name(name), + value_str=", ".join(["'%s'" % c for c in values])) + + def gen_enum(name, values, prefix=None): # append automatically generated _MAX value enum_values = values + ['_MAX']
This function is generating a macro definition, not a string. We could call it gen_enum_values_define(). But I'd simply fold it into gen_enum().
Adds another 9KiB to qapi-types.h, which is included widely. Instead of defining these macros, we could also iterate over FOO_lookup[] at run-time. But let's first review how the macro is used.
[Qemu-devel] 答复: Re: [PATCH v4 2/5] qapi: auto generate enum value strings
Quoted 55 lines
Quoted 3 lines
Quoted 3 lines
Markus Armbruster <[email protected]> 2016/11/4 星期五 上午 3:17 >>>
Quoted 35 lines · Lin Ma
Automatically generate enum value strings that containing the acceptable values. (Borrowed Daniel's code.)
Signed-off-by Lin Ma <[email protected]>--- scripts/qapi-types.py | 2 ++ scripts/qapi.py | 9 +++++++++ 2 files changed, 11 insertions(+)scripts/qapi-types.py +2
-0@@ -202,9 +202,11 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): self._btin += gen_enum(name, values, prefix) if do_builtins: self.defn += gen_enum_lookup(name, values, prefix) + self._btin += gen_enum_value_str(name, values) else: self._fwdecl += gen_enum(name, values, prefix) self.defn += gen_enum_lookup(name, values, prefix) + self._fwdecl += gen_enum_value_str(name, values) def visit_array_type(self, name, info, element_type): if isinstance(element_type, QAPISchemaBuiltinType):scripts/qapi.py +2
-0@@ -1649,6 +1649,15 @@ const char *const %(c_name)s_lookup[] = { return ret +def gen_enum_value_str(name, values): + return mcgen('''scripts/qapi.py const char *const %(c_name)s_lookup[] = { · line 1663
Quoted 10 lines
scripts/qapi.py +7
-0+ +#define %(c_name)s_value_str "%(value_str)s" +''', + c_name=c_name(name), + value_str=", ".join(["'%s'" % c for c in values])) + + def gen_enum(name, values, prefix=None): # append automatically generated _MAX value enum_values = values + ['_MAX']This function is generating a macro definition, not a string. We could call it
gen_enum_values_define(). But I'd simply fold it intogen_enum().
Quoted 3 lines
Adds another 9KiB to
qapi-types.h, which is included widely. Instead of defining these macros, we could also iterate over FOO_lookup[] at run-time. But let's first review how the macro is used.
Sorry, I'm not familiar with writing qemu test code. I didn't understand it. What's the meaning of 'Adds another 9KiB to qapi-types.h'? What is '9KiB'?
Thanks,
Lin
PATCH v4 3/5 qapi: add test case for the generated enum value str
In reply to Lin Ma--- tests/test-qmp-commands.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
tests/test-qmp-commands.c +18 -0
@@ -262,6 +262,23 @@ static void test_dealloc_partial(void)qapi_free_UserDefTwo (ud2); } +/* test generated enum value str */ +static void test_enum_value_str (void ) +{ +EnumOne i; +char *expected_str =NULL ; + +for (i =0 ; i <ENUM_ONE__MAX ; i++) { +if (i ==0 ) { + expected_str =g_strdup_printf ("\'%s\'" , EnumOne_lookup[i]); + }else { + expected_str =g_strdup_printf ("%s, \'%s\'" , + expected_str, EnumOne_lookup[i]); + } + } + g_assert_cmpstr(EnumOne_value_str, ==, expected_str); +} +int main (int argc,char **argv) {
@@ -272,6 +289,7 @@ int main(int argc, char **argv)g_test_add_func ("/0.15/dispatch_cmd_io" , test_dispatch_cmd_io);g_test_add_func ("/0.15/dealloc_types" , test_dealloc_types);g_test_add_func ("/0.15/dealloc_partial" , test_dealloc_partial); +g_test_add_func ("/0.15/enum_value_str" , test_enum_value_str);module_call_init (MODULE_INIT_QAPI );g_test_run ();
Signature · 1 line
2.9.2
[Qemu-devel] 答复: [PATCH v4 3/5] qapi: add test case for the generated enum value str
ping...
Quoted 1 line
Quoted 1 line
Quoted 1 line
Lin Ma <[email protected]> 2016/10/20 星期四 下午 7:28 >>>
---tests/test-qmp-commands.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
tests/test-qmp-commands.c +0 -0
@@ -262,6 +262,23 @@ static void test_dealloc_partial(void)
qapi_free_UserDefTwo(ud2); }
+/* test generated enum value str */
+static void test_enum_value_str(void)
+{
+ EnumOne i;
+ char *expected_str = NULL;
+
+ for (i = 0; i < ENUM_ONE__MAX; i++) {
+ if (i == 0) {
+ expected_str = g_strdup_printf("\'%s\'", EnumOne_lookup[i]);
+ } else {
+ expected_str = g_strdup_printf("%s, \'%s\'",
+ expected_str, EnumOne_lookup[i]);
+ }
+ }
+ g_assert_cmpstr(EnumOne_value_str, ==, expected_str);
+}
+
int main(int argc, char **argv)
{
@@ -272,6 +289,7 @@ int main(int argc, char **argv)
g_test_add_func("/0.15/dispatch_cmd_io", test_dispatch_cmd_io);
g_test_add_func("/0.15/dealloc_types", test_dealloc_types);
g_test_add_func("/0.15/dealloc_partial", test_dealloc_partial);+ g_test_add_func("/0.15/enum_value_str", test_enum_value_str);
module_call_init(MODULE_INIT_QAPI); g_test_run();
Signature · 1 line
2.9.2
PATCH v4 4/5 backends: add description for enum class properties
In reply to Lin Ma--- backends/hostmem.c | 4 ++++ crypto/secret.c | 4 ++++ crypto/tlscreds.c | 4 ++++ net/filter.c | 4 ++++ 4 files changed, 16 insertions(+)
backends/hostmem.c +4 -0
@@ -377,6 +377,10 @@ host_memory_backend_class_init(ObjectClass *oc, void *data) HostMemPolicy_lookup, host_memory_backend_get_policy, host_memory_backend_set_policy, &error_abort); +object_class_property_set_description (oc,"policy" , +"Data format: one of " + HostMemPolicy_value_str, + &error_abort); }static const TypeInfo host_memory_backend_info = {
crypto/secret.c +4 -0
@@ -382,6 +382,10 @@ qcrypto_secret_class_init(ObjectClass *oc, void *data) qcrypto_secret_prop_get_format, qcrypto_secret_prop_set_format, NULL); +object_class_property_set_description (oc,"format" , +"Data format: one of " + QCryptoSecretFormat_value_str, + &error_abort); object_class_property_add_str(oc, "data", qcrypto_secret_prop_get_data, qcrypto_secret_prop_set_data,
crypto/tlscreds.c +4 -0
@@ -237,6 +237,10 @@ qcrypto_tls_creds_class_init(ObjectClass *oc, void *data) qcrypto_tls_creds_prop_get_endpoint, qcrypto_tls_creds_prop_set_endpoint, NULL); +object_class_property_set_description (oc,"endpoint" , +"Data format: one of " + QCryptoTLSCredsEndpoint_value_str, + &error_abort); object_class_property_add_str(oc, "priority", qcrypto_tls_creds_prop_get_priority, qcrypto_tls_creds_prop_set_priority,
net/filter.c +4 -0
@@ -182,6 +182,10 @@ static void netfilter_init(Object *obj) NetFilterDirection_lookup, netfilter_get_direction, netfilter_set_direction, NULL); +object_property_set_description (obj,"queue" , +"Data format: one of " + NetFilterDirection_value_str, + &error_abort);object_property_add_str (obj,"status" , netfilter_get_status, netfilter_set_status,NULL );
Signature · 1 line
2.9.2
[Qemu-devel] 答复: [PATCH v4 4/5] backends: add description for enum class properties
ping...
Quoted 1 line
Quoted 1 line
Quoted 1 line
Lin Ma <[email protected]> 2016/10/20 星期四 下午 7:28 >>>
---
backends/hostmem.c | 4 ++++ crypto/secret.c | 4 ++++ crypto/tlscreds.c | 4 ++++ net/filter.c | 4 ++++ 4 files changed, 16 insertions(+)
backends/hostmem.c +0 -0
@@ -377,6 +377,10 @@ host_memory_backend_class_init(ObjectClass *oc, void *data)
HostMemPolicy_lookup, host_memory_backend_get_policy, host_memory_backend_set_policy, &error_abort); + object_class_property_set_description(oc, "policy", + "Data format: one of " + HostMemPolicy_value_str, + &error_abort);
}
static const TypeInfo host_memory_backend_info = {
crypto/secret.c +0 -0
@@ -382,6 +382,10 @@ qcrypto_secret_class_init(ObjectClass *oc, void *data)
qcrypto_secret_prop_get_format, qcrypto_secret_prop_set_format, NULL); + object_class_property_set_description(oc, "format", + "Data format: one of " + QCryptoSecretFormat_value_str, + &error_abort);
object_class_property_add_str(oc, "data",
qcrypto_secret_prop_get_data, qcrypto_secret_prop_set_data,
crypto/tlscreds.c +0 -0
@@ -237,6 +237,10 @@ qcrypto_tls_creds_class_init(ObjectClass *oc, void *data)
qcrypto_tls_creds_prop_get_endpoint, qcrypto_tls_creds_prop_set_endpoint, NULL); + object_class_property_set_description(oc, "endpoint", + "Data format: one of " + QCryptoTLSCredsEndpoint_value_str, + &error_abort);
object_class_property_add_str(oc, "priority",
qcrypto_tls_creds_prop_get_priority, qcrypto_tls_creds_prop_set_priority,
net/filter.c +0 -0
@@ -182,6 +182,10 @@ static void netfilter_init(Object *obj)
NetFilterDirection_lookup, netfilter_get_direction, netfilter_set_direction, NULL); + object_property_set_description(obj, "queue", + "Data format: one of " + NetFilterDirection_value_str, + &error_abort); object_property_add_str(obj, "status", netfilter_get_status, netfilter_set_status, NULL);
Signature · 1 line
2.9.2
Re: [Qemu-devel] [PATCH v4 4/5] backends: add description for enum class properties
In reply to Lin MaQuoted 58 lines · Lin Ma
Signed-off-by Lin Ma <[email protected]>--- backends/hostmem.c | 4 ++++ crypto/secret.c | 4 ++++ crypto/tlscreds.c | 4 ++++ net/filter.c | 4 ++++ 4 files changed, 16 insertions(+)backends/hostmem.c +4
-0@@ -377,6 +377,10 @@ host_memory_backend_class_init(ObjectClass *oc, void *data) HostMemPolicy_lookup, host_memory_backend_get_policy, host_memory_backend_set_policy, &error_abort); +object_class_property_set_description (oc,"policy" , +"Data format: one of " + HostMemPolicy_value_str, + &error_abort); }static const TypeInfo host_memory_backend_info = {crypto/secret.c +4
-0@@ -382,6 +382,10 @@ qcrypto_secret_class_init(ObjectClass *oc, void *data) qcrypto_secret_prop_get_format, qcrypto_secret_prop_set_format, NULL); +object_class_property_set_description (oc,"format" , +"Data format: one of " + QCryptoSecretFormat_value_str, + &error_abort); object_class_property_add_str(oc, "data", qcrypto_secret_prop_get_data, qcrypto_secret_prop_set_data,crypto/tlscreds.c +4
-0@@ -237,6 +237,10 @@ qcrypto_tls_creds_class_init(ObjectClass *oc, void *data) qcrypto_tls_creds_prop_get_endpoint, qcrypto_tls_creds_prop_set_endpoint, NULL); +object_class_property_set_description (oc,"endpoint" , +"Data format: one of " + QCryptoTLSCredsEndpoint_value_str, + &error_abort); object_class_property_add_str(oc, "priority", qcrypto_tls_creds_prop_get_priority, qcrypto_tls_creds_prop_set_priority,net/filter.c +0
-0
net/filter.c static void netfilter_init(Object *obj) · line 191
Quoted 10 lines
net/filter.c +4
-0@@ -182,6 +182,10 @@ static void netfilter_init(Object *obj) NetFilterDirection_lookup, netfilter_get_direction, netfilter_set_direction, NULL); +object_property_set_description (obj,"queue" , +"Data format: one of " + NetFilterDirection_value_str, + &error_abort);object_property_add_str (obj,"status" , netfilter_get_status, netfilter_set_status,NULL );
After each
object_class_property_add_enum(OC, PROP_NAME", ENUM_NAME, ...);
you add
object_class_property_set_description(OC, PROP_NAME,
"Data format: one of " ENUM_NAME_value_str, &error_abort);
Whenever somebody adds another object_class_property_add_enum(), he should also add an object_class_property_set_description(). Easily forgotten.
Why not do it in object_class_property_add_enum() automatically? We got strings[] there...
[Qemu-devel] 答复: Re: [PATCH v4 4/5] backends: add description for enum class properties
Quoted 85 lines
Quoted 3 lines
Quoted 3 lines
Markus Armbruster <[email protected]> 2016/11/4 星期五 上午 3:58 >>>
Quoted 58 lines · Lin Ma
Signed-off-by Lin Ma <[email protected]>--- backends/hostmem.c | 4 ++++ crypto/secret.c | 4 ++++ crypto/tlscreds.c | 4 ++++ net/filter.c | 4 ++++ 4 files changed, 16 insertions(+)backends/hostmem.c +4
-0@@ -377,6 +377,10 @@ host_memory_backend_class_init(ObjectClass *oc, void *data) HostMemPolicy_lookup, host_memory_backend_get_policy, host_memory_backend_set_policy, &error_abort); +object_class_property_set_description (oc,"policy" , +"Data format: one of " + HostMemPolicy_value_str, + &error_abort); }static const TypeInfo host_memory_backend_info = {crypto/secret.c +4
-0@@ -382,6 +382,10 @@ qcrypto_secret_class_init(ObjectClass *oc, void *data) qcrypto_secret_prop_get_format, qcrypto_secret_prop_set_format, NULL); +object_class_property_set_description (oc,"format" , +"Data format: one of " + QCryptoSecretFormat_value_str, + &error_abort); object_class_property_add_str(oc, "data", qcrypto_secret_prop_get_data, qcrypto_secret_prop_set_data,crypto/tlscreds.c +4
-0@@ -237,6 +237,10 @@ qcrypto_tls_creds_class_init(ObjectClass *oc, void *data) qcrypto_tls_creds_prop_get_endpoint, qcrypto_tls_creds_prop_set_endpoint, NULL); +object_class_property_set_description (oc,"endpoint" , +"Data format: one of " + QCryptoTLSCredsEndpoint_value_str, + &error_abort); object_class_property_add_str(oc, "priority", qcrypto_tls_creds_prop_get_priority, qcrypto_tls_creds_prop_set_priority,net/filter.c +0
-0net/filter.c static void netfilter_init(Object *obj) · line 191
Quoted 10 lines
net/filter.c +4
-0@@ -182,6 +182,10 @@ static void netfilter_init(Object *obj) NetFilterDirection_lookup, netfilter_get_direction, netfilter_set_direction, NULL); +object_property_set_description (obj,"queue" , +"Data format: one of " + NetFilterDirection_value_str, + &error_abort);object_property_add_str (obj,"status" , netfilter_get_status, netfilter_set_status,NULL );After each
object_class_property_add_enum(OC, PROP_NAME", ENUM_NAME, ...);you add
object_class_property_set_description(OC,
PROP_NAME,"Data format: one of " ENUM_NAME_value_str, &error_abort);
Quoted 6 lines
Whenever somebody adds another
object_class_property_add_enum(), he should also add anobject_class_property_set_description(). Easily forgotten.Why not do it in
object_class_property_add_enum()automatically? We got strings[] there...
Because in the help output, I'd like to treat the output as two part:
enum type name + description of enum type name.
So I didn't add it in object_class_property_add_enum().
Yes, it is easy to forget calling object_class_property_set_description(). But is it really better that combine it into object_class_property_add_enum()?
Thanks,
Lin
Re: [Qemu-devel] [PATCH v4 4/5] backends: add description for enum class properties
In reply to Markus ArmbrusterQuoted 82 lines · Markus Armbruster
Quoted 58 lines · Lin Ma
Signed-off-by Lin Ma <[email protected]>--- backends/hostmem.c | 4 ++++ crypto/secret.c | 4 ++++ crypto/tlscreds.c | 4 ++++ net/filter.c | 4 ++++ 4 files changed, 16 insertions(+)backends/hostmem.c +4
-0@@ -377,6 +377,10 @@ host_memory_backend_class_init(ObjectClass *oc, void *data) HostMemPolicy_lookup, host_memory_backend_get_policy, host_memory_backend_set_policy, &error_abort); +object_class_property_set_description (oc,"policy" , +"Data format: one of " + HostMemPolicy_value_str, + &error_abort); }static const TypeInfo host_memory_backend_info = {crypto/secret.c +4
-0@@ -382,6 +382,10 @@ qcrypto_secret_class_init(ObjectClass *oc, void *data) qcrypto_secret_prop_get_format, qcrypto_secret_prop_set_format, NULL); +object_class_property_set_description (oc,"format" , +"Data format: one of " + QCryptoSecretFormat_value_str, + &error_abort); object_class_property_add_str(oc, "data", qcrypto_secret_prop_get_data, qcrypto_secret_prop_set_data,crypto/tlscreds.c +4
-0@@ -237,6 +237,10 @@ qcrypto_tls_creds_class_init(ObjectClass *oc, void *data) qcrypto_tls_creds_prop_get_endpoint, qcrypto_tls_creds_prop_set_endpoint, NULL); +object_class_property_set_description (oc,"endpoint" , +"Data format: one of " + QCryptoTLSCredsEndpoint_value_str, + &error_abort); object_class_property_add_str(oc, "priority", qcrypto_tls_creds_prop_get_priority, qcrypto_tls_creds_prop_set_priority,net/filter.c +0
-0net/filter.c static void netfilter_init(Object *obj) · line 191
Quoted 10 lines
net/filter.c +4
-0@@ -182,6 +182,10 @@ static void netfilter_init(Object *obj) NetFilterDirection_lookup, netfilter_get_direction, netfilter_set_direction, NULL); +object_property_set_description (obj,"queue" , +"Data format: one of " + NetFilterDirection_value_str, + &error_abort);object_property_add_str (obj,"status" , netfilter_get_status, netfilter_set_status,NULL );After each
object_class_property_add_enum(OC, PROP_NAME", ENUM_NAME, ...);you add
object_class_property_set_description(OC,
PROP_NAME,
"Data format: one of "ENUM_NAME_value_str,&error_abort);
Quoted 6 lines
Whenever somebody adds another
object_class_property_add_enum(), he should also add anobject_class_property_set_description(). Easily forgotten.Why not do it in
object_class_property_add_enum()automatically? We got strings[] there...
We could make every single object_property_add_* method accept a description, but it'd be a huge code-churn to retrofit.
Regards,
Daniel
Signature · 3 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://entangle-photo.org -o- http://search.cpan.org/~danberr/ :|
PATCH v4 5/5 object: Add 'help' option for all available backends and properties
In reply to Lin Ma'-object help' prints available user creatable backends. '-object $typename,help' prints relevant properties.
--- include/qom/object_interfaces.h | 2 ++ qemu-options.hx | 7 +++++- qom/object_interfaces.c | 55 +++++++++++++++++++++++++++++++++++++++++ vl.c | 5 ++++ 4 files changed, 68 insertions(+), 1 deletion(-)
include/qom/object_interfaces.h +2 -0
@@ -165,4 +165,6 @@ int user_creatable_add_opts_foreach(void *opaque,*/ void user_creatable_del (const char *id,Error **errp); +int user_creatable_help_func (void *opaque,QemuOpts *opts,Error **errp); +#endif
qemu-options.hx +6 -1
@@ -3761,7 +3761,9 @@ DEF("object", HAS_ARG, QEMU_OPTION_object, " create a new object of type TYPENAME setting properties\n" " in the order they are specified. Note that the 'id'\n" " property must be set. These objects are placed in the\n" - " '/objects' path.\n", + " '/objects' path.\n" + " Use '-object help' to print available backend types and\n" + " '-object typename,help' to print relevant properties.\n", QEMU_ARCH_ALL) STEXI @item -object @var{typename}[,@var{prop1}=@var{value1},...]
@@ -3771,6 +3773,9 @@ in the order they are specified. Note that the 'id' property must be set. These objects are placed in the '/objects' path. +Use @code{-object help} to print available backend types and +@code{-object @var{typename},help} to print relevant properties. + @table @option @item -object memory-backend-file,id=@var{id},size=@var{size},mem-path=@var{dir},share=@var{on|off}
qom/object_interfaces.c +55 -0
67 lines not on this page · raw message
vl.c +5 -0
@@ -4100,6 +4100,11 @@ int main(int argc, char **argv, char **envp)exit (0 ); } +if (qemu_opts_foreach (qemu_find_opts ("object" ), user_creatable_help_func, +NULL ,NULL )) { +exit (1 ); + } +if (!trace_init_backends ()) {exit (1 ); }
Signature · 1 line
2.9.2
ping...
Quoted 1 line
Quoted 1 line
Quoted 1 line
Lin Ma <[email protected]> 2016/10/20 星期四 下午 7:28 >>>
'-object help' prints available user creatable backends. '-object $typename,help' prints relevant properties.
---include/qom/object_interfaces.h | 2 ++
qemu-options.hx | 7 +++++-qom/object_interfaces.c | 55 +++++++++++++++++++++++++++++++++++++++++vl.c | 5 ++++
4 files changed, 68 insertions(+), 1 deletion(-)
include/qom/object_interfaces.h +0 -0
@@ -165,4 +165,6 @@ int user_creatable_add_opts_foreach(void *opaque,*/
void user_creatable_del(const char *id, Error **errp);
+int user_creatable_help_func(void *opaque, QemuOpts *opts, Error **errp); +
#endif
qemu-options.hx +0 -0
@@ -3761,7 +3761,9 @@ DEF("object", HAS_ARG, QEMU_OPTION_object,
" create a new object of type TYPENAME setting properties\n" " in the order they are specified. Note that the 'id'\n" " property must be set. These objects are placed in the\n" - " '/objects' path.\n", + " '/objects' path.\n" + " Use '-object help' to print available backend types and\n" + " '-object typename,help' to print relevant properties.\n",
QEMU_ARCH_ALL)
STEXI
@item -object @var{typename}[,@var{prop1}=@var{value1},...]
@@ -3771,6 +3773,9 @@ in the order they are specified. Note that the 'id' property must be set. These objects are placed in the '/objects' path.
+Use @code{-object help} to print available backend types and +@code{-object @var{typename},help} to print relevant properties. +
@table @option
@item -object memory-backend-file,id=@var{id},size=@var{size},mem-path=@var{dir},share=@var{on|off}
qom/object_interfaces.c +0 -0
@@ -5,6 +5,7 @@
#include "qapi-visit.h"
#include "qapi/qmp-output-visitor.h"
#include "qapi/opts-visitor.h"
+#include "qemu/help_option.h"
void user_creatable_complete(Object *obj, Error **errp)
{
@@ -212,6 +213,60 @@ void user_creatable_del(const char *id, Error **errp)
object_unparent(obj); }
+int user_creatable_help_func(void *opaque, QemuOpts *opts, Error **errp) +{
+ const char *type = NULL;
+ Object *obj = NULL;
+ ObjectClass *klass;
+ ObjectProperty *prop;
+ ObjectPropertyIterator iter;
+
+ type = qemu_opt_get(opts, "qom-type");
+ if (type && is_help_option(type)) {
+ GSList *list;
+ printf("Available object backend types:\n");
+ for (list = object_class_get_list(TYPE_USER_CREATABLE, false); \
+ list; \
+ list = list->next) {
+ const char *name;
+ name = object_class_get_name(OBJECT_CLASS(list->data));
+ if (strcmp(name, TYPE_USER_CREATABLE)) {
+ printf("%s\n", name);
+ }
+ }
+ g_slist_free(list);
+ goto out;+ }
+
+ if (!type || !qemu_opt_has_help_opt(opts)) {
+ return 0;
+ }
+
+ klass = object_class_by_name(type);
+ if (!klass) {
+ printf("invalid object type: %s\n", type);
+ goto out;
+ }
+ if (object_class_is_abstract(klass)) {
+ printf("object type '%s' is abstract\n", type);
+ goto out;
+ } + obj = object_new(type); + object_property_iter_init(&iter, obj);
+
+ while ((prop = object_property_iter_next(&iter))) {
+ if (prop->description) {
+ printf("%s (%s, %s)\n", prop->name, prop->type, prop->description);
+ } else {
+ printf("%s (%s)\n", prop->name, prop->type);
+ }
+ }
+
+out:
+ object_unref(obj);
+ return 1;
+}
+
static void register_types(void)
{
static const TypeInfo uc_interface_info = {vl.c +0 -0
6eca 100644
vl.c +0 -0
@@ -4100,6 +4100,11 @@ int main(int argc, char **argv, char **envp)
exit(0); }
+ if (qemu_opts_foreach(qemu_find_opts("object"), user_creatable_help_func,
+ NULL, NULL)) {
+ exit(1);
+ }
+
if (!trace_init_backends()) {
exit(1);
}Signature · 1 line
2.9.2
Quoted 16 lines · Lin Ma
'-object help' prints available user creatable backends. '-object $typename,help' prints relevant properties.
Signed-off-by Lin Ma <[email protected]>--- include/qom/object_interfaces.h | 2 ++ qemu-options.hx | 7 +++++- qom/object_interfaces.c | 55 +++++++++++++++++++++++++++++++++++++++++ vl.c | 5 ++++ 4 files changed, 68 insertions(+), 1 deletion(-)include/qom/object_interfaces.h +0
-0
include/qom/object_interfaces.h int user_creatable_add_opts_foreach(void *opaque, · line 169
Quoted 5 lines
include/qom/object_interfaces.h +2
-0@@ -165,4 +165,6 @@ int user_creatable_add_opts_foreach(void *opaque,*/ void user_creatable_del (const char *id,Error **errp); +int user_creatable_help_func (void *opaque,QemuOpts *opts,Error **errp); +
Ugly interface: two arguments that aren't used, one of them void *. Suggest to follow the device help example: do a non-ugly interface here, and an ugly, but static wrapper in vl.c
qemu-options.hx DEF("object", HAS_ARG, QEMU_OPTION_object, · line 3766
Quoted 13 lines
include/qom/object_interfaces.h +0
-0#endif qemu-options.hx +3
-1@@ -3761,7 +3761,9 @@ DEF("object", HAS_ARG, QEMU_OPTION_object, " create a new object of type TYPENAME setting properties\n" " in the order they are specified. Note that the 'id'\n" " property must be set. These objects are placed in the\n" - " '/objects' path.\n", + " '/objects' path.\n" + " Use '-object help' to print available backend types and\n" + " '-object typename,help' to print relevant properties.\n",
The existing text talks about "object of type TYPENAME". The new text suddenly talks about "backend types". Switching terminology is not a good idea. Call them "object types".
For comparison, here's the text we use for -device:
use '-device help' to print all possible drivers use '-device driver,help' to print all possible properties
Let's make this one similar:
use '-object help' to print all possible object types use '-object driver,help' to print all possible properties
qemu-options.hx in the order they are specified. Note that the 'id' · line 3778
Quoted 10 lines
qemu-options.hx +3
-0QEMU_ARCH_ALL) STEXI @item -object @var{typename}[,@var{prop1}=@var{value1},...]@@ -3771,6 +3773,9 @@ in the order they are specified. Note that the 'id' property must be set. These objects are placed in the '/objects' path. +Use @code{-object help} to print available backend types and +@code{-object @var{typename},help} to print relevant properties. +
-device's text:
To get help on possible drivers and properties, use @code{-device help} and @code{-device @var{driver},help}.
Suggest:
To get help on possible object types and properties, use @code{-object help} and @code{-object @var{type},help}.
Quoted 21 lines
qemu-options.hx +0
-0@table @option @item -object memory-backend-file,id=@var{id},size=@var{size},mem-path=@var{dir},share=@var{on|off}qom/object_interfaces.c +3
-0@@ -5,6 +5,7 @@#include "qapi-visit.h" #include "qapi/qmp-output-visitor.h" #include "qapi/opts-visitor.h" +#include "qemu/help_option.h" void user_creatable_complete (Object *obj,Error **errp) {@@ -212,6 +213,60 @@ void user_creatable_del(const char *id, Error **errp)object_unparent (obj); } +int user_creatable_help_func (void *opaque,QemuOpts *opts,Error **errp) +{
qom/object_interfaces.c void user_creatable_del(const char *id, Error **errp) · line 227
Quoted 10 lines
qom/object_interfaces.c +10
-0+const char *type =NULL ; +Object *obj =NULL ; +ObjectClass *klass; +ObjectProperty *prop; +ObjectPropertyIterator iter; + + type =qemu_opt_get (opts,"qom-type" ); +if (type &&is_help_option (type)) { +GSList *list; +printf ("Available object backend types:\n" );
Wrong when running for an HMP monitor command, e.g. "object_add help". Use error_printf(). That's only slightly wrong in that it prints to stderr instead of stdout running for the command line.
qom/object_interfaces.c void user_creatable_del(const char *id, Error **errp) · line 230
Quoted 3 lines
qom/object_interfaces.c +3
-0+for (list =object_class_get_list (TYPE_USER_CREATABLE , false); \ + list; \ + list = list->next) {
Superfluous line continuations. Simply write
for (list = object_class_get_list(TYPE_USER_CREATABLE, false);
list;
list = list->next) {Alternatively,
list = object_class_get_list(TYPE_USER_CREATABLE, false);
for (elt = list; elt; elt = elt->next) {qom/object_interfaces.c void user_creatable_del(const char *id, Error **errp) · line 234
Quoted 4 lines
qom/object_interfaces.c +4
-0+const char *name; + name =object_class_get_name (OBJECT_CLASS (list->data)); +if (strcmp (name,TYPE_USER_CREATABLE )) { +printf ("%s\n" , name);
error_printf()
qom/object_interfaces.c void user_creatable_del(const char *id, Error **errp) · line 237
Quoted 3 lines
qom/object_interfaces.c +3
-0+ } + } +g_slist_free (list);
Leaks the list, because by now @list is null. Suggest to fix by adopting the code under "alternatively".
qom/object_interfaces.c void user_creatable_del(const char *id, Error **errp) · line 238
Quoted 1 line
qom/object_interfaces.c +1
-0+ goto out;
Suggest return 1, because ...
qom/object_interfaces.c void user_creatable_del(const char *id, Error **errp) · line 242
Quoted 4 lines
qom/object_interfaces.c +4
-0+ } + +if (!type || !qemu_opt_has_help_opt (opts)) { +return 0 ;
... you're not going to out here.
No need to initialize @obj then.
qom/object_interfaces.c void user_creatable_del(const char *id, Error **errp) · line 247
Quoted 5 lines
qom/object_interfaces.c +5
-0+ } + + klass =object_class_by_name (type); +if (!klass) { +printf ("invalid object type: %s\n" , type);
Please use error_report().
qom/object_interfaces.c void user_creatable_del(const char *id, Error **errp) · line 248
Quoted 1 line
qom/object_interfaces.c +1
-0+ goto out;
return 1 would do.
qom/object_interfaces.c void user_creatable_del(const char *id, Error **errp) · line 251
Quoted 3 lines
qom/object_interfaces.c +3
-0+ } +if (object_class_is_abstract (klass)) { +printf ("object type '%s' is abstract\n" , type);
Please use error_report().
qom/object_interfaces.c void user_creatable_del(const char *id, Error **errp) · line 252
Quoted 1 line
qom/object_interfaces.c +1
-0+ goto out;
return 1 would do.
qom/object_interfaces.c void user_creatable_del(const char *id, Error **errp) · line 253
Quoted 1 line
qom/object_interfaces.c +1
-0+ }
I'd put a blank line here ...
qom/object_interfaces.c void user_creatable_del(const char *id, Error **errp) · line 256
Quoted 3 lines
qom/object_interfaces.c +3
-0+ obj =object_new (type); +object_property_iter_init (&iter, obj); +
... instead of here.
qom/object_interfaces.c void user_creatable_del(const char *id, Error **errp) · line 262
Quoted 6 lines
qom/object_interfaces.c +6
-0+while ((prop =object_property_iter_next (&iter))) { +if (prop->description) { +printf ("%s (%s, %s)\n" , prop->name, prop->type, prop->description); + }else { +printf ("%s (%s)\n" , prop->name, prop->type); + }
error_printf()
qom/object_interfaces.c void user_creatable_del(const char *id, Error **errp) · line 263
Quoted 1 line
qom/object_interfaces.c +1
-0+ }
There's a very similar loop in machine_help_func(). Can we avoid the duplication?
qom/object_interfaces.c void user_creatable_del(const char *id, Error **errp) · line 265
Quoted 2 lines
qom/object_interfaces.c +2
-0+ +out:
You don't actually need this label.
Quoted 13 lines
qom/object_interfaces.c +4
-0+object_unref (obj); +return 1 ; +} +static void register_types (void ) {static const TypeInfo uc_interface_info = {vl.c +0
-0@@ -4100,6 +4100,11 @@ int main(int argc, char **argv, char **envp)exit (0 );
vl.c int main(int argc, char **argv, char **envp) · line 4110
Quoted 10 lines
vl.c +5
-0} +if (qemu_opts_foreach (qemu_find_opts ("object" ), user_creatable_help_func, +NULL ,NULL )) { +exit (1 ); + } +if (!trace_init_backends ()) {exit (1 ); }
Can you explain why you picked this spot in main()?
Quoted 24 lines
Quoted 3 lines
Quoted 3 lines
Markus Armbruster <[email protected]> 2016/11/4 星期五 上午 3:50 >>>
Quoted 19 lines · Lin Ma
'-object help' prints available user creatable backends. '-object $typename,help' prints relevant properties.
Signed-off-by Lin Ma <[email protected]>--- include/qom/object_interfaces.h | 2 ++ qemu-options.hx | 7 +++++- qom/object_interfaces.c | 55 +++++++++++++++++++++++++++++++++++++++++ vl.c | 5 ++++ 4 files changed, 68 insertions(+), 1 deletion(-)include/qom/object_interfaces.h +0
-0@@ -165,4 +165,6 @@ int user_creatable_add_opts_foreach(void *opaque,*/ void user_creatable_del (const char *id,Error **errp);
Quoted 6 lines
include/qom/object_interfaces.h int user_creatable_add_opts_foreach(void *opaque, · line 169
Quoted 2 lines
include/qom/object_interfaces.h +2
-0+int user_creatable_help_func (void *opaque,QemuOpts *opts,Error **errp); +Ugly interface: two arguments that aren't used, one of them void *. Suggest to follow the device help example: do a non-ugly interface here, and an ugly, but static wrapper in
vl.c
ok, will do.
Quoted 20 lines
qemu-options.hx DEF("object", HAS_ARG, QEMU_OPTION_object, · line 3766
Quoted 13 lines
include/qom/object_interfaces.h +0
-0#endif qemu-options.hx +3
-1@@ -3761,7 +3761,9 @@ DEF("object", HAS_ARG, QEMU_OPTION_object, " create a new object of type TYPENAME setting properties\n" " in the order they are specified. Note that the 'id'\n" " property must be set. These objects are placed in the\n" - " '/objects' path.\n", + " '/objects' path.\n" + " Use '-object help' to print available backend types and\n" + " '-object typename,help' to print relevant properties.\n",The existing text talks about "object of type TYPENAME". The new text suddenly talks about "backend types". Switching terminology is not a good idea. Call them "object types".
For comparison, here's the text we use for -device:
Quoted 7 lines
use '-device help' to print all possible drivers use '-device driver,help' to print all possible properties
Let's make this one similar:
use '-object help' to print all possible object types use '-object driver,help' to print all possible properties
ok, will do.
Quoted 13 lines
qemu-options.hx in the order they are specified. Note that the 'id' · line 3778
Quoted 10 lines
qemu-options.hx +3
-0QEMU_ARCH_ALL) STEXI @item -object @var{typename}[,@var{prop1}=@var{value1},...]@@ -3771,6 +3773,9 @@ in the order they are specified. Note that the 'id' property must be set. These objects are placed in the '/objects' path. +Use @code{-object help} to print available backend types and +@code{-object @var{typename},help} to print relevant properties. +-device's text:
Quoted 7 lines
To get help on possible drivers and properties, use @code{-device help} and @code{-device @var{driver},help}.
Suggest:
To get help on possible object types and properties, use @code{-object help} and @code{-object @var{type},help}.
ok, will do.
Quoted 19 lines
Quoted 19 lines
qemu-options.hx +0
-0@table @option @item -object memory-backend-file,id=@var{id},size=@var{size},mem-path=@var{dir},share=@var{on|off}qom/object_interfaces.c +1
-0@@ -5,6 +5,7 @@#include "qapi-visit.h" #include "qapi/qmp-output-visitor.h" #include "qapi/opts-visitor.h" +#include "qemu/help_option.h" void user_creatable_complete (Object *obj,Error **errp) {@@ -212,6 +213,60 @@ void user_creatable_del(const char *id, Error **errp)object_unparent (obj); }
Quoted 9 lines
qom/object_interfaces.c void user_creatable_del(const char *id, Error **errp)
Quoted 9 lines
qom/object_interfaces.c +9
-0+int user_creatable_help_func (void *opaque,QemuOpts *opts,Error **errp) +{ +const char *type =NULL ; +Object *obj =NULL ; +ObjectClass *klass; +ObjectProperty *prop; +ObjectPropertyIterator iter; + + type = qemu_opt_get(opts, "qom-typ
e");
Quoted 7 lines
qom/object_interfaces.c void user_creatable_del(const char *id, Error **errp) · line 227
Quoted 3 lines
qom/object_interfaces.c +3
-0+if (type &&is_help_option (type)) { +GSList *list; +printf ("Available object backend types:\n" );Wrong when running for an HMP monitor command, e.g. "
object_addhelp". Useerror_printf(). That's only slightly wrong in that it prints to stderr instead of stdout running for the command line.
using error_printf() instead of it, no problem.
But the current code doesn't support 'object_add help', Should I modify code to support it in this patch?
Quoted 6 lines
qom/object_interfaces.c void user_creatable_del(const char *id, Error **errp) · line 230
Quoted 3 lines
qom/object_interfaces.c +3
-0+for (list =object_class_get_list (TYPE_USER_CREATABLE , false); \ + list; \ + list = list->next) {Superfluous line continuations. Simply write
Quoted 8 lines
for (list = object_class_get_list(TYPE_USER_CREATABLE, false); list; list = list->next) {Alternatively,
list = object_class_get_list(TYPE_USER_CREATABLE, false); for (elt = list; elt; elt = elt->next) {
Perhaps this one is better.
Quoted 59 lines
qom/object_interfaces.c void user_creatable_del(const char *id, Error **errp) · line 234
Quoted 4 lines
qom/object_interfaces.c +4
-0+const char *name; + name =object_class_get_name (OBJECT_CLASS (list->data)); +if (strcmp (name,TYPE_USER_CREATABLE )) { +printf ("%s\n" , name);
error_printf()qom/object_interfaces.c void user_creatable_del(const char *id, Error **errp) · line 237
Quoted 3 lines
qom/object_interfaces.c +3
-0+ } + } +g_slist_free (list);Leaks the list, because by now @list is null. Suggest to fix by adopting the code under "alternatively".
qom/object_interfaces.c void user_creatable_del(const char *id, Error **errp) · line 238
Quoted 1 line
qom/object_interfaces.c +1
-0+ goto out;Suggest return 1, because ...
qom/object_interfaces.c void user_creatable_del(const char *id, Error **errp) · line 242
Quoted 4 lines
qom/object_interfaces.c +4
-0+ } + +if (!type || !qemu_opt_has_help_opt (opts)) { +return 0 ;... you're not going to out here.
No need to initialize @obj then.
qom/object_interfaces.c void user_creatable_del(const char *id, Error **errp) · line 247
Quoted 5 lines
qom/object_interfaces.c +5
-0+ } + + klass =object_class_by_name (type); +if (!klass) { +printf ("invalid object type: %s\n" , type);Please use
error_report().qom/object_interfaces.c void user_creatable_del(const char *id, Error **errp) · line 248
Quoted 1 line
qom/object_interfaces.c +1
-0+ goto out;return 1 would do.
qom/object_interfaces.c void user_creatable_del(const char *id, Error **errp) · line 251
Quoted 3 lines
qom/object_interfaces.c +3
-0+ } +if (object_class_is_abstract (klass)) { +printf ("object type '%s' is abstract\n" , type);Please use
error_report().qom/object_interfaces.c void user_creatable_del(const char *id, Error **errp) · line 252
Quoted 1 line
qom/object_interfaces.c +1
-0+ goto out;return 1 would do.
qom/object_interfaces.c void user_creatable_del(const char *id, Error **errp) · line 253
Quoted 1 line
qom/object_interfaces.c +1
-0+ }I'd put a blank line here ...
qom/object_interfaces.c void user_creatable_del(const char *id, Error **errp) · line 256
Quoted 3 lines
qom/object_interfaces.c +3
-0+ obj =object_new (type); +object_property_iter_init (&iter, obj); +... instead of here.
Quoted 8 lines
qom/object_interfaces.c void user_creatable_del(const char *id, Error **errp) · line 262
Quoted 6 lines
qom/object_interfaces.c +6
-0+while ((prop =object_property_iter_next (&iter))) { +if (prop->description) { +printf ("%s (%s, %s)\n" , prop->name, prop->type, prop->description); + }else { +printf ("%s (%s)\n" , prop->name, prop->type); + }
error_printf()
ok, will fix them.
Quoted 4 lines
qom/object_interfaces.c void user_creatable_del(const char *id, Error **errp) · line 263
Quoted 1 line
qom/object_interfaces.c +1
-0+ }There's a very similar loop in
machine_help_func(). Can we avoid the duplication?
I would say negative. using same code snippet in machine_help_func() and in here, we lost flexibility, says if we want to change the output content/format in the future.
Quoted 4 lines
qom/object_interfaces.c void user_creatable_del(const char *id, Error **errp) · line 265
Quoted 2 lines
qom/object_interfaces.c +2
-0+ +out:You don't actually need this label.
ok, will fix it.
Quoted 15 lines
Quoted 15 lines
qom/object_interfaces.c +4
-0+object_unref (obj); +return 1 ; +} +static void register_types (void ) {static const TypeInfo uc_interface_info = {vl.c +0
-0@@ -4100,6 +4100,11 @@ int main(int argc, char **argv, char **envp)exit (0 ); }
Quoted 10 lines
vl.c int main(int argc, char **argv, char **envp) · line 4110
Quoted 8 lines
vl.c +5
-0+if (qemu_opts_foreach (qemu_find_opts ("object" ), user_creatable_help_func, +NULL ,NULL )) { +exit (1 ); + } +if (!trace_init_backends ()) {exit (1 ); }Can you explain why you picked this spot in
main()?
Nothing special, just want to let it run as early as possible. and it can't be run too early because some basic structures/objects of qemu need to be constructed first. May I have your idea?
Thanks,
Lin
ping...
Quoted 1 line
Quoted 1 line
Quoted 1 line
Lin Ma <[email protected]> 2016/10/20 星期四 下午 7:28 >>>
V3->V4:
* drop the code about manually define interface 'user-creatable' as abstract.
* add test case for the generated enum value str.
* split the code about adding descriptions to class properties into a separate patch.
* minor changes in user_creatable_help_func to ignore interface TYPE_USER_CREATABLE.
V2->v3:
* make type user-creatable abstract.
* auto generate enum value strings during qemu configuration.(Borrowwed Daniel's code)
* save the generated enum value strings into member description of ObjectProperty.
* drop the judgement logic of whether a property has an enumeration type anymore, output member description of ObjectProperty directly.
* at least, user_creatable_help_func should be put after 'object_property_add_child(object_get_root(), "machine",OBJECT(current_machine), ...)', because host_memory_backend_init needs to access an instance of type machine.
V1->V2:
* Output the acceptable values of enum types by "-object TYPE-NAME,help"
Lin Ma (5):
qom: Add interface check in object_class_is_abstract
qapi: auto generate enum value strings
qapi: add test case for the generated enum value str
backends: add description for enum class properties
object: Add 'help' option for all available backends and properties
backends/hostmem.c | 4 +++ crypto/secret.c | 4 +++ crypto/tlscreds.c | 4 +++ include/qom/object_interfaces.h | 2 ++ net/filter.c | 4 +++ qemu-options.hx | 7 +++++- qom/object.c | 6 ++++-
qom/object_interfaces.c | 55 +++++++++++++++++++++++++++++++++++++++++scripts/qapi-types.py | 2 ++scripts/qapi.py | 9 +++++++tests/test-qmp-commands.c | 18 ++++++++++++++vl.c | 5 ++++
12 files changed, 118 insertions(+), 2 deletions(-)
Signature · 1 line
2.9.2