alternate layout (post-introspection cleanups, subset C)
Subsystems (8)
v9 cover alternate layout (post-introspection cleanups, subset C)
No pending prerequisites; based on qemu.git master
Also available as a tag at this location:
git fetch git://repo.or.cz/qemu/ericb.git qapi-cleanupv9c
and will soon be part of my branch with the rest of the v5 series, at:
http://repo.or.cz/qemu/ericb.git/shortlog/refs/heads/qapi
v9 notes:
More patches added, and several reorganized. Lots of new patches from Markus, although not in the order originally proposed.
The first 8 patches are fairly straightforward, and could probably be taken as-is. Patch 9 is a rewrite of v8 4/17, but in the opposite direction (document that no sorting is done, rather than attempting to sort), so it may need further fine-tuning. Patches 12-21 represents a fusion of Markus' and my attempts to rewrite v5 7/17 into a more-reviewable set of patches, and caused further churn later in the series.
Patch 23 still uses tag_member.type == None; I ran out of time to work on Markus' idea of providing an instance of QAPISchemaBuiltinType to fill the role for 'qtype_code' without being exposed through .json files and without breaking the invariant of a valid member.type after check(), and wanted to get the rest of the series started under revew. So I may need a followup patch or even a v10 of the later half of this series after exploring that idea more.
Here's what backport-diff has to say in relation to v8.
001/27:[----] [--] 'qapi: Use generated TestStruct machinery in tests' 002/27:[----] [--] 'qapi: Strengthen test of TestStructList' 003/27:[0001] [FC] 'qapi: Plug leaks in test-qmp-*'
004/27:[0010] [FC] 'qapi: Simplify error testing in test-qmp-*' 005/27:[down] 'qapi: More tests of alternate output'
006/27:[----] [--] 'qapi: Test failure in middle of array parse' 007/27:[----] [--] 'qapi: More tests of input arrays'
008/27:[----] [--] 'qapi: Provide nicer array names in introspection' 009/27:[down] 'qapi-introspect: Document lack of sorting' 010/27:[0008] [FC] 'qapi: Track simple union tag in object.local_members' 011/27:[0001] [FC] 'qapi-types: Consolidate gen_struct() and gen_union()' 012/27:[down] 'qapi-types: Simplify gen_struct_field[s]' 013/27:[down] 'qapi: Drop obsolete tag value collision assertions' 014/27:[down] 'qapi: Fix up commit 7618b91's clash sanity checking change' 015/27:[down] 'qapi: Simplify QAPISchemaObjectTypeMember.check()' 016/27:[down] 'qapi: Eliminate QAPISchemaObjectType.check() variable members' 017/27:[down] 'qapi: Clean up after previous commit'
018/27:[down] 'qapi: Factor out QAPISchemaObjectTypeMember.check_clash()' 019/27:[down] 'qapi: Check for qapi collisions of flat union branches' 020/27:[down] 'qapi: Simplify QAPISchemaObjectTypeVariants.check()' 021/27:[down] 'qapi: Factor out QAPISchemaObjectType.check_clash()' 022/27:[----] [--] 'qapi: Remove outdated tests related to QMP/branch collisions' 023/27:[0070] [FC] 'qapi: Simplify visiting of alternate types' 024/27:[0014] [FC] 'qapi: Fix alternates that accept 'number' but not 'int'' 025/27:[0018] [FC] 'qapi: Add positive tests to qapi-schema-test' 026/27:[----] [--] 'qapi: Remove dead visitor code'
027/27:[----] [--] 'qapi: Simplify visits of optional fields'
v8 notes:
https://lists.gnu.org/archive/html/qemu-devel/2015-10/msg06674.html
Minor changes when rebasing to latest, improved commit messages in a few places, plus the addition of a few new patches. Markus started reviewing v7, but hadn't gotten very far.
v7 notes:
https://lists.gnu.org/archive/html/qemu-devel/2015-10/msg04112.html
Patches 1-3 of the previous round have moved to subset B; patch 7 is gone, and a couple of new patches are present in this round. The latest version of subset B made it much easier to reason about collision detection (namely, tag values can't collide with QMP values thanks to a named rather than anonymous union in the C type), and I like how things turned out. I suspect the hardest part of the review will be patches 5/14 and 7/14, although none of this has really had much review in any earlier versions.
v6 notes:
https://lists.gnu.org/archive/html/qemu-devel/2015-10/msg01980.html
Add some patches and rebase onto work on subset B. Rearrange some patches from v5 (this set includes 17-20, 23, 25-27). Backport diff gets a bit confused by one patch title changing.
Not much direct review comments, although some of the changes here are updated based on comments made on other patches in the v5 series.
Subset D (and more?) will come later.
In v5:
https://lists.gnu.org/archive/html/qemu-devel/2015-09/msg05410.html
I _did_ rearrange patches to try and group related features:
1-2: Groundwork cleanups
3-5: Add more test cases
6-16: Front-end cleanups
17-18: Introspection output cleanups
19-20: 'alternate' type cleanups
21-29: qapi visitor cleanups
30-45: qapi-ify netdev_add
46: add qapi shorthand for flat unions
Lots of fixes based on additional testing, and rebased to track other changes that happened in the meantime. The series is huge; I can split off smaller portions as requested.
In v4:
https://lists.gnu.org/archive/html/qemu-devel/2015-09/msg02580.html
add some more clean up patches
rebase to Markus' recent work
pull in part of Zoltán's work to make netdev_add a flat union, further enhancing it to be introspectible
I might be able to rearrange some of these patches, or separate it into smaller independent series, if requested; but I'm posting now to get review started.
In v3:
https://lists.gnu.org/archive/html/qemu-devel/2015-08/msg02059.html
redo cleanup of dealloc of partial struct
add patches to make all visit_type_*() avoid leaks on failure add patches to allow boxed command arguments and events
In v2:
https://lists.gnu.org/archive/html/qemu-devel/2015-08/msg00900.html
rebase to Markus' v3 series
rework how comments are emitted for fields inherited from base additional patches added for deleting colliding 'void *data' documentation updates to match code changes
v1 was here:
https://lists.gnu.org/archive/html/qemu-devel/2015-07/msg05266.html
https://lists.gnu.org/archive/html/qemu-devel/2015-07/msg05325.html
Eric Blake (20):
qapi: Use generated TestStruct machinery in tests
qapi: Strengthen test of TestStructList
qapi: Plug leaks in test-qmp-*
qapi: Simplify error testing in test-qmp-*
qapi: More tests of alternate output
qapi: Test failure in middle of array parse
qapi: More tests of input arrays
qapi: Provide nicer array names in introspection
qapi-introspect: Document lack of sorting
qapi: Track simple union tag in object.local_members
qapi-types: Consolidate gen_struct() and gen_union()
qapi-types: Simplify gen_struct_field[s]
qapi: Check for qapi collisions of flat union branches
qapi: Factor out QAPISchemaObjectType.check_clash()
qapi: Remove outdated tests related to QMP/branch collisions
qapi: Simplify visiting of alternate types
qapi: Fix alternates that accept 'number' but not 'int'
qapi: Add positive tests to qapi-schema-test
qapi: Remove dead visitor code
qapi: Simplify visits of optional fields
Markus Armbruster (7):
qapi: Drop obsolete tag value collision assertions
qapi: Fix up commit 7618b91's clash sanity checking change
qapi: Simplify QAPISchemaObjectTypeMember.check()
qapi: Eliminate QAPISchemaObjectType.check() variable members
qapi: Clean up after previous commits
qapi: Factor out QAPISchemaObjectTypeMember.check_clash()
qapi: Simplify QAPISchemaObjectTypeVariants.check()
docs/qapi-code-gen.txt | 29 ++- include/qapi/visitor-impl.h | 27 ++- include/qapi/visitor.h | 22 +- qapi/introspect.json | 21 +- qapi/opts-visitor.c | 2 +- qapi/qapi-visit-core.c | 141 +++++-------- qapi/qmp-input-visitor.c | 11 +- qapi/string-input-visitor.c | 3 +- scripts/qapi-introspect.py | 8 +- scripts/qapi-types.py | 102 +++------- scripts/qapi-visit.py | 28 ++- scripts/qapi.py | 115 ++++++----- tests/Makefile | 3 - tests/qapi-schema/alternate-empty.out | 1 - tests/qapi-schema/flat-union-clash-branch.err | 0 tests/qapi-schema/flat-union-clash-branch.exit | 1 - tests/qapi-schema/flat-union-clash-branch.json | 18 -- tests/qapi-schema/flat-union-clash-branch.out | 14 -- tests/qapi-schema/flat-union-clash-type.err | 1 - tests/qapi-schema/flat-union-clash-type.exit | 1 - tests/qapi-schema/flat-union-clash-type.json | 14 -- tests/qapi-schema/flat-union-clash-type.out | 0 tests/qapi-schema/qapi-schema-test.json | 22 +- tests/qapi-schema/qapi-schema-test.out | 42 +++- tests/qapi-schema/union-clash-data.out | 1 + tests/qapi-schema/union-clash-type.err | 1 - tests/qapi-schema/union-clash-type.exit | 1 - tests/qapi-schema/union-clash-type.json | 9 - tests/qapi-schema/union-clash-type.out | 0 tests/qapi-schema/union-empty.out | 1 + tests/test-qmp-input-strict.c | 108 +++------- tests/test-qmp-input-visitor.c | 268 +++++++++++-------------- tests/test-qmp-output-visitor.c | 153 ++++---------- tests/test-visitor-serialization.c | 76 ++----- 34 files changed, 498 insertions(+), 746 deletions(-) delete mode 100644 tests/qapi-schema/flat-union-clash-branch.err delete mode 100644 tests/qapi-schema/flat-union-clash-branch.exit delete mode 100644 tests/qapi-schema/flat-union-clash-branch.json delete mode 100644 tests/qapi-schema/flat-union-clash-branch.out delete mode 100644 tests/qapi-schema/flat-union-clash-type.err delete mode 100644 tests/qapi-schema/flat-union-clash-type.exit delete mode 100644 tests/qapi-schema/flat-union-clash-type.json delete mode 100644 tests/qapi-schema/flat-union-clash-type.out delete mode 100644 tests/qapi-schema/union-clash-type.err delete mode 100644 tests/qapi-schema/union-clash-type.exit delete mode 100644 tests/qapi-schema/union-clash-type.json delete mode 100644 tests/qapi-schema/union-clash-type.out
Signature · 1 line
2.4.3
PATCH v9 1/27 qapi: Use generated TestStruct machinery in tests
Commit d88f5fd and friends first introduced the various test-qmp-* tests in 2011, with duplicated hand-rolled TestStruct machinery, to make sure the qapi visitor interface was tested. Later, commit 4f193e3 in 2013 added a .json file for further testing use by the files, but without consolidating any of the existing hand-rolled visitors. And with four copies, subtle differences have crept in, between the tests themselves (mainly whitespace differences, but also a question of whether to use NULL or "TestStruct" when calling visit_start_struct()) and from what the generator produces (the hand-rolled versions did not cater to partially-allocated objects, because they did not have a deallocation usage).
Of course, just because the visitor interface is tested does not mean it is a sane interface; and future patches will be changing some of the visitor contracts. Rather than having to duplicate the cleanup work in each copy of the TestStruct visitor, and keep each hand-rolled copy in sync with what the generator supplies, we might as well just test what the generator should give us in the first place.
---
v9: no change
v8: improve commit message
v7: rebase on top of subset B v9; defer unrelated trailing whitespace cleanups to later in series
v6: new patch
--- tests/qapi-schema/qapi-schema-test.json | 6 +++- tests/qapi-schema/qapi-schema-test.out | 5 +++ tests/test-qmp-input-strict.c | 35 -------------------- tests/test-qmp-input-visitor.c | 34 ------------------- tests/test-qmp-output-visitor.c | 58 --------------------------------- tests/test-visitor-serialization.c | 34 ------------------- 6 files changed, 10 insertions(+), 162 deletions(-)
tests/qapi-schema/qapi-schema-test.json +5 -1
@@ -3,6 +3,9 @@ # This file is a stress test of supported qapi constructs that must # parse and compile correctly. +{ 'struct': 'TestStruct', + 'data': { 'integer': 'int', 'boolean': 'bool', 'string': 'str' } } + # for testing enums { 'struct': 'NestedEnumsOne', 'data': { 'enum1': 'EnumOne', # Intentional forward reference
@@ -46,7 +49,8 @@ # dummy struct to force generation of array types not otherwise mentioned { 'struct': 'ForceArrays', - 'data': { 'unused1':['UserDefOne'], 'unused2':['UserDefTwo'] } } + 'data': { 'unused1':['UserDefOne'], 'unused2':['UserDefTwo'], + 'unused3':['TestStruct'] } } # for testing unions # Among other things, test that a name collision between branches does
tests/qapi-schema/qapi-schema-test.out +5 -0
@@ -92,6 +92,7 @@ object EventStructOne object ForceArrays member unused1: UserDefOneList optional=False member unused2: UserDefTwoList optional=False + member unused3: TestStructList optional=False enum MyEnum [] object NestedEnumsOne member enum1: EnumOne optional=False
@@ -100,6 +101,10 @@ object NestedEnumsOne member enum4: EnumOne optional=True enum QEnumTwo ['value1', 'value2'] prefix QENUM_TWO +object TestStruct + member integer: int optional=False + member boolean: bool optional=False + member string: str optional=False object UserDefA member boolean: bool optional=False member a_b: int optional=True
tests/test-qmp-input-strict.c +0 -35
@@ -89,41 +89,6 @@ static Visitor *validate_test_init_raw(TestInputVisitorData *data,return v; } -typedef struct TestStruct -{ -int64_t integer; -bool boolean; -char *string; -}TestStruct ; - -static void visit_type_TestStruct (Visitor *v,TestStruct **obj, -const char *name,Error **errp) -{ -Error *err =NULL ; - -visit_start_struct (v, (void **)obj,"TestStruct" , name,sizeof (TestStruct), - &err); -if (err) { - goto out; - } - -visit_type_int (v, &(*obj)->integer,"integer" , &err); -if (err) { - goto out_end; - } -visit_type_bool (v, &(*obj)->boolean,"boolean" , &err); -if (err) { - goto out_end; - } -visit_type_str (v, &(*obj)->string,"string" , &err); - -out_end: -error_propagate (errp, err); - err =NULL ; -visit_end_struct (v, &err); -out: -error_propagate (errp, err); -}static void test_validate_struct (TestInputVisitorData *data,const void *unused)
tests/test-qmp-input-visitor.c +0 -34
@@ -185,40 +185,6 @@ static void test_visitor_in_enum(TestInputVisitorData *data, data->qiv =NULL ; } -typedef struct TestStruct -{ -int64_t integer; -bool boolean; -char *string; -}TestStruct ; - -static void visit_type_TestStruct (Visitor *v,TestStruct **obj, -const char *name,Error **errp) -{ -Error *err =NULL ; - -visit_start_struct (v, (void **)obj,"TestStruct" , name,sizeof (TestStruct), - &err); -if (err) { - goto out; - } -visit_type_int (v, &(*obj)->integer,"integer" , &err); -if (err) { - goto out_end; - } -visit_type_bool (v, &(*obj)->boolean,"boolean" , &err); -if (err) { - goto out_end; - } -visit_type_str (v, &(*obj)->string,"string" , &err); - -out_end: -error_propagate (errp, err); - err =NULL ; -visit_end_struct (v, &err); -out: -error_propagate (errp, err); -}static void test_visitor_in_struct (TestInputVisitorData *data,const void *unused)
tests/test-qmp-output-visitor.c +0 -58
70 lines not on this page · raw message
tests/test-visitor-serialization.c +0 -34
@@ -186,40 +186,6 @@ static void visit_primitive_list(Visitor *v, void **native, Error **errp) } } -typedef struct TestStruct -{ -int64_t integer; -bool boolean; -char *string; -}TestStruct ; - -static void visit_type_TestStruct (Visitor *v,TestStruct **obj, -const char *name,Error **errp) -{ -Error *err =NULL ; - -visit_start_struct (v, (void **)obj,NULL , name,sizeof (TestStruct), &err); -if (err) { - goto out; - } - -visit_type_int (v, &(*obj)->integer,"integer" , &err); -if (err) { - goto out_end; - } -visit_type_bool (v, &(*obj)->boolean,"boolean" , &err); -if (err) { - goto out_end; - } -visit_type_str (v, &(*obj)->string,"string" , &err); - -out_end: -error_propagate (errp, err); - err =NULL ; -visit_end_struct (v, &err); -out: -error_propagate (errp, err); -}static TestStruct *struct_create (void ) {
Signature · 1 line
2.4.3
PATCH v9 2/27 qapi: Strengthen test of TestStructList
In reply to Eric BlakeMake each list element different, to ensure that order is preserved, and use the generated free function instead of hand-rolling our own to ensure (under valgrind) that the list is properly cleaned.
---
v9: no change
v8: no change
v7: new patch
--- tests/test-qmp-output-visitor.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-)
tests/test-qmp-output-visitor.c +7 -11
@@ -283,7 +283,7 @@ static void test_visitor_out_struct_errors(TestOutputVisitorData *data,static void test_visitor_out_list (TestOutputVisitorData *data,const void *unused) { -char *value_str = (char *)"list value" ; +const char *value_str ="list value" ;TestStructList *p, *head =NULL ;const int max_items =10 ;bool value_bool = true;
@@ -294,12 +294,13 @@ static void test_visitor_out_list(TestOutputVisitorData *data,QList *qlist;int i; +/* Build the list in reverse order... */ for (i =0 ; i < max_items; i++) { p =g_malloc0 (sizeof (*p)); p->value =g_malloc0 (sizeof (*p->value)); - p->value->integer = value_int; + p->value->integer = value_int + (max_items - i -1 ); p->value->boolean = value_bool; - p->value->string = value_str; + p->value->string =g_strdup (value_str); p->next = head; head = p;
@@ -315,6 +316,7 @@ static void test_visitor_out_list(TestOutputVisitorData *data, qlist =qobject_to_qlist (obj);g_assert (!qlist_empty (qlist)); +/* ...and ensure that the visitor sees it in order */ i =0 ; QLIST_FOREACH_ENTRY(qlist, entry) {QDict *qdict;
@@ -322,7 +324,7 @@ static void test_visitor_out_list(TestOutputVisitorData *data,g_assert (qobject_type (entry->value) ==QTYPE_QDICT ); qdict =qobject_to_qdict (entry->value); g_assert_cmpint(qdict_size(qdict), ==, 3); - g_assert_cmpint(qdict_get_int(qdict, "integer"), ==, value_int); + g_assert_cmpint(qdict_get_int(qdict, "integer"), ==, value_int + i); g_assert_cmpint(qdict_get_bool(qdict, "boolean"), ==, value_bool); g_assert_cmpstr(qdict_get_str(qdict, "string"), ==, value_str); i++;
@@ -330,13 +332,7 @@ static void test_visitor_out_list(TestOutputVisitorData *data, g_assert_cmpint(i, ==, max_items);QDECREF (qlist); - -for (p = head; p;) { -TestStructList *tmp = p->next; -g_free (p->value); -g_free (p); - p = tmp; - } +qapi_free_TestStructList (head); } static void test_visitor_out_list_qapi_free(TestOutputVisitorData *data,
Signature · 1 line
2.4.3
PATCH v9 3/27 qapi: Plug leaks in test-qmp-*
In reply to Eric BlakeMake valgrind happy with the current state of the tests, so that it is easier to see if future patches introduce new memory problems without being drowned in noise. Many of the leaks were due to calling a second init without tearing down the data from an earlier visit. But since teardown is already idempotent, and we already register teardown as part of input_visitor_test_add(), it is nicer to just make init() safe to call multiple times than it is to have to make all tests call teardown.
Another common leak was forgetting to clean up an error object, after testing that an error was raised.
Another leak was in test_visitor_in_struct_nested(), failing to clean the base member of UserDefTwo. Cleaning that up left check_and_free_str() as dead code (since using the qapi_free_* takes care of recursion, and we don't want double frees).
---
v9: move earlier in series (was 13/17)
v8: no change
v7: no change
v6: make init repeatable rather than adding teardown everywhere, fix additional leak with UserDefTwo base, plug additional files
--- tests/test-qmp-input-strict.c | 10 ++++++++++ tests/test-qmp-input-visitor.c | 41 +++++++---------------------------------- tests/test-qmp-output-visitor.c | 3 ++- 3 files changed, 19 insertions(+), 35 deletions(-)
tests/test-qmp-input-strict.c +10 -0
@@ -77,6 +77,8 @@ static Visitor *validate_test_init_raw(TestInputVisitorData *data, {Visitor *v; +validate_teardown (data,NULL ); + data->obj =qobject_from_json (json_string);g_assert (data->obj !=NULL );
@@ -193,6 +195,8 @@ static void test_validate_fail_struct(TestInputVisitorData *data,visit_type_TestStruct (v, &p,NULL , &err);g_assert (err); +error_free (err); +/* FIXME: visitor should not allocate p when returning error */ if (p) {g_free (p->string); }
@@ -210,6 +214,7 @@ static void test_validate_fail_struct_nested(TestInputVisitorData *data,visit_type_UserDefTwo (v, &udp,NULL , &err);g_assert (err); +error_free (err);qapi_free_UserDefTwo (udp); }
@@ -224,6 +229,7 @@ static void test_validate_fail_list(TestInputVisitorData *data,visit_type_UserDefOneList (v, &head,NULL , &err);g_assert (err); +error_free (err);qapi_free_UserDefOneList (head); }
@@ -239,6 +245,7 @@ static void test_validate_fail_union_native_list(TestInputVisitorData *data,visit_type_UserDefNativeListUnion (v, &tmp,NULL , &err);g_assert (err); +error_free (err);qapi_free_UserDefNativeListUnion (tmp); }
@@ -253,6 +260,7 @@ static void test_validate_fail_union_flat(TestInputVisitorData *data,visit_type_UserDefFlatUnion (v, &tmp,NULL , &err);g_assert (err); +error_free (err);qapi_free_UserDefFlatUnion (tmp); }
@@ -268,6 +276,7 @@ static void test_validate_fail_union_flat_no_discrim(TestInputVisitorData *data,visit_type_UserDefFlatUnion2 (v, &tmp,NULL , &err);g_assert (err); +error_free (err);qapi_free_UserDefFlatUnion2 (tmp); }
@@ -282,6 +291,7 @@ static void test_validate_fail_alternate(TestInputVisitorData *data,visit_type_UserDefAlternate (v, &tmp,NULL , &err);g_assert (err); +error_free (err);qapi_free_UserDefAlternate (tmp); }
tests/test-qmp-input-visitor.c +7 -34
159 lines not on this page · raw message
tests/test-qmp-output-visitor.c +2 -1
@@ -391,6 +391,7 @@ static void test_visitor_out_any(TestOutputVisitorData *data, qobj =QOBJECT (qdict);visit_type_any (data->ov, &qobj,NULL , &err);g_assert (!err); +qobject_decref (qobj); obj =qmp_output_get_qobject (data->qov);g_assert (obj !=NULL ); qdict =qobject_to_qdict (obj);
@@ -411,7 +412,6 @@ static void test_visitor_out_any(TestOutputVisitorData *data,g_assert (qstring); g_assert_cmpstr(qstring_get_str(qstring), ==, "foo");qobject_decref (obj); -qobject_decref (qobj); } static void test_visitor_out_union_flat(TestOutputVisitorData *data,
@@ -463,6 +463,7 @@ static void test_visitor_out_alternate(TestOutputVisitorData *data, g_assert_cmpint(qint_get_int(qobject_to_qint(arg)), ==, 42);qapi_free_UserDefAlternate (tmp); +qobject_decref (arg); } static void test_visitor_out_empty(TestOutputVisitorData *data,
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v9 03/27] qapi: Plug leaks in test-qmp-*
Quoted 25 lines · Eric Blake
Make valgrind happy with the current state of the tests, so that it is easier to see if future patches introduce new memory problems without being drowned in noise. Many of the leaks were due to calling a second init without tearing down the data from an earlier visit. But since teardown is already idempotent, and we already register teardown as part of
input_visitor_test_add(), it is nicer to just makeinit()safe to call multiple times than it is to have to make all tests call teardown.Another common leak was forgetting to clean up an error object, after testing that an error was raised.
Another leak was in
test_visitor_in_struct_nested(), failing to clean the base member of UserDefTwo. Cleaning that up leftcheck_and_free_str()as dead code (since using the qapi_free_* takes care of recursion, and we don't want double frees).Signed-off-by Eric Blake <[email protected]>---
v9: move earlier in series (was 13/17)
v8: no change
v7: no change
v6: make init repeatable rather than adding teardown everywhere, fix additional leak with UserDefTwo base, plug additional files
Quoted 5 lines
--- tests/test-qmp-input-strict.c | 10 ++++++++++ tests/test-qmp-input-visitor.c | 41 +++++++---------------------------------- tests/test-qmp-output-visitor.c | 3 ++- 3 files changed, 19 insertions(+), 35 deletions(-)
No leaks to plug in test/-qmp-commands.c and test-qmp-event.c?
tests/test-qmp-input-strict.c static Visitor *validate_test_init_raw(TestInputVisitorData *data, · line 84
Quoted 13 lines
tests/test-qmp-input-strict.c +2
-0@@ -77,6 +77,8 @@ static Visitor *validate_test_init_raw(TestInputVisitorData *data, {Visitor *v; +validate_teardown (data,NULL ); + data->obj =qobject_from_json (json_string);g_assert (data->obj !=NULL );
A test added with validate_test_add() may call validate_test_init_raw() any number of time. Since validate_test_add() passes validate_teardown() as fixture teardown function, the last one will be cleaned up on test finalization. The others will be cleaned up by the next validate_test_init_raw(). Okay. Actually, the whole fixture business starts to make sense only now.
But why only validate_test_init_raw() and not validate_test_init()?
The two duplicate code, by the way.
tests/test-qmp-input-strict.c static void test_validate_fail_struct(TestInputVisitorData *data, · line 199
Quoted 6 lines
tests/test-qmp-input-strict.c +2
-0@@ -193,6 +195,8 @@ static void test_validate_fail_struct(TestInputVisitorData *data,visit_type_TestStruct (v, &p,NULL , &err);g_assert (err); +error_free (err); +/* FIXME: visitor should not allocate p when returning error */
Indeed.
Recommend to always mention new FIXMEs in the commit message.
Quoted 56 lines
tests/test-qmp-input-strict.c +6
-0if (p) {g_free (p->string); }@@ -210,6 +214,7 @@ static void test_validate_fail_struct_nested(TestInputVisitorData *data,visit_type_UserDefTwo (v, &udp,NULL , &err);g_assert (err); +error_free (err);qapi_free_UserDefTwo (udp); }@@ -224,6 +229,7 @@ static void test_validate_fail_list(TestInputVisitorData *data,visit_type_UserDefOneList (v, &head,NULL , &err);g_assert (err); +error_free (err);qapi_free_UserDefOneList (head); }@@ -239,6 +245,7 @@ static void test_validate_fail_union_native_list(TestInputVisitorData *data,visit_type_UserDefNativeListUnion (v, &tmp,NULL , &err);g_assert (err); +error_free (err);qapi_free_UserDefNativeListUnion (tmp); }@@ -253,6 +260,7 @@ static void test_validate_fail_union_flat(TestInputVisitorData *data,visit_type_UserDefFlatUnion (v, &tmp,NULL , &err);g_assert (err); +error_free (err);qapi_free_UserDefFlatUnion (tmp); }@@ -268,6 +276,7 @@ static void test_validate_fail_union_flat_no_discrim(TestInputVisitorData *data,visit_type_UserDefFlatUnion2 (v, &tmp,NULL , &err);g_assert (err); +error_free (err);qapi_free_UserDefFlatUnion2 (tmp); }@@ -282,6 +291,7 @@ static void test_validate_fail_alternate(TestInputVisitorData *data,visit_type_UserDefAlternate (v, &tmp,NULL , &err);g_assert (err); +error_free (err);qapi_free_UserDefAlternate (tmp); }tests/test-qmp-input-visitor.c +0
-0
tests/test-qmp-input-visitor.c Visitor *visitor_input_test_init(TestInputVisitorData *data, · line 53
Quoted 8 lines
tests/test-qmp-input-visitor.c +2
-0@@ -46,6 +46,8 @@ Visitor *visitor_input_test_init(TestInputVisitorData *data,Visitor *v;va_list ap; +visitor_input_teardown (data,NULL ); +va_start (ap, json_string); data->obj =qobject_from_jsonv (json_string, &ap);va_end (ap);
Here, you add it to visitor_input_test_init(), but not visitor_input_test_init_raw().
These two duplicate code, too.
tests/test-qmp-output-visitor.c static void test_visitor_out_any(TestOutputVisitorData *data,
Quoted 173 lines
tests/test-qmp-input-visitor.c +5
-34@@ -177,12 +179,7 @@ static void test_visitor_in_enum(TestInputVisitorData *data,visit_type_EnumOne (v, &res,NULL , &err);g_assert (!err); g_assert_cmpint(i, ==, res); - -visitor_input_teardown (data,NULL ); } - - data->obj =NULL ; - data->qiv =NULL ; }@@ -205,12 +202,6 @@ static void test_visitor_in_struct(TestInputVisitorData *data,g_free (p); } -static void check_and_free_str (char *str,const char *cmp) -{ - g_assert_cmpstr(str, ==, cmp); -g_free (str); -} -static void test_visitor_in_struct_nested (TestInputVisitorData *data,const void *unused) {@@ -226,17 +217,14 @@ static void test_visitor_in_struct_nested(TestInputVisitorData *data,visit_type_UserDefTwo (v, &udp,NULL , &err);g_assert (!err); -check_and_free_str (udp->string0,"string0" ); -check_and_free_str (udp->dict1->string1,"string1" ); + g_assert_cmpstr(udp->string0, ==, "string0"); + g_assert_cmpstr(udp->dict1->string1, ==, "string1"); g_assert_cmpint(udp->dict1->dict2->userdef->integer, ==, 42); -check_and_free_str (udp->dict1->dict2->userdef->string,"string" ); -check_and_free_str (udp->dict1->dict2->string,"string2" ); + g_assert_cmpstr(udp->dict1->dict2->userdef->string, ==, "string"); + g_assert_cmpstr(udp->dict1->dict2->string, ==, "string2");g_assert (udp->dict1->has_dict3 == false); -g_free (udp->dict1->dict2->userdef); -g_free (udp->dict1->dict2); -g_free (udp->dict1); -g_free (udp); +qapi_free_UserDefTwo (udp); } static void test_visitor_in_list(TestInputVisitorData *data,@@ -346,14 +334,12 @@ static void test_visitor_in_alternate(TestInputVisitorData *data, g_assert_cmpint(tmp->type, ==, USER_DEF_ALTERNATE_KIND_I); g_assert_cmpint(tmp->u.i, ==, 42);qapi_free_UserDefAlternate (tmp); -visitor_input_teardown (data,NULL ); v =visitor_input_test_init (data,"'string'" );visit_type_UserDefAlternate (v, &tmp,NULL , &error_abort); g_assert_cmpint(tmp->type, ==, USER_DEF_ALTERNATE_KIND_S); g_assert_cmpstr(tmp->u.s, ==, "string");qapi_free_UserDefAlternate (tmp); -visitor_input_teardown (data,NULL ); v =visitor_input_test_init (data,"false" );visit_type_UserDefAlternate (v, &tmp,NULL , &err);@@ -361,7 +347,6 @@ static void test_visitor_in_alternate(TestInputVisitorData *data,error_free (err); err =NULL ;qapi_free_UserDefAlternate (tmp); -visitor_input_teardown (data,NULL ); } static void test_visitor_in_alternate_number(TestInputVisitorData *data,@@ -384,7 +369,6 @@ static void test_visitor_in_alternate_number(TestInputVisitorData *data,error_free (err); err =NULL ;qapi_free_AltStrBool (asb); -visitor_input_teardown (data,NULL );/* FIXME: Order of alternate should not affect semantics; asn should * parse the same as ans */ @@ -396,35 +380,30 @@ static void test_visitor_in_alternate_number(TestInputVisitorData *data,error_free (err); err =NULL ;qapi_free_AltStrNum (asn); -visitor_input_teardown (data,NULL ); v =visitor_input_test_init (data,"42" );visit_type_AltNumStr (v, &ans,NULL , &error_abort); g_assert_cmpint(ans->type, ==, ALT_NUM_STR_KIND_N); g_assert_cmpfloat(ans->u.n, ==, 42);qapi_free_AltNumStr (ans); -visitor_input_teardown (data,NULL ); v =visitor_input_test_init (data,"42" );visit_type_AltStrInt (v, &asi,NULL , &error_abort); g_assert_cmpint(asi->type, ==, ALT_STR_INT_KIND_I); g_assert_cmpint(asi->u.i, ==, 42);qapi_free_AltStrInt (asi); -visitor_input_teardown (data,NULL ); v =visitor_input_test_init (data,"42" );visit_type_AltIntNum (v, &ain,NULL , &error_abort); g_assert_cmpint(ain->type, ==, ALT_INT_NUM_KIND_I); g_assert_cmpint(ain->u.i, ==, 42);qapi_free_AltIntNum (ain); -visitor_input_teardown (data,NULL ); v =visitor_input_test_init (data,"42" );visit_type_AltNumInt (v, &ani,NULL , &error_abort); g_assert_cmpint(ani->type, ==, ALT_NUM_INT_KIND_I); g_assert_cmpint(ani->u.i, ==, 42);qapi_free_AltNumInt (ani); -visitor_input_teardown (data,NULL );/* Parsing a double */ @@ -434,21 +413,18 @@ static void test_visitor_in_alternate_number(TestInputVisitorData *data,error_free (err); err =NULL ;qapi_free_AltStrBool (asb); -visitor_input_teardown (data,NULL ); v =visitor_input_test_init (data,"42.5" );visit_type_AltStrNum (v, &asn,NULL , &error_abort); g_assert_cmpint(asn->type, ==, ALT_STR_NUM_KIND_N); g_assert_cmpfloat(asn->u.n, ==, 42.5);qapi_free_AltStrNum (asn); -visitor_input_teardown (data,NULL ); v =visitor_input_test_init (data,"42.5" );visit_type_AltNumStr (v, &ans,NULL , &error_abort); g_assert_cmpint(ans->type, ==, ALT_NUM_STR_KIND_N); g_assert_cmpfloat(ans->u.n, ==, 42.5);qapi_free_AltNumStr (ans); -visitor_input_teardown (data,NULL ); v =visitor_input_test_init (data,"42.5" );visit_type_AltStrInt (v, &asi,NULL , &err);@@ -456,21 +432,18 @@ static void test_visitor_in_alternate_number(TestInputVisitorData *data,error_free (err); err =NULL ;qapi_free_AltStrInt (asi); -visitor_input_teardown (data,NULL ); v =visitor_input_test_init (data,"42.5" );visit_type_AltIntNum (v, &ain,NULL , &error_abort); g_assert_cmpint(ain->type, ==, ALT_INT_NUM_KIND_N); g_assert_cmpfloat(ain->u.n, ==, 42.5);qapi_free_AltIntNum (ain); -visitor_input_teardown (data,NULL ); v =visitor_input_test_init (data,"42.5" );visit_type_AltNumInt (v, &ani,NULL , &error_abort); g_assert_cmpint(ani->type, ==, ALT_NUM_INT_KIND_N); g_assert_cmpfloat(ani->u.n, ==, 42.5);qapi_free_AltNumInt (ani); -visitor_input_teardown (data,NULL ); } static void test_native_list_integer_helper(TestInputVisitorData *data,tests/test-qmp-output-visitor.c +1
-0@@ -391,6 +391,7 @@ static void test_visitor_out_any(TestOutputVisitorData *data, qobj =QOBJECT (qdict);visit_type_any (data->ov, &qobj,NULL , &err);g_assert (!err); +qobject_decref (qobj); obj =qmp_output_get_qobject (data->qov);g_assert (obj !=NULL ); qdict =qobject_to_qdict (obj);@@ -411,7 +412,6 @@ static void test_visitor_out_any(TestOutputVisitorData *data,
qobj = qdict_get(qdict, "string");
g_assert(qobj);
qstring = qobject_to_qstring(qobj);tests/test-qmp-output-visitor.c static void test_visitor_out_any(TestOutputVisitorData *data, · line 414
Quoted 4 lines
tests/test-qmp-output-visitor.c +0
-1g_assert (qstring); g_assert_cmpstr(qstring_get_str(qstring), ==, "foo");qobject_decref (obj); -qobject_decref (qobj);
Hmm... obj is an alias for qdict, qobj is a member of qdict, freeing obj frees qobj (unless there's another reference to qobj I can't see). The line you delete then is a use-after-free bug that underflows the reference counter. Correct?
If yes, commit message should mention it briefly, because this isn't just a leak. Actually, I'd make it a separate commit, to keep commit messages simple, particularly the headlines.
Aside: qobject_decref() neglects to assert(!obj || obj->refcnt > 0).
Quoted 11 lines
tests/test-qmp-output-visitor.c +1
-0} static void test_visitor_out_union_flat(TestOutputVisitorData *data,@@ -463,6 +463,7 @@ static void test_visitor_out_alternate(TestOutputVisitorData *data, g_assert_cmpint(qint_get_int(qobject_to_qint(arg)), ==, 42);qapi_free_UserDefAlternate (tmp); +qobject_decref (arg); } static void test_visitor_out_empty(TestOutputVisitorData *data,
Re: [Qemu-devel] [PATCH v9 03/27] qapi: Plug leaks in test-qmp-*
Quoted 33 lines · Markus Armbruster
Quoted 25 lines · Eric Blake
Make valgrind happy with the current state of the tests, so that it is easier to see if future patches introduce new memory problems without being drowned in noise. Many of the leaks were due to calling a second init without tearing down the data from an earlier visit. But since teardown is already idempotent, and we already register teardown as part of
input_visitor_test_add(), it is nicer to just makeinit()safe to call multiple times than it is to have to make all tests call teardown.Another common leak was forgetting to clean up an error object, after testing that an error was raised.
Another leak was in
test_visitor_in_struct_nested(), failing to clean the base member of UserDefTwo. Cleaning that up leftcheck_and_free_str()as dead code (since using the qapi_free_* takes care of recursion, and we don't want double frees).Signed-off-by Eric Blake <[email protected]>---
v9: move earlier in series (was 13/17)
v8: no change
v7: no change
v6: make init repeatable rather than adding teardown everywhere, fix additional leak with UserDefTwo base, plug additional filesQuoted 5 lines
--- tests/test-qmp-input-strict.c | 10 ++++++++++ tests/test-qmp-input-visitor.c | 41 +++++++---------------------------------- tests/test-qmp-output-visitor.c | 3 ++- 3 files changed, 19 insertions(+), 35 deletions(-)
Quoted 1 line
No leaks to plug in
test/-qmp-commands.candtest-qmp-event.c?
Didn't check. I'll do that.
Quoted 22 lines
Quoted 6 lines
tests/test-qmp-input-strict.c +0
-0tests/test-qmp-input-strict.c static Visitor *validate_test_init_raw(TestInputVisitorData *data, · line 84
Quoted 8 lines
tests/test-qmp-input-strict.c +2
-0@@ -77,6 +77,8 @@ static Visitor *validate_test_init_raw(TestInputVisitorData *data, {Visitor *v; +validate_teardown (data,NULL ); + data->obj =qobject_from_json (json_string);g_assert (data->obj !=NULL );A test added with
validate_test_add()may callvalidate_test_init_raw()any number of time. Sincevalidate_test_add()passesvalidate_teardown()as fixture teardown function, the last one will be cleaned up on test finalization. The others will be cleaned up by the nextvalidate_test_init_raw(). Okay. Actually, the whole fixture business starts to make sense only now.
Quoted 2 lines
But why only
validate_test_init_raw()and notvalidate_test_init()?
Umm, because I didn't look, and just plugged holes? Will fix.
Quoted 1 line
The two duplicate code, by the way.
And the fix will probably be by having one call the other.
Quoted 11 lines
tests/test-qmp-input-strict.c static void test_validate_fail_struct(TestInputVisitorData *data, · line 199
Quoted 7 lines
tests/test-qmp-input-strict.c +2
-0@@ -193,6 +195,8 @@ static void test_validate_fail_struct(TestInputVisitorData *data,visit_type_TestStruct (v, &p,NULL , &err);g_assert (err); +error_free (err); +/* FIXME: visitor should not allocate p when returning error */ Indeed.
Recommend to always mention new FIXMEs in the commit message.
This fixme is part of the answer to your question about 6/27 - we do have test coverage on non-arrays.
Quoted 14 lines
tests/test-qmp-input-strict.c Visitor *visitor_input_test_init(TestInputVisitorData *data, · line 53
Quoted 10 lines
tests/test-qmp-input-strict.c +3
-0+++ b/tests/test-qmp-input-visitor.c@@ -46,6 +46,8 @@ Visitor *visitor_input_test_init(TestInputVisitorData *data,Visitor *v;va_list ap; +visitor_input_teardown (data,NULL ); +va_start (ap, json_string); data->obj =qobject_from_jsonv (json_string, &ap);va_end (ap);Here, you add it to
visitor_input_test_init(), but notvisitor_input_test_init_raw().
Quoted 1 line
These two duplicate code, too.
Looks like I get to fix this too.
Quoted 3 lines
tests/test-qmp-input-strict.c static void test_visitor_out_any(TestOutputVisitorData *data, · line 391
Quoted 3 lines
+++
b/tests/test-qmp-output-visitor.ctests/test-qmp-input-strict.c +0
-0@@ -391,6 +391,7 @@ static void test_visitor_out_any(TestOutputVisitorData *data, qobj =QOBJECT (qdict);
Here, qobj is an alias to qdict...
Quoted 8 lines
tests/test-qmp-input-strict.c static void test_visitor_out_any(TestOutputVisitorData *data,
Quoted 7 lines
tests/test-qmp-input-strict.c +1
-0visit_type_any (data->ov, &qobj,NULL , &err);g_assert (!err); +qobject_decref (qobj); obj =qmp_output_get_qobject (data->qov);g_assert (obj !=NULL ); qdict =qobject_to_qdict (obj);@@ -411,7 +412,6 @@ static void test_visitor_out_any(TestOutputVisitorData *data,qobj = qdict_get(qdict, "string");
...but then we are reassigning it to instead be an alias within qdict.
Quoted 6 lines
g_assert(qobj); qstring = qobject_to_qstring(qobj);Quoted 4 lines
tests/test-qmp-input-strict.c +0
-1g_assert (qstring); g_assert_cmpstr(qstring_get_str(qstring), ==, "foo");qobject_decref (obj); -qobject_decref (qobj);
Dereferencing a subset of the qdict leaks the overal qdict.
Quoted 5 lines
Hmm... obj is an alias for qdict, qobj is a member of qdict, freeing obj frees qobj (unless there's another reference to qobj I can't see). The line you delete then is a use-after-free bug that underflows the reference counter. Correct?
Valgrind complained about a leak, not a use-after-free. But there indeed may be more than one issue that got solved by correctly dropping the reference at the right point in time, prior to reassigning qobj for use as pointing to a different portion of the qdict.
Quoted 4 lines
If yes, commit message should mention it briefly, because this isn't just a leak. Actually, I'd make it a separate commit, to keep commit messages simple, particularly the headlines.
I'll have to refresh my memory what else is going on, but I can indeed split this out if it is different than a simple memleak fix.
Quoted 2 lines
Aside:
qobject_decref()neglects toassert(!obj || obj->refcnt > 0).
Sounds like a separate patch.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v9 03/27] qapi: Plug leaks in test-qmp-*
Quoted 81 lines · Eric Blake
Quoted 34 lines · Markus Armbruster
Quoted 25 lines · Eric Blake
Make valgrind happy with the current state of the tests, so that it is easier to see if future patches introduce new memory problems without being drowned in noise. Many of the leaks were due to calling a second init without tearing down the data from an earlier visit. But since teardown is already idempotent, and we already register teardown as part of
input_visitor_test_add(), it is nicer to just makeinit()safe to call multiple times than it is to have to make all tests call teardown.Another common leak was forgetting to clean up an error object, after testing that an error was raised.
Another leak was in
test_visitor_in_struct_nested(), failing to clean the base member of UserDefTwo. Cleaning that up leftcheck_and_free_str()as dead code (since using the qapi_free_* takes care of recursion, and we don't want double frees).Signed-off-by Eric Blake <[email protected]>---
v9: move earlier in series (was 13/17)
v8: no change
v7: no change
v6: make init repeatable rather than adding teardown everywhere, fix additional leak with UserDefTwo base, plug additional filesQuoted 6 lines
--- tests/test-qmp-input-strict.c | 10 ++++++++++ tests/test-qmp-input-visitor.c | 41 +++++++---------------------------------- tests/test-qmp-output-visitor.c | 3 ++- 3 files changed, 19 insertions(+), 35 deletions(-)Quoted 1 line
No leaks to plug in
test/-qmp-commands.candtest-qmp-event.c?Didn't check. I'll do that.
Quoted 22 lines
Quoted 6 lines
tests/test-qmp-input-strict.c +0
-0tests/test-qmp-input-strict.c static Visitor *validate_test_init_raw(TestInputVisitorData *data, · line 84
Quoted 8 lines
tests/test-qmp-input-strict.c +2
-0@@ -77,6 +77,8 @@ static Visitor *validate_test_init_raw(TestInputVisitorData *data, {Visitor *v; +validate_teardown (data,NULL ); + data->obj =qobject_from_json (json_string);g_assert (data->obj !=NULL );A test added with
validate_test_add()may callvalidate_test_init_raw()any number of time. Sincevalidate_test_add()passesvalidate_teardown()as fixture teardown function, the last one will be cleaned up on test finalization. The others will be cleaned up by the nextvalidate_test_init_raw(). Okay. Actually, the whole fixture business starts to make sense only now.Quoted 2 lines
But why only
validate_test_init_raw()and notvalidate_test_init()?Umm, because I didn't look, and just plugged holes? Will fix.
Quoted 1 line
The two duplicate code, by the way.
And the fix will probably be by having one call the other.
Quoted 11 lines
tests/test-qmp-input-strict.c static void · line 200
Quoted 8 lines
tests/test-qmp-input-strict.c +2
-0@@ -193,6 +195,8 @@ static voidtest_validate_fail_struct (TestInputVisitorData *data, visit_type_TestStruct(v, &p, NULL, &err);g_assert (err); +error_free (err); +/* FIXME: visitor should not allocate p when returning error */ Indeed.
Quoted 4 lines
Quoted 1 line
Recommend to always mention new FIXMEs in the commit message.
This fixme is part of the answer to your question about 6/27 - we do have test coverage on non-arrays.
What we (royal we) don't have is memory going back from 06/27 to 03/27 %-}
Quoted 60 lines
Quoted 15 lines
Quoted 11 lines
tests/test-qmp-input-strict.c +3
-0+++ b/tests/test-qmp-input-visitor.c@@ -46,6 +46,8 @@ Visitor *visitor_input_test_init (TestInputVisitorData *data, Visitor *v;va_list ap; +visitor_input_teardown (data,NULL ); +va_start (ap, json_string); data->obj =qobject_from_jsonv (json_string, &ap);va_end(ap);Here, you add it to
visitor_input_test_init(), but notvisitor_input_test_init_raw().Quoted 1 line
These two duplicate code, too.
Looks like I get to fix this too.
Quoted 4 lines
tests/test-qmp-input-strict.c static void · line 392
Quoted 4 lines
+++
b/tests/test-qmp-output-visitor.ctests/test-qmp-input-strict.c +0
-0@@ -391,6 +391,7 @@ static voidtest_visitor_out_any (TestOutputVisitorData *data, qobj = QOBJECT(qdict);Here, qobj is an alias to qdict...
Quoted 9 lines
tests/test-qmp-input-strict.c static void · line 412
Quoted 8 lines
tests/test-qmp-input-strict.c +1
-0visit_type_any (data->ov, &qobj,NULL , &err);g_assert (!err); +qobject_decref (qobj); obj =qmp_output_get_qobject (data->qov);g_assert (obj !=NULL );qdict = qobject_to_qdict(obj);tests/test-qmp-input-strict.c +0
-0@@ -411,7 +412,6 @@ static void test_visitor_out_any(TestOutputVisitorData *data,qobj = qdict_get(qdict, "string");...but then we are reassigning it to instead be an alias within qdict.
Quoted 6 lines
g_assert(qobj); qstring = qobject_to_qstring(qobj);Quoted 4 lines
tests/test-qmp-input-strict.c +0
-1g_assert (qstring); g_assert_cmpstr(qstring_get_str(qstring), ==, "foo");qobject_decref (obj); -qobject_decref (qobj);Dereferencing a subset of the qdict leaks the overal qdict.
Quoted 5 lines
Hmm... obj is an alias for qdict, qobj is a member of qdict, freeing obj frees qobj (unless there's another reference to qobj I can't see). The line you delete then is a use-after-free bug that underflows the reference counter. Correct?
Valgrind complained about a leak, not a use-after-free. But there indeed may be more than one issue that got solved by correctly dropping the reference at the right point in time, prior to reassigning qobj for use as pointing to a different portion of the qdict.
Quoted 1 line
Quoted 6 lines
Quoted 3 lines
If yes, commit message should mention it briefly, because this isn't just a leak. Actually, I'd make it a separate commit, to keep commit messages simple, particularly the headlines.
I'll have to refresh my memory what else is going on, but I can indeed split this out if it is different than a simple memleak fix.
I really, really like bug fixes coming with an impact assessment. However, since this is just *tests*, I recommend *not* to spend time on figuring out what exactly was broken, and simply adjust the commit messages claims a bit.
Quoted 3 lines
Quoted 1 line
Aside:
qobject_decref()neglects toassert(!obj || obj->refcnt > 0).Sounds like a separate patch.
Definitely.
Re: [Qemu-devel] [PATCH v9 03/27] qapi: Plug leaks in test-qmp-*
Quoted 13 lines · Markus Armbruster
Quoted 11 lines · Eric Blake
Quoted 10 lines · Markus Armbruster
Quoted 7 lines · Eric Blake
Make valgrind happy with the current state of the tests, so that
tests/test-qmp-input-strict.c | 10 ++++++++++ tests/test-qmp-input-visitor.c | 41 +++++++---------------------------------- tests/test-qmp-output-visitor.c | 3 ++- 3 files changed, 19 insertions(+), 35 deletions(-)
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
No leaks to plug in
test/-qmp-commands.candtest-qmp-event.c?Didn't check. I'll do that.
Checked; no leaks to fix. But they do include some 'err' fixes for 4/27 to add.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH v9 4/27 qapi: Simplify error testing in test-qmp-*
In reply to Eric BlakeBy using &error_abort, we can avoid a local err variable in situations where we expect success.
By moving err into data, we can let test teardown take care of cleaning up any collected error; it also gives us fewer lines of code between repeated tests where init runs teardown on our behalf.
---
v9: move earlier in series (was 14/17), reword commit message
v8: no change
v7: pick up whitespace changes dropped from earlier commit
v6: new patch
--- tests/test-qmp-input-strict.c | 77 +++++++++----------------- tests/test-qmp-input-visitor.c | 107 ++++++++++++------------------------- tests/test-qmp-output-visitor.c | 56 +++++-------------- tests/test-visitor-serialization.c | 42 ++++++--------- 4 files changed, 89 insertions(+), 193 deletions(-)
tests/test-qmp-input-strict.c +25 -52
@@ -26,6 +26,7 @@typedef struct TestInputVisitorData {QObject *obj;QmpInputVisitor *qiv; +Error *err; }TestInputVisitorData ; static void validate_teardown(TestInputVisitorData *data,
@@ -34,6 +35,9 @@ static void validate_teardown(TestInputVisitorData *data,qobject_decref (data->obj); data->obj =NULL ; +error_free (data->err); + data->err =NULL ; +if (data->qiv) {qmp_input_visitor_cleanup (data->qiv); data->qiv =NULL ;
@@ -96,13 +100,11 @@ static void test_validate_struct(TestInputVisitorData *data, const void *unused) {TestStruct *p =NULL ; -Error *err =NULL ;Visitor *v; v =validate_test_init (data,"{ 'integer': -42, 'boolean': true, 'string': 'foo' }" ); -visit_type_TestStruct (v, &p,NULL , &err); -g_assert (!err); +visit_type_TestStruct (v, &p,NULL , &error_abort);g_free (p->string);g_free (p); }
@@ -111,7 +113,6 @@ static void test_validate_struct_nested(TestInputVisitorData *data, const void *unused) {UserDefTwo *udp =NULL ; -Error *err =NULL ;Visitor *v; v = validate_test_init(data, "{ 'string0': 'string0', "
@@ -119,8 +120,7 @@ static void test_validate_struct_nested(TestInputVisitorData *data,"'dict2': { 'userdef': { 'integer': 42, " "'string': 'string' }, 'string': 'string2'}}}"); -visit_type_UserDefTwo (v, &udp,NULL , &err); -g_assert (!err); +visit_type_UserDefTwo (v, &udp,NULL , &error_abort);qapi_free_UserDefTwo (udp); }
@@ -128,13 +128,11 @@ static void test_validate_list(TestInputVisitorData *data, const void *unused) {UserDefOneList *head =NULL ; -Error *err =NULL ;Visitor *v; v =validate_test_init (data,"[ { 'string': 'string0', 'integer': 42 }, { 'string': 'string1', 'integer': 43 }, { 'string': 'string2', 'integer': 44 } ]" ); -visit_type_UserDefOneList (v, &head,NULL , &err); -g_assert (!err); +visit_type_UserDefOneList (v, &head,NULL , &error_abort);qapi_free_UserDefOneList (head); }
@@ -143,12 +141,10 @@ static void test_validate_union_native_list(TestInputVisitorData *data, {UserDefNativeListUnion *tmp =NULL ;Visitor *v; -Error *err =NULL ; v =validate_test_init (data,"{ 'type': 'integer', 'data' : [ 1, 2 ] }" ); -visit_type_UserDefNativeListUnion (v, &tmp,NULL , &err); -g_assert (!err); +visit_type_UserDefNativeListUnion (v, &tmp,NULL , &error_abort);qapi_free_UserDefNativeListUnion (tmp); }
@@ -157,7 +153,6 @@ static void test_validate_union_flat(TestInputVisitorData *data, {UserDefFlatUnion *tmp =NULL ;Visitor *v; -Error *err =NULL ; v =validate_test_init (data, "{ 'enum1': 'value1', "
@@ -165,8 +160,7 @@ static void test_validate_union_flat(TestInputVisitorData *data,"'string': 'str', " "'boolean': true }"); -visit_type_UserDefFlatUnion (v, &tmp,NULL , &err); -g_assert (!err); +visit_type_UserDefFlatUnion (v, &tmp,NULL , &error_abort);qapi_free_UserDefFlatUnion (tmp); }
@@ -175,12 +169,10 @@ static void test_validate_alternate(TestInputVisitorData *data, {UserDefAlternate *tmp =NULL ;Visitor *v; -Error *err =NULL ; v =validate_test_init (data,"42" ); -visit_type_UserDefAlternate (v, &tmp,NULL , &err); -g_assert (!err); +visit_type_UserDefAlternate (v, &tmp,NULL , &error_abort);qapi_free_UserDefAlternate (tmp); }
@@ -188,14 +180,12 @@ static void test_validate_fail_struct(TestInputVisitorData *data, const void *unused) {TestStruct *p =NULL ; -Error *err =NULL ;Visitor *v; v =validate_test_init (data,"{ 'integer': -42, 'boolean': true, 'string': 'foo', 'extra': 42 }" ); -visit_type_TestStruct (v, &p,NULL , &err); -g_assert (err); -error_free (err); +visit_type_TestStruct (v, &p,NULL , &data->err); +g_assert (data->err);/* FIXME: visitor should not allocate p when returning error */ if (p) {g_free (p->string);
@@ -207,14 +197,12 @@ static void test_validate_fail_struct_nested(TestInputVisitorData *data, const void *unused) {UserDefTwo *udp =NULL ; -Error *err =NULL ;Visitor *v; v =validate_test_init (data,"{ 'string0': 'string0', 'dict1': { 'string1': 'string1', 'dict2': { 'userdef1': { 'integer': 42, 'string': 'string', 'extra': [42, 23, {'foo':'bar'}] }, 'string2': 'string2'}}}" ); -visit_type_UserDefTwo (v, &udp,NULL , &err); -g_assert (err); -error_free (err); +visit_type_UserDefTwo (v, &udp,NULL , &data->err); +g_assert (data->err);qapi_free_UserDefTwo (udp); }
@@ -222,14 +210,12 @@ static void test_validate_fail_list(TestInputVisitorData *data, const void *unused) {UserDefOneList *head =NULL ; -Error *err =NULL ;Visitor *v; v =validate_test_init (data,"[ { 'string': 'string0', 'integer': 42 }, { 'string': 'string1', 'integer': 43 }, { 'string': 'string2', 'integer': 44, 'extra': 'ggg' } ]" ); -visit_type_UserDefOneList (v, &head,NULL , &err); -g_assert (err); -error_free (err); +visit_type_UserDefOneList (v, &head,NULL , &data->err); +g_assert (data->err);qapi_free_UserDefOneList (head); }
@@ -237,15 +223,13 @@ static void test_validate_fail_union_native_list(TestInputVisitorData *data, const void *unused) {UserDefNativeListUnion *tmp =NULL ; -Error *err =NULL ;Visitor *v; v =validate_test_init (data,"{ 'type': 'integer', 'data' : [ 'string' ] }" ); -visit_type_UserDefNativeListUnion (v, &tmp,NULL , &err); -g_assert (err); -error_free (err); +visit_type_UserDefNativeListUnion (v, &tmp,NULL , &data->err); +g_assert (data->err);qapi_free_UserDefNativeListUnion (tmp); }
@@ -253,14 +237,12 @@ static void test_validate_fail_union_flat(TestInputVisitorData *data, const void *unused) {UserDefFlatUnion *tmp =NULL ; -Error *err =NULL ;Visitor *v; v =validate_test_init (data,"{ 'string': 'c', 'integer': 41, 'boolean': true }" ); -visit_type_UserDefFlatUnion (v, &tmp,NULL , &err); -g_assert (err); -error_free (err); +visit_type_UserDefFlatUnion (v, &tmp,NULL , &data->err); +g_assert (data->err);qapi_free_UserDefFlatUnion (tmp); }
@@ -268,15 +250,13 @@ static void test_validate_fail_union_flat_no_discrim(TestInputVisitorData *data, const void *unused) {UserDefFlatUnion2 *tmp =NULL ; -Error *err =NULL ;Visitor *v;/* test situation where discriminator field ('enum1' here) is missing */ v =validate_test_init (data,"{ 'integer': 42, 'string': 'c', 'string1': 'd', 'string2': 'e' }" ); -visit_type_UserDefFlatUnion2 (v, &tmp,NULL , &err); -g_assert (err); -error_free (err); +visit_type_UserDefFlatUnion2 (v, &tmp,NULL , &data->err); +g_assert (data->err);qapi_free_UserDefFlatUnion2 (tmp); }
@@ -285,13 +265,11 @@ static void test_validate_fail_alternate(TestInputVisitorData *data, {UserDefAlternate *tmp =NULL ;Visitor *v; -Error *err =NULL ; v =validate_test_init (data,"3.14" ); -visit_type_UserDefAlternate (v, &tmp,NULL , &err); -g_assert (err); -error_free (err); +visit_type_UserDefAlternate (v, &tmp,NULL , &data->err); +g_assert (data->err);qapi_free_UserDefAlternate (tmp); }
@@ -299,16 +277,11 @@ static void do_test_validate_qmp_introspect(TestInputVisitorData *data, const char *schema_json) {SchemaInfoList *schema =NULL ; -Error *err =NULL ;Visitor *v; v =validate_test_init_raw (data, schema_json); -visit_type_SchemaInfoList (v, &schema,NULL , &err); -if (err) { -fprintf (stderr,"%s" ,error_get_pretty (err)); - } -g_assert (!err); +visit_type_SchemaInfoList (v, &schema,NULL , &error_abort);g_assert (schema);qapi_free_SchemaInfoList (schema);
tests/test-qmp-input-visitor.c +33 -74
351 lines not on this page · raw message
tests/test-qmp-output-visitor.c +14 -42
193 lines not on this page · raw message
tests/test-visitor-serialization.c +17 -25
103 lines not on this page · raw message
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v9 04/27] qapi: Simplify error testing in test-qmp-*
Quoted 2 lines · Eric Blake
By using
&error_abort, we can avoid a local err variable in situations where we expect success.
This part is a no-brainer.
Bonus: before we abort(), we print
Unexpected error in FUNC() at FILE:LINE:
THE-ERROR-MESSAGE
to stdout on unexpected errors, which is a whole lot more useful than what g_assert(!err) prints.
By the way: Coccinelle job :)
Quoted 4 lines
By moving err into data, we can let test teardown take care of cleaning up any collected error; it also gives us fewer lines of code between repeated tests where init runs teardown on our behalf.
This part isn't as obvious.
Having two parts of differing obviousness indicates patch splitting could make sense. Especially when the parts are large and mechanical, because reviewing large mechanical changes is much easier when there's just one kind of it.
Quoted 1 line
Signed-off-by Eric Blake <[email protected]>
[...]
Quoted 2 lines
tests/test-qmp-input-visitor.c +0
-0
[...]
tests/test-qmp-input-visitor.c static void test_visitor_in_alternate_number(TestInputVisitorData *data, · line 346
Quoted 11 lines
tests/test-qmp-input-visitor.c +2
-4@@ -364,21 +341,17 @@ static void test_visitor_in_alternate_number(TestInputVisitorData *data,/* Parsing an int */ v =visitor_input_test_init (data,"42" ); -visit_type_AltStrBool (v, &asb,NULL , &err); -g_assert (err); -error_free (err); - err =NULL ; +visit_type_AltStrBool (v, &asb,NULL , &data->err); +g_assert (data->err);qapi_free_AltStrBool (asb);
This leaves data->err non-null.
tests/test-qmp-input-visitor.c static void test_visitor_in_alternate_number(TestInputVisitorData *data, · line 351
Quoted 6 lines
tests/test-qmp-input-visitor.c +1
-1/* FIXME: Order of alternate should not affect semantics; asn should * parse the same as ans */ v =visitor_input_test_init (data,"42" ); -visit_type_AltStrNum (v, &asn,NULL , &err); +visit_type_AltStrNum (v, &asn,NULL , &data->err);
If visit_type_AltStrNum() errors out, its error will be thrown away by its error_propagate(), because data->err is already non-null.
If it fails to error out, its error_propagate() does nothing, and we won't detect the test failure.
Your patch makes forgetting to reset err an even easier mistake to make, because it removes most of the error_free() that serve as reminders.
Is it a good idea anyway? Let's discuss before I check the remainder of this patch.
Quoted 9 lines
tests/test-qmp-input-visitor.c +1
-3/* FIXME g_assert_cmpint(asn->type, == ALT_STR_NUM_KIND_N); */ /* FIXME g_assert_cmpfloat(asn->u.n, ==, 42); */ -g_assert (err); -error_free (err); - err =NULL ; +g_assert (data->err);qapi_free_AltStrNum (asn); v =visitor_input_test_init (data,"42" );
[...]
Re: [Qemu-devel] [PATCH v9 04/27] qapi: Simplify error testing in test-qmp-*
Quoted 6 lines · Markus Armbruster
Quoted 5 lines
By moving err into data, we can let test teardown take care of cleaning up any collected error; it also gives us fewer lines of code between repeated tests where init runs teardown on our behalf.
Quoted 6 lines
This part isn't as obvious.
Having two parts of differing obviousness indicates patch splitting could make sense. Especially when the parts are large and mechanical, because reviewing large mechanical changes is much easier when there's just one kind of it.
Will split.
Quoted 18 lines
tests/test-qmp-input-visitor.c static void test_visitor_in_alternate_number(TestInputVisitorData *data, · line 346
Quoted 11 lines
tests/test-qmp-input-visitor.c +2
-4@@ -364,21 +341,17 @@ static void test_visitor_in_alternate_number(TestInputVisitorData *data,/* Parsing an int */ v =visitor_input_test_init (data,"42" ); -visit_type_AltStrBool (v, &asb,NULL , &err); -g_assert (err); -error_free (err); - err =NULL ; +visit_type_AltStrBool (v, &asb,NULL , &data->err); +g_assert (data->err);qapi_free_AltStrBool (asb);This leaves
data->errnon-null.Quoted 4 lines
tests/test-qmp-input-visitor.c +0
-0/* FIXME: Order of alternate should not affect semantics; asn should * parse the same as ans */ v =visitor_input_test_init (data,"42" );
And this part wipes out data, so that data->err is once again NULL.
Quoted 5 lines
tests/test-qmp-input-visitor.c static void test_visitor_in_alternate_number(TestInputVisitorData *data, · line 351
Quoted 2 lines
tests/test-qmp-input-visitor.c +1
-1-visit_type_AltStrNum (v, &asn,NULL , &err); +visit_type_AltStrNum (v, &asn,NULL , &data->err);If
visit_type_AltStrNum()errors out, its error will be thrown away by itserror_propagate(), becausedata->erris already non-null.
No, you missed that this patch is relying on the magic in 3/27 that wipes out data on every new test.
Quoted 9 lines
If it fails to error out, its
error_propagate()does nothing, and we won't detect the test failure.Your patch makes forgetting to reset err an even easier mistake to make, because it removes most of the
error_free()that serve as reminders.Is it a good idea anyway? Let's discuss before I check the remainder of this patch.
The point was that by moving err _into_ data, then the resetting of err becomes as simple as resetting data, rather than having to be verbose at every use of data->err. We just need a visitor_input_test_init() in between.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v9 04/27] qapi: Simplify error testing in test-qmp-*
Quoted 39 lines · Eric Blake
Quoted 6 lines · Markus Armbruster
Quoted 5 lines
By moving err into data, we can let test teardown take care of cleaning up any collected error; it also gives us fewer lines of code between repeated tests where init runs teardown on our behalf.
Quoted 6 lines
This part isn't as obvious.
Having two parts of differing obviousness indicates patch splitting could make sense. Especially when the parts are large and mechanical, because reviewing large mechanical changes is much easier when there's just one kind of it.
Will split.
Quoted 4 lines
Quoted 4 lines
tests/test-qmp-input-visitor.c +0
-0@@ -364,21 +341,17 @@ static void test_visitor_in_alternate_number(TestInputVisitorData *data,/* Parsing an int */ Quoted 15 lines
tests/test-qmp-input-visitor.c static void test_visitor_in_alternate_number(TestInputVisitorData *data, · line 346
Quoted 8 lines
tests/test-qmp-input-visitor.c +2
-4v =visitor_input_test_init (data,"42" ); -visit_type_AltStrBool (v, &asb,NULL , &err); -g_assert (err); -error_free (err); - err =NULL ; +visit_type_AltStrBool (v, &asb,NULL , &data->err); +g_assert (data->err);qapi_free_AltStrBool (asb);This leaves
data->errnon-null.Quoted 4 lines
tests/test-qmp-input-visitor.c +0
-0/* FIXME: Order of alternate should not affect semantics; asn should * parse the same as ans */ v =visitor_input_test_init (data,"42" );And this part wipes out data, so that
data->erris once again NULL.
Quoted 8 lines
Quoted 5 lines
tests/test-qmp-input-visitor.c static void test_visitor_in_alternate_number(TestInputVisitorData *data, · line 351
Quoted 2 lines
tests/test-qmp-input-visitor.c +1
-1-visit_type_AltStrNum (v, &asn,NULL , &err); +visit_type_AltStrNum (v, &asn,NULL , &data->err);If
visit_type_AltStrNum()errors out, its error will be thrown away by itserror_propagate(), becausedata->erris already non-null.No, you missed that this patch is relying on the magic in 3/27 that wipes out data on every new test.
You're right.
Quoted 6 lines
Quoted 6 lines
If it fails to error out, its
error_propagate()does nothing, and we won't detect the test failure.Your patch makes forgetting to reset err an even easier mistake to make, because it removes most of the
error_free()that serve as reminders.
Quoted 7 lines
Quoted 2 lines
Is it a good idea anyway? Let's discuss before I check the remainder of this patch.
The point was that by moving err _into_ data, then the resetting of err becomes as simple as resetting data, rather than having to be verbose at every use of
data->err. We just need avisitor_input_test_init()in between.
Reducing boilerplate is good. However, I'm afraid hiding error_free(err); err = NULL; like this sets an example that is easily copied incorrectly.
Here's what error.h has to say about consuming an Error object:
* Report an error to stderr:
* error_report_err(err);
* This frees the error object.
*
* Report an error somewhere else:
* const char *msg = error_get_pretty(err); * do with msg what needs to be done... * error_free(err);
*
* Handle an error without reporting it (just for completeness):
* error_free(err);
Perhaps we want something like
* Expect an error, abort() if there is none:
* error_free_or_abort(&err);
* This frees the error object and clears err. Convenient for tests.
Then the patch quoted above becomes
@@ -364,21 +341,17 @@ static void test_visitor_in_alternate_number(TestInputVisitorData *data,
/* Parsing an int */
v = visitor_input_test_init(data, "42");
visit_type_AltStrBool(v, &asb, NULL, &err);
- g_assert(err);
- error_free(err);
- err = NULL;
+ error_free_or_abort(&err);
qapi_free_AltStrBool(asb);
/* FIXME: Order of alternate should not affect semantics; asn should
* parse the same as ans */
v = visitor_input_test_init(data, "42");
visit_type_AltStrNum(v, &asn, NULL, &err);
/* FIXME g_assert_cmpint(asn->type, == ALT_STR_NUM_KIND_N); */
/* FIXME g_assert_cmpfloat(asn->u.n, ==, 42); */
- g_assert(err);
- error_free(err);
- err = NULL;
+ error_free_or_abort(&err);
qapi_free_AltStrNum(asn);
v = visitor_input_test_init(data, "42");Similar boilerplate reduction, but keeps the clearing of err more visible.
Re: [Qemu-devel] [PATCH v9 04/27] qapi: Simplify error testing in test-qmp-*
Quoted 17 lines · Markus Armbruster
Quoted 15 lines · Eric Blake
Quoted 12 lines · Markus Armbruster
Quoted 5 lines
By moving err into data, we can let test teardown take care of cleaning up any collected error; it also gives us fewer lines of code between repeated tests where init runs teardown on our behalf.
This part isn't as obvious.
Having two parts of differing obviousness indicates patch splitting could make sense. Especially when the parts are large and mechanical, because reviewing large mechanical changes is much easier when there's just one kind of it.
Quoted 7 lines
Quoted 1 line
Will split.
Perhaps we want something like
* Expect an error,
abort()if there is none:
*error_free_or_abort(&err);
* This frees the error object and clears err. Convenient for tests.
Don't know if we'd want that directly in error.h, or just in the affected tests, but I like the idea. All the more reason for me to split the patch into expected error vs. expected no error cases.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH v9 5/27 qapi: More tests of alternate output
In reply to Eric BlakeThe testsuite was only covering that we could output a built-in branch of an alternate; make sure that things still work even when a branch involves allocation, to ensure that we don't leak when run under valgrind.
Update to modern style of g_new0() over g_malloc0() while touching it.
---
v9: new patch, split off of 10/17
--- tests/test-qmp-output-visitor.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
tests/test-qmp-output-visitor.c +15 -1
@@ -425,8 +425,9 @@ static void test_visitor_out_alternate(TestOutputVisitorData *data, const void *unused) {QObject *arg; +UserDefAlternate *tmp; -UserDefAlternate *tmp =g_malloc0 (sizeof (UserDefAlternate)); + tmp =g_new0 (UserDefAlternate,1 ); tmp->type =USER_DEF_ALTERNATE_KIND_I ; tmp->u.i =42 ;
@@ -438,6 +439,19 @@ static void test_visitor_out_alternate(TestOutputVisitorData *data,qapi_free_UserDefAlternate (tmp);qobject_decref (arg); + + tmp =g_new0 (UserDefAlternate,1 ); + tmp->type =USER_DEF_ALTERNATE_KIND_S ; + tmp->u.s =g_strdup ("hello" ); + +visit_type_UserDefAlternate (data->ov, &tmp,NULL , &error_abort); + arg =qmp_output_get_qobject (data->qov); + +g_assert (qobject_type (arg) ==QTYPE_QSTRING ); + g_assert_cmpstr(qstring_get_str(qobject_to_qstring(arg)), ==, "hello"); + +qapi_free_UserDefAlternate (tmp); +qobject_decref (arg); } static void test_visitor_out_empty(TestOutputVisitorData *data,
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v9 05/27] qapi: More tests of alternate output
Suggest "qapi: Test alternate output visitor with boxed type"
Quoted 2 lines · Eric Blake
The testsuite was only covering that we could output a built-in branch of an alternate; make sure that things still work even
Well, 'str' is built-in, too. "'int' branch"?
Quoted 2 lines
when a branch involves allocation, to ensure that we don't leak when run under valgrind.
More pedantry: we'd leak when not running under valgrind just as much.
Quoted 4 lines
Update to modern style of
g_new0()overg_malloc0()while touching it.Signed-off-by Eric Blake <[email protected]>
Patch looks good.
PATCH v9 6/27 qapi: Test failure in middle of array parse
In reply to Eric BlakeOur generated list visitors have the same problem as has been mentioned elsewhere (see commit 2f52e20): they allocate data even on failure. An upcoming patch will correct things to provide saner guarantees, but first we need to expose the behavior in the testsuite to ensure we aren't introducing any memory usage bugs.
---
v9: move earlier in series (was 15/17)
v8: no change
v7: no change
v6: rebase onto earlier gen_err_check() and testsuite improvements
--- scripts/qapi-visit.py | 4 ++++ tests/test-qmp-input-visitor.c | 10 ++++++++++ 2 files changed, 14 insertions(+)
scripts/qapi-visit.py +4 -0
@@ -138,6 +138,10 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error def gen_visit_list(name, element_type): + # FIXME: if *obj is NULL on entry, and the first visit_next_list() + # assigns to *obj, while a later one fails, we should clean up *obj + # rather than leaving it non-NULL. As currently written, the caller must + # call qapi_free_FOOList() to avoid a memory leak of the partial FOOList. return mcgen(''' void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error **errp)
tests/test-qmp-input-visitor.c +10 -0
@@ -701,6 +701,7 @@ static void test_visitor_in_errors(TestInputVisitorData *data, {TestStruct *p =NULL ;Visitor *v; +strList *q =NULL ; v =visitor_input_test_init (data,"{ 'integer': false, 'boolean': 'foo', 'string': -42 }" );
@@ -712,6 +713,15 @@ static void test_visitor_in_errors(TestInputVisitorData *data,g_free (p->string);g_free (p); + + v =visitor_input_test_init (data,"[ '1', '2', false, '3' ]" ); +/* FIXME - a failed parse should not leave a partially-allocated +* array for us to clean up; this could cause callers to leak +* memory. */ +visit_type_strList (v, &q,NULL , &data->err); +assert (q); +assert (data->err); +qapi_free_strList (q); }int main (int argc,char **argv)
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v9 06/27] qapi: Test failure in middle of array parse
Quoted 8 lines · Eric Blake
Our generated list visitors have the same problem as has been mentioned elsewhere (see commit 2f52e20): they allocate data even on failure. An upcoming patch will correct things to provide saner guarantees, but first we need to expose the behavior in the testsuite to ensure we aren't introducing any memory usage bugs.
Signed-off-by Eric Blake <[email protected]>
This commit documents the problem and adds test coverage. Commit 2f52e20 only documented. Do we have test coverage?
Patch looks good.
PATCH v9 7/27 qapi: More tests of input arrays
In reply to Eric BlakeOur testsuite had no coverage of empty arrays, nor of what happens when the input does not match the expected type. Useful to have, especially if we start changing the visitor contracts.
---
v9: move earlier in series (was 16/17)
v8: no change
v7: no change
v6: new patch
--- tests/test-qmp-input-visitor.c | 51 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+)
tests/test-qmp-input-visitor.c +51 -0
@@ -236,6 +236,12 @@ static void test_visitor_in_list(TestInputVisitorData *data, }qapi_free_UserDefOneList (head); + head =NULL ; + +/* An empty list is valid */ + v =visitor_input_test_init (data,"[]" ); +visit_type_UserDefOneList (v, &head,NULL , &error_abort); +g_assert (!head); } static void test_visitor_in_any(TestInputVisitorData *data,
@@ -724,6 +730,49 @@ static void test_visitor_in_errors(TestInputVisitorData *data,qapi_free_strList (q); } +static void test_visitor_in_wrong_type (TestInputVisitorData *data, +const void *unused) +{ +TestStruct *p =NULL ; +Visitor *v; +strList *q =NULL ; +int64_t i; + +/* Make sure arrays and structs cannot be confused */ + + v =visitor_input_test_init (data,"[]" ); +visit_type_TestStruct (v, &p,NULL , &data->err); +g_assert (data->err); +g_assert (!p); + + v =visitor_input_test_init (data,"{}" ); +visit_type_strList (v, &q,NULL , &data->err); +assert (data->err); +assert (!q); + +/* Make sure primitives and struct cannot be confused */ + + v =visitor_input_test_init (data,"1" ); +visit_type_TestStruct (v, &p,NULL , &data->err); +g_assert (data->err); +g_assert (!p); + + v =visitor_input_test_init (data,"{}" ); +visit_type_int (v, &i,NULL , &data->err); +assert (data->err); + +/* Make sure primitives and arrays cannot be confused */ + + v =visitor_input_test_init (data,"1" ); +visit_type_strList (v, &q,NULL , &data->err); +assert (data->err); +assert (!q); + + v =visitor_input_test_init (data,"[]" ); +visit_type_int (v, &i,NULL , &data->err); +assert (data->err); +} +int main (int argc,char **argv) {TestInputVisitorData in_visitor_data;
@@ -756,6 +805,8 @@ int main(int argc, char **argv) &in_visitor_data, test_visitor_in_alternate);input_visitor_test_add ("/visitor/input/errors" , &in_visitor_data, test_visitor_in_errors); +input_visitor_test_add ("/visitor/input/wrong-type" , + &in_visitor_data, test_visitor_in_wrong_type);input_visitor_test_add ("/visitor/input/alternate-number" , &in_visitor_data, test_visitor_in_alternate_number); input_visitor_test_add("/visitor/input/native_list/int",
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v9 07/27] qapi: More tests of input arrays
Quoted 7 lines · Eric Blake
Our testsuite had no coverage of empty arrays, nor of what happens when the input does not match the expected type. Useful to have, especially if we start changing the visitor contracts.
Signed-off-by Eric Blake <[email protected]>
Quoted 8 lines
---
v9: move earlier in series (was 16/17)
v8: no change
v7: no change
v6: new patch--- tests/test-qmp-input-visitor.c | 51 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+)
Should we update test-qmp-input-strict.c as well?
Patch looks good.
PATCH v9 8/27 qapi: Provide nicer array names in introspection
In reply to Eric BlakeFor the sake of humans reading introspection output, it is nice to have the name of implicit array types be recognizable as arrays of the underlying type. However, while this patch allows humans to skip from a command with return type "[123]" straight to the definition of type "123" without having to first inspect type "[123]", document that this shortcut should not be taken by client apps.
This makes the resulting introspection string slightly larger by default (just over 200 bytes), but it's in the noise (less than 0.3% of the overall 70k size of 'query-qmp-capabilities').
---
v9: no change
v8: commit message stats on the size increase
v7: no change
v6: no change
--- docs/qapi-code-gen.txt | 7 +++++-- scripts/qapi-introspect.py | 8 +++++--- 2 files changed, 10 insertions(+), 5 deletions(-)
docs/qapi-code-gen.txt +5 -2
@@ -662,11 +662,14 @@ Example: the SchemaInfo for BlockRef from section Alternate types The SchemaInfo for an array type has meta-type "array", and variant member "element-type", which names the array's element type. Array -types are implicitly defined. +types are implicitly defined. For convenience, the array's name may +resemble the element type; however, clients should examine member +"element-type" instead of making assumptions based on parsing member +"name". Example: the SchemaInfo for ['str'] - { "name": "strList", "meta-type": "array", + { "name": "[str]", "meta-type": "array", "element-type": "str" } The SchemaInfo for an enumeration type has meta-type "enum" and
scripts/qapi-introspect.py +5 -3
@@ -107,10 +107,12 @@ const char %(c_name)s[] = %(c_string)s; # characters. if isinstance(typ, QAPISchemaBuiltinType): return typ.name + if isinstance(typ, QAPISchemaArrayType): + return '[' + self._use_type(typ.element_type) + ']' return self._name(typ.name) def _gen_json(self, name, mtype, obj): - if mtype != 'command' and mtype != 'event' and mtype != 'builtin': + if mtype not in ('command', 'event', 'builtin', 'array'): name = self._name(name) obj['name'] = name obj['meta-type'] = mtype
@@ -136,8 +138,8 @@ const char %(c_name)s[] = %(c_string)s; self._gen_json(name, 'enum', {'values': values}) def visit_array_type(self, name, info, element_type): - self._gen_json(name, 'array', - {'element-type': self._use_type(element_type)}) + element = self._use_type(element_type) + self._gen_json('[' + element + ']', 'array', {'element-type': element}) def visit_object_type_flat(self, name, info, members, variants): obj = {'members': [self._gen_member(m) for m in members]}
Signature · 1 line
2.4.3
PATCH v9 9/27 qapi-introspect: Document lack of sorting
In reply to Eric Blakeqapi-code-gen.txt already claims that types, commands, and events share a common namespace; set this in stone by further documenting that our introspection output will never have collisions with the same name tied to more than one meta-type.
Our largest QMP enum currently has 125 values, our largest object type has 27 members, and the mean for each is less than
10. These sizes are small enough that the per-element overhead of O(log n) binary searching probably outweighs the speed possible with direct O(n) linear searching (a better algorithm with more overhead will only beat a leaner naive algorithm only as you scale to larger input sizes).
Arguably, the overall SchemaInfo array could be sorted by name; there, we currently have 531 entities, large enough for a binary search to be faster than linear. However, remember that we have mutually-recursive types, which means there is no topological ordering that will allow clients to learn all information about that type in a single linear pass; thus clients will want to do random access over the data, and they will probably read the introspection output into a hashtable for O(1) lookup rather than O(log n) binary searching, at which point, pre-sorting our introspection output doesn't help the client.
Finally, I am not sure how to guarantee that python sorts strings for the C locale even if the generator is run under a different locale. Our current output order is deterministic (based on the order present in .json files, even if that order has no inherent bearing on how a client will present their QMP commands), while sorting data risks non-determinism if the generator is subject to any locale differences.
For these reasons, we simply document that clients should not rely on any particular order of items in introspection output. Additionally, this gives us the freedom to later change our mind, so that we could rearrange output in a different order than the way it was listed in the .json file, without breaking any client that was already aware it had to do a linear search.
Document these conventions, so that clients will know what can and cannot be relied on.
---
v9: retitle; and swing in the opposite direction: give the user no guarantee about order
v8: no change
v7: tweak commit wording
v6: no change from v5
--- docs/qapi-code-gen.txt | 19 +++++++++++++++---- qapi/introspect.json | 21 ++++++++++++++++----- 2 files changed, 31 insertions(+), 9 deletions(-)
docs/qapi-code-gen.txt +15 -4
@@ -516,6 +516,10 @@ query-qmp-schema. QGA currently doesn't support introspection. query-qmp-schema returns a JSON array of SchemaInfo objects. These objects together describe the wire ABI, as defined in the QAPI schema. +There is no specified order to the SchemaInfo objects returned; a +client must search for a particular name throughout the entire array +to learn more about that name, but is at least guaranteed that there +will be no collisions between type, command, and event names. However, the SchemaInfo can't reflect all the rules and restrictions that apply to QMP. It's interface introspection (figuring out what's
@@ -596,7 +600,9 @@ any. Each element is a JSON object with members "name" (the member's name), "type" (the name of its type), and optionally "default". The member is optional if "default" is present. Currently, "default" can only have value null. Other values are reserved for future -extensions. +extensions. The "members" array is in no particular order; clients +must search every member when learning whether a particular member is +supported. Example: the SchemaInfo for MyType from section Struct types
@@ -610,7 +616,9 @@ Example: the SchemaInfo for MyType from section Struct types "variants" is a JSON array describing the object's variant members. Each element is a JSON object with members "case" (the value of type tag this element applies to) and "type" (the name of an object type -that provides the variant members for this type tag value). +that provides the variant members for this type tag value). The +"variants" array is in no particular order, and is not guaranteed to +list cases in the same order as the corresponding "tag" enum type. Example: the SchemaInfo for flat union BlockdevOptions from section Union types
@@ -651,7 +659,8 @@ Union types The SchemaInfo for an alternate type has meta-type "alternate", and variant member "members". "members" is a JSON array. Each element is a JSON object with member "type", which names a type. Values of the -alternate type conform to exactly one of its member types. +alternate type conform to exactly one of its member types. There is +no guarantee on the order in which "members" will be listed. Example: the SchemaInfo for BlockRef from section Alternate types
@@ -673,7 +682,9 @@ Example: the SchemaInfo for ['str'] "element-type": "str" } The SchemaInfo for an enumeration type has meta-type "enum" and -variant member "values". +variant member "values". The values are listed in no particular +order; clients must search every value when learning whether a +particular value is supported. Example: the SchemaInfo for MyEnum from section Enumeration types
qapi/introspect.json +16 -5
@@ -25,6 +25,10 @@ # Returns: array of @SchemaInfo, where each element describes an # entity in the ABI: command, event, type, ... # +# The order of the various SchemaInfo is unspecified; however, all +# names are guaranteed to be unique (no name will be duplicated with +# different meta-types). +# # Note: the QAPI schema is also used to help define *internal* # interfaces, by defining QAPI types. These are not part of the QMP # wire ABI, and therefore not returned by this command.
@@ -78,7 +82,8 @@ # Commands and events have the name defined in the QAPI schema. # Unlike command and event names, type names are not part of # the wire ABI. Consequently, type names are meaningless -# strings here. +# strings here, although they are still guaranteed unique +# regardless of @meta-type. # # All references to other SchemaInfo are by name. #
@@ -130,7 +135,9 @@ # # Additional SchemaInfo members for meta-type 'enum'. # -# @values: the enumeration type's values. +# @values: the enumeration type's values. The values are in no particular +# order, so clients must search every value when learning if a +# particular value is present. # # Values of this type are JSON string on the wire. #
@@ -158,14 +165,18 @@ # # Additional SchemaInfo members for meta-type 'object'. # -# @members: the object type's (non-variant) members. +# @members: the object type's (non-variant) members. The members are +# in no particular order, so clients must search every member +# when learning if a particular member is present. # # @tag: #optional the name of the member serving as type tag. # An element of @members with this name must exist. # # @variants: #optional variant members, i.e. additional members that # depend on the type tag's value. Present exactly when -# @tag is present. +# @tag is present. The variants are in no particular order, +# and may even differ from the order of the values of the +# enum type of the @tag. # # Values of this type are JSON object on the wire. #
@@ -219,7 +230,7 @@ # # Additional SchemaInfo members for meta-type 'alternate'. # -# @members: the alternate type's members. +# @members: the alternate type's members, in no particular order. # The members' wire encoding is distinct, see # docs/qapi-code-gen.txt section Alternate types. #
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v9 09/27] qapi-introspect: Document lack of sorting
Quoted 24 lines · Eric Blake
qapi-code-gen.txt already claims that types, commands, and events share a common namespace; set this in stone by further documenting that our introspection output will never have collisions with the same name tied to more than one meta-type.
Our largest QMP enum currently has 125 values, our largest object type has 27 members, and the mean for each is less than
10. These sizes are small enough that the per-element overhead of O(log n) binary searching probably outweighs the speed possible with direct O(n) linear searching (a better algorithm with more overhead will only beat a leaner naive algorithm only as you scale to larger input sizes).Arguably, the overall SchemaInfo array could be sorted by name; there, we currently have 531 entities, large enough for a binary search to be faster than linear. However, remember that we have mutually-recursive types, which means there is no topological ordering that will allow clients to learn all information about that type in a single linear pass; thus clients will want to do random access over the data, and they will probably read the introspection output into a hashtable for O(1) lookup rather than O(log n) binary searching, at which point, pre-sorting our introspection output doesn't help the client.
Quoted 3 lines
Finally, I am not sure how to guarantee that python sorts strings for the C locale even if the generator is run under a different locale.
Python's "Sorting HOW TO" advises:
For locale aware sorting, use locale.strxfrm() for a key function or locale.strcoll() for a comparison function.
https://docs.python.org/2.7/howto/sorting.html#odd-and-ends
Explicit, opt-in locale-dependence sure feels a lot cleaner and safer than the historical mess we have in C.
Quoted 3 lines
Our current output order is deterministic (based on the
order present in .json files, even if that order has no inherent bearing on how a client will present their QMP commands),
Actually no longer the case:
def visit(self, visitor):
visitor.visit_begin(self)
for (name, entity) in sorted(self._entity_dict.items()):
if visitor.visit_needed(entity):
entity.visit(visitor)
visitor.visit_end()
Dates back to commit 3f7dc21 "qapi: New QAPISchemaVisitor". Without sorting, we'd some unpredictable order. I could've used OrderedDict instead, preserving insertion order.
Quoted 32 lines
while
sorting data risks non-determinism if the generator is subject to any locale differences.For these reasons, we simply document that clients should not rely on any particular order of items in introspection output. Additionally, this gives us the freedom to later change our mind, so that we could rearrange output in a different order than the way it was listed in the .json file, without breaking any client that was already aware it had to do a linear search.
Document these conventions, so that clients will know what can and cannot be relied on.
Signed-off-by Eric Blake <[email protected]>---
v9: retitle; and swing in the opposite direction: give the user no guarantee about order
v8: no change
v7: tweak commit wording
v6: no change from v5--- docs/qapi-code-gen.txt | 19 +++++++++++++++---- qapi/introspect.json | 21 ++++++++++++++++----- 2 files changed, 31 insertions(+), 9 deletions(-)docs/qapi-code-gen.txt +0
-0
docs/qapi-code-gen.txt query-qmp-schema. QGA currently doesn't support introspection. · line 522
Quoted 7 lines
docs/qapi-code-gen.txt +4
-0@@ -516,6 +516,10 @@ query-qmp-schema. QGA currently doesn't support introspection. query-qmp-schema returns a JSON array of SchemaInfo objects. These objects together describe the wire ABI, as defined in the QAPI schema. +There is no specified order to the SchemaInfo objects returned; a +client must search for a particular name throughout the entire array +to learn more about that name, but is at least guaranteed that there +will be no collisions between type, command, and event names.
I would've omitted the "client must search" clause, but I habitually write subtle contracts that need to be read slowly and carefully. Feel free to keep it.
docs/qapi-code-gen.txt any. Each element is a JSON object with members "name" (the member's · line 605
Quoted 10 lines
docs/qapi-code-gen.txt +3
-1However, the SchemaInfo can't reflect all the rules and restrictions that apply to QMP. It's interface introspection (figuring out what's@@ -596,7 +600,9 @@ any. Each element is a JSON object with members "name" (the member's name), "type" (the name of its type), and optionally "default". The member is optional if "default" is present. Currently, "default" can only have value null. Other values are reserved for future -extensions. +extensions. The "members" array is in no particular order; clients +must search every member when learning whether a particular member is +supported.
Nitpick: clients must search the object, not every member.
Quoted 24 lines
docs/qapi-code-gen.txt +5
-2Example: the SchemaInfo for MyType from section Struct types@@ -610,7 +616,9 @@ Example: the SchemaInfo for MyType from section Struct types "variants" is a JSON array describing the object's variant members. Each element is a JSON object with members "case" (the value of type tag this element applies to) and "type" (the name of an object type -that provides the variant members for this type tag value). +that provides the variant members for this type tag value). The +"variants" array is in no particular order, and is not guaranteed to +list cases in the same order as the corresponding "tag" enum type. Example: the SchemaInfo for flat union BlockdevOptions from section Union types@@ -651,7 +659,8 @@ Union types The SchemaInfo for an alternate type has meta-type "alternate", and variant member "members". "members" is a JSON array. Each element is a JSON object with member "type", which names a type. Values of the -alternate type conform to exactly one of its member types. +alternate type conform to exactly one of its member types. There is +no guarantee on the order in which "members" will be listed. Example: the SchemaInfo for BlockRef from section Alternate types
docs/qapi-code-gen.txt Example: the SchemaInfo for ['str'] · line 687
Quoted 7 lines
docs/qapi-code-gen.txt +3
-1@@ -673,7 +682,9 @@ Example: the SchemaInfo for ['str'] "element-type": "str" } The SchemaInfo for an enumeration type has meta-type "enum" and -variant member "values". +variant member "values". The values are listed in no particular +order; clients must search every value when learning whether a +particular value is supported.
Similar nitpick.
Quoted 28 lines
docs/qapi-code-gen.txt +0
-0Example: the SchemaInfo for MyEnum from section Enumeration typesqapi/introspect.json +6
-1@@ -25,6 +25,10 @@ # Returns: array of @SchemaInfo, where each element describes an # entity in the ABI: command, event, type, ... # +# The order of the various SchemaInfo is unspecified; however, all +# names are guaranteed to be unique (no name will be duplicated with +# different meta-types). +# # Note: the QAPI schema is also used to help define *internal* # interfaces, by defining QAPI types. These are not part of the QMP # wire ABI, and therefore not returned by this command.@@ -78,7 +82,8 @@ # Commands and events have the name defined in the QAPI schema. # Unlike command and event names, type names are not part of # the wire ABI. Consequently, type names are meaningless -# strings here. +# strings here, although they are still guaranteed unique +# regardless of @meta-type. # # All references to other SchemaInfo are by name. #
qapi/introspect.json line 140
Quoted 7 lines
qapi/introspect.json +3
-1@@ -130,7 +135,9 @@ # # Additional SchemaInfo members for meta-type 'enum'. # -# @values: the enumeration type's values. +# @values: the enumeration type's values. The values are in no particular +# order, so clients must search every value when learning if a +# particular value is present.
I'd drop the ", so clients must search" part as obvious.
qapi/introspect.json line 170
Quoted 11 lines
qapi/introspect.json +3
-1# # Values of this type are JSON string on the wire. #@@ -158,14 +165,18 @@ # # Additional SchemaInfo members for meta-type 'object'. # -# @members: the object type's (non-variant) members. +# @members: the object type's (non-variant) members. The members are +# in no particular order, so clients must search every member +# when learning if a particular member is present.
Likewise.
Quoted 22 lines
qapi/introspect.json +4
-2# # @tag: #optional the name of the member serving as type tag. # An element of @members with this name must exist. # # @variants: #optional variant members, i.e. additional members that # depend on the type tag's value. Present exactly when -# @tag is present. +# @tag is present. The variants are in no particular order, +# and may even differ from the order of the values of the +# enum type of the @tag. # # Values of this type are JSON object on the wire. #@@ -219,7 +230,7 @@ # # Additional SchemaInfo members for meta-type 'alternate'. # -# @members: the alternate type's members. +# @members: the alternate type's members, in no particular order. # The members' wire encoding is distinct, see # docs/qapi-code-gen.txt section Alternate types. #
PATCH v9 10/27 qapi: Track simple union tag in object.local_members
In reply to Eric BlakeWe were previously creating all unions with an empty list for local_members. However, it will make it easier to unify struct and union generation if we include the generated tag member in local_members. That way, we can have a common code pattern:
visit the base (if any), visit the local members (if any), visit the variants (if any). The local_members of a flat union remains empty (because the discriminator is already visited as part of the base). Then, by visiting tag_member.check() during AlternateType.check(), we no longer need to call it during Variants.check().
The various front end entities now exist as follows:
struct: optional base, optional local_members, no variants simple union: no base, one-element local_members, variants with tag_member
from local_members
flat union: base, no local_members, variants with tag_member from base
alternate: no base, no local_members, variants
With the new local members, we require a bit of finesse to avoid assertions in the clients.
No change to generated code.
---
v9: improve commit message, add comments, tweak how alternates check tag_member
v8: new patch
--- scripts/qapi-types.py | 5 ++++- scripts/qapi-visit.py | 5 ++++- scripts/qapi.py | 16 +++++++++++----- tests/qapi-schema/qapi-schema-test.out | 2 ++ tests/qapi-schema/union-clash-data.out | 1 + tests/qapi-schema/union-empty.out | 1 + 6 files changed, 23 insertions(+), 7 deletions(-)
scripts/qapi-types.py +4 -1
@@ -269,7 +269,10 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): def visit_object_type(self, name, info, base, members, variants): self._fwdecl += gen_fwd_object_or_array(name) if variants: - assert not members # not implemented + if members: + # Members other than variants.tag_member not implemented + assert len(members) == 1 + assert members[0] == variants.tag_member self.decl += gen_union(name, base, variants) else: self.decl += gen_struct(name, base, members)
scripts/qapi-visit.py +4 -1
@@ -364,7 +364,10 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor): def visit_object_type(self, name, info, base, members, variants): self.decl += gen_visit_decl(name) if variants: - assert not members # not implemented + if members: + # Members other than variants.tag_member not implemented + assert len(members) == 1 + assert members[0] == variants.tag_member self.defn += gen_visit_union(name, base, variants) else: self.defn += gen_visit_struct(name, base, members)
scripts/qapi.py +11 -5
@@ -957,6 +957,9 @@ class QAPISchemaArrayType(QAPISchemaType): class QAPISchemaObjectType(QAPISchemaType): def __init__(self, name, info, base, local_members, variants): + # struct has local_members, optional base, and no variants + # flat union has base, variants, and no local_members + # simple union has local_members, variants, and no base QAPISchemaType.__init__(self, name, info) assert base is None or isinstance(base, str) for m in local_members:
@@ -1048,10 +1051,11 @@ class QAPISchemaObjectTypeVariants(object): self.variants = variants def check(self, schema, members, seen): - if self.tag_name: + # seen is non-empty for unions, empty for alternates + if self.tag_name: # flat union self.tag_member = seen[self.tag_name] - else: - self.tag_member.check(schema, members, seen) + if seen: + assert self.tag_member in seen.itervalues() assert isinstance(self.tag_member.type, QAPISchemaEnumType) for v in self.variants: vseen = dict(seen)
@@ -1085,6 +1089,7 @@ class QAPISchemaAlternateType(QAPISchemaType): self.variants = variants def check(self, schema): + self.variants.tag_member.check(schema, [], {}) self.variants.check(schema, [], {}) def json_type(self):
@@ -1270,13 +1275,14 @@ class QAPISchema(object): if tag_name: variants = [self._make_variant(key, value) for (key, value) in data.iteritems()] + members = [] else: variants = [self._make_simple_variant(key, value, info) for (key, value) in data.iteritems()] tag_member = self._make_implicit_tag(name, info, variants) + members = [tag_member] self._def_entity( - QAPISchemaObjectType(name, info, base, - self._make_members(OrderedDict(), info), + QAPISchemaObjectType(name, info, base, members, QAPISchemaObjectTypeVariants(tag_name, tag_member, variants)))
tests/qapi-schema/qapi-schema-test.out +2 -0
@@ -132,6 +132,7 @@ object UserDefFlatUnion2 case value2: UserDefB case value3: UserDefA object UserDefNativeListUnion + member type: UserDefNativeListUnionKind optional=False case integer: :obj-intList-wrapper case s8: :obj-int8List-wrapper case s16: :obj-int16List-wrapper
@@ -187,6 +188,7 @@ object __org.qemu_x-Struct object __org.qemu_x-Struct2 member array: __org.qemu_x-Union1List optional=False object __org.qemu_x-Union1 + member type: __org.qemu_x-Union1Kind optional=False case __org.qemu_x-branch: :obj-str-wrapper enum __org.qemu_x-Union1Kind ['__org.qemu_x-branch'] object __org.qemu_x-Union2
tests/qapi-schema/union-clash-data.out +1 -0
@@ -2,5 +2,6 @@ object :empty object :obj-int-wrapper member data: int optional=False object TestUnion + member type: TestUnionKind optional=False case data: :obj-int-wrapper enum TestUnionKind ['data']
tests/qapi-schema/union-empty.out +1 -0
@@ -1,3 +1,4 @@ object :empty object Union + member type: UnionKind optional=False enum UnionKind []
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v9 10/27] qapi: Track simple union tag in object.local_members
Quoted 10 lines · Eric Blake
We were previously creating all unions with an empty list for
local_members. However, it will make it easier to unify struct and union generation if we include the generated tag member inlocal_members. That way, we can have a common code pattern:
visit the base (if any), visit the local members (if any), visit the variants (if any). Thelocal_membersof a flat union remains empty (because the discriminator is already visited as part of the base). Then, by visitingtag_member.check()duringAlternateType.check(), we no longer need to call it duringVariants.check().
Moving tag_member.check() could perhaps be a separate patch. But it's okay as is.
Quoted 6 lines
The various front end entities now exist as follows:
struct: optional base, optionallocal_members, no variants simple union: no base, one-elementlocal_members, variants withtag_member
fromlocal_members
flat union: base, nolocal_members, variants withtag_memberfrom base
alternate: no base, nolocal_members, variants
Ultimately, I'd like a single object type. Then this becomes:
object: optional base, optional local_members,
optional variants with tag_member from base or local_members
alternate: only variants
In both cases, I view the tag member as belonging to the outer container, not variants:
object stores it like any other member, and variants.tag_member
merely identifies the member that serves as tag
alternate doesn't store it member in self, but simply uses
self.variants.tag_member instead.
Perhaps QAPISchemaObjectTypeVariants should be inlined.
Just rambling, the commit message is fine as is.
Quoted 6 lines
With the new local members, we require a bit of finesse to avoid assertions in the clients.
No change to generated code.
Signed-off-by Eric Blake <[email protected]>
Patch looks good.
PATCH v9 11/27 qapi-types: Consolidate gen_struct() and gen_union()
In reply to Eric BlakeThese two methods are now close enough that we can finally merge them, relying on the fact that simple unions now provide a reasonable local_members. Change gen_struct() to gen_object() that handles all forms of QAPISchemaObjectType, and rename and shrink gen_union() to gen_variants() to handle the portion of gen_object() needed when variants are present.
gen_struct_fields() now has a single caller, so it no longer needs an optional parameter; however, I did not choose to inline it into the caller.
No difference to generated code.
---
v9: rebase to earlier changes
v8: new patch
--- scripts/qapi-types.py | 37 +++++++++++-------------------------- 1 file changed, 11 insertions(+), 26 deletions(-)
scripts/qapi-types.py +11 -26
@@ -51,7 +51,7 @@ def gen_struct_field(member): return ret -def gen_struct_fields(local_members, base=None): +def gen_struct_fields(local_members, base): ret = '' if base:
@@ -70,7 +70,7 @@ def gen_struct_fields(local_members, base=None): return ret -def gen_struct(name, base, members): +def gen_object(name, base, members, variants): ret = mcgen(''' struct %(c_name)s {
@@ -79,11 +79,14 @@ struct %(c_name)s { ret += gen_struct_fields(members, base) + if variants: + ret += gen_variants(variants) + # Make sure that all structs have at least one field; this avoids # potential issues with attempting to malloc space for zero-length # structs in C, and also incompatibility with C++ (where an empty # struct is size 1). - if not (base and base.members) and not members: + if not (base and base.members) and not members and not variants: ret += mcgen(''' char qapi_dummy_field_for_empty_struct; ''')
@@ -140,17 +143,7 @@ const int %(c_name)s_qtypes[QTYPE_MAX] = { return ret -def gen_union(name, base, variants): - ret = mcgen(''' - -struct %(c_name)s { -''', - c_name=c_name(name)) - if base: - ret += gen_struct_fields([], base) - else: - ret += gen_struct_field(variants.tag_member) - +def gen_variants(variants): # FIXME: What purpose does data serve, besides preventing a union that # has a branch named 'data'? We use it in qapi-visit.py to decide # whether to bypass the switch statement if visiting the discriminator
@@ -159,11 +152,11 @@ struct %(c_name)s { # should not be any data leaks even without a data pointer. Or, if # 'data' is merely added to guarantee we don't have an empty union, # shouldn't we enforce that at .json parse time? - ret += mcgen(''' + ret = mcgen(''' union { /* union tag is @%(c_name)s */ void *data; ''', - c_name=c_name(variants.tag_member.name)) + c_name=c_name(variants.tag_member.name)) for var in variants.variants: # Ugly special case for simple union TODO get rid of it
@@ -176,7 +169,6 @@ struct %(c_name)s { ret += mcgen(''' } u; -}; ''') return ret
@@ -268,14 +260,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): def visit_object_type(self, name, info, base, members, variants): self._fwdecl += gen_fwd_object_or_array(name) - if variants: - if members: - # Members other than variants.tag_member not implemented - assert len(members) == 1 - assert members[0] == variants.tag_member - self.decl += gen_union(name, base, variants) - else: - self.decl += gen_struct(name, base, members) + self.decl += gen_object(name, base, members, variants) if base: self.decl += gen_upcast(name, base) self._gen_type_cleanup(name)
@@ -283,7 +268,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): def visit_alternate_type(self, name, info, variants): self._fwdecl += gen_fwd_object_or_array(name) self._fwdefn += gen_alternate_qtypes(name, variants) - self.decl += gen_union(name, None, variants) + self.decl += gen_object(name, None, [variants.tag_member], variants) self.decl += gen_alternate_qtypes_decl(name) self._gen_type_cleanup(name)
Signature · 1 line
2.4.3
PATCH v9 12/27 qapi-types: Simplify gen_struct_field[s]
In reply to Eric BlakeSimplify gen_struct_fields() back to a single iteration over a list of fields (like it was prior to commit f87ab7f9), by moving the generated comments to gen_object(). Then, inline gen_struct_field() into its only caller.
---
v9: new patch
--- scripts/qapi-types.py | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-)
scripts/qapi-types.py +15 -25
@@ -36,48 +36,38 @@ struct %(c_name)s { c_name=c_name(name), c_type=element_type.c_type()) -def gen_struct_field(member): +def gen_struct_fields(members): ret = '' - - if member.optional: - ret += mcgen(''' + for memb in members: + if memb.optional: + ret += mcgen(''' bool has_%(c_name)s; ''', - c_name=c_name(member.name)) - ret += mcgen(''' + c_name=c_name(memb.name)) + ret += mcgen(''' %(c_type)s %(c_name)s; ''', - c_type=member.type.c_type(), c_name=c_name(member.name)) + c_type=memb.type.c_type(), c_name=c_name(memb.name)) return ret -def gen_struct_fields(local_members, base): - ret = '' +def gen_object(name, base, members, variants): + ret = mcgen(''' + +struct %(c_name)s { +''', + c_name=c_name(name)) if base: ret += mcgen(''' /* Members inherited from %(c_name)s: */ ''', c_name=base.c_name()) - for memb in base.members: - ret += gen_struct_field(memb) + ret += gen_struct_fields(base.members) ret += mcgen(''' /* Own members: */ ''') - - for memb in local_members: - ret += gen_struct_field(memb) - return ret - - -def gen_object(name, base, members, variants): - ret = mcgen(''' - -struct %(c_name)s { -''', - c_name=c_name(name)) - - ret += gen_struct_fields(members, base) + ret += gen_struct_fields(members) if variants: ret += gen_variants(variants)
Signature · 1 line
2.4.3
PATCH v9 13/27 qapi: Drop obsolete tag value collision assertions
In reply to Eric BlakeFrom: Markus Armbruster <[email protected]>
Union tag values can't clash with member names in generated C anymore since commit e4ba22b, but QAPISchemaObjectTypeVariant.check() still asserts they don't. Drop it.
Message-Id: <[email protected]> [A later patch will still need to pass vseen from Variants.check() to Variant.check(), so to avoid churn, change the cleanup to occur lower in Variant.check()]
---
v9: new patch
--- scripts/qapi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/qapi.py +1 -1
@@ -1067,7 +1067,7 @@ class QAPISchemaObjectTypeVariant(QAPISchemaObjectTypeMember): QAPISchemaObjectTypeMember.__init__(self, name, typ, False) def check(self, schema, tag_type, seen): - QAPISchemaObjectTypeMember.check(self, schema, [], seen) + QAPISchemaObjectTypeMember.check(self, schema, [], {}) assert self.name in tag_type.values # This function exists to support ugly simple union special cases
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v9 13/27] qapi: Drop obsolete tag value collision assertions
Quoted 11 lines · Eric Blake
From: Markus Armbruster <[email protected]>
Union tag values can't clash with member names in generated C anymore since commit e4ba22b, but
QAPISchemaObjectTypeVariant.check()still asserts they don't. Drop it.Signed-off-by Markus Armbruster <[email protected]>Message-Id: <[email protected]> [A later patch will still need to pass vseen from
Variants.check()toVariant.check(), so to avoid churn, change the cleanup to occur lower inVariant.check()]
Leaves QAPISchemaObjectTypeVariant.check() parameter seen temporarily unused. Okay, as long as we get in the patch that again uses it in the same batch.
Quoted 21 lines
Signed-off-by Eric Blake <[email protected]>---
v9: new patch--- scripts/qapi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/qapi.py +1
-1@@ -1067,7 +1067,7 @@ class QAPISchemaObjectTypeVariant(QAPISchemaObjectTypeMember): QAPISchemaObjectTypeMember.__init__(self, name, typ, False) def check(self, schema, tag_type, seen): - QAPISchemaObjectTypeMember.check(self, schema, [], seen) + QAPISchemaObjectTypeMember.check(self, schema, [], {}) assert self.name in tag_type.values # This function exists to support ugly simple union special cases
PATCH v9 14/27 qapi: Fix up commit 7618b91's clash sanity checking change
In reply to Eric BlakeFrom: Markus Armbruster <[email protected]>
This hunk
@@ -964,6 +965,7 @@ class QAPISchemaObjectType(QAPISchemaType):
members = []
seen = {}
for m in members:
+ assert c_name(m.name) not in seen
seen[m.name] = m
for m in self.local_members:
m.check(schema, members, seen)
is plainly broken.
Asserting the members inherited from base don't clash is somewhat redundant, because self.base.check() just checked that. But it doesn't hurt.
The idea to use c_name(m.name) instead of m.name for collision checking is sound, because we need to catch clashes between the m.name and between the c_name(m.name), and when two m.name clash, then their c_name() also clash.
However, using c_name(m.name) instead of m.name in one of several places doesn't work. See the very next line.
Keep the assertion, but drop the c_name() for now. A future commit will bring it back.
Message-Id: <[email protected]>
---
v9: new patch
--- scripts/qapi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/qapi.py +1 -1
@@ -987,7 +987,7 @@ class QAPISchemaObjectType(QAPISchemaType): members = [] seen = {} for m in members: - assert c_name(m.name) not in seen + assert m.name not in seen seen[m.name] = m for m in self.local_members: m.check(schema, members, seen)
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v9 14/27] qapi: Fix up commit 7618b91's clash sanity checking change
Quoted 27 lines · Eric Blake
From: Markus Armbruster <[email protected]>
This hunk
@@ -964,6 +965,7 @@ class QAPISchemaObjectType(QAPISchemaType):
members = []
seen = {}
for m in members:
+ assertc_name(m.name)not in seen
seen[m.name] = m
for m in self.local_members:
m.check(schema, members, seen)is plainly broken.
Asserting the members inherited from base don't clash is somewhat redundant, because
self.base.check()just checked that. But it doesn't hurt.The idea to use
c_name(m.name)instead of m.name for collision checking is sound, because we need to catch clashes between the m.name and between thec_name(m.name), and when two m.name clash, then theirc_name()also clash.However, using
c_name(m.name)instead of m.name in one of several places doesn't work. See the very next line.
Quoted 6 lines
Keep the assertion, but drop the
c_name()for now. A future commit will bring it back.Signed-off-by Markus Armbruster <[email protected]>Message-Id: <[email protected]> [change TAB to space]
In the commit message. You had me wondering briefly whether my Emacs configuration to avoid tabs in QEMU code failed :)
Quoted 21 lines
Signed-off-by Eric Blake <[email protected]>---
v9: new patch--- scripts/qapi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/qapi.py +1
-1@@ -987,7 +987,7 @@ class QAPISchemaObjectType(QAPISchemaType): members = [] seen = {} for m in members: - assert c_name(m.name) not in seen + assert m.name not in seen seen[m.name] = m for m in self.local_members: m.check(schema, members, seen)
PATCH v9 15/27 qapi: Simplify QAPISchemaObjectTypeMember.check()
In reply to Eric BlakeFrom: Markus Armbruster <[email protected]>
QAPISchemaObjectTypeMember.check() currently does four things:
1. Compute self.type
2. Accumulate members in all_members
Only one caller cares: QAPISchemaObjectType.check() uses it to compute self.members. The other callers pass a throw-away accumulator.
3. Accumulate a map from names to members in seen
Only one caller cares: QAPISchemaObjectType.check() uses it to compute its local variable seen, for self.variants.check(), which uses it to compute self.variants.tag_member from self.variants.tag_name. The other callers pass a throw-away accumulator.
4. Check for collisions
This piggybacks on 3: before adding a new entry, we assert it's new.
Only one caller cares: QAPISchemaObjectType.check() uses it to assert non-variant members don't clash.
Simplify QAPISchemaObjectType.check(): move 2.-4. to QAPISchemaObjectType.check(), and drop parameters all_members and seen.
Message-Id: <[email protected]> [reorder patch; commit wording touch ups; resolve conflicts because AlternateType.check() already calls tag_member.check() locally rather than in Variants.check()]
---
v9: new patch
--- scripts/qapi.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
scripts/qapi.py +7 -7
@@ -990,7 +990,10 @@ class QAPISchemaObjectType(QAPISchemaType): assert m.name not in seen seen[m.name] = m for m in self.local_members: - m.check(schema, members, seen) + m.check(schema) + assert m.name not in seen + seen[m.name] = m + members.append(m) if self.variants: self.variants.check(schema, members, seen) self.members = members
@@ -1027,12 +1030,9 @@ class QAPISchemaObjectTypeMember(object): self.type = None self.optional = optional - def check(self, schema, all_members, seen): - assert self.name not in seen + def check(self, schema): self.type = schema.lookup_type(self._type_name) assert self.type - all_members.append(self) - seen[self.name] = self class QAPISchemaObjectTypeVariants(object):
@@ -1067,7 +1067,7 @@ class QAPISchemaObjectTypeVariant(QAPISchemaObjectTypeMember): QAPISchemaObjectTypeMember.__init__(self, name, typ, False) def check(self, schema, tag_type, seen): - QAPISchemaObjectTypeMember.check(self, schema, [], {}) + QAPISchemaObjectTypeMember.check(self, schema) assert self.name in tag_type.values # This function exists to support ugly simple union special cases
@@ -1089,7 +1089,7 @@ class QAPISchemaAlternateType(QAPISchemaType): self.variants = variants def check(self, schema): - self.variants.tag_member.check(schema, [], {}) + self.variants.tag_member.check(schema) self.variants.check(schema, [], {}) def json_type(self):
Signature · 1 line
2.4.3
PATCH v9 16/27 qapi: Eliminate QAPISchemaObjectType.check() variable members
In reply to Eric BlakeFrom: Markus Armbruster <[email protected]>
We can use seen.values() instead if we make it an OrderedDict.
Message-Id: <[email protected]>
---
v9: new patch
--- scripts/qapi.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
scripts/qapi.py +6 -10
@@ -977,26 +977,22 @@ class QAPISchemaObjectType(QAPISchemaType): if self.members: return self.members = False # mark as being checked + seen = OrderedDict() if self._base_name: self.base = schema.lookup_type(self._base_name) assert isinstance(self.base, QAPISchemaObjectType) assert not self.base.variants # not implemented self.base.check(schema) - members = list(self.base.members) - else: - members = [] - seen = {} - for m in members: - assert m.name not in seen - seen[m.name] = m + for m in self.base.members: + assert m.name not in seen + seen[m.name] = m for m in self.local_members: m.check(schema) assert m.name not in seen seen[m.name] = m - members.append(m) if self.variants: - self.variants.check(schema, members, seen) - self.members = members + self.variants.check(schema, [], seen) + self.members = seen.values() def is_implicit(self): # See QAPISchema._make_implicit_object_type()
Signature · 1 line
2.4.3
PATCH v9 17/27 qapi: Clean up after previous commit
In reply to Eric BlakeFrom: Markus Armbruster <[email protected]>
QAPISchemaObjectTypeVariants.check() parameter members is no longer used, drop it.
Message-Id: <[email protected]> [Variant.check(seen) is used after all, so reword and reduce scope of this patch; rearrange later in the series]
---
v9: new patch
--- scripts/qapi.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
scripts/qapi.py +3 -3
@@ -991,7 +991,7 @@ class QAPISchemaObjectType(QAPISchemaType): assert m.name not in seen seen[m.name] = m if self.variants: - self.variants.check(schema, [], seen) + self.variants.check(schema, seen) self.members = seen.values() def is_implicit(self):
@@ -1046,7 +1046,7 @@ class QAPISchemaObjectTypeVariants(object): self.tag_member = tag_member self.variants = variants - def check(self, schema, members, seen): + def check(self, schema, seen): # seen is non-empty for unions, empty for alternates if self.tag_name: # flat union self.tag_member = seen[self.tag_name]
@@ -1086,7 +1086,7 @@ class QAPISchemaAlternateType(QAPISchemaType): def check(self, schema): self.variants.tag_member.check(schema) - self.variants.check(schema, [], {}) + self.variants.check(schema, {}) def json_type(self): return 'value'
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v9 17/27] qapi: Clean up after previous commit
Quoted 9 lines · Eric Blake
From: Markus Armbruster <[email protected]>
QAPISchemaObjectTypeVariants.check()parameter members is no longer used, drop it.Signed-off-by Markus Armbruster <[email protected]>Message-Id: <[email protected]> [
Variant.check(seen)is used after all, so reword and reduce scope of this patch; rearrange later in the series]
Don't you need to update the subject? My "previous commit" was "qapi:
Simplify QAPISchemaObjectTypeMember.check()", while yours is "qapi:
Eliminate QAPISchemaObjectType.check() variable members".
Not sure what moving my two patches apart buys you :)
Quoted 39 lines
Signed-off-by Eric Blake <[email protected]>---
v9: new patch--- scripts/qapi.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)scripts/qapi.py +3
-3@@ -991,7 +991,7 @@ class QAPISchemaObjectType(QAPISchemaType): assert m.name not in seen seen[m.name] = m if self.variants: - self.variants.check(schema, [], seen) + self.variants.check(schema, seen) self.members = seen.values() def is_implicit(self):@@ -1046,7 +1046,7 @@ class QAPISchemaObjectTypeVariants(object): self.tag_member = tag_member self.variants = variants - def check(self, schema, members, seen): + def check(self, schema, seen): # seen is non-empty for unions, empty for alternates if self.tag_name: # flat union self.tag_member = seen[self.tag_name]@@ -1086,7 +1086,7 @@ class QAPISchemaAlternateType(QAPISchemaType): def check(self, schema): self.variants.tag_member.check(schema) - self.variants.check(schema, [], {}) + self.variants.check(schema, {}) def json_type(self): return 'value'
Re: [Qemu-devel] [PATCH v9 17/27] qapi: Clean up after previous commit
Quoted 12 lines · Markus Armbruster
Quoted 9 lines · Eric Blake
From: Markus Armbruster <[email protected]>
QAPISchemaObjectTypeVariants.check()parameter members is no longer used, drop it.Signed-off-by Markus Armbruster <[email protected]>Message-Id: <[email protected]> [
Variant.check(seen)is used after all, so reword and reduce scope of this patch; rearrange later in the series]
Quoted 5 lines
Don't you need to update the subject? My "previous commit" was "qapi:
SimplifyQAPISchemaObjectTypeMember.check()", while yours is "qapi:
EliminateQAPISchemaObjectType.check()variable members".Not sure what moving my two patches apart buys you :)
I'm not quite sure either. [Can I blame late-night coding?] For reference, this was your 3/7 patch. I was trying to get to the point of my 'qapi: Check for qapi collisions of flat union branches' (ended up as 19/27) as soon as possible after my tweaks to your 'qapi: Drop obsolete tag value collision assertions' (your 1/7), so that there was less of a gap where avoiding churn on passing vseen(dict) to Variant.check() looked like an unused variable.
In my first attempt, I tried floating my patch right after yours. But I quickly discovered that my patch worked better if I built it on top of your 'qapi: Factor out QAPISchemaObjectTypeMember.check_clash()' (your 6/7), which in turn depended on several of your other patches. So the end result of what I posted happens to be whatever order worked for all my cherry-picking, and I still ended up having to tweak both your 1/7 and 3/7 after all.
For v10, I may just go back to the order that you first supplied patches in (if for no other reason than to make your commit message more accurate about being a cleanup of the previous patch, with the meaning that you had given it).
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH v9 18/27 qapi: Factor out QAPISchemaObjectTypeMember.check_clash()
In reply to Eric BlakeFrom: Markus Armbruster <[email protected]>
While there, stick in a TODO change key of seen from QAPI name to C name. Can't do it right away, because it would fail the assertion for tests/qapi-schema/args-has-clash.json.
Message-Id: <[email protected]>
---
v9: new patch
--- scripts/qapi.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
scripts/qapi.py +7 -4
@@ -984,12 +984,10 @@ class QAPISchemaObjectType(QAPISchemaType): assert not self.base.variants # not implemented self.base.check(schema) for m in self.base.members: - assert m.name not in seen - seen[m.name] = m + m.check_clash(seen) for m in self.local_members: m.check(schema) - assert m.name not in seen - seen[m.name] = m + m.check_clash(seen) if self.variants: self.variants.check(schema, seen) self.members = seen.values()
@@ -1030,6 +1028,11 @@ class QAPISchemaObjectTypeMember(object): self.type = schema.lookup_type(self._type_name) assert self.type + def check_clash(self, seen): + # TODO change key of seen from QAPI name to C name + assert self.name not in seen + seen[self.name] = self + class QAPISchemaObjectTypeVariants(object): def __init__(self, tag_name, tag_member, variants):
Signature · 1 line
2.4.3
PATCH v9 19/27 qapi: Check for qapi collisions of flat union branches
In reply to Eric BlakeRight now, our ad hoc parser ensures that we cannot have a flat union that introduces any qapi member names that would conflict with the non-variant qapi members already present from the union's base type (see flat-union-clash-member.json). We want QAPISchema*.check() to make the same check, so we can later reduce some of the ad hoc checks.
We already ensure that all branches of a flat union are qapi structs with no variants, at which point those members appear in the same JSON object as all non-variant members. And we already have a map 'seen' of all non-variant members passed in to QAPISchemaObjectTypeVariants.check(), which we clone for each particular variant (since the members of one variant do not clash with another). So all that is additionally needed is to actually check the each member of the variant type do not add any collisions.
In general, a type used as a branch of a flat union cannot also be the base type of the flat union, so even though we are adding a call to variant.type.check() in order to populate variant.type.members, this is merely a case of gaining topological sorting of how types are visited (and type.check() is already set up to allow multiple calls due to base types).
For simple unions, the same code happens to work by design, because of our synthesized wrapper classes (however, the wrapper has a single member 'data' which will never collide with the one non-variant member 'type', so it doesn't really matter).
But for alternates, we do NOT want to check the type members for adding collisions (an alternate has no parent JSON object that is merging in member names, the way a flat union does), so we branch on whether seen is empty to distinguish whether we are checking a union or an alternate.
No change to generated code.
---
v9: new patch, split off from v8 7/17
--- scripts/qapi.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
scripts/qapi.py +11 -2
@@ -1057,8 +1057,9 @@ class QAPISchemaObjectTypeVariants(object): assert self.tag_member in seen.itervalues() assert isinstance(self.tag_member.type, QAPISchemaEnumType) for v in self.variants: - vseen = dict(seen) - v.check(schema, self.tag_member.type, vseen) + # Reset seen array for each variant, since qapi names from one + # branch do not affect another branch + v.check(schema, self.tag_member.type, dict(seen)) class QAPISchemaObjectTypeVariant(QAPISchemaObjectTypeMember):
@@ -1068,6 +1069,14 @@ class QAPISchemaObjectTypeVariant(QAPISchemaObjectTypeMember): def check(self, schema, tag_type, seen): QAPISchemaObjectTypeMember.check(self, schema) assert self.name in tag_type.values + if seen: + # This variant is used within a union; ensure each qapi member + # field does not collide with the union's non-variant members. + assert isinstance(self.type, QAPISchemaObjectType) + assert not self.type.variants # not implemented + self.type.check(schema) + for m in self.type.members: + m.check_clash(seen) # This function exists to support ugly simple union special cases # TODO get rid of them, and drop the function
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v9 19/27] qapi: Check for qapi collisions of flat union branches
Quoted 67 lines · Eric Blake
Right now, our ad hoc parser ensures that we cannot have a flat union that introduces any qapi member names that would conflict with the non-variant qapi members already present from the union's base type (see flat-union-clash-member.json). We want QAPISchema*.check() to make the same check, so we can later reduce some of the ad hoc checks.
We already ensure that all branches of a flat union are qapi structs with no variants, at which point those members appear in the same JSON object as all non-variant members. And we already have a map 'seen' of all non-variant members passed in to
QAPISchemaObjectTypeVariants.check(), which we clone for each particular variant (since the members of one variant do not clash with another). So all that is additionally needed is to actually check the each member of the variant type do not add any collisions.In general, a type used as a branch of a flat union cannot also be the base type of the flat union, so even though we are adding a call to
variant.type.check()in order to populate variant.type.members, this is merely a case of gaining topological sorting of how types are visited (andtype.check()is already set up to allow multiple calls due to base types).For simple unions, the same code happens to work by design, because of our synthesized wrapper classes (however, the wrapper has a single member 'data' which will never collide with the one non-variant member 'type', so it doesn't really matter).
But for alternates, we do NOT want to check the type members for adding collisions (an alternate has no parent JSON object that is merging in member names, the way a flat union does), so we branch on whether seen is empty to distinguish whether we are checking a union or an alternate.
No change to generated code.
Signed-off-by Eric Blake <[email protected]>---
v9: new patch, split off from v8 7/17--- scripts/qapi.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)scripts/qapi.py +4
-2@@ -1057,8 +1057,9 @@ class QAPISchemaObjectTypeVariants(object): assert self.tag_member in seen.itervalues() assert isinstance(self.tag_member.type, QAPISchemaEnumType) for v in self.variants: - vseen = dict(seen) - v.check(schema, self.tag_member.type, vseen) + # Reset seen array for each variant, since qapi names from one + # branch do not affect another branch + v.check(schema, self.tag_member.type, dict(seen)) class QAPISchemaObjectTypeVariant(QAPISchemaObjectTypeMember):@@ -1068,6 +1069,14 @@ class QAPISchemaObjectTypeVariant(QAPISchemaObjectTypeMember): def check(self, schema, tag_type, seen): QAPISchemaObjectTypeMember.check(self, schema) assert self.name in tag_type.values + if seen:
scripts/qapi.py class QAPISchemaObjectTypeVariant(QAPISchemaObjectTypeMember): · line 1082
Quoted 10 lines
scripts/qapi.py +7
-0+ # This variant is used within a union; ensure each qapi member + # field does not collide with the union's non-variant members. + assert isinstance(self.type, QAPISchemaObjectType) + assert not self.type.variants # not implemented + self.type.check(schema) + for m in self.type.members: + m.check_clash(seen) # This function exists to support ugly simple union special cases # TODO get rid of them, and drop the function
Two call chains:
* QAPISchemaObjectType.check() via QAPISchemaObjectTypeVariants.check()
In this case, the new conditional executes.
* QAPISchemaAlternateType.check() via same
In this case, it doesn't.
Why can't we simply add the new code to QAPISchemaObjectType.check()? The rest of the clash checking is already there...
Re: [Qemu-devel] [PATCH v9 19/27] qapi: Check for qapi collisions of flat union branches
Quoted 30 lines · Markus Armbruster
Quoted 13 lines · Eric Blake
Right now, our ad hoc parser ensures that we cannot have a flat union that introduces any qapi member names that would conflict with the non-variant qapi members already present from the union's base type (see flat-union-clash-member.json). We want QAPISchema*.check() to make the same check, so we can later reduce some of the ad hoc checks.
scripts/qapi.py +1
-0@@ -1068,6 +1069,14 @@ class QAPISchemaObjectTypeVariant(QAPISchemaObjectTypeMember): def check(self, schema, tag_type, seen): QAPISchemaObjectTypeMember.check(self, schema) assert self.name in tag_type.values + if seen:scripts/qapi.py class QAPISchemaObjectTypeVariant(QAPISchemaObjectTypeMember): · line 1082
Quoted 10 lines
scripts/qapi.py +7
-0+ # This variant is used within a union; ensure each qapi member + # field does not collide with the union's non-variant members. + assert isinstance(self.type, QAPISchemaObjectType) + assert not self.type.variants # not implemented + self.type.check(schema) + for m in self.type.members: + m.check_clash(seen) # This function exists to support ugly simple union special cases # TODO get rid of them, and drop the functionTwo call chains:
*
QAPISchemaObjectType.check()viaQAPISchemaObjectTypeVariants.check()
Quoted 7 lines
In this case, the new conditional executes.
*
QAPISchemaAlternateType.check()via sameIn this case, it doesn't.
Why can't we simply add the new code to
QAPISchemaObjectType.check()?
We could, but we'd need a nested for-loop:
for v in variants.variants:
v.type.check(schema)
assert not v.type.variants
vseen = dict(seen)
for m in v.type.members:
m.check_clash(seen)
Quoted 1 line
The rest of the clash checking is already there...
You do have a point there. I guess it wouldn't be the end of the world to have the loop nesting be explicit rather than indirect through the intermediate Variants.check().
I'll play with it; and depending on what I do, that may mean I don't have to munge your other patches quite so heavily.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v9 19/27] qapi: Check for qapi collisions of flat union branches
Quoted 23 lines · Eric Blake
Quoted 11 lines · Markus Armbruster
Quoted 7 lines · Eric Blake
Right now, our ad hoc parser ensures that we cannot have a flat union that introduces any qapi member names that would conflict with the non-variant qapi members already present from the union's base type (see flat-union-clash-member.json). We want QAPISchema*.check() to make the same check, so we can later reduce some of the ad hoc checks.
Quoted 1 line
Why can't we simply add the new code to
QAPISchemaObjectType.check()?We could, but we'd need a nested for-loop:
for v in variants.variants:
v.type.check(schema)
assert not v.type.variants
vseen = dict(seen)
for m in v.type.members:
m.check_clash(seen)
Quoted 8 lines
Quoted 1 line
The rest of the clash checking is already there...
You do have a point there. I guess it wouldn't be the end of the world to have the loop nesting be explicit rather than indirect through the intermediate
Variants.check().I'll play with it; and depending on what I do, that may mean I don't have to munge your other patches quite so heavily.
And of course, as soon as I hit send, I had another thought - your patches already added Member.check_clash() called separately from the .check() chain; maybe I am better off adding a Variants.check_clash() separate from the .check() chain, rather than trying to cram the whole nested loop directly in ObjectType.check().
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v9 19/27] qapi: Check for qapi collisions of flat union branches
Quoted 15 lines · Eric Blake
Quoted 14 lines · Eric Blake
Quoted 12 lines · Markus Armbruster
Quoted 7 lines · Eric Blake
Right now, our ad hoc parser ensures that we cannot have a flat union that introduces any qapi member names that would conflict with the non-variant qapi members already present from the union's base type (see flat-union-clash-member.json). We want QAPISchema*.check() to make the same check, so we can later reduce some of the ad hoc checks.
Why can't we simply add the new code to
QAPISchemaObjectType.check()?
Quoted 8 lines
Quoted 8 lines
We could, but we'd need a nested for-loop:
for v in variants.variants:
v.type.check(schema)
assert not v.type.variants
vseen = dict(seen)
for m in v.type.members:
m.check_clash(seen)
Looks clear enough to me.
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
The rest of the clash checking is already there...
You do have a point there. I guess it wouldn't be the end of the world to have the loop nesting be explicit rather than indirect through the intermediate
Variants.check().
Hiding loop nesting behind method calls doesn't make code simpler :)
Methods help when they're useful abstractions. For instance, hiding the details of checking a member m behind m.check() is good. But here, we're checking relations between members.
Quoted 8 lines
Quoted 2 lines
I'll play with it; and depending on what I do, that may mean I don't have to munge your other patches quite so heavily.
And of course, as soon as I hit send, I had another thought - your patches already added
Member.check_clash()called separately from the .check() chain; maybe I am better off adding aVariants.check_clash()separate from the .check() chain, rather than trying to cram the whole nested loop directly inObjectType.check().
Matter of taste, can't tell without trying, use your judgement.
PATCH v9 20/27 qapi: Simplify QAPISchemaObjectTypeVariants.check()
In reply to Eric BlakeFrom: Markus Armbruster <[email protected]>
Avoid the 'if seen' conditional by doing just the essential work here, namely setting self.tag_member for flat unions. Move the rest to callers.
Message-Id: <[email protected]>
---
v9: new patch
--- scripts/qapi.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
scripts/qapi.py +2 -3
@@ -988,9 +988,10 @@ class QAPISchemaObjectType(QAPISchemaType): for m in self.local_members: m.check(schema) m.check_clash(seen) + self.members = seen.values() if self.variants: self.variants.check(schema, seen) - self.members = seen.values() + assert self.variants.tag_member in self.members def is_implicit(self): # See QAPISchema._make_implicit_object_type()
@@ -1053,8 +1054,6 @@ class QAPISchemaObjectTypeVariants(object): # seen is non-empty for unions, empty for alternates if self.tag_name: # flat union self.tag_member = seen[self.tag_name] - if seen: - assert self.tag_member in seen.itervalues() assert isinstance(self.tag_member.type, QAPISchemaEnumType) for v in self.variants: # Reset seen array for each variant, since qapi names from one
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v9 20/27] qapi: Simplify QAPISchemaObjectTypeVariants.check()
Quoted 34 lines · Eric Blake
From: Markus Armbruster <[email protected]>
Avoid the 'if seen' conditional by doing just the essential work here, namely setting self.tag_member for flat unions. Move the rest to callers.
Signed-off-by Markus Armbruster <[email protected]>Message-Id: <[email protected]>
[reword commit, rebase to earlier AlternateType.check() changes]Signed-off-by Eric Blake <[email protected]>---
v9: new patch--- scripts/qapi.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)scripts/qapi.py +2
-1@@ -988,9 +988,10 @@ class QAPISchemaObjectType(QAPISchemaType): for m in self.local_members: m.check(schema) m.check_clash(seen) + self.members = seen.values() if self.variants: self.variants.check(schema, seen) - self.members = seen.values() + assert self.variants.tag_member in self.members def is_implicit(self): # See QAPISchema._make_implicit_object_type()
scripts/qapi.py class QAPISchemaObjectTypeVariants(object): · line 1054
Quoted 1 line
scripts/qapi.py +0
-0@@ -1053,8 +1054,6 @@ class QAPISchemaObjectTypeVariants(object): # seen is non-empty for unions, empty for alternates
You added this comment in PATCH 10 to explain the conditional I'm dropping here. Let's drop the comment, too.
Quoted 7 lines
scripts/qapi.py +0
-2if self.tag_name: # flat union self.tag_member = seen[self.tag_name] - if seen: - assert self.tag_member in seen.itervalues() assert isinstance(self.tag_member.type, QAPISchemaEnumType) for v in self.variants: # Reset seen array for each variant, since qapi names from one
Re: [Qemu-devel] [PATCH v9 20/27] qapi: Simplify QAPISchemaObjectTypeVariants.check()
Quoted 33 lines · Markus Armbruster
Quoted 31 lines · Eric Blake
From: Markus Armbruster <[email protected]>
Avoid the 'if seen' conditional by doing just the essential work here, namely setting self.tag_member for flat unions. Move the rest to callers.
Signed-off-by Markus Armbruster <[email protected]>Message-Id: <[email protected]>
[reword commit, rebase to earlier AlternateType.check() changes]Signed-off-by Eric Blake <[email protected]>---
v9: new patch--- scripts/qapi.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)scripts/qapi.py +2
-1@@ -988,9 +988,10 @@ class QAPISchemaObjectType(QAPISchemaType): for m in self.local_members: m.check(schema) m.check_clash(seen) + self.members = seen.values() if self.variants: self.variants.check(schema, seen) - self.members = seen.values() + assert self.variants.tag_member in self.members
Quoted 7 lines
scripts/qapi.py class QAPISchemaObjectTypeVariants(object): · line 1054
Quoted 4 lines
scripts/qapi.py +0
-0def is_implicit(self): # See QAPISchema._make_implicit_object_type()@@ -1053,8 +1054,6 @@ class QAPISchemaObjectTypeVariants(object): # seen is non-empty for unions, empty for alternatesYou added this comment in PATCH 10 to explain the conditional I'm dropping here. Let's drop the comment, too.
Except the comment becomes relevant again in 23/27. Or maybe I just move the comment to that point.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH v9 21/27 qapi: Factor out QAPISchemaObjectType.check_clash()
In reply to Eric BlakeConsolidate two common sequences of clash detection into a new QAPISchemaObjectType.check_clash() helper method.
No change to generated code.
---
v9: new patch, split off from v8 7/17
--- scripts/qapi.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)
scripts/qapi.py +8 -10
@@ -980,11 +980,7 @@ class QAPISchemaObjectType(QAPISchemaType): seen = OrderedDict() if self._base_name: self.base = schema.lookup_type(self._base_name) - assert isinstance(self.base, QAPISchemaObjectType) - assert not self.base.variants # not implemented - self.base.check(schema) - for m in self.base.members: - m.check_clash(seen) + self.base.check_clash(schema, seen) for m in self.local_members: m.check(schema) m.check_clash(seen)
@@ -993,6 +989,12 @@ class QAPISchemaObjectType(QAPISchemaType): self.variants.check(schema, seen) assert self.variants.tag_member in self.members + def check_clash(self, schema, seen): + self.check(schema) + assert not self.variants # not implemented + for m in self.members: + m.check_clash(seen) + def is_implicit(self): # See QAPISchema._make_implicit_object_type() return self.name[0] == ':'
@@ -1071,11 +1073,7 @@ class QAPISchemaObjectTypeVariant(QAPISchemaObjectTypeMember): if seen: # This variant is used within a union; ensure each qapi member # field does not collide with the union's non-variant members. - assert isinstance(self.type, QAPISchemaObjectType) - assert not self.type.variants # not implemented - self.type.check(schema) - for m in self.type.members: - m.check_clash(seen) + self.type.check_clash(schema, seen) # This function exists to support ugly simple union special cases # TODO get rid of them, and drop the function
Signature · 1 line
2.4.3
cover qapi: Use common name mangling for enumeration constants
I really like the simplification. The (one-time) churn is annoying. Worthwhile?
See PATCH 3 for details.
Markus Armbruster (5):
qapi: Generate a sed script to help eliminate camel_to_upper() Revert "qapi: Generate a sed script to help eliminate
camel_to_upper()"
qapi: Use common name mangling for enumeration constants
crypto: Drop name mangling override
Revert "qapi: allow override of default enum prefix naming"
backends/baum.c | 2 +- backends/hostmem.c | 10 +- backends/msmouse.c | 2 +- backends/rng-egd.c | 2 +- backends/testdev.c | 2 +- balloon.c | 4 +- block.c | 18 +- block/backup.c | 20 +- block/block-backend.c | 38 +-- block/commit.c | 12 +- block/io.c | 4 +- block/mirror.c | 22 +- block/nbd.c | 6 +- block/qcow2.c | 10 +- block/quorum.c | 10 +- block/raw-posix.c | 8 +- block/stream.c | 10 +- block/vmdk.c | 2 +- blockdev-nbd.c | 2 +- blockdev.c | 134 ++++----- blockjob.c | 30 +- crypto/tlscredsanon.c | 6 +- crypto/tlscredsx509.c | 6 +- crypto/tlssession.c | 6 +- docs/qapi-code-gen.txt | 18 +- docs/writing-qmp-commands.txt | 8 +- dump.c | 28 +- gdbstub.c | 26 +- hmp.c | 80 +++--- hw/acpi/memory_hotplug.c | 2 +- hw/arm/musicpal.c | 2 +- hw/block/block.c | 2 +- hw/block/fdc.c | 4 +- hw/block/hd-geometry.c | 12 +- hw/block/virtio-blk.c | 8 +- hw/char/escc.c | 246 ++++++++-------- hw/core/qdev-properties-system.c | 2 +- hw/display/qxl.c | 4 +- hw/i386/kvm/i8254.c | 6 +- hw/i386/pc.c | 10 +- hw/i386/pc_piix.c | 10 +- hw/i386/pc_q35.c | 10 +- hw/ide/ahci.c | 4 +- hw/ide/core.c | 6 +- hw/ide/qdev.c | 2 +- hw/input/hid.c | 26 +- hw/input/ps2.c | 20 +- hw/input/virtio-input-hid.c | 242 ++++++++-------- hw/mem/pc-dimm.c | 2 +- hw/net/allwinner_emac.c | 2 +- hw/net/cadence_gem.c | 2 +- hw/net/dp8393x.c | 2 +- hw/net/e1000.c | 2 +- hw/net/eepro100.c | 2 +- hw/net/etraxfs_eth.c | 2 +- hw/net/fsl_etsec/etsec.c | 2 +- hw/net/imx_fec.c | 2 +- hw/net/lan9118.c | 2 +- hw/net/lance.c | 2 +- hw/net/mcf_fec.c | 2 +- hw/net/milkymist-minimac2.c | 2 +- hw/net/mipsnet.c | 2 +- hw/net/ne2000-isa.c | 2 +- hw/net/ne2000.c | 2 +- hw/net/opencores_eth.c | 2 +- hw/net/pcnet-pci.c | 2 +- hw/net/rocker/rocker.c | 4 +- hw/net/rocker/rocker_fp.c | 2 +- hw/net/rocker/rocker_of_dpa.c | 8 +- hw/net/rtl8139.c | 2 +- hw/net/smc91c111.c | 2 +- hw/net/spapr_llan.c | 2 +- hw/net/stellaris_enet.c | 2 +- hw/net/vhost_net.c | 18 +- hw/net/virtio-net.c | 28 +- hw/net/vmxnet3.c | 2 +- hw/net/xen_nic.c | 2 +- hw/net/xgmac.c | 2 +- hw/net/xilinx_axienet.c | 2 +- hw/net/xilinx_ethlite.c | 2 +- hw/ppc/spapr_rtas.c | 2 +- hw/scsi/scsi-disk.c | 6 +- hw/scsi/scsi-generic.c | 4 +- hw/timer/mc146818rtc.c | 14 +- hw/tpm/tpm_passthrough.c | 2 +- hw/tpm/tpm_tis.c | 4 +- hw/usb/dev-network.c | 2 +- hw/usb/hcd-ehci.c | 4 +- hw/usb/redirect.c | 8 +- hw/vfio/pci.c | 2 +- hw/watchdog/watchdog.c | 16 +- include/block/block_int.h | 2 +- include/crypto/tlssession.h | 2 +- include/migration/migration.h | 4 +- include/qapi/error.h | 6 +- include/ui/input.h | 8 +- include/ui/qemu-spice.h | 2 +- kvm-all.c | 2 +- migration/migration.c | 170 +++++------ migration/ram.c | 4 +- migration/rdma.c | 2 +- migration/savevm.c | 4 +- monitor.c | 62 ++-- net/dump.c | 4 +- net/filter.c | 10 +- net/hub.c | 20 +- net/l2tpv3.c | 4 +- net/net.c | 78 ++--- net/netmap.c | 2 +- net/slirp.c | 4 +- net/socket.c | 6 +- net/tap-win32.c | 4 +- net/tap.c | 20 +- net/vde.c | 4 +- net/vhost-user.c | 16 +- numa.c | 4 +- qapi/crypto.json | 1 - qapi/qmp-dispatch.c | 2 +- qdev-monitor.c | 4 +- qemu-char.c | 54 ++-- qemu-img.c | 2 +- qemu-nbd.c | 12 +- qga/commands-posix.c | 34 +-- qga/commands-win32.c | 44 +-- qmp.c | 16 +- qom/object.c | 6 +- scripts/qapi-introspect.py | 2 +- scripts/qapi-types.py | 6 +- scripts/qapi-visit.py | 2 +- scripts/qapi.py | 85 ++---- spice-qemu-char.c | 4 +- stubs/runstate-check.c | 2 +- target-i386/cpu.c | 2 +- target-lm32/op_helper.c | 2 +- tests/Makefile | 1 - tests/qapi-schema/enum-bad-prefix.err | 1 - tests/qapi-schema/enum-bad-prefix.exit | 1 - tests/qapi-schema/enum-bad-prefix.json | 2 - tests/qapi-schema/enum-bad-prefix.out | 0 tests/qapi-schema/enum-clash-member.err | 2 +- tests/qapi-schema/enum-clash-member.json | 2 +- tests/qapi-schema/enum-max-member.err | 2 +- tests/qapi-schema/enum-max-member.json | 4 +- tests/qapi-schema/qapi-schema-test.json | 5 - tests/qapi-schema/qapi-schema-test.out | 2 - tests/qapi-schema/test-qapi.py | 4 +- tests/qapi-schema/union-bad-branch.err | 2 +- tests/qapi-schema/union-bad-branch.json | 4 +- tests/qapi-schema/union-max.err | 2 +- tests/qapi-schema/union-max.json | 2 +- tests/test-crypto-tlscredsx509.c | 6 +- tests/test-crypto-tlssession.c | 12 +- tests/test-qmp-commands.c | 2 +- tests/test-qmp-event.c | 6 +- tests/test-qmp-input-visitor.c | 66 ++--- tests/test-qmp-output-visitor.c | 84 +++--- tests/test-string-output-visitor.c | 4 +- tpm.c | 14 +- trace/qmp.c | 6 +- ui/cocoa.m | 20 +- ui/console.c | 22 +- ui/gtk.c | 20 +- ui/input-keymap.c | 274 +++++++++--------- ui/input-legacy.c | 38 +-- ui/input.c | 56 ++-- ui/sdl.c | 22 +- ui/sdl2-keymap.h | 480 +++++++++++++++---------------- ui/sdl2.c | 20 +- ui/spice-core.c | 4 +- ui/spice-input.c | 20 +- ui/vnc-auth-vencrypt.c | 2 +- ui/vnc-ws.c | 2 +- ui/vnc.c | 84 +++--- util/error.c | 6 +- util/qemu-config.c | 8 +- util/qemu-sockets.c | 32 +-- vl.c | 166 +++++------ xen-hvm.c | 4 +- 178 files changed, 1746 insertions(+), 1816 deletions(-) delete mode 100644 tests/qapi-schema/enum-bad-prefix.err delete mode 100644 tests/qapi-schema/enum-bad-prefix.exit delete mode 100644 tests/qapi-schema/enum-bad-prefix.json delete mode 100644 tests/qapi-schema/enum-bad-prefix.out
Signature · 1 line
2.4.3
RFC PATCH 1/5 qapi: Generate a sed script to help eliminate camel_to_upper()
Temporary patch, will be reverted right away.
Out of laziness, generate it right into the C code, in comments.
To generate the sed script, use
$ make
$ make check
$ enum_gen_files='qapi-event.c qapi-types.c qga/qapi-generated/qga-qapi-types.c tests/test-qapi-event.c tests/test-qapi-types.c'
$ sed -n 's,// @@@ ,,p' $enum_gen_files >enum-mangle.sedTo find the files to patch, use
$ enum_mangle_regexp=`sed -n 's,// ### ,,p' $enum_gen_files | tr '\n' '|' | sed 's/|$//'`
$ git-grep -El "$enum_mangle_regexp" $srcdir >enum-mangle-fileswhere $srcdir is the root of your source tree.
To patch them, use
$ xargs sed -ri --file enum-mangle.sed <enum-mangle-files
--- scripts/qapi.py | 6 ++++++ 1 file changed, 6 insertions(+)
scripts/qapi.py +6 -0
@@ -1517,20 +1517,26 @@ def gen_enum_lookup(name, values, prefix=None): ret = mcgen(''' const char *const %(c_name)s_lookup[] = { +// ### %(prefix)s ''', + prefix=camel_to_upper(prefix or name), c_name=c_name(name)) for value in values: index = c_enum_const(name, value, prefix) ret += mcgen(''' [%(index)s] = "%(value)s", +// @@@ s/(^|[^A-Za-z0-9_])%(index)s($|[^A-Za-z0-9_])/\\1%(new)s\\2/g ''', + new=c_name((prefix or name) + '_' + value), index=index, value=value) max_index = c_enum_const(name, 'MAX', prefix) ret += mcgen(''' [%(max_index)s] = NULL, +// @@@ s/(^|[^A-Za-z0-9_])%(max_index)s($|[^A-Za-z0-9_])/\\1%(new)s\\2/g }; ''', + new=c_name((prefix or name) + '_' + 'MAX'), max_index=max_index) return ret
Signature · 1 line
2.4.3
RFC PATCH 2/5 Revert "qapi: Generate a sed script to help eliminate camel_to_upper()"
In reply to Markus ArmbrusterThis reverts commit a1827a5b53f9749a8b062a1927e11daab6df98ce.
--- scripts/qapi.py | 6 ------ 1 file changed, 6 deletions(-)
scripts/qapi.py +0 -6
@@ -1517,26 +1517,20 @@ def gen_enum_lookup(name, values, prefix=None): ret = mcgen(''' const char *const %(c_name)s_lookup[] = { -// ### %(prefix)s ''', - prefix=camel_to_upper(prefix or name), c_name=c_name(name)) for value in values: index = c_enum_const(name, value, prefix) ret += mcgen(''' [%(index)s] = "%(value)s", -// @@@ s/(^|[^A-Za-z0-9_])%(index)s($|[^A-Za-z0-9_])/\\1%(new)s\\2/g ''', - new=c_name((prefix or name) + '_' + value), index=index, value=value) max_index = c_enum_const(name, 'MAX', prefix) ret += mcgen(''' [%(max_index)s] = NULL, -// @@@ s/(^|[^A-Za-z0-9_])%(max_index)s($|[^A-Za-z0-9_])/\\1%(new)s\\2/g }; ''', - new=c_name((prefix or name) + '_' + 'MAX'), max_index=max_index) return ret
Signature · 1 line
2.4.3
RFC PATCH 3/5 qapi: Use common name mangling for enumeration constants
In reply to Markus ArmbrusterQAPI names needn't be valid C identifiers, so we mangle them with c_name(). Except for enumeration constants, which we mangle with camel_to_upper().
c_name() is easy enough to understand: replace '.' and '-' by '_', prefix certain ticklish identifiers with 'q_'.
camel_to_upper() is a hairball of heuristics, and guessing how it'll mangle interesting input could serve as a (nerdy) game. Despite some tweaking (commit 5d371f4), it's still inadqeuate for some QAPI names (commit 351d36e).
Example: QAPI definition
{ 'enum': 'BlockDeviceIoStatus', 'data': [ 'ok', 'failed', 'nospace' ] }generates
typedef enum BlockDeviceIoStatus {
BLOCK_DEVICE_IO_STATUS_OK = 0,
BLOCK_DEVICE_IO_STATUS_FAILED = 1,
BLOCK_DEVICE_IO_STATUS_NOSPACE = 2,
BLOCK_DEVICE_IO_STATUS_MAX = 3,
} BlockDeviceIoStatus;
Observe that c_name() maps BlockDeviceIoStatus to itself, and camel_to_upper() maps it to BLOCK_DEVICE_IO_STATUS, i.e. the enumeration constants are shouted, the enumeration type isn't.
Because mangled names must not clash, name mangling restricts the names you can use. For example, you can't have member 'a-b' and 'a_b'.
Having two separate manglings complicates this. Enumeration constants must be distinct after mangling with camel_to_upper(). But as soon as you use the enumeration as union tag, they must *also* be distinct after mangling with c_name().
Having shouted enumeration constants isn't worth the complexity cost. Mangle them with c_name() instead, and drop camel_to_upper() along with its helper camel_case(). The example above becomes
typedef enum BlockDeviceIoStatus {
BlockDeviceIoStatus_ok = 0,
BlockDeviceIoStatus_failed = 1,
BlockDeviceIoStatus_nospace = 2,
BlockDeviceIoStatus_MAX = 3,
} BlockDeviceIoStatus;
Use the sed script generated with the help of the commit just reverted to update the code using QAPI-generated enumeration constants.
The sed script misses an occurence in target-i386/cpu.c, because we construct enumeration constants with the ## operator there. Updated manually.
The sed script misses commented out occurences in ui/sdl2-keymap.h that show possible future extensions, i.e. enumeration constants that aren't defined, yet. Update them like this:
$ sed -r -i 's/Q_KEY_CODE(_[A-Za-z0-9_]*)/QKeyCode\L\1/' ui/sdl2-keymap.h
The changed mangling affects a few tests. Fix them up.
Examples in docs/qapi-code-gen.txt updated manually. The paragraph explaining enumeration type name mangling is now obsolete. I'll fix it shortly, mark it FIXME until then.
"git-grep -E $enum_mangle_regexp" with enum_mangle_regexp from the commit just reverted shows possible missed occurences. Most of them are QCRYPTO_TLS_CREDS_ENDPOINT, which is not to be replaced now, because it uses the name mangling override from commit 351d36e. The rest are all false positives.
--- backends/baum.c | 2 +- backends/hostmem.c | 10 +- backends/msmouse.c | 2 +- backends/rng-egd.c | 2 +- backends/testdev.c | 2 +- balloon.c | 4 +- block.c | 18 +- block/backup.c | 20 +- block/block-backend.c | 38 +-- block/commit.c | 12 +- block/io.c | 4 +- block/mirror.c | 22 +- block/nbd.c | 6 +- block/qcow2.c | 10 +- block/quorum.c | 10 +- block/raw-posix.c | 8 +- block/stream.c | 10 +- block/vmdk.c | 2 +- blockdev-nbd.c | 2 +- blockdev.c | 134 ++++----- blockjob.c | 30 +- crypto/tlscredsanon.c | 6 +- crypto/tlscredsx509.c | 6 +- crypto/tlssession.c | 6 +- docs/qapi-code-gen.txt | 11 +- docs/writing-qmp-commands.txt | 8 +- dump.c | 28 +- gdbstub.c | 26 +- hmp.c | 80 +++--- hw/acpi/memory_hotplug.c | 2 +- hw/arm/musicpal.c | 2 +- hw/block/block.c | 2 +- hw/block/fdc.c | 4 +- hw/block/hd-geometry.c | 12 +- hw/block/virtio-blk.c | 8 +- hw/char/escc.c | 246 ++++++++-------- hw/core/qdev-properties-system.c | 2 +- hw/display/qxl.c | 4 +- hw/i386/kvm/i8254.c | 6 +- hw/i386/pc.c | 10 +- hw/i386/pc_piix.c | 10 +- hw/i386/pc_q35.c | 10 +- hw/ide/ahci.c | 4 +- hw/ide/core.c | 6 +- hw/ide/qdev.c | 2 +- hw/input/hid.c | 26 +- hw/input/ps2.c | 20 +- hw/input/virtio-input-hid.c | 242 ++++++++-------- hw/mem/pc-dimm.c | 2 +- hw/net/allwinner_emac.c | 2 +- hw/net/cadence_gem.c | 2 +- hw/net/dp8393x.c | 2 +- hw/net/e1000.c | 2 +- hw/net/eepro100.c | 2 +- hw/net/etraxfs_eth.c | 2 +- hw/net/fsl_etsec/etsec.c | 2 +- hw/net/imx_fec.c | 2 +- hw/net/lan9118.c | 2 +- hw/net/lance.c | 2 +- hw/net/mcf_fec.c | 2 +- hw/net/milkymist-minimac2.c | 2 +- hw/net/mipsnet.c | 2 +- hw/net/ne2000-isa.c | 2 +- hw/net/ne2000.c | 2 +- hw/net/opencores_eth.c | 2 +- hw/net/pcnet-pci.c | 2 +- hw/net/rocker/rocker.c | 4 +- hw/net/rocker/rocker_fp.c | 2 +- hw/net/rocker/rocker_of_dpa.c | 8 +- hw/net/rtl8139.c | 2 +- hw/net/smc91c111.c | 2 +- hw/net/spapr_llan.c | 2 +- hw/net/stellaris_enet.c | 2 +- hw/net/vhost_net.c | 18 +- hw/net/virtio-net.c | 28 +- hw/net/vmxnet3.c | 2 +- hw/net/xen_nic.c | 2 +- hw/net/xgmac.c | 2 +- hw/net/xilinx_axienet.c | 2 +- hw/net/xilinx_ethlite.c | 2 +- hw/ppc/spapr_rtas.c | 2 +- hw/scsi/scsi-disk.c | 6 +- hw/scsi/scsi-generic.c | 4 +- hw/timer/mc146818rtc.c | 14 +- hw/tpm/tpm_passthrough.c | 2 +- hw/tpm/tpm_tis.c | 4 +- hw/usb/dev-network.c | 2 +- hw/usb/hcd-ehci.c | 4 +- hw/usb/redirect.c | 8 +- hw/vfio/pci.c | 2 +- hw/watchdog/watchdog.c | 16 +- include/block/block_int.h | 2 +- include/crypto/tlssession.h | 2 +- include/migration/migration.h | 4 +- include/qapi/error.h | 6 +- include/ui/input.h | 8 +- include/ui/qemu-spice.h | 2 +- kvm-all.c | 2 +- migration/migration.c | 170 +++++------ migration/ram.c | 4 +- migration/rdma.c | 2 +- migration/savevm.c | 4 +- monitor.c | 62 ++-- net/dump.c | 4 +- net/filter.c | 10 +- net/hub.c | 20 +- net/l2tpv3.c | 4 +- net/net.c | 78 ++--- net/netmap.c | 2 +- net/slirp.c | 4 +- net/socket.c | 6 +- net/tap-win32.c | 4 +- net/tap.c | 20 +- net/vde.c | 4 +- net/vhost-user.c | 16 +- numa.c | 4 +- qapi/qmp-dispatch.c | 2 +- qdev-monitor.c | 4 +- qemu-char.c | 54 ++-- qemu-img.c | 2 +- qemu-nbd.c | 12 +- qga/commands-posix.c | 34 +-- qga/commands-win32.c | 44 +-- qmp.c | 16 +- qom/object.c | 6 +- scripts/qapi.py | 48 +--- spice-qemu-char.c | 4 +- stubs/runstate-check.c | 2 +- target-i386/cpu.c | 2 +- target-lm32/op_helper.c | 2 +- tests/qapi-schema/enum-clash-member.err | 2 +- tests/qapi-schema/enum-clash-member.json | 2 +- tests/qapi-schema/enum-max-member.err | 2 +- tests/qapi-schema/enum-max-member.json | 4 +- tests/qapi-schema/union-bad-branch.err | 2 +- tests/qapi-schema/union-bad-branch.json | 4 +- tests/qapi-schema/union-max.err | 2 +- tests/qapi-schema/union-max.json | 2 +- tests/test-crypto-tlscredsx509.c | 6 +- tests/test-crypto-tlssession.c | 12 +- tests/test-qmp-commands.c | 2 +- tests/test-qmp-event.c | 6 +- tests/test-qmp-input-visitor.c | 66 ++--- tests/test-qmp-output-visitor.c | 84 +++--- tests/test-string-output-visitor.c | 4 +- tpm.c | 14 +- trace/qmp.c | 6 +- ui/cocoa.m | 20 +- ui/console.c | 22 +- ui/gtk.c | 20 +- ui/input-keymap.c | 274 +++++++++--------- ui/input-legacy.c | 38 +-- ui/input.c | 56 ++-- ui/sdl.c | 22 +- ui/sdl2-keymap.h | 480 +++++++++++++++---------------- ui/sdl2.c | 20 +- ui/spice-core.c | 4 +- ui/spice-input.c | 20 +- ui/vnc-auth-vencrypt.c | 2 +- ui/vnc-ws.c | 2 +- ui/vnc.c | 84 +++--- util/error.c | 6 +- util/qemu-config.c | 8 +- util/qemu-sockets.c | 32 +-- vl.c | 166 +++++------ xen-hvm.c | 4 +- 166 files changed, 1728 insertions(+), 1763 deletions(-)
backends/baum.c +1 -1
@@ -635,7 +635,7 @@ fail_handle:static void register_types (void ) { -register_char_driver ("braille" ,CHARDEV_BACKEND_KIND_BRAILLE ,NULL , +register_char_driver ("braille" , ChardevBackendKind_braille,NULL , chr_baum_init); }
backends/hostmem.c +5 -5
@@ -19,10 +19,10 @@#ifdef CONFIG_NUMA #include <numaif.h> -QEMU_BUILD_BUG_ON (HOST_MEM_POLICY_DEFAULT !=MPOL_DEFAULT ); -QEMU_BUILD_BUG_ON (HOST_MEM_POLICY_PREFERRED !=MPOL_PREFERRED ); -QEMU_BUILD_BUG_ON (HOST_MEM_POLICY_BIND !=MPOL_BIND ); -QEMU_BUILD_BUG_ON (HOST_MEM_POLICY_INTERLEAVE !=MPOL_INTERLEAVE ); +QEMU_BUILD_BUG_ON (HostMemPolicy_default !=MPOL_DEFAULT ); +QEMU_BUILD_BUG_ON (HostMemPolicy_preferred !=MPOL_PREFERRED ); +QEMU_BUILD_BUG_ON (HostMemPolicy_bind !=MPOL_BIND ); +QEMU_BUILD_BUG_ON (HostMemPolicy_interleave !=MPOL_INTERLEAVE );#endif static void
@@ -127,7 +127,7 @@ host_memory_backend_set_policy(Object *obj, int policy, Error **errp) backend->policy = policy;#ifndef CONFIG_NUMA -if (policy !=HOST_MEM_POLICY_DEFAULT ) { +if (policy != HostMemPolicy_default) {error_setg (errp,"NUMA policies are not supported by this QEMU" ); }#endif
backends/msmouse.c +1 -1
@@ -82,7 +82,7 @@ static CharDriverState *qemu_chr_open_msmouse(const char *id,static void register_types (void ) { -register_char_driver ("msmouse" ,CHARDEV_BACKEND_KIND_MSMOUSE ,NULL , +register_char_driver ("msmouse" , ChardevBackendKind_msmouse,NULL , qemu_chr_open_msmouse); }
backends/rng-egd.c +1 -1
@@ -147,7 +147,7 @@ static void rng_egd_opened(RngBackend *b, Error **errp) s->chr =qemu_chr_find (s->chr_name);if (s->chr ==NULL ) { -error_set (errp,ERROR_CLASS_DEVICE_NOT_FOUND , +error_set (errp, ErrorClass_DeviceNotFound,"Device '%s' not found" , s->chr_name);return ; }
backends/testdev.c +1 -1
@@ -128,7 +128,7 @@ static CharDriverState *chr_testdev_init(const char *id,static void register_types (void ) { -register_char_driver ("testdev" ,CHARDEV_BACKEND_KIND_TESTDEV ,NULL , +register_char_driver ("testdev" , ChardevBackendKind_testdev,NULL , chr_testdev_init); }
balloon.c +2 -2
@@ -40,12 +40,12 @@ static void *balloon_opaque;static bool have_balloon (Error **errp) {if (kvm_enabled () && !kvm_has_sync_mmu ()) { -error_set (errp,ERROR_CLASS_KVM_MISSING_CAP , +error_set (errp, ErrorClass_KVMMissingCap,"Using KVM without synchronous MMU, balloon unavailable" );return false; }if (!balloon_event_fn) { -error_set (errp,ERROR_CLASS_DEVICE_NOT_ACTIVE , +error_set (errp, ErrorClass_DeviceNotActive,"No balloon device has been activated" );return false; }
block.c +9 -9
@@ -1079,7 +1079,7 @@ static int bdrv_fill_options(QDict **options, const char **pfilename, } } -if (runstate_check (RUN_STATE_INMIGRATE )) { +if (runstate_check (RunState_inmigrate)) { *flags |=BDRV_O_INCOMING ; }
@@ -1548,9 +1548,9 @@ static int bdrv_open_inherit(BlockDriverState **pbs, const char *filename,if (bs->blk) {blk_dev_change_media_cb (bs->blk, true); } - }else if (!runstate_check (RUN_STATE_PRELAUNCH ) - && !runstate_check (RUN_STATE_INMIGRATE ) - && !runstate_check (RUN_STATE_PAUSED )) {/* HACK */ + }else if (!runstate_check (RunState_prelaunch) + && !runstate_check (RunState_inmigrate) + && !runstate_check (RunState_paused)) {/* HACK */ error_setg (errp,"Guest must be stopped for opening of encrypted image" ); ret = -EBUSY ;
@@ -1795,7 +1795,7 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue, ret =bdrv_flush (reopen_state->bs);if (ret) { -error_set (errp,ERROR_CLASS_GENERIC_ERROR ,"Error (%s) flushing drive" , +error_set (errp, ErrorClass_GenericError,"Error (%s) flushing drive" ,strerror (-ret)); goto error; }
@@ -2585,7 +2585,7 @@ void bdrv_add_key(BlockDriverState *bs, const char *key, Error **errp) } }else {if (bdrv_key_required (bs)) { -error_set (errp,ERROR_CLASS_DEVICE_ENCRYPTED , +error_set (errp, ErrorClass_DeviceEncrypted,"'%s' (%s) is encrypted" ,bdrv_get_device_or_node_name (bs),bdrv_get_encrypted_filename (bs));
@@ -3190,11 +3190,11 @@ bool bdrv_dirty_bitmap_enabled(BdrvDirtyBitmap *bitmap)DirtyBitmapStatus bdrv_dirty_bitmap_status (BdrvDirtyBitmap *bitmap) {if (bdrv_dirty_bitmap_frozen (bitmap)) { -return DIRTY_BITMAP_STATUS_FROZEN ; +return DirtyBitmapStatus_frozen; }else if (!bdrv_dirty_bitmap_enabled (bitmap)) { -return DIRTY_BITMAP_STATUS_DISABLED ; +return DirtyBitmapStatus_disabled; }else { -return DIRTY_BITMAP_STATUS_ACTIVE ; +return DirtyBitmapStatus_active; } }
block/backup.c +10 -10
@@ -223,7 +223,7 @@ static void backup_iostatus_reset(BlockJob *job)static const BlockJobDriver backup_job_driver = { .instance_size =sizeof (BackupBlockJob), - .job_type =BLOCK_JOB_TYPE_BACKUP , + .job_type = BlockJobType_backup, .set_speed = backup_set_speed, .iostatus_reset = backup_iostatus_reset, };
@@ -317,7 +317,7 @@ static int coroutine_fn backup_run_incremental(BackupBlockJob *job) false);if ((ret <0 ) &&backup_error_action (job, error_is_read, -ret) == -BLOCK_ERROR_ACTION_REPORT ) { + BlockErrorAction_report) {return ret; } }while (ret <0 );
@@ -370,7 +370,7 @@ static void coroutine_fn backup_run(void *opaque)bdrv_add_before_write_notifier (bs, &before_write); -if (job->sync_mode ==MIRROR_SYNC_MODE_NONE ) { +if (job->sync_mode == MirrorSyncMode_none) {while (!block_job_is_cancelled (&job->common)) {/* Yield until the job is cancelled. We just let our before_write * notify callback service CoW requests. */
@@ -378,7 +378,7 @@ static void coroutine_fn backup_run(void *opaque)qemu_coroutine_yield (); job->common.busy = true; } - }else if (job->sync_mode ==MIRROR_SYNC_MODE_INCREMENTAL ) { + }else if (job->sync_mode == MirrorSyncMode_incremental) { ret =backup_run_incremental (job); }else {/* Both FULL and TOP SYNC_MODE's require copying.. */
@@ -388,7 +388,7 @@ static void coroutine_fn backup_run(void *opaque)break ; } -if (job->sync_mode ==MIRROR_SYNC_MODE_TOP ) { +if (job->sync_mode == MirrorSyncMode_top) {int i, n;int alloced =0 ;
@@ -426,7 +426,7 @@ static void coroutine_fn backup_run(void *opaque)/* Depending on error action, fail now or retry cluster */ BlockErrorAction action =backup_error_action (job, error_is_read, -ret); -if (action ==BLOCK_ERROR_ACTION_REPORT ) { +if (action == BlockErrorAction_report) {break ; }else { start--;
@@ -485,8 +485,8 @@ void backup_start(BlockDriverState *bs, BlockDriverState *target,return ; } -if ((on_source_error ==BLOCKDEV_ON_ERROR_STOP || - on_source_error ==BLOCKDEV_ON_ERROR_ENOSPC ) && +if ((on_source_error == BlockdevOnError_stop || + on_source_error == BlockdevOnError_enospc) && (!bs->blk || !blk_iostatus_is_enabled (bs->blk))) {error_setg (errp,QERR_INVALID_PARAMETER ,"on-source-error" );return ;
@@ -512,7 +512,7 @@ void backup_start(BlockDriverState *bs, BlockDriverState *target,return ; } -if (sync_mode ==MIRROR_SYNC_MODE_INCREMENTAL ) { +if (sync_mode == MirrorSyncMode_incremental) {if (!sync_bitmap) {error_setg (errp,"must provide a valid bitmap name for " "\"incremental\" sync mode" );
@@ -550,7 +550,7 @@ void backup_start(BlockDriverState *bs, BlockDriverState *target, job->on_target_error = on_target_error; job->target = target; job->sync_mode = sync_mode; - job->sync_bitmap = sync_mode ==MIRROR_SYNC_MODE_INCREMENTAL ? + job->sync_bitmap = sync_mode == MirrorSyncMode_incremental ? sync_bitmap :NULL ; job->common.len = len; job->common.co =qemu_coroutine_create (backup_run);
block/block-backend.c +19 -19
@@ -489,7 +489,7 @@ void blk_dev_resize_cb(BlockBackend *blk)void blk_iostatus_enable (BlockBackend *blk) { blk->iostatus_enabled = true; - blk->iostatus =BLOCK_DEVICE_IO_STATUS_OK ; + blk->iostatus = BlockDeviceIoStatus_ok; }/* The I/O status is only enabled if the drive explicitly
@@ -497,9 +497,9 @@ void blk_iostatus_enable(BlockBackend *blk)bool blk_iostatus_is_enabled (const BlockBackend *blk) {return (blk->iostatus_enabled && - (blk->on_write_error ==BLOCKDEV_ON_ERROR_ENOSPC || - blk->on_write_error ==BLOCKDEV_ON_ERROR_STOP || - blk->on_read_error ==BLOCKDEV_ON_ERROR_STOP )); + (blk->on_write_error == BlockdevOnError_enospc || + blk->on_write_error == BlockdevOnError_stop || + blk->on_read_error == BlockdevOnError_stop)); }BlockDeviceIoStatus blk_iostatus (const BlockBackend *blk)
@@ -515,7 +515,7 @@ void blk_iostatus_disable(BlockBackend *blk)void blk_iostatus_reset (BlockBackend *blk) {if (blk_iostatus_is_enabled (blk)) { - blk->iostatus =BLOCK_DEVICE_IO_STATUS_OK ; + blk->iostatus = BlockDeviceIoStatus_ok;if (blk->bs && blk->bs->job) {block_job_iostatus_reset (blk->bs->job); }
@@ -525,9 +525,9 @@ void blk_iostatus_reset(BlockBackend *blk)void blk_iostatus_set_err (BlockBackend *blk,int error) {assert (blk_iostatus_is_enabled (blk)); -if (blk->iostatus ==BLOCK_DEVICE_IO_STATUS_OK ) { - blk->iostatus = error ==ENOSPC ?BLOCK_DEVICE_IO_STATUS_NOSPACE : -BLOCK_DEVICE_IO_STATUS_FAILED ; +if (blk->iostatus == BlockDeviceIoStatus_ok) { + blk->iostatus = error ==ENOSPC ? BlockDeviceIoStatus_nospace : + BlockDeviceIoStatus_failed; } }
@@ -856,15 +856,15 @@ BlockErrorAction blk_get_error_action(BlockBackend *blk, bool is_read,BlockdevOnError on_err =blk_get_on_error (blk, is_read);switch (on_err) { -case BLOCKDEV_ON_ERROR_ENOSPC : +case BlockdevOnError_enospc:return (error ==ENOSPC ) ? -BLOCK_ERROR_ACTION_STOP :BLOCK_ERROR_ACTION_REPORT ; -case BLOCKDEV_ON_ERROR_STOP : -return BLOCK_ERROR_ACTION_STOP ; -case BLOCKDEV_ON_ERROR_REPORT : -return BLOCK_ERROR_ACTION_REPORT ; -case BLOCKDEV_ON_ERROR_IGNORE : -return BLOCK_ERROR_ACTION_IGNORE ; + BlockErrorAction_stop : BlockErrorAction_report; +case BlockdevOnError_stop: +return BlockErrorAction_stop; +case BlockdevOnError_report: +return BlockErrorAction_report; +case BlockdevOnError_ignore: +return BlockErrorAction_ignore;default :abort (); }
@@ -876,7 +876,7 @@ static void send_qmp_error_event(BlockBackend *blk, {IoOperationType optype; - optype = is_read ?IO_OPERATION_TYPE_READ :IO_OPERATION_TYPE_WRITE ; + optype = is_read ? IoOperationType_read : IoOperationType_write; qapi_event_send_block_io_error(blk_name(blk), optype, action, blk_iostatus_is_enabled(blk), error == ENOSPC, strerror(error),
@@ -892,7 +892,7 @@ void blk_error_action(BlockBackend *blk, BlockErrorAction action, {assert (error >=0 ); -if (action ==BLOCK_ERROR_ACTION_STOP ) { +if (action == BlockErrorAction_stop) {/* First set the iostatus, so that "info block" returns an iostatus * that matches the events raised so far (an additional error iostatus * is fine, but not a lost one).
@@ -909,7 +909,7 @@ void blk_error_action(BlockBackend *blk, BlockErrorAction action,*/ qemu_system_vmstop_request_prepare ();send_qmp_error_event (blk, action, is_read, error); -qemu_system_vmstop_request (RUN_STATE_IO_ERROR ); +qemu_system_vmstop_request (RunState_io_error); }else {send_qmp_error_event (blk, action, is_read, error); }
block/commit.c +6 -6
@@ -160,9 +160,9 @@ wait: bytes_written += n *BDRV_SECTOR_SIZE ; }if (ret <0 ) { -if (s->on_error ==BLOCKDEV_ON_ERROR_STOP || - s->on_error ==BLOCKDEV_ON_ERROR_REPORT || - (s->on_error ==BLOCKDEV_ON_ERROR_ENOSPC && ret == -ENOSPC )) { +if (s->on_error == BlockdevOnError_stop || + s->on_error == BlockdevOnError_report|| + (s->on_error == BlockdevOnError_enospc && ret == -ENOSPC )) { goto out; }else { n =0 ;
@@ -196,7 +196,7 @@ static void commit_set_speed(BlockJob *job, int64_t speed, Error **errp)static const BlockJobDriver commit_job_driver = { .instance_size =sizeof (CommitBlockJob), - .job_type =BLOCK_JOB_TYPE_COMMIT , + .job_type = BlockJobType_commit, .set_speed = commit_set_speed, };
@@ -212,8 +212,8 @@ void commit_start(BlockDriverState *bs, BlockDriverState *base,BlockDriverState *overlay_bs;Error *local_err =NULL ; -if ((on_error ==BLOCKDEV_ON_ERROR_STOP || - on_error ==BLOCKDEV_ON_ERROR_ENOSPC ) && +if ((on_error == BlockdevOnError_stop || + on_error == BlockdevOnError_enospc) && (!bs->blk || !blk_iostatus_is_enabled (bs->blk))) {error_setg (errp,"Invalid parameter combination" );return ;
block/io.c +2 -2
@@ -1129,11 +1129,11 @@ static int coroutine_fn bdrv_aligned_pwritev(BlockDriverState *bs, ret =notifier_with_return_list_notify (&bs->before_write_notifiers, req); -if (!ret && bs->detect_zeroes !=BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF && +if (!ret && bs->detect_zeroes != BlockdevDetectZeroesOptions_off && !(flags &BDRV_REQ_ZERO_WRITE ) && drv->bdrv_co_write_zeroes &&qemu_iovec_is_zero (qiov)) { flags |=BDRV_REQ_ZERO_WRITE ; -if (bs->detect_zeroes ==BLOCKDEV_DETECT_ZEROES_OPTIONS_UNMAP ) { +if (bs->detect_zeroes == BlockdevDetectZeroesOptions_unmap) { flags |=BDRV_REQ_MAY_UNMAP ; } }
block/mirror.c +11 -11
@@ -130,7 +130,7 @@ static void mirror_write_complete(void *opaque, int ret)bdrv_set_dirty_bitmap (s->dirty_bitmap, op->sector_num, op->nb_sectors); action =mirror_error_action (s, false, -ret); -if (action ==BLOCK_ERROR_ACTION_REPORT && s->ret >=0 ) { +if (action == BlockErrorAction_report && s->ret >=0 ) { s->ret = ret; } }
@@ -146,7 +146,7 @@ static void mirror_read_complete(void *opaque, int ret)bdrv_set_dirty_bitmap (s->dirty_bitmap, op->sector_num, op->nb_sectors); action =mirror_error_action (s, true, -ret); -if (action ==BLOCK_ERROR_ACTION_REPORT && s->ret >=0 ) { +if (action == BlockErrorAction_report && s->ret >=0 ) { s->ret = ret; }
@@ -511,7 +511,7 @@ static void coroutine_fn mirror_run(void *opaque)* or when the source is clean, whichever comes first. */ if (qemu_clock_get_ns (QEMU_CLOCK_REALTIME ) - last_pause_ns <SLICE_TIME && - s->common.iostatus ==BLOCK_DEVICE_IO_STATUS_OK ) { + s->common.iostatus == BlockDeviceIoStatus_ok) {if (s->in_flight ==MAX_IN_FLIGHT || s->buf_free_count ==0 || (cnt ==0 && s->in_flight >0 )) {trace_mirror_yield (s, s->in_flight, s->buf_free_count, cnt);
@@ -530,7 +530,7 @@ static void coroutine_fn mirror_run(void *opaque) ret =bdrv_flush (s->target);if (ret <0 ) {if (mirror_error_action (s, false, -ret) == -BLOCK_ERROR_ACTION_REPORT ) { + BlockErrorAction_report) { goto immediate_exit; } }else {
@@ -672,7 +672,7 @@ static void mirror_complete(BlockJob *job, Error **errp)static const BlockJobDriver mirror_job_driver = { .instance_size =sizeof (MirrorBlockJob), - .job_type =BLOCK_JOB_TYPE_MIRROR , + .job_type = BlockJobType_mirror, .set_speed = mirror_set_speed, .iostatus_reset= mirror_iostatus_reset, .complete = mirror_complete,
@@ -680,7 +680,7 @@ static const BlockJobDriver mirror_job_driver = {static const BlockJobDriver commit_active_job_driver = { .instance_size =sizeof (MirrorBlockJob), - .job_type =BLOCK_JOB_TYPE_COMMIT , + .job_type = BlockJobType_commit, .set_speed = mirror_set_speed, .iostatus_reset = mirror_iostatus_reset,
@@ -707,8 +707,8 @@ static void mirror_start_job(BlockDriverState *bs, BlockDriverState *target,assert ((granularity & (granularity -1 )) ==0 ); -if ((on_source_error ==BLOCKDEV_ON_ERROR_STOP || - on_source_error ==BLOCKDEV_ON_ERROR_ENOSPC ) && +if ((on_source_error == BlockdevOnError_stop || + on_source_error == BlockdevOnError_enospc) && (!bs->blk || !blk_iostatus_is_enabled (bs->blk))) {error_setg (errp,QERR_INVALID_PARAMETER ,"on-source-error" );return ;
@@ -766,12 +766,12 @@ void mirror_start(BlockDriverState *bs, BlockDriverState *target,bool is_none_mode;BlockDriverState *base; -if (mode ==MIRROR_SYNC_MODE_INCREMENTAL ) { +if (mode == MirrorSyncMode_incremental) {error_setg (errp,"Sync mode 'incremental' not supported" );return ; } - is_none_mode = mode ==MIRROR_SYNC_MODE_NONE ; - base = mode ==MIRROR_SYNC_MODE_TOP ?backing_bs (bs) :NULL ; + is_none_mode = mode == MirrorSyncMode_none; + base = mode == MirrorSyncMode_top ?backing_bs (bs) :NULL ; mirror_start_job(bs, target, replaces, speed, granularity, buf_size, on_source_error, on_target_error, unmap, cb, opaque, errp,
block/nbd.c +3 -3
@@ -206,12 +206,12 @@ static SocketAddress *nbd_config(BDRVNBDState *s, QDict *options, char **export, saddr =g_new0 (SocketAddress,1 );if (qdict_haskey (options,"path" )) { - saddr->type =SOCKET_ADDRESS_KIND_UNIX ; + saddr->type = SocketAddressKind_unix; saddr->u.q_unix =g_new0 (UnixSocketAddress,1 ); saddr->u.q_unix->path =g_strdup (qdict_get_str (options,"path" ));qdict_del (options,"path" ); }else { - saddr->type =SOCKET_ADDRESS_KIND_INET ; + saddr->type = SocketAddressKind_inet; saddr->u.inet =g_new0 (InetSocketAddress,1 ); saddr->u.inet->host =g_strdup (qdict_get_str (options,"host" ));if (!qdict_get_try_str (options,"port" )) {
@@ -223,7 +223,7 @@ static SocketAddress *nbd_config(BDRVNBDState *s, QDict *options, char **export,qdict_del (options,"port" ); } - s->client.is_unix = saddr->type ==SOCKET_ADDRESS_KIND_UNIX ; + s->client.is_unix = saddr->type == SocketAddressKind_unix; *export =g_strdup (qdict_get_try_str (options,"export" ));if (*export) {
block/qcow2.c +5 -5
@@ -2040,7 +2040,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,Error *local_err =NULL ;int ret; -if (prealloc ==PREALLOC_MODE_FULL || prealloc ==PREALLOC_MODE_FALLOC ) { +if (prealloc == PreallocMode_full || prealloc == PreallocMode_falloc) {/* Note: The following calculation does not need to be exact; if it is a * bit off, either some bytes will be "leaked" (which is fine) or we * will need to increase the file size by some bytes (which is fine,
@@ -2209,7 +2209,7 @@ static int qcow2_create2(const char *filename, int64_t total_size, }/* And if we're supposed to preallocate metadata, do that now */ -if (prealloc !=PREALLOC_MODE_OFF ) { +if (prealloc != PreallocMode_off) {BDRVQcow2State *s = bs->opaque;qemu_co_mutex_lock (&s->lock); ret =preallocate (bs);
@@ -2269,7 +2269,7 @@ static int qcow2_create(const char *filename, QemuOpts *opts, Error **errp) DEFAULT_CLUSTER_SIZE); buf =qemu_opt_get_del (opts,BLOCK_OPT_PREALLOC ); prealloc =qapi_enum_parse (PreallocMode_lookup, buf, -PREALLOC_MODE_MAX ,PREALLOC_MODE_OFF , + PreallocMode_MAX, PreallocMode_off, &local_err);if (local_err) {error_propagate (errp, local_err);
@@ -2294,7 +2294,7 @@ static int qcow2_create(const char *filename, QemuOpts *opts, Error **errp) flags |=BLOCK_FLAG_LAZY_REFCOUNTS ; } -if (backing_file && prealloc !=PREALLOC_MODE_OFF ) { +if (backing_file && prealloc != PreallocMode_off) {error_setg (errp,"Backing file and preallocation cannot be used at " "the same time" ); ret = -EINVAL ;
@@ -2738,7 +2738,7 @@ static ImageInfoSpecific *qcow2_get_specific_info(BlockDriverState *bs)ImageInfoSpecific *spec_info =g_new (ImageInfoSpecific,1 ); *spec_info = (ImageInfoSpecific ){ - .type =IMAGE_INFO_SPECIFIC_KIND_QCOW2 , + .type = ImageInfoSpecificKind_qcow2, .u.qcow2 =g_new (ImageInfoSpecificQCow2,1 ), };if (s->qcow_version ==2 ) {
block/quorum.c +5 -5
@@ -283,7 +283,7 @@ static void quorum_aio_cb(void *opaque, int ret)BDRVQuorumState *s = acb->common.bs->opaque;bool rewrite = false; -if (acb->is_read && s->read_pattern ==QUORUM_READ_PATTERN_FIFO ) { +if (acb->is_read && s->read_pattern == QuorumReadPattern_fifo) {/* We try to read next child in FIFO order if we fail to read */ if (ret <0 && ++acb->child_iter < s->num_children) {read_fifo_child (acb);
@@ -681,7 +681,7 @@ static BlockAIOCB *quorum_aio_readv(BlockDriverState *bs, nb_sectors, cb, opaque); acb->is_read = true; -if (s->read_pattern ==QUORUM_READ_PATTERN_QUORUM ) { +if (s->read_pattern == QuorumReadPattern_quorum) { acb->child_iter = s->num_children -1 ;return read_quorum_children (acb); }
@@ -844,10 +844,10 @@ static int parse_read_pattern(const char *opt)if (!opt) {/* Set quorum as default */ -return QUORUM_READ_PATTERN_QUORUM ; +return QuorumReadPattern_quorum; } -for (i =0 ; i <QUORUM_READ_PATTERN_MAX ; i++) { +for (i =0 ; i < QuorumReadPattern_MAX; i++) {if (!strcmp (opt, QuorumReadPattern_lookup[i])) {return i; }
@@ -903,7 +903,7 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags, } s->read_pattern = ret; -if (s->read_pattern ==QUORUM_READ_PATTERN_QUORUM ) { +if (s->read_pattern == QuorumReadPattern_quorum) {/* is the driver in blkverify mode */ if (qemu_opt_get_bool (opts,QUORUM_OPT_BLKVERIFY , false) && s->num_children ==2 && s->threshold ==2 ) {
block/raw-posix.c +4 -4
@@ -1636,7 +1636,7 @@ static int raw_create(const char *filename, QemuOpts *opts, Error **errp) nocow =qemu_opt_get_bool (opts,BLOCK_OPT_NOCOW , false); buf =qemu_opt_get_del (opts,BLOCK_OPT_PREALLOC ); prealloc =qapi_enum_parse (PreallocMode_lookup, buf, -PREALLOC_MODE_MAX ,PREALLOC_MODE_OFF , + PreallocMode_MAX, PreallocMode_off, &local_err);g_free (buf);if (local_err) {
@@ -1676,7 +1676,7 @@ static int raw_create(const char *filename, QemuOpts *opts, Error **errp)switch (prealloc) {#ifdef CONFIG_POSIX_FALLOCATE -case PREALLOC_MODE_FALLOC : +case PreallocMode_falloc:/* posix_fallocate() doesn't set errno. */ result = -posix_fallocate (fd,0 , total_size);if (result !=0 ) {
@@ -1685,7 +1685,7 @@ static int raw_create(const char *filename, QemuOpts *opts, Error **errp) }break ;#endif -case PREALLOC_MODE_FULL : +case PreallocMode_full: {int64_t num =0 , left = total_size; buf =g_malloc0 (65536 );
@@ -1712,7 +1712,7 @@ static int raw_create(const char *filename, QemuOpts *opts, Error **errp)g_free (buf);break ; } -case PREALLOC_MODE_OFF : +case PreallocMode_off:break ;default : result = -EINVAL ;
block/stream.c +5 -5
@@ -163,14 +163,14 @@ wait:BlockErrorAction action =block_job_error_action (&s->common, s->common.bs, s->on_error, true, -ret); -if (action ==BLOCK_ERROR_ACTION_STOP ) { +if (action == BlockErrorAction_stop) { n =0 ;continue ; }if (error ==0 ) { error = ret; } -if (action ==BLOCK_ERROR_ACTION_REPORT ) { +if (action == BlockErrorAction_report) {break ; } }
@@ -209,7 +209,7 @@ static void stream_set_speed(BlockJob *job, int64_t speed, Error **errp)static const BlockJobDriver stream_job_driver = { .instance_size =sizeof (StreamBlockJob), - .job_type =BLOCK_JOB_TYPE_STREAM , + .job_type = BlockJobType_stream, .set_speed = stream_set_speed, };
@@ -221,8 +221,8 @@ void stream_start(BlockDriverState *bs, BlockDriverState *base, {StreamBlockJob *s; -if ((on_error ==BLOCKDEV_ON_ERROR_STOP || - on_error ==BLOCKDEV_ON_ERROR_ENOSPC ) && +if ((on_error == BlockdevOnError_stop || + on_error == BlockdevOnError_enospc) && (!bs->blk || !blk_iostatus_is_enabled (bs->blk))) {error_setg (errp,QERR_INVALID_PARAMETER ,"on-error" );return ;
block/vmdk.c +1 -1
@@ -2161,7 +2161,7 @@ static ImageInfoSpecific *vmdk_get_specific_info(BlockDriverState *bs)ImageInfoList **next; *spec_info = (ImageInfoSpecific ){ - .type =IMAGE_INFO_SPECIFIC_KIND_VMDK , + .type = ImageInfoSpecificKind_vmdk, { .vmdk =g_new0 (ImageInfoSpecificVmdk,1 ), },
blockdev-nbd.c +1 -1
@@ -90,7 +90,7 @@ void qmp_nbd_server_add(const char *device, bool has_writable, bool writable, blk =blk_by_name (device);if (!blk) { -error_set (errp,ERROR_CLASS_DEVICE_NOT_FOUND , +error_set (errp, ErrorClass_DeviceNotFound,"Device '%s' not found" , device);return ; }
blockdev.c +67 -67
428 lines not on this page · raw message
blockjob.c +15 -15
@@ -164,7 +164,7 @@ bool block_job_is_cancelled(BlockJob *job)void block_job_iostatus_reset (BlockJob *job) { - job->iostatus =BLOCK_DEVICE_IO_STATUS_OK ; + job->iostatus = BlockDeviceIoStatus_ok;if (job->driver->iostatus_reset) { job->driver->iostatus_reset (job); }
@@ -284,9 +284,9 @@ BlockJobInfo *block_job_query(BlockJob *job)static void block_job_iostatus_set_err (BlockJob *job,int error) { -if (job->iostatus ==BLOCK_DEVICE_IO_STATUS_OK ) { - job->iostatus = error ==ENOSPC ?BLOCK_DEVICE_IO_STATUS_NOSPACE : -BLOCK_DEVICE_IO_STATUS_FAILED ; +if (job->iostatus == BlockDeviceIoStatus_ok) { + job->iostatus = error ==ENOSPC ? BlockDeviceIoStatus_nospace : + BlockDeviceIoStatus_failed; } }
@@ -330,27 +330,27 @@ BlockErrorAction block_job_error_action(BlockJob *job, BlockDriverState *bs,BlockErrorAction action;switch (on_err) { -case BLOCKDEV_ON_ERROR_ENOSPC : +case BlockdevOnError_enospc: action = (error ==ENOSPC ) ? -BLOCK_ERROR_ACTION_STOP :BLOCK_ERROR_ACTION_REPORT ; + BlockErrorAction_stop : BlockErrorAction_report;break ; -case BLOCKDEV_ON_ERROR_STOP : - action =BLOCK_ERROR_ACTION_STOP ; +case BlockdevOnError_stop: + action = BlockErrorAction_stop;break ; -case BLOCKDEV_ON_ERROR_REPORT : - action =BLOCK_ERROR_ACTION_REPORT ; +case BlockdevOnError_report: + action = BlockErrorAction_report;break ; -case BLOCKDEV_ON_ERROR_IGNORE : - action =BLOCK_ERROR_ACTION_IGNORE ; +case BlockdevOnError_ignore: + action = BlockErrorAction_ignore;break ;default :abort (); }qapi_event_send_block_job_error (job->id, - is_read ?IO_OPERATION_TYPE_READ : -IO_OPERATION_TYPE_WRITE , + is_read ? IoOperationType_read : + IoOperationType_write, action, &error_abort); -if (action ==BLOCK_ERROR_ACTION_STOP ) { +if (action == BlockErrorAction_stop) {/* make the pause user visible, which will be resumed from QMP. */ job->user_paused = true;block_job_pause (job);
crypto/tlscredsanon.c +3 -3
@@ -38,7 +38,7 @@ qcrypto_tls_creds_anon_load(QCryptoTLSCredsAnon *creds,trace_qcrypto_tls_creds_anon_load (creds, creds->parent_obj.dir ? creds->parent_obj.dir :"<nodir>" ); -if (creds->parent_obj.endpoint ==QCRYPTO_TLS_CREDS_ENDPOINT_SERVER ) { +if (creds->parent_obj.endpoint == QCRYPTO_TLS_CREDS_ENDPOINT_server) {if (qcrypto_tls_creds_get_path (&creds->parent_obj,QCRYPTO_TLS_CREDS_DH_PARAMS , false, &dhparams, errp) <0 ) {
@@ -79,7 +79,7 @@ qcrypto_tls_creds_anon_load(QCryptoTLSCredsAnon *creds,static void qcrypto_tls_creds_anon_unload (QCryptoTLSCredsAnon *creds) { -if (creds->parent_obj.endpoint ==QCRYPTO_TLS_CREDS_ENDPOINT_CLIENT ) { +if (creds->parent_obj.endpoint == QCRYPTO_TLS_CREDS_ENDPOINT_client) {if (creds->data.client) {gnutls_anon_free_client_credentials (creds->data.client); creds->data.client =NULL ;
@@ -141,7 +141,7 @@ qcrypto_tls_creds_anon_prop_get_loaded(Object *obj, {QCryptoTLSCredsAnon *creds =QCRYPTO_TLS_CREDS_ANON (obj); -if (creds->parent_obj.endpoint ==QCRYPTO_TLS_CREDS_ENDPOINT_SERVER ) { +if (creds->parent_obj.endpoint == QCRYPTO_TLS_CREDS_ENDPOINT_server) {return creds->data.server !=NULL ; }else {return creds->data.client !=NULL ;
crypto/tlscredsx509.c +3 -3
@@ -549,7 +549,7 @@ qcrypto_tls_creds_x509_load(QCryptoTLSCredsX509 *creds,trace_qcrypto_tls_creds_x509_load (creds, creds->parent_obj.dir ? creds->parent_obj.dir :"<nodir>" ); -if (creds->parent_obj.endpoint ==QCRYPTO_TLS_CREDS_ENDPOINT_SERVER ) { +if (creds->parent_obj.endpoint == QCRYPTO_TLS_CREDS_ENDPOINT_server) { if (qcrypto_tls_creds_get_path(&creds->parent_obj, QCRYPTO_TLS_CREDS_X509_CA_CERT, true, &cacert, errp) < 0 ||
@@ -583,7 +583,7 @@ qcrypto_tls_creds_x509_load(QCryptoTLSCredsX509 *creds,if (creds->sanityCheck &&qcrypto_tls_creds_x509_sanity_check (creds, - creds->parent_obj.endpoint ==QCRYPTO_TLS_CREDS_ENDPOINT_SERVER , + creds->parent_obj.endpoint == QCRYPTO_TLS_CREDS_ENDPOINT_server, cacert, cert, errp) <0 ) { goto cleanup; }
@@ -626,7 +626,7 @@ qcrypto_tls_creds_x509_load(QCryptoTLSCredsX509 *creds, } } -if (creds->parent_obj.endpoint ==QCRYPTO_TLS_CREDS_ENDPOINT_SERVER ) { +if (creds->parent_obj.endpoint == QCRYPTO_TLS_CREDS_ENDPOINT_server) {if (qcrypto_tls_creds_get_dh_params_file (&creds->parent_obj, dhparams, &creds->parent_obj.dh_params, errp) <0 ) {
crypto/tlssession.c +3 -3
@@ -116,7 +116,7 @@ qcrypto_tls_session_new(QCryptoTLSCreds *creds, goto error; } -if (endpoint ==QCRYPTO_TLS_CREDS_ENDPOINT_SERVER ) { +if (endpoint == QCRYPTO_TLS_CREDS_ENDPOINT_server) { ret =gnutls_init (&session->handle,GNUTLS_SERVER ); }else { ret =gnutls_init (&session->handle,GNUTLS_CLIENT );
@@ -138,7 +138,7 @@ qcrypto_tls_session_new(QCryptoTLSCreds *creds, gnutls_strerror(ret)); goto error; } -if (creds->endpoint ==QCRYPTO_TLS_CREDS_ENDPOINT_SERVER ) { +if (creds->endpoint == QCRYPTO_TLS_CREDS_ENDPOINT_server) { ret =gnutls_credentials_set (session->handle,GNUTLS_CRD_ANON , acreds->data.server);
@@ -171,7 +171,7 @@ qcrypto_tls_session_new(QCryptoTLSCreds *creds, goto error; } -if (creds->endpoint ==QCRYPTO_TLS_CREDS_ENDPOINT_SERVER ) { +if (creds->endpoint == QCRYPTO_TLS_CREDS_ENDPOINT_server) {/* This requests, but does not enforce a client cert. * The cert checking code later does enforcement */ gnutls_certificate_server_set_request(session->handle,
docs/qapi-code-gen.txt +6 -5
@@ -257,6 +257,7 @@ useful. The list of strings should be lower case; if an enum name represents multiple words, use '-' between words. The string 'max' is not allowed as an enum value, and values should not be repeated. +FIXME obsolete, rewrite The enum constants will be named by using a heuristic to turn the type name into a set of underscore separated words. For the example above, 'MyEnum' will turn into 'MY_ENUM' giving a constant name
@@ -1034,15 +1035,15 @@ Example: qmp = qmp_event_build_dict("MY_EVENT"); - emit(EXAMPLE_QAPI_EVENT_MY_EVENT, qmp, &err); + emit(example_QAPIEvent_MY_EVENT, qmp, &err); error_propagate(errp, err); QDECREF(qmp); } const char *const example_QAPIEvent_lookup[] = { - [EXAMPLE_QAPI_EVENT_MY_EVENT] = "MY_EVENT", - [EXAMPLE_QAPI_EVENT_MAX] = NULL, + [example_QAPIEvent_MY_EVENT] = "MY_EVENT", + [example_QAPIEvent_MAX] = NULL, }; $ cat qapi-generated/example-qapi-event.h [Uninteresting stuff omitted...]
@@ -1058,8 +1059,8 @@ Example: void qapi_event_send_my_event(Error **errp); typedef enum example_QAPIEvent { - EXAMPLE_QAPI_EVENT_MY_EVENT = 0, - EXAMPLE_QAPI_EVENT_MAX = 1, + example_QAPIEvent_MY_EVENT = 0, + example_QAPIEvent_MAX = 1, } example_QAPIEvent; extern const char *const example_QAPIEvent_lookup[];
docs/writing-qmp-commands.txt +4 -4
@@ -219,7 +219,7 @@ void qmp_hello_world(bool has_message, const char *message, Error **errp) { if (has_message) { if (strstr(message, "love")) { - error_set(errp, ERROR_CLASS_GENERIC_ERROR, + error_set(errp, ErrorClass_GenericError, "the word 'love' is not allowed"); return; }
@@ -231,7 +231,7 @@ void qmp_hello_world(bool has_message, const char *message, Error **errp) The first argument to the error_set() function is the Error pointer to pointer, which is passed to all QMP functions. The second argument is a ErrorClass -value, which should be ERROR_CLASS_GENERIC_ERROR most of the time (more +value, which should be ErrorClass_GenericError most of the time (more details about error classes are given below). The third argument is a human description of the error, this is a free-form printf-like string.
@@ -249,7 +249,7 @@ The QMP server's response should be: } } -As a general rule, all QMP errors should use ERROR_CLASS_GENERIC_ERROR. There +As a general rule, all QMP errors should use ErrorClass_GenericError. There are two exceptions to this rule: 1. A non-generic ErrorClass value exists* for the failure you want to report
@@ -260,7 +260,7 @@ are two exceptions to this rule: can check for it If the failure you want to report doesn't fall in one of the two cases above, -just report ERROR_CLASS_GENERIC_ERROR. +just report ErrorClass_GenericError. * All existing ErrorClass values are defined in the qapi-schema.json file
dump.c +14 -14
@@ -1443,12 +1443,12 @@ static void dump_init(DumpState *s, int fd, bool has_format,int ret;/* kdump-compressed is conflict with paging and filter */ -if (has_format && format !=DUMP_GUEST_MEMORY_FORMAT_ELF ) { +if (has_format && format != DumpGuestMemoryFormat_elf) {assert (!paging && !has_filter); }if (runstate_is_running ()) { -vm_stop (RUN_STATE_SAVE_VM ); +vm_stop (RunState_save_vm); s->resume = true; }else { s->resume = false;
@@ -1516,13 +1516,13 @@ static void dump_init(DumpState *s, int fd, bool has_format, s->len_dump_bitmap = tmp *TARGET_PAGE_SIZE ;/* init for kdump-compressed format */ -if (has_format && format !=DUMP_GUEST_MEMORY_FORMAT_ELF ) { +if (has_format && format != DumpGuestMemoryFormat_elf) {switch (format) { -case DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB : +case DumpGuestMemoryFormat_kdump_zlib: s->flag_compress =DUMP_DH_COMPRESSED_ZLIB ;break ; -case DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO : +case DumpGuestMemoryFormat_kdump_lzo:#ifdef CONFIG_LZO if (lzo_init () !=LZO_E_OK ) {error_setg (errp,"failed to initialize the LZO library" );
@@ -1532,7 +1532,7 @@ static void dump_init(DumpState *s, int fd, bool has_format, s->flag_compress =DUMP_DH_COMPRESSED_LZO ;break ; -case DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY : +case DumpGuestMemoryFormat_kdump_snappy: s->flag_compress =DUMP_DH_COMPRESSED_SNAPPY ;break ;
@@ -1609,7 +1609,7 @@ void qmp_dump_guest_memory(bool paging, const char *file, bool has_begin,* kdump-compressed format need the whole memory dumped, so paging or * filter is not supported here. */ -if ((has_format && format !=DUMP_GUEST_MEMORY_FORMAT_ELF ) && +if ((has_format && format != DumpGuestMemoryFormat_elf) && (paging || has_begin || has_length)) {error_setg (errp,"kdump-compressed format doesn't support paging or " "filter" );
@@ -1626,14 +1626,14 @@ void qmp_dump_guest_memory(bool paging, const char *file, bool has_begin,/* check whether lzo/snappy is supported */ #ifndef CONFIG_LZO -if (has_format && format ==DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO ) { +if (has_format && format == DumpGuestMemoryFormat_kdump_lzo) {error_setg (errp,"kdump-lzo is not available now" );return ; }#endif #ifndef CONFIG_SNAPPY -if (has_format && format ==DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY ) { +if (has_format && format == DumpGuestMemoryFormat_kdump_snappy) {error_setg (errp,"kdump-snappy is not available now" );return ; }
@@ -1671,7 +1671,7 @@ void qmp_dump_guest_memory(bool paging, const char *file, bool has_begin,return ; } -if (has_format && format !=DUMP_GUEST_MEMORY_FORMAT_ELF ) { +if (has_format && format != DumpGuestMemoryFormat_elf) {create_kdump_vmcore (s, errp); }else {create_vmcore (s, errp);
@@ -1689,25 +1689,25 @@ DumpGuestMemoryCapability *qmp_query_dump_guest_memory_capability(Error **errp)/* elf is always available */ item =g_malloc0 (sizeof (DumpGuestMemoryFormatList)); cap->formats = item; - item->value =DUMP_GUEST_MEMORY_FORMAT_ELF ; + item->value = DumpGuestMemoryFormat_elf;/* kdump-zlib is always available */ item->next =g_malloc0 (sizeof (DumpGuestMemoryFormatList)); item = item->next; - item->value =DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB ; + item->value = DumpGuestMemoryFormat_kdump_zlib;/* add new item if kdump-lzo is available */ #ifdef CONFIG_LZO item->next =g_malloc0 (sizeof (DumpGuestMemoryFormatList)); item = item->next; - item->value =DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO ; + item->value = DumpGuestMemoryFormat_kdump_lzo;#endif /* add new item if kdump-snappy is available */ #ifdef CONFIG_SNAPPY item->next =g_malloc0 (sizeof (DumpGuestMemoryFormatList)); item = item->next; - item->value =DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY ; + item->value = DumpGuestMemoryFormat_kdump_snappy;#endif return cap;
gdbstub.c +13 -13
@@ -1237,7 +1237,7 @@ static void gdb_vm_state_change(void *opaque, int running, RunState state)return ; }switch (state) { -case RUN_STATE_DEBUG : +case RunState_debug:if (cpu->watchpoint_hit) {switch (cpu->watchpoint_hit->flags &BP_MEM_ACCESS ) {case BP_MEM_READ :
@@ -1260,25 +1260,25 @@ static void gdb_vm_state_change(void *opaque, int running, RunState state)tb_flush (cpu); ret =GDB_SIGNAL_TRAP ;break ; -case RUN_STATE_PAUSED : +case RunState_paused: ret =GDB_SIGNAL_INT ;break ; -case RUN_STATE_SHUTDOWN : +case RunState_shutdown: ret =GDB_SIGNAL_QUIT ;break ; -case RUN_STATE_IO_ERROR : +case RunState_io_error: ret =GDB_SIGNAL_IO ;break ; -case RUN_STATE_WATCHDOG : +case RunState_watchdog: ret =GDB_SIGNAL_ALRM ;break ; -case RUN_STATE_INTERNAL_ERROR : +case RunState_internal_error: ret =GDB_SIGNAL_ABRT ;break ; -case RUN_STATE_SAVE_VM : -case RUN_STATE_RESTORE_VM : +case RunState_save_vm: +case RunState_restore_vm:return ; -case RUN_STATE_FINISH_MIGRATE : +case RunState_finish_migrate: ret =GDB_SIGNAL_XCPU ;break ;default :
@@ -1314,7 +1314,7 @@ void gdb_do_syscallv(gdb_syscall_complete_cb cb, const char *fmt, va_list va)return ; s->current_syscall_cb = cb;#ifndef CONFIG_USER_ONLY -vm_stop (RUN_STATE_DEBUG ); +vm_stop (RunState_debug);#endif p = s->syscall_buf; p_end = &s->syscall_buf[sizeof (s->syscall_buf)];
@@ -1401,7 +1401,7 @@ static void gdb_read_byte(GDBState *s, int ch)if (runstate_is_running ()) {/* when the CPU is running, we cannot do anything except stop it when receiving a char */ -vm_stop (RUN_STATE_PAUSED ); +vm_stop (RunState_paused); } else#endif {
@@ -1666,7 +1666,7 @@ static void gdb_chr_event(void *opaque, int event) {switch (event) {case CHR_EVENT_OPENED : -vm_stop (RUN_STATE_PAUSED ); +vm_stop (RunState_paused); gdb_has_xml = false;break ;default :
@@ -1707,7 +1707,7 @@ static int gdb_monitor_write(CharDriverState *chr, const uint8_t *buf, int len)static void gdb_sigterm_handler (int signal) {if (runstate_is_running ()) { -vm_stop (RUN_STATE_PAUSED ); +vm_stop (RunState_paused); } }#endif
hmp.c +40 -40
250 lines not on this page · raw message
hw/acpi/memory_hotplug.c +1 -1
@@ -10,7 +10,7 @@ static ACPIOSTInfo *acpi_memory_device_status(int slot, MemStatus *mdev) {ACPIOSTInfo *info =g_new0 (ACPIOSTInfo,1 ); - info->slot_type =ACPI_SLOT_TYPE_DIMM ; + info->slot_type = ACPISlotType_DIMM; info->slot =g_strdup_printf ("%d" , slot); info->source = mdev->ost_event; info->status = mdev->ost_status;
hw/arm/musicpal.c +1 -1
@@ -374,7 +374,7 @@ static void eth_cleanup(NetClientState *nc) }static NetClientInfo net_mv88w8618_info = { - .type =NET_CLIENT_OPTIONS_KIND_NIC , + .type = NetClientOptionsKind_nic, .size =sizeof (NICState), .receive = eth_receive, .cleanup = eth_cleanup,
hw/block/block.c +1 -1
@@ -71,7 +71,7 @@ void blkconf_geometry(BlockConf *conf, int *ptrans,hd_geometry_guess (conf->blk, &conf->cyls, &conf->heads, &conf->secs, ptrans); - }else if (ptrans && *ptrans ==BIOS_ATA_TRANSLATION_AUTO ) { + }else if (ptrans && *ptrans == BiosAtaTranslation_auto) { *ptrans =hd_bios_chs_auto_trans (conf->cyls, conf->heads, conf->secs); }if (conf->cyls || conf->heads || conf->secs) {
hw/block/fdc.c +2 -2
@@ -2214,11 +2214,11 @@ static void fdctrl_connect_drives(FDCtrl *fdctrl, Error **errp) drive->fdctrl = fdctrl;if (drive->blk) { -if (blk_get_on_error (drive->blk,0 ) !=BLOCKDEV_ON_ERROR_ENOSPC ) { +if (blk_get_on_error (drive->blk,0 ) != BlockdevOnError_enospc) {error_setg (errp,"fdc doesn't support drive option werror" );return ; } -if (blk_get_on_error (drive->blk,1 ) !=BLOCKDEV_ON_ERROR_REPORT ) { +if (blk_get_on_error (drive->blk,1 ) != BlockdevOnError_report) {error_setg (errp,"fdc doesn't support drive option rerror" );return ; }
hw/block/hd-geometry.c +6 -6
@@ -129,7 +129,7 @@ void hd_geometry_guess(BlockBackend *blk, *pcyls = geo.cylinders; *psecs = geo.sectors; *pheads = geo.heads; - translation =BIOS_ATA_TRANSLATION_NONE ; + translation = BiosAtaTranslation_none; }else if (guess_disk_lchs (blk, &cylinders, &heads, &secs) <0 ) {/* no LCHS guess: use a standard physical disk geometry */ guess_chs_for_size (blk, pcyls, pheads, psecs);
@@ -140,8 +140,8 @@ void hd_geometry_guess(BlockBackend *blk,geometry is OK */ guess_chs_for_size (blk, pcyls, pheads, psecs); translation = *pcyls * *pheads <=131072 - ?BIOS_ATA_TRANSLATION_LARGE - :BIOS_ATA_TRANSLATION_LBA ; + ? BiosAtaTranslation_large + : BiosAtaTranslation_lba; }else {/* LCHS guess with heads <= 16: use as physical geometry */ *pcyls = cylinders;
@@ -149,7 +149,7 @@ void hd_geometry_guess(BlockBackend *blk, *psecs = secs;/* disable any translation to be in sync with the logical geometry */ - translation =BIOS_ATA_TRANSLATION_NONE ; + translation = BiosAtaTranslation_none; }if (ptrans) { *ptrans = translation;
@@ -160,6 +160,6 @@ void hd_geometry_guess(BlockBackend *blk,int hd_bios_chs_auto_trans (uint32_t cyls,uint32_t heads,uint32_t secs) {return cyls <=1024 && heads <=16 && secs <=63 - ?BIOS_ATA_TRANSLATION_NONE - :BIOS_ATA_TRANSLATION_LBA ; + ? BiosAtaTranslation_none + : BiosAtaTranslation_lba; }
hw/block/virtio-blk.c +4 -4
@@ -71,17 +71,17 @@ static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error, is_read, error);VirtIOBlock *s = req->dev; -if (action ==BLOCK_ERROR_ACTION_STOP ) { +if (action == BlockErrorAction_stop) { req->next = s->rq; s->rq = req; - }else if (action ==BLOCK_ERROR_ACTION_REPORT ) { + }else if (action == BlockErrorAction_report) {virtio_blk_req_complete (req,VIRTIO_BLK_S_IOERR );block_acct_done (blk_get_stats (s->blk), &req->acct);virtio_blk_free_request (req); }blk_error_action (s->blk, action, is_read, error); -return action !=BLOCK_ERROR_ACTION_IGNORE ; +return action != BlockErrorAction_ignore; }static void virtio_blk_rw_complete (void *opaque,int ret)
@@ -105,7 +105,7 @@ static void virtio_blk_rw_complete(void *opaque, int ret)bool is_read = !(p &VIRTIO_BLK_T_OUT );/* Note that memory may be dirtied on read failure. If the * virtio request is not completed here, as is the case for -* BLOCK_ERROR_ACTION_STOP, the memory may not be copied +* BlockErrorAction_stop, the memory may not be copied * correctly during live migration. While this is ugly, * it is acceptable because the device is free to write to * the memory until the request is completed (which will
hw/char/escc.c +123 -123
268 lines not on this page · raw message
hw/core/qdev-properties-system.c +1 -1
@@ -229,7 +229,7 @@ static void set_netdev(Object *obj, Visitor *v, void *opaque, } queues =qemu_find_net_clients_except (str, peers, -NET_CLIENT_OPTIONS_KIND_NIC , + NetClientOptionsKind_nic,MAX_QUEUE_NUM );if (queues ==0 ) { err = -ENOENT ;
hw/display/qxl.c +2 -2
@@ -963,8 +963,8 @@ static void interface_set_client_capabilities(QXLInstance *sin,return ; } -if (runstate_check (RUN_STATE_INMIGRATE ) || -runstate_check (RUN_STATE_POSTMIGRATE )) { +if (runstate_check (RunState_inmigrate) || +runstate_check (RunState_postmigrate)) {return ; }
hw/i386/kvm/i8254.c +3 -3
@@ -269,9 +269,9 @@ static void kvm_pit_realizefn(DeviceState *dev, Error **errp)return ; }switch (s->lost_tick_policy) { -case LOST_TICK_POLICY_DELAY : +case LostTickPolicy_delay:break ;/* enabled by default */ -case LOST_TICK_POLICY_DISCARD : +case LostTickPolicy_discard:if (kvm_check_extension (kvm_state,KVM_CAP_REINJECT_CONTROL )) {struct kvm_reinject_control control = { .pit_reinject =0 };
@@ -301,7 +301,7 @@ static void kvm_pit_realizefn(DeviceState *dev, Error **errp)static Property kvm_pit_properties[] = {DEFINE_PROP_UINT32 ("iobase" , PITCommonState, iobase,-1 ),DEFINE_PROP_LOSTTICKPOLICY ("lost_tick_policy" , KVMPITState, - lost_tick_policy,LOST_TICK_POLICY_DELAY ), + lost_tick_policy, LostTickPolicy_delay),DEFINE_PROP_END_OF_LIST (), };
hw/i386/pc.c +5 -5
@@ -1795,7 +1795,7 @@ static void pc_machine_set_max_ram_below_4g(Object *obj, Visitor *v,return ; }if (value > (1ULL <<32 )) { -error_set (&error,ERROR_CLASS_GENERIC_ERROR , +error_set (&error, ErrorClass_GenericError,"Machine option 'max-ram-below-4g=%" PRIu64"' expects size less than or equal to 4G" , value);error_propagate (errp, error);
@@ -1832,7 +1832,7 @@ bool pc_machine_is_smm_enabled(PCMachineState *pcms) {bool smm_available = false; -if (pcms->smm ==ON_OFF_AUTO_OFF ) { +if (pcms->smm == OnOffAuto_off) {return false; }
@@ -1846,7 +1846,7 @@ bool pc_machine_is_smm_enabled(PCMachineState *pcms)return true; } -if (pcms->smm ==ON_OFF_AUTO_ON ) { +if (pcms->smm == OnOffAuto_on) {error_report ("System Management Mode not supported by this hypervisor." );exit (1 ); }
@@ -1894,7 +1894,7 @@ static void pc_machine_initfn(Object *obj)"Maximum ram below the 4G boundary (32bit boundary)" , &error_abort); - pcms->smm =ON_OFF_AUTO_AUTO ; + pcms->smm = OnOffAuto_auto; object_property_add(obj, PC_MACHINE_SMM, "OnOffAuto", pc_machine_get_smm, pc_machine_set_smm,
@@ -1903,7 +1903,7 @@ static void pc_machine_initfn(Object *obj)"Enable SMM (pc & q35)" , &error_abort); - pcms->vmport =ON_OFF_AUTO_AUTO ; + pcms->vmport = OnOffAuto_auto; object_property_add(obj, PC_MACHINE_VMPORT, "OnOffAuto", pc_machine_get_vmport, pc_machine_set_vmport,
hw/i386/pc_piix.c +5 -5
@@ -225,14 +225,14 @@ static void pc_init1(MachineState *machine,pc_vga_init (isa_bus, pci_enabled ? pci_bus :NULL ); -assert (pcms->vmport !=ON_OFF_AUTO_MAX ); -if (pcms->vmport ==ON_OFF_AUTO_AUTO ) { - pcms->vmport =xen_enabled () ?ON_OFF_AUTO_OFF :ON_OFF_AUTO_ON ; +assert (pcms->vmport != OnOffAuto_MAX); +if (pcms->vmport == OnOffAuto_auto) { + pcms->vmport =xen_enabled () ? OnOffAuto_off : OnOffAuto_on; }/* init basic PC hardware */ pc_basic_device_init (isa_bus, gsi, &rtc_state, true, - (pcms->vmport !=ON_OFF_AUTO_ON ),0x4 ); + (pcms->vmport != OnOffAuto_on),0x4 );pc_nic_init (isa_bus, pci_bus);
@@ -306,7 +306,7 @@ static void pc_compat_2_3(MachineState *machine)PCMachineState *pcms =PC_MACHINE (machine);savevm_skip_section_footers ();if (kvm_enabled ()) { - pcms->smm =ON_OFF_AUTO_OFF ; + pcms->smm = OnOffAuto_off; }global_state_set_optional ();savevm_skip_configuration ();
hw/i386/pc_q35.c +5 -5
@@ -233,14 +233,14 @@ static void pc_q35_init(MachineState *machine)pc_register_ferr_irq (gsi[13 ]); -assert (pcms->vmport !=ON_OFF_AUTO_MAX ); -if (pcms->vmport ==ON_OFF_AUTO_AUTO ) { - pcms->vmport =xen_enabled () ?ON_OFF_AUTO_OFF :ON_OFF_AUTO_ON ; +assert (pcms->vmport != OnOffAuto_MAX); +if (pcms->vmport == OnOffAuto_auto) { + pcms->vmport =xen_enabled () ? OnOffAuto_off : OnOffAuto_on; }/* init basic PC hardware */ pc_basic_device_init (isa_bus, gsi, &rtc_state, !mc->no_floppy, - (pcms->vmport !=ON_OFF_AUTO_ON ),0xff0104 ); + (pcms->vmport != OnOffAuto_on),0xff0104 );/* connect pm stuff to lpc */ ich9_lpc_pm_init (lpc,pc_machine_is_smm_enabled (pcms), !mc->no_tco);
@@ -289,7 +289,7 @@ static void pc_compat_2_3(MachineState *machine)PCMachineState *pcms =PC_MACHINE (machine);savevm_skip_section_footers ();if (kvm_enabled ()) { - pcms->smm =ON_OFF_AUTO_OFF ; + pcms->smm = OnOffAuto_off; }global_state_set_optional ();savevm_skip_configuration ();
hw/ide/ahci.c +2 -2
@@ -938,10 +938,10 @@ static void ncq_cb(void *opaque, int ret)bool is_read = ncq_tfs->cmd ==READ_FPDMA_QUEUED ;BlockErrorAction action =blk_get_error_action (ide_state->blk, is_read, -ret); -if (action ==BLOCK_ERROR_ACTION_STOP ) { +if (action == BlockErrorAction_stop) { ncq_tfs->halt = true; ide_state->bus->error_status =IDE_RETRY_HBA ; - }else if (action ==BLOCK_ERROR_ACTION_REPORT ) { + }else if (action == BlockErrorAction_report) {ncq_err (ncq_tfs); }blk_error_action (ide_state->blk, action, is_read, -ret);
hw/ide/core.c +3 -3
@@ -668,10 +668,10 @@ static int ide_handle_rw_error(IDEState *s, int error, int op)bool is_read = (op &IDE_RETRY_READ ) !=0 ;BlockErrorAction action =blk_get_error_action (s->blk, is_read, error); -if (action ==BLOCK_ERROR_ACTION_STOP ) { +if (action == BlockErrorAction_stop) {assert (s->bus->retry_unit == s->unit); s->bus->error_status = op; - }else if (action ==BLOCK_ERROR_ACTION_REPORT ) { + }else if (action == BlockErrorAction_report) {if (op &IDE_RETRY_DMA ) {ide_dma_error (s); }else {
@@ -679,7 +679,7 @@ static int ide_handle_rw_error(IDEState *s, int error, int op) } }blk_error_action (s->blk, action, is_read, error); -return action !=BLOCK_ERROR_ACTION_IGNORE ; +return action != BlockErrorAction_ignore; }static void ide_dma_cb (void *opaque,int ret)
hw/ide/qdev.c +1 -1
@@ -271,7 +271,7 @@ static Property ide_hd_properties[] = {DEFINE_IDE_DEV_PROPERTIES (),DEFINE_BLOCK_CHS_PROPERTIES (IDEDrive, dev.conf),DEFINE_PROP_BIOS_CHS_TRANS ("bios-chs-trans" , - IDEDrive, dev.chs_trans,BIOS_ATA_TRANSLATION_AUTO ), + IDEDrive, dev.chs_trans, BiosAtaTranslation_auto), DEFINE_PROP_END_OF_LIST(), };
hw/input/hid.c +13 -13
@@ -108,10 +108,10 @@ void hid_set_next_idle(HIDState *hs)static void hid_pointer_event (DeviceState *dev,QemuConsole *src,InputEvent *evt) { -static const int bmap[INPUT_BUTTON_MAX ] = { - [INPUT_BUTTON_LEFT ] =0x01 , - [INPUT_BUTTON_RIGHT ] =0x02 , - [INPUT_BUTTON_MIDDLE ] =0x04 , +static const int bmap[InputButton_MAX] = { + [InputButton_Left] =0x01 , + [InputButton_Right] =0x02 , + [InputButton_Middle] =0x04 , };HIDState *hs = (HIDState *)dev;HIDPointerEvent *e;
@@ -120,28 +120,28 @@ static void hid_pointer_event(DeviceState *dev, QemuConsole *src, e = &hs->ptr.queue[(hs->head + hs->n) &QUEUE_MASK ];switch (evt->type) { -case INPUT_EVENT_KIND_REL : -if (evt->u.rel->axis ==INPUT_AXIS_X ) { +case InputEventKind_rel: +if (evt->u.rel->axis == InputAxis_X) { e->xdx += evt->u.rel->value; - }else if (evt->u.rel->axis ==INPUT_AXIS_Y ) { + }else if (evt->u.rel->axis == InputAxis_Y) { e->ydy += evt->u.rel->value; }break ; -case INPUT_EVENT_KIND_ABS : -if (evt->u.rel->axis ==INPUT_AXIS_X ) { +case InputEventKind_abs: +if (evt->u.rel->axis == InputAxis_X) { e->xdx = evt->u.rel->value; - }else if (evt->u.rel->axis ==INPUT_AXIS_Y ) { + }else if (evt->u.rel->axis == InputAxis_Y) { e->ydy = evt->u.rel->value; }break ; -case INPUT_EVENT_KIND_BTN : +case InputEventKind_btn:if (evt->u.btn->down) { e->buttons_state |= bmap[evt->u.btn->button]; -if (evt->u.btn->button ==INPUT_BUTTON_WHEEL_UP ) { +if (evt->u.btn->button == InputButton_WheelUp) { e->dz--; - }else if (evt->u.btn->button ==INPUT_BUTTON_WHEEL_DOWN ) { + }else if (evt->u.btn->button == InputButton_WheelDown) { e->dz++; } }else {
hw/input/ps2.c +10 -10
@@ -382,10 +382,10 @@ static void ps2_mouse_send_packet(PS2MouseState *s)static void ps2_mouse_event (DeviceState *dev,QemuConsole *src,InputEvent *evt) { -static const int bmap[INPUT_BUTTON_MAX ] = { - [INPUT_BUTTON_LEFT ] =MOUSE_EVENT_LBUTTON , - [INPUT_BUTTON_MIDDLE ] =MOUSE_EVENT_MBUTTON , - [INPUT_BUTTON_RIGHT ] =MOUSE_EVENT_RBUTTON , +static const int bmap[InputButton_MAX] = { + [InputButton_Left] =MOUSE_EVENT_LBUTTON , + [InputButton_Middle] =MOUSE_EVENT_MBUTTON , + [InputButton_Right] =MOUSE_EVENT_RBUTTON , };PS2MouseState *s = (PS2MouseState *)dev;
@@ -394,20 +394,20 @@ static void ps2_mouse_event(DeviceState *dev, QemuConsole *src,return ;switch (evt->type) { -case INPUT_EVENT_KIND_REL : -if (evt->u.rel->axis ==INPUT_AXIS_X ) { +case InputEventKind_rel: +if (evt->u.rel->axis == InputAxis_X) { s->mouse_dx += evt->u.rel->value; - }else if (evt->u.rel->axis ==INPUT_AXIS_Y ) { + }else if (evt->u.rel->axis == InputAxis_Y) { s->mouse_dy -= evt->u.rel->value; }break ; -case INPUT_EVENT_KIND_BTN : +case InputEventKind_btn:if (evt->u.btn->down) { s->mouse_buttons |= bmap[evt->u.btn->button]; -if (evt->u.btn->button ==INPUT_BUTTON_WHEEL_UP ) { +if (evt->u.btn->button == InputButton_WheelUp) { s->mouse_dz--; - }else if (evt->u.btn->button ==INPUT_BUTTON_WHEEL_DOWN ) { + }else if (evt->u.btn->button == InputButton_WheelDown) { s->mouse_dz++; } }else {
hw/input/virtio-input-hid.c +121 -121
287 lines not on this page · raw message
hw/mem/pc-dimm.c +1 -1
@@ -204,7 +204,7 @@ ram_addr_t get_current_ram_size(void)if (value) {switch (value->type) { -case MEMORY_DEVICE_INFO_KIND_DIMM : +case MemoryDeviceInfoKind_dimm: size += value->u.dimm->size;break ;default :
hw/net/allwinner_emac.c +1 -1
@@ -422,7 +422,7 @@ static const MemoryRegionOps aw_emac_mem_ops = { };static NetClientInfo net_aw_emac_info = { - .type =NET_CLIENT_OPTIONS_KIND_NIC , + .type = NetClientOptionsKind_nic, .size =sizeof (NICState), .can_receive = aw_emac_can_receive, .receive = aw_emac_receive,
hw/net/cadence_gem.c +1 -1
@@ -1181,7 +1181,7 @@ static void gem_set_link(NetClientState *nc) }static NetClientInfo net_gem_info = { - .type =NET_CLIENT_OPTIONS_KIND_NIC , + .type = NetClientOptionsKind_nic, .size =sizeof (NICState), .can_receive = gem_can_receive, .receive = gem_receive,
hw/net/dp8393x.c +1 -1
@@ -810,7 +810,7 @@ static void dp8393x_reset(DeviceState *dev) }static NetClientInfo net_dp83932_info = { - .type =NET_CLIENT_OPTIONS_KIND_NIC , + .type = NetClientOptionsKind_nic, .size =sizeof (NICState), .can_receive = dp8393x_can_receive, .receive = dp8393x_receive,
hw/net/e1000.c +1 -1
@@ -1516,7 +1516,7 @@ pci_e1000_uninit(PCIDevice *dev) }static NetClientInfo net_e1000_info = { - .type =NET_CLIENT_OPTIONS_KIND_NIC , + .type = NetClientOptionsKind_nic, .size =sizeof (NICState), .can_receive = e1000_can_receive, .receive = e1000_receive,
hw/net/eepro100.c +1 -1
@@ -1832,7 +1832,7 @@ static void pci_nic_uninit(PCIDevice *pci_dev) }static NetClientInfo net_eepro100_info = { - .type =NET_CLIENT_OPTIONS_KIND_NIC , + .type = NetClientOptionsKind_nic, .size =sizeof (NICState), .receive = nic_receive, };
hw/net/etraxfs_eth.c +1 -1
@@ -577,7 +577,7 @@ static const MemoryRegionOps eth_ops = { };static NetClientInfo net_etraxfs_info = { - .type =NET_CLIENT_OPTIONS_KIND_NIC , + .type = NetClientOptionsKind_nic, .size =sizeof (NICState), .receive = eth_receive, .link_status_changed = eth_set_link,
hw/net/fsl_etsec/etsec.c +1 -1
@@ -369,7 +369,7 @@ static void etsec_set_link_status(NetClientState *nc) }static NetClientInfo net_etsec_info = { - .type =NET_CLIENT_OPTIONS_KIND_NIC , + .type = NetClientOptionsKind_nic, .size =sizeof (NICState), .receive = etsec_receive, .link_status_changed = etsec_set_link_status,
hw/net/imx_fec.c +1 -1
@@ -651,7 +651,7 @@ static void imx_fec_cleanup(NetClientState *nc) }static NetClientInfo net_imx_fec_info = { - .type =NET_CLIENT_OPTIONS_KIND_NIC , + .type = NetClientOptionsKind_nic, .size =sizeof (NICState), .can_receive = imx_fec_can_receive, .receive = imx_fec_receive,
hw/net/lan9118.c +1 -1
@@ -1305,7 +1305,7 @@ static const MemoryRegionOps lan9118_16bit_mem_ops = { };static NetClientInfo net_lan9118_info = { - .type =NET_CLIENT_OPTIONS_KIND_NIC , + .type = NetClientOptionsKind_nic, .size =sizeof (NICState), .receive = lan9118_receive, .link_status_changed = lan9118_set_link,
hw/net/lance.c +1 -1
@@ -92,7 +92,7 @@ static const MemoryRegionOps lance_mem_ops = { };static NetClientInfo net_lance_info = { - .type =NET_CLIENT_OPTIONS_KIND_NIC , + .type = NetClientOptionsKind_nic, .size =sizeof (NICState), .receive = pcnet_receive, .link_status_changed = pcnet_set_link_status,
hw/net/mcf_fec.c +1 -1
@@ -506,7 +506,7 @@ static const MemoryRegionOps mcf_fec_ops = { };static NetClientInfo net_mcf_fec_info = { - .type =NET_CLIENT_OPTIONS_KIND_NIC , + .type = NetClientOptionsKind_nic, .size =sizeof (NICState), .receive = mcf_fec_receive, };
hw/net/milkymist-minimac2.c +1 -1
@@ -443,7 +443,7 @@ static void milkymist_minimac2_reset(DeviceState *d) }static NetClientInfo net_milkymist_minimac2_info = { - .type =NET_CLIENT_OPTIONS_KIND_NIC , + .type = NetClientOptionsKind_nic, .size =sizeof (NICState), .receive = minimac2_rx, };
hw/net/mipsnet.c +1 -1
@@ -218,7 +218,7 @@ static const VMStateDescription vmstate_mipsnet = { };static NetClientInfo net_mipsnet_info = { - .type =NET_CLIENT_OPTIONS_KIND_NIC , + .type = NetClientOptionsKind_nic, .size =sizeof (NICState), .receive = mipsnet_receive, };
hw/net/ne2000-isa.c +1 -1
@@ -42,7 +42,7 @@ typedef struct ISANE2000State { } ISANE2000State;static NetClientInfo net_ne2000_isa_info = { - .type =NET_CLIENT_OPTIONS_KIND_NIC , + .type = NetClientOptionsKind_nic, .size =sizeof (NICState), .receive = ne2000_receive, };
hw/net/ne2000.c +1 -1
@@ -705,7 +705,7 @@ void ne2000_setup_io(NE2000State *s, DeviceState *dev, unsigned size) }static NetClientInfo net_ne2000_info = { - .type =NET_CLIENT_OPTIONS_KIND_NIC , + .type = NetClientOptionsKind_nic, .size =sizeof (NICState), .receive = ne2000_receive, };
hw/net/opencores_eth.c +1 -1
@@ -473,7 +473,7 @@ static ssize_t open_eth_receive(NetClientState *nc, }static NetClientInfo net_open_eth_info = { - .type =NET_CLIENT_OPTIONS_KIND_NIC , + .type = NetClientOptionsKind_nic, .size =sizeof (NICState), .can_receive = open_eth_can_receive, .receive = open_eth_receive,
hw/net/pcnet-pci.c +1 -1
@@ -271,7 +271,7 @@ static void pci_pcnet_uninit(PCIDevice *dev) }static NetClientInfo net_pci_pcnet_info = { - .type =NET_CLIENT_OPTIONS_KIND_NIC , + .type = NetClientOptionsKind_nic, .size =sizeof (NICState), .receive = pcnet_receive, .link_status_changed = pcnet_set_link_status,
hw/net/rocker/rocker.c +2 -2
@@ -101,7 +101,7 @@ RockerSwitch *qmp_query_rocker(const char *name, Error **errp) r =rocker_find (name);if (!r) { -error_set (errp,ERROR_CLASS_GENERIC_ERROR , +error_set (errp, ErrorClass_GenericError,"rocker %s not found" , name);return NULL ; }
@@ -122,7 +122,7 @@ RockerPortList *qmp_query_rocker_ports(const char *name, Error **errp) r =rocker_find (name);if (!r) { -error_set (errp,ERROR_CLASS_GENERIC_ERROR , +error_set (errp, ErrorClass_GenericError,"rocker %s not found" , name);return NULL ; }
hw/net/rocker/rocker_fp.c +1 -1
@@ -166,7 +166,7 @@ static void fp_port_set_link_status(NetClientState *nc) }static NetClientInfo fp_port_info = { - .type =NET_CLIENT_OPTIONS_KIND_NIC , + .type = NetClientOptionsKind_nic, .size =sizeof (NICState), .receive = fp_port_receive, .receive_iov = fp_port_receive_iov,
hw/net/rocker/rocker_of_dpa.c +4 -4
@@ -2462,14 +2462,14 @@ RockerOfDpaFlowList *qmp_query_rocker_of_dpa_flows(const char *name, r =rocker_find (name);if (!r) { -error_set (errp,ERROR_CLASS_GENERIC_ERROR , +error_set (errp, ErrorClass_GenericError,"rocker %s not found" , name);return NULL ; } w =rocker_get_world (r,ROCKER_WORLD_TYPE_OF_DPA );if (!w) { -error_set (errp,ERROR_CLASS_GENERIC_ERROR , +error_set (errp, ErrorClass_GenericError,"rocker %s doesn't have OF-DPA world" , name);return NULL ; }
@@ -2597,14 +2597,14 @@ RockerOfDpaGroupList *qmp_query_rocker_of_dpa_groups(const char *name, r =rocker_find (name);if (!r) { -error_set (errp,ERROR_CLASS_GENERIC_ERROR , +error_set (errp, ErrorClass_GenericError,"rocker %s not found" , name);return NULL ; } w =rocker_get_world (r,ROCKER_WORLD_TYPE_OF_DPA );if (!w) { -error_set (errp,ERROR_CLASS_GENERIC_ERROR , +error_set (errp, ErrorClass_GenericError,"rocker %s doesn't have OF-DPA world" , name);return NULL ; }
hw/net/rtl8139.c +1 -1
@@ -3411,7 +3411,7 @@ static void rtl8139_set_link_status(NetClientState *nc) }static NetClientInfo net_rtl8139_info = { - .type =NET_CLIENT_OPTIONS_KIND_NIC , + .type = NetClientOptionsKind_nic, .size =sizeof (NICState), .can_receive = rtl8139_can_receive, .receive = rtl8139_receive,
hw/net/smc91c111.c +1 -1
@@ -754,7 +754,7 @@ static const MemoryRegionOps smc91c111_mem_ops = { };static NetClientInfo net_smc91c111_info = { - .type =NET_CLIENT_OPTIONS_KIND_NIC , + .type = NetClientOptionsKind_nic, .size =sizeof (NICState), .can_receive = smc91c111_can_receive_nc, .receive = smc91c111_receive,
hw/net/spapr_llan.c +1 -1
@@ -188,7 +188,7 @@ static ssize_t spapr_vlan_receive(NetClientState *nc, const uint8_t *buf, }static NetClientInfo net_spapr_vlan_info = { - .type =NET_CLIENT_OPTIONS_KIND_NIC , + .type = NetClientOptionsKind_nic, .size =sizeof (NICState), .can_receive = spapr_vlan_can_receive, .receive = spapr_vlan_receive,
hw/net/stellaris_enet.c +1 -1
@@ -449,7 +449,7 @@ static void stellaris_enet_reset(stellaris_enet_state *s) }static NetClientInfo net_stellaris_enet_info = { - .type =NET_CLIENT_OPTIONS_KIND_NIC , + .type = NetClientOptionsKind_nic, .size =sizeof (NICState), .receive = stellaris_enet_receive, };
hw/net/vhost_net.c +9 -9
@@ -97,10 +97,10 @@ static const int *vhost_net_get_feature_bits(struct vhost_net *net)const int *feature_bits =0 ;switch (net->nc->info->type) { -case NET_CLIENT_OPTIONS_KIND_TAP : +case NetClientOptionsKind_tap: feature_bits = kernel_feature_bits;break ; -case NET_CLIENT_OPTIONS_KIND_VHOST_USER : +case NetClientOptionsKind_vhost_user: feature_bits = user_feature_bits;break ;default :
@@ -132,7 +132,7 @@ uint64_t vhost_net_get_max_queues(VHostNetState *net)static int vhost_net_get_fd (NetClientState *backend) {switch (backend->info->type) { -case NET_CLIENT_OPTIONS_KIND_TAP : +case NetClientOptionsKind_tap:return tap_get_fd (backend);default :fprintf (stderr,"vhost-net requires tap backend\n" );
@@ -249,7 +249,7 @@ static int vhost_net_start_one(struct vhost_net *net, net->nc->info->poll (net->nc, false); } -if (net->nc->info->type ==NET_CLIENT_OPTIONS_KIND_TAP ) { +if (net->nc->info->type == NetClientOptionsKind_tap) {qemu_set_fd_handler (net->backend,NULL ,NULL ,NULL ); file.fd = net->backend;for (file.index =0 ; file.index < net->dev.nvqs; ++file.index) {
@@ -264,7 +264,7 @@ static int vhost_net_start_one(struct vhost_net *net,return 0 ; fail: file.fd =-1 ; -if (net->nc->info->type ==NET_CLIENT_OPTIONS_KIND_TAP ) { +if (net->nc->info->type == NetClientOptionsKind_tap) {while (file.index-- >0 ) {const VhostOps *vhost_ops = net->dev.vhost_ops;int r = vhost_ops->vhost_net_set_backend (&net->dev, &file);
@@ -286,13 +286,13 @@ static void vhost_net_stop_one(struct vhost_net *net, {struct vhost_vring_file file = { .fd =-1 }; -if (net->nc->info->type ==NET_CLIENT_OPTIONS_KIND_TAP ) { +if (net->nc->info->type == NetClientOptionsKind_tap) {for (file.index =0 ; file.index < net->dev.nvqs; ++file.index) {const VhostOps *vhost_ops = net->dev.vhost_ops;int r = vhost_ops->vhost_net_set_backend (&net->dev, &file);assert (r >=0 ); } - }else if (net->nc->info->type ==NET_CLIENT_OPTIONS_KIND_VHOST_USER ) { + }else if (net->nc->info->type == NetClientOptionsKind_vhost_user) {for (file.index =0 ; file.index < net->dev.nvqs; ++file.index) {const VhostOps *vhost_ops = net->dev.vhost_ops;int r = vhost_ops->vhost_reset_device (&net->dev);
@@ -420,10 +420,10 @@ VHostNetState *get_vhost_net(NetClientState *nc) }switch (nc->info->type) { -case NET_CLIENT_OPTIONS_KIND_TAP : +case NetClientOptionsKind_tap: vhost_net =tap_get_vhost_net (nc);break ; -case NET_CLIENT_OPTIONS_KIND_VHOST_USER : +case NetClientOptionsKind_vhost_user: vhost_net =vhost_user_get_vhost_net (nc);break ;default :
hw/net/virtio-net.c +14 -14
@@ -264,19 +264,19 @@ static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc) info->promiscuous = n->promisc;if (n->nouni) { - info->unicast =RX_STATE_NONE ; + info->unicast = RxState_none; }else if (n->alluni) { - info->unicast =RX_STATE_ALL ; + info->unicast = RxState_all; }else { - info->unicast =RX_STATE_NORMAL ; + info->unicast = RxState_normal; }if (n->nomulti) { - info->multicast =RX_STATE_NONE ; + info->multicast = RxState_none; }else if (n->allmulti) { - info->multicast =RX_STATE_ALL ; + info->multicast = RxState_all; }else { - info->multicast =RX_STATE_NORMAL ; + info->multicast = RxState_normal; } info->broadcast_allowed = n->nobcast;
@@ -305,11 +305,11 @@ static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc) info->vlan_table =get_vlan_table (n);if (!virtio_vdev_has_feature (vdev,VIRTIO_NET_F_CTRL_VLAN )) { - info->vlan =RX_STATE_ALL ; + info->vlan = RxState_all; }else if (!info->vlan_table) { - info->vlan =RX_STATE_NONE ; + info->vlan = RxState_none; }else { - info->vlan =RX_STATE_NORMAL ; + info->vlan = RxState_normal; }/* enable event notification after query */
@@ -406,11 +406,11 @@ static int peer_attach(VirtIONet *n, int index)return 0 ; } -if (nc->peer->info->type ==NET_CLIENT_OPTIONS_KIND_VHOST_USER ) { +if (nc->peer->info->type == NetClientOptionsKind_vhost_user) {vhost_set_vring_enable (nc->peer,1 ); } -if (nc->peer->info->type !=NET_CLIENT_OPTIONS_KIND_TAP ) { +if (nc->peer->info->type != NetClientOptionsKind_tap) {return 0 ; }
@@ -425,11 +425,11 @@ static int peer_detach(VirtIONet *n, int index)return 0 ; } -if (nc->peer->info->type ==NET_CLIENT_OPTIONS_KIND_VHOST_USER ) { +if (nc->peer->info->type == NetClientOptionsKind_vhost_user) {vhost_set_vring_enable (nc->peer,0 ); } -if (nc->peer->info->type !=NET_CLIENT_OPTIONS_KIND_TAP ) { +if (nc->peer->info->type != NetClientOptionsKind_tap) {return 0 ; }
@@ -1604,7 +1604,7 @@ static int virtio_net_load_device(VirtIODevice *vdev, QEMUFile *f, }static NetClientInfo net_virtio_info = { - .type =NET_CLIENT_OPTIONS_KIND_NIC , + .type = NetClientOptionsKind_nic, .size =sizeof (NICState), .can_receive = virtio_net_can_receive, .receive = virtio_net_receive,
hw/net/vmxnet3.c +1 -1
@@ -2001,7 +2001,7 @@ static void vmxnet3_set_link_status(NetClientState *nc) }static NetClientInfo net_vmxnet3_info = { - .type =NET_CLIENT_OPTIONS_KIND_NIC , + .type = NetClientOptionsKind_nic, .size =sizeof (NICState), .receive = vmxnet3_receive, .link_status_changed = vmxnet3_set_link_status,
hw/net/xen_nic.c +1 -1
@@ -279,7 +279,7 @@ static ssize_t net_rx_packet(NetClientState *nc, const uint8_t *buf, size_t size/* ------------------------------------------------------------- */ static NetClientInfo net_xen_info = { - .type =NET_CLIENT_OPTIONS_KIND_NIC , + .type = NetClientOptionsKind_nic, .size =sizeof (NICState), .receive = net_rx_packet, };
hw/net/xgmac.c +1 -1
@@ -370,7 +370,7 @@ out: }static NetClientInfo net_xgmac_enet_info = { - .type =NET_CLIENT_OPTIONS_KIND_NIC , + .type = NetClientOptionsKind_nic, .size =sizeof (NICState), .receive = eth_rx, };
hw/net/xilinx_axienet.c +1 -1
@@ -933,7 +933,7 @@ xilinx_axienet_data_stream_push(StreamSlave *obj, uint8_t *buf, size_t size) }static NetClientInfo net_xilinx_enet_info = { - .type =NET_CLIENT_OPTIONS_KIND_NIC , + .type = NetClientOptionsKind_nic, .size =sizeof (NICState), .receive = eth_rx, };
hw/net/xilinx_ethlite.c +1 -1
@@ -214,7 +214,7 @@ static void xilinx_ethlite_reset(DeviceState *dev) }static NetClientInfo net_xilinx_ethlite_info = { - .type =NET_CLIENT_OPTIONS_KIND_NIC , + .type = NetClientOptionsKind_nic, .size =sizeof (NICState), .can_receive = eth_can_rx, .receive = eth_rx,
hw/ppc/spapr_rtas.c +1 -1
@@ -297,7 +297,7 @@ static void rtas_ibm_os_term(PowerPCCPU *cpu, {target_ulong ret =0 ; -qapi_event_send_guest_panicked (GUEST_PANIC_ACTION_PAUSE , &error_abort); +qapi_event_send_guest_panicked (GuestPanicAction_pause, &error_abort);rtas_st (rets,0 , ret); }
hw/scsi/scsi-disk.c +3 -3
@@ -414,7 +414,7 @@ static int scsi_handle_rw_error(SCSIDiskReq *r, int error)BlockErrorAction action =blk_get_error_action (s->qdev.conf.blk, is_read, error); -if (action ==BLOCK_ERROR_ACTION_REPORT ) { +if (action == BlockErrorAction_report) {switch (error) {case ENOMEDIUM :scsi_check_condition (r,SENSE_CODE (NO_MEDIUM ));
@@ -434,10 +434,10 @@ static int scsi_handle_rw_error(SCSIDiskReq *r, int error) } }blk_error_action (s->qdev.conf.blk, action, is_read, error); -if (action ==BLOCK_ERROR_ACTION_STOP ) { +if (action == BlockErrorAction_stop) {scsi_req_retry (&r->req); } -return action !=BLOCK_ERROR_ACTION_IGNORE ; +return action != BlockErrorAction_ignore; }static void scsi_write_complete_noio (SCSIDiskReq *r,int ret)
hw/scsi/scsi-generic.c +2 -2
@@ -407,11 +407,11 @@ static void scsi_generic_realize(SCSIDevice *s, Error **errp)return ; } -if (blk_get_on_error (s->conf.blk,0 ) !=BLOCKDEV_ON_ERROR_ENOSPC ) { +if (blk_get_on_error (s->conf.blk,0 ) != BlockdevOnError_enospc) {error_setg (errp,"Device doesn't support drive option werror" );return ; } -if (blk_get_on_error (s->conf.blk,1 ) !=BLOCKDEV_ON_ERROR_REPORT ) { +if (blk_get_on_error (s->conf.blk,1 ) != BlockdevOnError_report) {error_setg (errp,"Device doesn't support drive option rerror" );return ; }
hw/timer/mc146818rtc.c +7 -7
@@ -187,7 +187,7 @@ static void rtc_periodic_timer(void *opaque)if (s->cmos_data[RTC_REG_B ] ®_B_PIE ) { s->cmos_data[RTC_REG_C ] |=REG_C_IRQF ;#ifdef TARGET_I386 -if (s->lost_tick_policy ==LOST_TICK_POLICY_SLEW ) { +if (s->lost_tick_policy == LostTickPolicy_slew) {if (s->irq_reinject_on_ack_count >=RTC_REINJECT_ON_ACK_COUNT ) s->irq_reinject_on_ack_count =0 ;apic_reset_irq_delivered ();
@@ -732,7 +732,7 @@ static int rtc_post_load(void *opaque, int version_id)#ifdef TARGET_I386 if (version_id >=2 ) { -if (s->lost_tick_policy ==LOST_TICK_POLICY_SLEW ) { +if (s->lost_tick_policy == LostTickPolicy_slew) {rtc_coalesced_timer_update (s); }
Lines of this file are not shown. View the raw message.
migration/migration.c +85 -85
170 lines not on this page · raw message
monitor.c +31 -31
62 lines not on this page · raw message
net/net.c +39 -39
78 lines not on this page · raw message
qemu-char.c +27 -27
54 lines not on this page · raw message
qga/commands-win32.c +22 -22
44 lines not on this page · raw message
scripts/qapi.py +6 -42
48 lines not on this page · raw message
tests/qapi-schema/enum-clash-member.err +1 -1
Lines of this file are not shown. View the raw message.
tests/qapi-schema/enum-clash-member.json +1 -1
Lines of this file are not shown. View the raw message.
tests/qapi-schema/union-bad-branch.json +2 -2
Lines of this file are not shown. View the raw message.
tests/test-qmp-input-visitor.c +33 -33
66 lines not on this page · raw message
tests/test-qmp-output-visitor.c +42 -42
84 lines not on this page · raw message
ui/input-keymap.c +137 -137
274 lines not on this page · raw message
ui/input.c +28 -28
56 lines not on this page · raw message
ui/sdl2-keymap.h +240 -240
480 lines not on this page · raw message
ui/vnc.c +42 -42
84 lines not on this page · raw message
vl.c +83 -83
166 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.4.3
Part of the diff is not shown here. View the raw message.
Re: [Qemu-devel] [PATCH RFC 3/5] qapi: Use common name mangling for enumeration constants
Quoted 33 lines · Markus Armbruster
QAPI names needn't be valid C identifiers, so we mangle them with
c_name(). Except for enumeration constants, which we mangle withcamel_to_upper().
c_name()is easy enough to understand: replace '.' and '-' by '_', prefix certain ticklish identifiers with 'q_'.
camel_to_upper()is a hairball of heuristics, and guessing how it'll mangle interesting input could serve as a (nerdy) game. Despite some tweaking (commit 5d371f4), it's still inadqeuate for some QAPI names (commit 351d36e).Example: QAPI definition
{ 'enum': 'BlockDeviceIoStatus', 'data': [ 'ok', 'failed', 'nospace' ] }generates
typedef enum BlockDeviceIoStatus {
BLOCK_DEVICE_IO_STATUS_OK= 0,
BLOCK_DEVICE_IO_STATUS_FAILED= 1,
BLOCK_DEVICE_IO_STATUS_NOSPACE= 2,
BLOCK_DEVICE_IO_STATUS_MAX= 3,
} BlockDeviceIoStatus;Observe that
c_name()maps BlockDeviceIoStatus to itself, andcamel_to_upper()maps it toBLOCK_DEVICE_IO_STATUS, i.e. the enumeration constants are shouted, the enumeration type isn't.Because mangled names must not clash, name mangling restricts the names you can use. For example, you can't have member 'a-b' and '
a_b'.
Quoted 6 lines
Having two separate manglings complicates this. Enumeration constants must be distinct after mangling with
camel_to_upper(). But as soon as you use the enumeration as union tag, they must *also* be distinct after mangling withc_name().Having shouted enumeration constants isn't worth the complexity cost.
I rather disagree with this. Having all-uppercase for enum constants is a really widely used convention and I think it is pretty useful when reading to code to have constants (whether #define/enum) clearly marked in uppercase. After this change we'll have situation where QAPI enums uses CamelCase, while all other non-QAPI enums (whether defined in QEMU source, or via #included 3rd party headers use UPPER_CASE for constants. I think that's rather unpleasant.
I agree with your premise that predicting the output of the qapi name mangler though is essentially impossible for mortals. How about a counter proposal....
First make 'prefix' compulsory for enums, instead of trying to figure out a suitable prefix automatically. Then, have a very simple rule for the enum constants where you just uppercase a-z and translate any non-alpha-numeric character into a _. Don't try todo anything else special like figuring out word boundaries.
That would get of much of the complexity in the qapi name mangler and give a easily predictable enum constant name. Thus the vast majority of .c source files (possibly even all of them) would not need any change.
Regards,
Daniel
Signature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Re: [Qemu-devel] [PATCH RFC 3/5] qapi: Use common name mangling for enumeration constants
Quoted 5 lines · Daniel P. Berrange
Quoted 4 lines · Markus Armbruster
QAPI names needn't be valid C identifiers, so we mangle them with
c_name(). Except for enumeration constants, which we mangle withcamel_to_upper().
Quoted 7 lines
Quoted 7 lines
c_name()is easy enough to understand: replace '.' and '-' by '_', prefix certain ticklish identifiers with 'q_'.
camel_to_upper()is a hairball of heuristics, and guessing how it'll mangle interesting input could serve as a (nerdy) game. Despite some tweaking (commit 5d371f4), it's still inadqeuate for some QAPI names (commit 351d36e).
One of the issues at hand is whether we want to (eventually) teach QMP to be case-insensitive. Right now, our c_name() mangling preserves case (you can have a struct with members 'a' and 'A'), although (hopefully) no one is relying on it. But camel_to_upper() is case-insensitive ('a' and 'A' would result in the same enum constant).
In order to (later) support case-insensitive QMP, we need to decide up front that we will not allow any qapi member names to collide case-insensitively (outlaw 'a' and 'A' in the same struct; although the C code is still case-preserving); and now that this series is adding a single check_clash() function, it's very easy to do. In fact, I'll add that to my series for 2.5 (it's always easier to reserve something now, especially if no one was using it, and then relax later; than it is to try and restrict things later but run into counter-cases).
Quoted 5 lines
Quoted 5 lines
Having two separate manglings complicates this. Enumeration constants must be distinct after mangling with
camel_to_upper(). But as soon as you use the enumeration as union tag, they must *also* be distinct after mangling withc_name().
But this should already be the case - can you come up with a pair of valid enum values that won't clash under camel_to_upper() but would result in in a c_name() value collision? The converse is not true - there ARE pairs of c_name() values that are distinct, but which map to the same mangling with camel_to_upper(). But if we insist that names do not collide case-insensitively, then that issue goes away - having ALL_CAP enum constants won't cause any collisions even when those constants are derived from member names, because member names are already forbidden from case-insensitive clash.
There is still the question of whether we can get rid of the spurious collision with 'max', by putting the enum sentinel out of the namespace generated for other values. But even with ALL_CAPS, that is possible:
BLOCK_DEVICE_IO_STATUS_OK = 0,
BLOCK_DEVICE_IO_STATUS_FAILED = 1,
BLOCK_DEVICE_IO_STATUS_NOSPACE = 2,
BLOCK_DEVICE_IO_STATUSMAX = 3,
Or insist that no enum value can start with a lone _ (double __ is okay for downstream extensions, though):
BLOCK_DEVICE_IO_STATUS_OK = 0,
BLOCK_DEVICE_IO_STATUS_FAILED = 1,
BLOCK_DEVICE_IO_STATUS_NOSPACE = 2,
BLOCK_DEVICE_IO_STATUS__MAX = 3,
Quoted 16 lines
Quoted 2 lines
Having shouted enumeration constants isn't worth the complexity cost.
I rather disagree with this. Having all-uppercase for enum constants is a really widely used convention and I think it is pretty useful when reading to code to have constants (whether #define/enum) clearly marked in uppercase. After this change we'll have situation where QAPI enums uses CamelCase, while all other non-QAPI enums (whether defined in QEMU source, or via #included 3rd party headers use
UPPER_CASEfor constants. I think that's rather unpleasant.I agree with your premise that predicting the output of the qapi name mangler though is essentially impossible for mortals. How about a counter proposal....
Quoted 5 lines
First make 'prefix' compulsory for enums, instead of trying to figure out a suitable prefix automatically. Then, have a very simple rule for the enum constants where you just uppercase a-z and translate any non-alpha-numeric character into a _. Don't try todo anything else special like figuring out word boundaries.
Basically, prefix + '_' + c_name(value).to_upper().
Auto-generating prefix via heuristics may still be okay, but what we want to gain is that the suffix portion is easily predictable if we know the c_name() mangling of the enum identifer.
Quoted 5 lines
That would get of much of the complexity in the qapi name mangler and give a easily predictable enum constant name. Thus the vast majority of .c source files (possibly even all of them) would not need any change.
I also feel like this RFC is bordering on feature rather than bugfix, making it risky to take in 2.5 softfreeze. If we decide we want this, I think it belongs better in 2.6.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH RFC 3/5] qapi: Use common name mangling for enumeration constants
Quoted 8 lines · Eric Blake
In order to (later) support case-insensitive QMP, we need to decide up front that we will not allow any qapi member names to collide case-insensitively (outlaw 'a' and 'A' in the same struct; although the C code is still case-preserving); and now that this series is adding a single
check_clash()function, it's very easy to do. In fact, I'll add that to my series for 2.5 (it's always easier to reserve something now, especially if no one was using it, and then relax later; than it is to try and restrict things later but run into counter-cases).
Eww - it's not quite as trivial as I thought: we have QMP struct 'CpuInfo' as part of command 'query-cpus' that has both a 'pc' and 'PC' member. However, it's not unsalvageable: the type is made up of a bunch of architecture-specific optional fields along with documentation that "field x is only present for architecture y". So it would be possible to turn this type into a flat union, adding a new enum for architecture, and separating the object so that 'pc' is part of the 'i386', 'x86_64', and 'Sparc' branches, while 'PC' is part of the 'Mips' branch.
At any rate, I'll post an RFC.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH RFC 3/5] qapi: Use common name mangling for enumeration constants
In reply to Eric BlakeQuoted 20 lines · Eric Blake
Quoted 5 lines · Daniel P. Berrange
Quoted 4 lines · Markus Armbruster
QAPI names needn't be valid C identifiers, so we mangle them with
c_name(). Except for enumeration constants, which we mangle withcamel_to_upper().Quoted 7 lines
Quoted 7 lines
c_name()is easy enough to understand: replace '.' and '-' by '_', prefix certain ticklish identifiers with 'q_'.
camel_to_upper()is a hairball of heuristics, and guessing how it'll mangle interesting input could serve as a (nerdy) game. Despite some tweaking (commit 5d371f4), it's still inadqeuate for some QAPI names (commit 351d36e).One of the issues at hand is whether we want to (eventually) teach QMP to be case-insensitive. Right now, our
c_name()mangling preserves case (you can have a struct with members 'a' and 'A'), although (hopefully) no one is relying on it. Butcamel_to_upper()is case-insensitive ('a' and 'A' would result in the same enum constant).
Quoted 8 lines
In order to (later) support case-insensitive QMP, we need to decide up front that we will not allow any qapi member names to collide case-insensitively (outlaw 'a' and 'A' in the same struct; although the C code is still case-preserving); and now that this series is adding a single
check_clash()function, it's very easy to do. In fact, I'll add that to my series for 2.5 (it's always easier to reserve something now, especially if no one was using it, and then relax later; than it is to try and restrict things later but run into counter-cases).
I doubt QMP should be made case-insensitive. JSON isn't, C isn't. Our use of case is actually fairly consistent: event names are ALL_CAPS, everything else is in lower case. Complete list of exceptions found in result of query-qmp-schema:
* struct UuidInfo member UUID
* struct CpuInfo members CPU and PC
* enum ACPISlotType member DIMM
* enum InputButton members Left, Middle, Right, WheelUp, WheelDown
* enum InputAxis members X, Y
That said, an interface where names differ only in case is a badly designed interface. I'd be fine with rejecting such abuse.
Oddballs not related to case:
* enum BlkdebugEvent uses '.' in member names
* enum QKeyCode uses member names starting with a digit
For me, the one argument for some kind of insensitivity is our idiotic habit to sometimes string words together with '_' instead of '-', which has led to an unholy mess. The offenders are
* commands block_passwd, block_resize, block_set_io_throttle, client_migrate_info, device_del, expire_password, migrate_cancel, migrate_set_downtime, migrate_set_speed, netdev_add, netdev_del, set_link, set_password, system_powerdown, system_reset, system_wakeup
* enum types BlkdebugEvent, BlockdevDriver, QKeyCode
* object types BlkdebugSetStateOptions, BlockDeviceInfo, BlockDeviceInfo, BlockDeviceStats, BlockInfo, CpuInfo, PciBusInfo, PciDeviceInfo, PciMemoryRegion, VncClientInfo
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Having two separate manglings complicates this. Enumeration constants must be distinct after mangling with
camel_to_upper(). But as soon as you use the enumeration as union tag, they must *also* be distinct after mangling withc_name().But this should already be the case - can you come up with a pair of valid enum values that won't clash under
camel_to_upper()but would result in in ac_name()value collision?
One glance at camel_to_upper() should make it obvious why I'd prefer not to have to know. But since you asked... I guess it can't happen, because camel_to_upper() first mangles with c_name(), then mangles some more. If c_name() clashes, further mangling can't make it clash less.
Quoted 3 lines
The converse is not true -
there ARE pairs ofc_name()values that are distinct, but which map to the same mangling withcamel_to_upper().
Yes. Example: 'GotCha' and 'got-cha' both map to 'GOT_CHA'.
Quoted 9 lines
But if we insist that names do
not collide case-insensitively, then that issue goes away - havingALL_CAPenum constants won't cause any collisions even when those constants are derived from member names, because member names are already forbidden from case-insensitive clash.There is still the question of whether we can get rid of the spurious collision with 'max', by putting the enum sentinel out of the namespace generated for other values.
I wanted to get out an RFC quickly, so I didn't try.
Quoted 6 lines
But even with
ALL_CAPS, that is possible:
BLOCK_DEVICE_IO_STATUS_OK= 0,
BLOCK_DEVICE_IO_STATUS_FAILED= 1,
BLOCK_DEVICE_IO_STATUS_NOSPACE= 2,
BLOCK_DEVICE_IO_STATUSMAX= 3,
Running shouted words together like STATUSMAX is even less legible than StatusMax. There's a reason why scriptio continua was abandoned in the middle ages.
Quoted 7 lines
Or insist that no enum value can start with a lone _ (double __ is okay for downstream extensions, though):
BLOCK_DEVICE_IO_STATUS_OK= 0,
BLOCK_DEVICE_IO_STATUS_FAILED= 1,
BLOCK_DEVICE_IO_STATUS_NOSPACE= 2,
BLOCK_DEVICE_IO_STATUS__MAX= 3,
Workable. With the separate mangling dropped, we could do
typedef enum BlockDeviceIoStatus {
BlockDeviceIoStatus_ok = 0,
BlockDeviceIoStatus_failed = 1,
BlockDeviceIoStatus_nospace = 2,
BlockDeviceIoStatusMAX = 3,
} BlockDeviceIoStatus;
which I think is a least ugly solution given our convention to use CamelCase for type names and my proposal to use the enum name as enum constant prefix.
I'll reply to Dan separately.
[...]
Re: [Qemu-devel] [PATCH RFC 3/5] qapi: Use common name mangling for enumeration constants
Quoted 54 lines · Markus Armbruster
Quoted 20 lines · Eric Blake
Quoted 5 lines · Daniel P. Berrange
Quoted 4 lines · Markus Armbruster
QAPI names needn't be valid C identifiers, so we mangle them with
c_name(). Except for enumeration constants, which we mangle withcamel_to_upper().Quoted 7 lines
Quoted 7 lines
c_name()is easy enough to understand: replace '.' and '-' by '_', prefix certain ticklish identifiers with 'q_'.
camel_to_upper()is a hairball of heuristics, and guessing how it'll mangle interesting input could serve as a (nerdy) game. Despite some tweaking (commit 5d371f4), it's still inadqeuate for some QAPI names (commit 351d36e).One of the issues at hand is whether we want to (eventually) teach QMP to be case-insensitive. Right now, our
c_name()mangling preserves case (you can have a struct with members 'a' and 'A'), although (hopefully) no one is relying on it. Butcamel_to_upper()is case-insensitive ('a' and 'A' would result in the same enum constant).Quoted 8 lines
In order to (later) support case-insensitive QMP, we need to decide up front that we will not allow any qapi member names to collide case-insensitively (outlaw 'a' and 'A' in the same struct; although the C code is still case-preserving); and now that this series is adding a single
check_clash()function, it's very easy to do. In fact, I'll add that to my series for 2.5 (it's always easier to reserve something now, especially if no one was using it, and then relax later; than it is to try and restrict things later but run into counter-cases).I doubt QMP should be made case-insensitive. JSON isn't, C isn't. Our use of case is actually fairly consistent: event names are
ALL_CAPS, everything else is in lower case. Complete list of exceptions found in result of query-qmp-schema:* struct UuidInfo member UUID
* struct CpuInfo members CPU and PC
* enum ACPISlotType member DIMM
* enum InputButton members Left, Middle, Right, WheelUp, WheelDown
* enum InputAxis members X, YThat said, an interface where names differ only in case is a badly designed interface. I'd be fine with rejecting such abuse.
Oddballs not related to case:
* enum BlkdebugEvent uses '.' in member names
* enum QKeyCode uses member names starting with a digitFor me, the one argument for some kind of insensitivity is our idiotic habit to sometimes string words together with '_' instead of '-', which has led to an unholy mess. The offenders are
Quoted 8 lines
* commands
block_passwd,block_resize,block_set_io_throttle,client_migrate_info,device_del,expire_password,migrate_cancel,migrate_set_downtime,migrate_set_speed,netdev_add,netdev_del,set_link,set_password,system_powerdown,system_reset,system_wakeup
* enum types BlkdebugEvent, BlockdevDriver, QKeyCode
* object types BlkdebugSetStateOptions, BlockDeviceInfo, BlockDeviceInfo, BlockDeviceStats, BlockInfo, CpuInfo, PciBusInfo, PciDeviceInfo, PciMemoryRegion, VncClientInfo
I can think of a few ways to clean up the '_' vs. '-' mess:
1. Fix the offenders, keep the unfixed names as aliases.
Requires an alias mechanism.
If we do it in 2.5, we can keep the aliases out of QMP introspection.
2. Fix the offenders, map '_' to '-' in QMP input, but only in object keys and values of enumeration type, not other strings.
Distinguishing the two kinds of strings might be non-trivial, dunno.
3. Compare '_' and '-' equal in all the necessary places.
Need to find these places.
The mess remains visible in QMP introspection unless we also fix the offenders.
Fixing the offenders without keeping the unfixed names along changes QMP introspection value incompatibly. May not be practical after 2.5.
I wish I had made the connection between the '_' vs. '-' mess and introspection earlier.
If we decide to clean up '_' vs. '-', then other irregularities like case could be cleaned up along with it.
Thoughts?
[...]
[Qemu-devel] What to do about QAPI naming convention violations (was: [PATCH RFC 3/5] qapi: Use common name mangling for enumeration constants)
Quoted 52 lines · Markus Armbruster
Quoted 50 lines · Markus Armbruster
Quoted 20 lines · Eric Blake
Quoted 5 lines · Daniel P. Berrange
Quoted 4 lines · Markus Armbruster
QAPI names needn't be valid C identifiers, so we mangle them with
c_name(). Except for enumeration constants, which we mangle withcamel_to_upper().Quoted 7 lines
Quoted 7 lines
c_name()is easy enough to understand: replace '.' and '-' by '_', prefix certain ticklish identifiers with 'q_'.
camel_to_upper()is a hairball of heuristics, and guessing how it'll mangle interesting input could serve as a (nerdy) game. Despite some tweaking (commit 5d371f4), it's still inadqeuate for some QAPI names (commit 351d36e).One of the issues at hand is whether we want to (eventually) teach QMP to be case-insensitive. Right now, our
c_name()mangling preserves case (you can have a struct with members 'a' and 'A'), although (hopefully) no one is relying on it. Butcamel_to_upper()is case-insensitive ('a' and 'A' would result in the same enum constant).Quoted 8 lines
In order to (later) support case-insensitive QMP, we need to decide up front that we will not allow any qapi member names to collide case-insensitively (outlaw 'a' and 'A' in the same struct; although the C code is still case-preserving); and now that this series is adding a single
check_clash()function, it's very easy to do. In fact, I'll add that to my series for 2.5 (it's always easier to reserve something now, especially if no one was using it, and then relax later; than it is to try and restrict things later but run into counter-cases).I doubt QMP should be made case-insensitive. JSON isn't, C isn't. Our use of case is actually fairly consistent: event names are
ALL_CAPS, everything else is in lower case. Complete list of exceptions found in result of query-qmp-schema:* struct UuidInfo member UUID
* struct CpuInfo members CPU and PC
* enum ACPISlotType member DIMM
* enum InputButton members Left, Middle, Right, WheelUp, WheelDown
* enum InputAxis members X, YThat said, an interface where names differ only in case is a badly designed interface. I'd be fine with rejecting such abuse.
Oddballs not related to case:
* enum BlkdebugEvent uses '.' in member names
* enum QKeyCode uses member names starting with a digit
Quoted 8 lines
Quoted 8 lines
For me, the one argument for some kind of insensitivity is our idiotic habit to sometimes string words together with '_' instead of '-', which has led to an unholy mess. The offenders are
* commands
block_passwd,block_resize,block_set_io_throttle,client_migrate_info,device_del,expire_password,migrate_cancel,migrate_set_downtime,migrate_set_speed,netdev_add,netdev_del,set_link,set_password,system_powerdown,system_reset,system_wakeup
Missing: add_client.
Quoted 16 lines
Quoted 4 lines
* enum types BlkdebugEvent, BlockdevDriver, QKeyCode
* object types BlkdebugSetStateOptions, BlockDeviceInfo, BlockDeviceInfo, BlockDeviceStats, BlockInfo, CpuInfo, PciBusInfo, PciDeviceInfo, PciMemoryRegion, VncClientInfoI can think of a few ways to clean up the '_' vs. '-' mess:
1. Fix the offenders, keep the unfixed names as aliases.
Requires an alias mechanism.
If we do it in 2.5, we can keep the aliases out of QMP introspection.
2. Fix the offenders, map '_' to '-' in QMP input, but only in object keys and values of enumeration type, not other strings.
Quoted 8 lines
Distinguishing the two kinds of strings might be non-trivial, dunno.
3. Compare '_' and '-' equal in all the necessary places.
Need to find these places.
The mess remains visible in QMP introspection unless we also fix the offenders.
Of course, there's a big difference between QMP input and output.
On input, we can accept a nicer name in addition to the ugly name, and that's compatible.
On output, we can only duplicate data with an ugly name under a nicer one. Duplicating members or events doesn't feel like an improvement. That leaves deprecating commands.
I had a closer look at how the screwy names are used in QMP to see how much of the mess is fixable within reason.
Command names are all fixable.
InputButton and InputAxis are input for x-input-send-event. Fixable. May not even need backward compatibility.
QKeyCode is input for x-input-send-event and send-key. Fixable. However, I think we want to bend the rules instead.
ACPISlotType, BlockDeviceInfo, BlockDeviceStats, BlockInfo, CpuInfo, PciBusInfo, PciDeviceInfo, PciMemoryRegion, UuidInfo, VncClientInfo are all output of some query command. The only fix is deprecating the query commands, which is a big hammer.
BlkdebugEvent is related to the external blkdebug interface described by docs/blkdebug.txt. The two are actually decoupled, i.e. changing the QAPI names doesn't affect the external debugging interface, and vice versa. Making them different can only cause confusion, though. Not sure we can fix the names.
BlkdebugSetStateOptions and BlockdevDriver are input for blockdev-add. Fixable. May not even need backward compatibility.
Quoted 6 lines
Fixing the offenders without keeping the unfixed names along changes QMP introspection value incompatibly. May not be practical after 2.5.
I wish I had made the connection between the '_' vs. '-' mess and introspection earlier.
Quoted 6 lines
If we decide to clean up '_' vs. '-', then other irregularities like case could be cleaned up along with it.
Thoughts?
[...]
Here's what I think we should do:
* Make qapi.py enforce the naming conventions, to stop us from digging ourselves deeper into this hole.
Requires a whitelist, similar to returns_whitelist. I'd whitelist whole types, not members.
* Try to fix x-input-send-event and blockdev-add before they become unfixable.
* Live with the rest.
[Qemu-devel] blkdebug event names [was: What to do about QAPI naming convention violations]
Quoted 8 lines · Markus Armbruster
Quoted 3 lines
Quoted 3 lines
Oddballs not related to case:
* enum BlkdebugEvent uses '.' in member names
I had a closer look at how the screwy names are used in QMP to see how much of the mess is fixable within reason.
Quoted 5 lines
BlkdebugEvent is related to the external blkdebug interface described by
docs/blkdebug.txt. The two are actually decoupled, i.e. changing the QAPI names doesn't affect the external debugging interface, and vice versa. Making them different can only cause confusion, though. Not sure we can fix the names.
I think that having block/blkdebug.c:event_name[] duplicate qapi BlkdebugEvent is a mistake, and that we are better off unifying them. The other question is whether backwards compatibility is important here, or if we can just break the naming conventions to something sane. That is, if the primary user of blkdebug is our testsuite, and we fix our testsuite to match the new names, will we be breaking external users? Libvirt certainly doesn't expose blkdebug, and I doubt any other external wrapper will be that upset if we force better names here.
Quoted 3 lines
BlkdebugSetStateOptions and BlockdevDriver are input for blockdev-add. Fixable. May not even need backward compatibility.
Yep, I concur that blockdev-add is not stable yet, and that there are no other QMP uses of BlkdebugEvent, so unless anyone else complains, I think we can make the change to conventional spelling.
At this point, I think 2.5 is too late, so the change will have to go into 2.6, but I'm preparing a patch for fixing this interface.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] blkdebug event names [was: What to do about QAPI naming convention violations]
Quoted 29 lines · Eric Blake
Quoted 8 lines · Markus Armbruster
Quoted 3 lines
Quoted 3 lines
Oddballs not related to case:
* enum BlkdebugEvent uses '.' in member names
I had a closer look at how the screwy names are used in QMP to see how much of the mess is fixable within reason.
Quoted 5 lines
BlkdebugEvent is related to the external blkdebug interface described by
docs/blkdebug.txt. The two are actually decoupled, i.e. changing the QAPI names doesn't affect the external debugging interface, and vice versa. Making them different can only cause confusion, though. Not sure we can fix the names.I think that having block/blkdebug.c:event_name[] duplicate qapi BlkdebugEvent is a mistake, and that we are better off unifying them. The other question is whether backwards compatibility is important here, or if we can just break the naming conventions to something sane. That is, if the primary user of blkdebug is our testsuite, and we fix our testsuite to match the new names, will we be breaking external users? Libvirt certainly doesn't expose blkdebug, and I doubt any other external wrapper will be that upset if we force better names here.
Quoted 3 lines
BlkdebugSetStateOptions and BlockdevDriver are input for blockdev-add. Fixable. May not even need backward compatibility.
Quoted 6 lines
Yep, I concur that blockdev-add is not stable yet, and that there are no other QMP uses of BlkdebugEvent, so unless anyone else complains, I think we can make the change to conventional spelling.
At this point, I think 2.5 is too late, so the change will have to go into 2.6, but I'm preparing a patch for fixing this interface.
Definitely 2.6. Make sure to cc: Kevin (blkdebug maintainer).
Re: [Qemu-devel] [PATCH RFC 3/5] qapi: Use common name mangling for enumeration constants
In reply to Daniel P. BerrangeQuoted 41 lines · Daniel P. Berrange
Quoted 33 lines · Markus Armbruster
QAPI names needn't be valid C identifiers, so we mangle them with
c_name(). Except for enumeration constants, which we mangle withcamel_to_upper().
c_name()is easy enough to understand: replace '.' and '-' by '_', prefix certain ticklish identifiers with 'q_'.
camel_to_upper()is a hairball of heuristics, and guessing how it'll mangle interesting input could serve as a (nerdy) game. Despite some tweaking (commit 5d371f4), it's still inadqeuate for some QAPI names (commit 351d36e).Example: QAPI definition
{ 'enum': 'BlockDeviceIoStatus', 'data': [ 'ok', 'failed', 'nospace' ] }generates
typedef enum BlockDeviceIoStatus {
BLOCK_DEVICE_IO_STATUS_OK= 0,
BLOCK_DEVICE_IO_STATUS_FAILED= 1,
BLOCK_DEVICE_IO_STATUS_NOSPACE= 2,
BLOCK_DEVICE_IO_STATUS_MAX= 3,
} BlockDeviceIoStatus;Observe that
c_name()maps BlockDeviceIoStatus to itself, andcamel_to_upper()maps it toBLOCK_DEVICE_IO_STATUS, i.e. the enumeration constants are shouted, the enumeration type isn't.Because mangled names must not clash, name mangling restricts the names you can use. For example, you can't have member 'a-b' and '
a_b'.Quoted 6 lines
Having two separate manglings complicates this. Enumeration constants must be distinct after mangling with
camel_to_upper(). But as soon as you use the enumeration as union tag, they must *also* be distinct after mangling withc_name().Having shouted enumeration constants isn't worth the complexity cost.
Quoted 7 lines
I rather disagree with this. Having all-uppercase for enum constants is a really widely used convention and I think it is pretty useful when reading to code to have constants (whether #define/enum) clearly marked in uppercase. After this change we'll have situation where QAPI enums uses CamelCase, while all other non-QAPI enums (whether defined in QEMU source, or via #included 3rd party headers use
UPPER_CASEfor constants. I think that's rather unpleasant.
CODING_STYLE doesn't mandate shouting constants.
Existing code doesn't shout constants consistently.
Third parties don't shout constants consistently.
A competing convention is to use the enumeration type's name as prefix for the constants.
Quoted 9 lines
I agree with your premise that predicting the output of the qapi name mangler though is essentially impossible for mortals. How about a counter proposal....
First make 'prefix' compulsory for enums, instead of trying to figure out a suitable prefix automatically. Then, have a very simple rule for the enum constants where you just uppercase a-z and translate any non-alpha-numeric character into a _. Don't try todo anything else special like figuring out word boundaries.
Essentially c_name(qapi_name).upper().
Quoted 4 lines
That would get of much of the complexity in the qapi name mangler and give a easily predictable enum constant name. Thus the vast majority of .c source files (possibly even all of them) would not need any change.
'prefix' is a work-around for deficient name mangling. Making it mandatory declares defeat on enumeration constant name mangling. The reason for defeat are unreasonable goals, namely combining these three conventions:
* QAPI and C type names are in CamelCase
* Enumeration constants are prefixed by the type name
* Enumeration constants are shouted, including the prefix
They necessitate converting the CamelCase prefix to shouting, which is the troublesome part. Note that shouting the remainder (the QAPI member name) is trivial: .upper() serves.
Let's take a step back and examine what I want to achieve.
First, I want simple, consistent rules for QAPI names. Two kinds:
reserved names and name clashes.
A few names are globally reserved (e.g. prefix 'q_') , and a few more only in certain name spaces (e.g. type name suffix 'List'). Simple enough.
Two names clash if they're equal after replacing '-' and '.' by '_'. Simple enough.
*Except* for enumeration member names, which can clash in other ways (example: 'GotCha' with 'got-cha'). The exact special clashing rules haven't been written down. Nobody knows them, actually. Instead of writing them down, I want to get rid of then.
We could change the normal clashing rule to additionally ignore case. Still simple enough, and makes sense to me.
Ignoring case would let us safely shout names in generated code.
Second, I want our C names generated in a simple, predictable way. This is largely the case:
* We use the QAPI name with '-' and '.' replaced by '_'
* Sometimes, we prepend a 'q_' to avoid certain ticklish names
* We prepend and append fixed strings
*Except* for enumeration member names, which undergo a different mangling that is neither simple nor predictable.
My proposal simply drops the special case.
Your counter-proposal instead moves the name mangling from the generator to the QAPI schema. In other words, it abuses the programmer as name mangler. I don't like that, and I wouldn't call it "simple". It does address the "not predictable" part.
If we must have shouting in enumeration constants, we could do the
following: use the unadulterated type name as prefix, shout the member name. Example:
typedef enum BlockDeviceIoStatus {
BlockDeviceIoStatus_OK = 0,
BlockDeviceIoStatus_FAILED = 1,
BlockDeviceIoStatus_NOSPACE = 2,
BlockDeviceIoStatus_MAX = 3,
} BlockDeviceIoStatus;
If the QAPI enumeration constant rename flag day bothers us, we can keep the 'prefix' feature for now, use it to avoid the renames that touch code we don't want to touch now, then rename them one by one at our convenience.
Re: [Qemu-devel] [PATCH RFC 3/5] qapi: Use common name mangling for enumeration constants
Quoted 51 lines · Markus Armbruster
Quoted 41 lines · Daniel P. Berrange
Quoted 33 lines · Markus Armbruster
QAPI names needn't be valid C identifiers, so we mangle them with
c_name(). Except for enumeration constants, which we mangle withcamel_to_upper().
c_name()is easy enough to understand: replace '.' and '-' by '_', prefix certain ticklish identifiers with 'q_'.
camel_to_upper()is a hairball of heuristics, and guessing how it'll mangle interesting input could serve as a (nerdy) game. Despite some tweaking (commit 5d371f4), it's still inadqeuate for some QAPI names (commit 351d36e).Example: QAPI definition
{ 'enum': 'BlockDeviceIoStatus', 'data': [ 'ok', 'failed', 'nospace' ] }generates
typedef enum BlockDeviceIoStatus {
BLOCK_DEVICE_IO_STATUS_OK= 0,
BLOCK_DEVICE_IO_STATUS_FAILED= 1,
BLOCK_DEVICE_IO_STATUS_NOSPACE= 2,
BLOCK_DEVICE_IO_STATUS_MAX= 3,
} BlockDeviceIoStatus;Observe that
c_name()maps BlockDeviceIoStatus to itself, andcamel_to_upper()maps it toBLOCK_DEVICE_IO_STATUS, i.e. the enumeration constants are shouted, the enumeration type isn't.Because mangled names must not clash, name mangling restricts the names you can use. For example, you can't have member 'a-b' and '
a_b'.Quoted 6 lines
Having two separate manglings complicates this. Enumeration constants must be distinct after mangling with
camel_to_upper(). But as soon as you use the enumeration as union tag, they must *also* be distinct after mangling withc_name().Having shouted enumeration constants isn't worth the complexity cost.
Quoted 7 lines
I rather disagree with this. Having all-uppercase for enum constants is a really widely used convention and I think it is pretty useful when reading to code to have constants (whether #define/enum) clearly marked in uppercase. After this change we'll have situation where QAPI enums uses CamelCase, while all other non-QAPI enums (whether defined in QEMU source, or via #included 3rd party headers use
UPPER_CASEfor constants. I think that's rather unpleasant.
Quoted 3 lines
CODING_STYLEdoesn't mandate shouting constants.Existing code doesn't shout constants consistently.
I wrote a script (attached) to parse the code and try to get extract some data on upper/lower/mixed case usage in enum declarations
Enum member naming
Uppercase: 993 in 325 files
Lowercase: 119 in 76 files
Mixedcase: 110 in 22 files
So, uppercase is preferred 10:1 over both lowercase and mixedcase The filecount for uppercase would be far higher were it not for fact that all QAPI enums end up in one file.
If we try to count #define's which provide constants, again all uppercase is the clear majority
Upper 32256
Lower 829
Mixed 8869
(50% of those Mixed constants come from the userspace emulator
#defines for syscall numbers)
Quoted 1 line
Third parties don't shout constants consistently.
Running the same script across all the QEMU RPM dependancies again shows uppercase is the favoured style:
Enum member naming
Uppercase: 538 in 178 files
Lowercase: 38 in 17 files
Mixedcase: 141 in 53 files
The breakdown per-RPM is as follows:
bluez-libs-devel
Enum member naming
Uppercase: 4 in 3 files
brlapi-devel
Enum member naming
Uppercase: 43 in 23 files
Mixedcase: 83 in 29 files
bzip2-devel
Enum member naming
None
ceph-devel
Enum member naming
None
cyrus-sasl-devel
Enum member naming
Uppercase: 1 in 1 files
glusterfs-api-devel
Enum member naming
Uppercase: 1 in 1 files
glusterfs-devel
Enum member naming
Uppercase: 94 in 26 files
Lowercase: 10 in 6 files
Mixedcase: 2 in 1 files
gnutls-devel
Enum member naming
Uppercase: 63 in 10 files
gtk3-devel
Enum member naming
Uppercase: 152 in 60 files
Lowercase: 1 in 1 files
libaio-devel
Enum member naming
Uppercase: 1 in 1 files
libattr-devel
Enum member naming
None
libcap-devel
Enum member naming
None
libcurl-devel
Enum member naming
Uppercase: 17 in 2 files
Lowercase: 3 in 1 files
Mixedcase: 1 in 1 files
libfdt-devel
Enum member naming
None
libiscsi-devel
Enum member naming
Uppercase: 32 in 2 files
libjpeg-devel
Enum member naming
None
libpng-devel
Enum member naming
None
librdmacm-devel
Enum member naming
Uppercase: 7 in 3 files
libseccomp-devel
Enum member naming
Uppercase: 2 in 1 files
libssh2-devel
Enum member naming
None
libusbx-devel
Enum member naming
Uppercase: 21 in 1 files
libuuid-devel
Enum member naming
None
ncurses-devel
Enum member naming
Uppercase: 3 in 3 files
Mixedcase: 6 in 6 files
nss-devel
Enum member naming
Uppercase: 2 in 2 files
Lowercase: 10 in 2 files
Mixedcase: 41 in 10 files
numactl-devel
Enum member naming
None
pciutils-devel
Enum member naming
Uppercase: 2 in 1 files
pixman-devel
Enum member naming
Uppercase: 5 in 1 files
Mixedcase: 1 in 1 files
pulseaudio-libs-devel
Enum member naming
Uppercase: 17 in 6 files
SDL2-devel
Enum member naming
Uppercase: 30 in 17 files
Mixedcase: 3 in 2 files
spice-server-devel
Enum member naming
Uppercase: 5 in 3 files
systemtap-sdt-devel
Enum member naming
None
usbredir-devel
Enum member naming
Lowercase: 11 in 4 files
vte3-devel
Enum member naming
Uppercase: 7 in 3 files
xen-devel
Enum member naming
Uppercase: 29 in 8 files
Lowercase: 3 in 3 files
Mixedcase: 2 in 2 files
xfsprogs-devel
Enum member naming
Mixedcase: 2 in 1 files
zlib-devel
Enum member naming
None
Quoted 2 lines
A competing convention is to use the enumeration type's name as prefix for the constants.
That is counted by the 'mixedcase' stats and as seen above that's still 10:1 less popular than all uppercase.
Quoted 63 lines
Quoted 10 lines
I agree with your premise that predicting the output of the qapi name mangler though is essentially impossible for mortals. How about a counter proposal....
First make 'prefix' compulsory for enums, instead of trying to figure out a suitable prefix automatically. Then, have a very simple rule for the enum constants where you just uppercase a-z and translate any non-alpha-numeric character into a _. Don't try todo anything else special like figuring out word boundaries.
Essentially c_name(qapi_name).upper().
Quoted 4 lines
That would get of much of the complexity in the qapi name mangler and give a easily predictable enum constant name. Thus the vast majority of .c source files (possibly even all of them) would not need any change.
'prefix' is a work-around for deficient name mangling. Making it mandatory declares defeat on enumeration constant name mangling. The reason for defeat are unreasonable goals, namely combining these three conventions:
* QAPI and C type names are in CamelCase
* Enumeration constants are prefixed by the type name
* Enumeration constants are shouted, including the prefix
They necessitate converting the CamelCase prefix to shouting, which is the troublesome part. Note that shouting the remainder (the QAPI member name) is trivial: .upper() serves.
Let's take a step back and examine what I want to achieve.
First, I want simple, consistent rules for QAPI names. Two kinds:
reserved names and name clashes.A few names are globally reserved (e.g. prefix 'q_') , and a few more only in certain name spaces (e.g. type name suffix 'List'). Simple enough.
Two names clash if they're equal after replacing '-' and '.' by '_'. Simple enough.
*Except* for enumeration member names, which can clash in other ways (example: 'GotCha' with 'got-cha'). The exact special clashing rules haven't been written down. Nobody knows them, actually. Instead of writing them down, I want to get rid of then.
We could change the normal clashing rule to additionally ignore case. Still simple enough, and makes sense to me.
Ignoring case would let us safely shout names in generated code.
Second, I want our C names generated in a simple, predictable way. This is largely the case:
* We use the QAPI name with '-' and '.' replaced by '_'
Quoted 8 lines
* Sometimes, we prepend a 'q_' to avoid certain ticklish names
* We prepend and append fixed strings
*Except* for enumeration member names, which undergo a different mangling that is neither simple nor predictable.
My proposal simply drops the special case.
This is really all about the POV you look at the problem from. From the code generator's POV having enum's all uppercase is a special case scenario. From the general developer's POV, having enums all uppercase is the normal case scenario. IMHO the code generator is there to serve the developers, so following the developer's normal case should be the priority, even if that makes life harder for maintaining the code generator.
Quoted 4 lines
Your counter-proposal instead moves the name mangling from the generator to the QAPI schema. In other words, it abuses the programmer as name mangler. I don't like that, and I wouldn't call it "simple". It does address the "not predictable" part.
Saying it abuses the programmer is pretty extreme. When a programmer is defining an enum, they will always intuitively have an idea of what they expect the enum constants to look like. Simply defining that in the QAPI schema at that time is no burden at all and really is simple/trivial for the programmer.
Quoted 11 lines
If we must have shouting in enumeration constants, we could do the
following: use the unadulterated type name as prefix, shout the member name. Example:typedef enum BlockDeviceIoStatus {
BlockDeviceIoStatus_OK= 0,
BlockDeviceIoStatus_FAILED= 1,
BlockDeviceIoStatus_NOSPACE= 2,
BlockDeviceIoStatus_MAX= 3,
} BlockDeviceIoStatus;
Quoted 4 lines
If the QAPI enumeration constant rename flag day bothers us, we can keep the 'prefix' feature for now, use it to avoid the renames that touch code we don't want to touch now, then rename them one by one at our convenience.
Regards,
Daniel
Signature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
RFC PATCH 4/5 crypto: Drop name mangling override
In reply to Markus ArmbrusterCommit a090187 used the name mangling override, because the QAPI name 'QCryptoTLSCredsEndpoint' would have generated enumeration constants with the rather unsatisfactory Q_CRYPTOTLS_CREDS_ENDPOINT_CLIENT prefix without it. It now generates QCryptoTLSCredsEndpoint without it, which is just fine.
--- crypto/tlscredsanon.c | 6 +++--- crypto/tlscredsx509.c | 6 +++--- crypto/tlssession.c | 6 +++--- include/crypto/tlssession.h | 2 +- qapi/crypto.json | 1 - tests/test-crypto-tlscredsx509.c | 6 +++--- tests/test-crypto-tlssession.c | 12 ++++++------ ui/vnc-auth-vencrypt.c | 2 +- ui/vnc-ws.c | 2 +- ui/vnc.c | 2 +- 10 files changed, 22 insertions(+), 23 deletions(-)
crypto/tlscredsanon.c +3 -3
@@ -38,7 +38,7 @@ qcrypto_tls_creds_anon_load(QCryptoTLSCredsAnon *creds,trace_qcrypto_tls_creds_anon_load (creds, creds->parent_obj.dir ? creds->parent_obj.dir :"<nodir>" ); -if (creds->parent_obj.endpoint == QCRYPTO_TLS_CREDS_ENDPOINT_server) { +if (creds->parent_obj.endpoint == QCryptoTLSCredsEndpoint_server) {if (qcrypto_tls_creds_get_path (&creds->parent_obj,QCRYPTO_TLS_CREDS_DH_PARAMS , false, &dhparams, errp) <0 ) {
@@ -79,7 +79,7 @@ qcrypto_tls_creds_anon_load(QCryptoTLSCredsAnon *creds,static void qcrypto_tls_creds_anon_unload (QCryptoTLSCredsAnon *creds) { -if (creds->parent_obj.endpoint == QCRYPTO_TLS_CREDS_ENDPOINT_client) { +if (creds->parent_obj.endpoint == QCryptoTLSCredsEndpoint_client) {if (creds->data.client) {gnutls_anon_free_client_credentials (creds->data.client); creds->data.client =NULL ;
@@ -141,7 +141,7 @@ qcrypto_tls_creds_anon_prop_get_loaded(Object *obj, {QCryptoTLSCredsAnon *creds =QCRYPTO_TLS_CREDS_ANON (obj); -if (creds->parent_obj.endpoint == QCRYPTO_TLS_CREDS_ENDPOINT_server) { +if (creds->parent_obj.endpoint == QCryptoTLSCredsEndpoint_server) {return creds->data.server !=NULL ; }else {return creds->data.client !=NULL ;
crypto/tlscredsx509.c +3 -3
@@ -549,7 +549,7 @@ qcrypto_tls_creds_x509_load(QCryptoTLSCredsX509 *creds,trace_qcrypto_tls_creds_x509_load (creds, creds->parent_obj.dir ? creds->parent_obj.dir :"<nodir>" ); -if (creds->parent_obj.endpoint == QCRYPTO_TLS_CREDS_ENDPOINT_server) { +if (creds->parent_obj.endpoint == QCryptoTLSCredsEndpoint_server) { if (qcrypto_tls_creds_get_path(&creds->parent_obj, QCRYPTO_TLS_CREDS_X509_CA_CERT, true, &cacert, errp) < 0 ||
@@ -583,7 +583,7 @@ qcrypto_tls_creds_x509_load(QCryptoTLSCredsX509 *creds,if (creds->sanityCheck &&qcrypto_tls_creds_x509_sanity_check (creds, - creds->parent_obj.endpoint == QCRYPTO_TLS_CREDS_ENDPOINT_server, + creds->parent_obj.endpoint == QCryptoTLSCredsEndpoint_server, cacert, cert, errp) <0 ) { goto cleanup; }
@@ -626,7 +626,7 @@ qcrypto_tls_creds_x509_load(QCryptoTLSCredsX509 *creds, } } -if (creds->parent_obj.endpoint == QCRYPTO_TLS_CREDS_ENDPOINT_server) { +if (creds->parent_obj.endpoint == QCryptoTLSCredsEndpoint_server) {if (qcrypto_tls_creds_get_dh_params_file (&creds->parent_obj, dhparams, &creds->parent_obj.dh_params, errp) <0 ) {
crypto/tlssession.c +3 -3
@@ -116,7 +116,7 @@ qcrypto_tls_session_new(QCryptoTLSCreds *creds, goto error; } -if (endpoint == QCRYPTO_TLS_CREDS_ENDPOINT_server) { +if (endpoint == QCryptoTLSCredsEndpoint_server) { ret =gnutls_init (&session->handle,GNUTLS_SERVER ); }else { ret =gnutls_init (&session->handle,GNUTLS_CLIENT );
@@ -138,7 +138,7 @@ qcrypto_tls_session_new(QCryptoTLSCreds *creds, gnutls_strerror(ret)); goto error; } -if (creds->endpoint == QCRYPTO_TLS_CREDS_ENDPOINT_server) { +if (creds->endpoint == QCryptoTLSCredsEndpoint_server) { ret =gnutls_credentials_set (session->handle,GNUTLS_CRD_ANON , acreds->data.server);
@@ -171,7 +171,7 @@ qcrypto_tls_session_new(QCryptoTLSCreds *creds, goto error; } -if (creds->endpoint == QCRYPTO_TLS_CREDS_ENDPOINT_server) { +if (creds->endpoint == QCryptoTLSCredsEndpoint_server) {/* This requests, but does not enforce a client cert. * The cert checking code later does enforcement */ gnutls_certificate_server_set_request(session->handle,
include/crypto/tlssession.h +1 -1
@@ -63,7 +63,7 @@* sess = qcrypto_tls_session_new(creds, * "vnc.example.com", * NULL, -* QCRYPTO_TLS_CREDS_ENDPOINT_client, +* QCryptoTLSCredsEndpoint_client, * errp); * if (sess == NULL) { * return -1;
qapi/crypto.json +0 -1
@@ -17,5 +17,4 @@ # Since: 2.5 ## { 'enum': 'QCryptoTLSCredsEndpoint', - 'prefix': 'QCRYPTO_TLS_CREDS_ENDPOINT', 'data': ['client', 'server']}
tests/test-crypto-tlscredsx509.c +3 -3
@@ -48,7 +48,7 @@ static QCryptoTLSCreds *test_tls_creds_create(QCryptoTLSCredsEndpoint endpoint, parent,"testtlscreds" , errp, -"endpoint" , (endpoint == QCRYPTO_TLS_CREDS_ENDPOINT_server ? +"endpoint" , (endpoint == QCryptoTLSCredsEndpoint_server ?"server" :"client" ),"dir" , certdir, "verify-peer", "yes",
@@ -111,8 +111,8 @@ static void test_tls_creds(const void *opaque) creds =test_tls_creds_create ( (data->isServer ? - QCRYPTO_TLS_CREDS_ENDPOINT_server : - QCRYPTO_TLS_CREDS_ENDPOINT_client), + QCryptoTLSCredsEndpoint_server : + QCryptoTLSCredsEndpoint_client),CERT_DIR , &err);
tests/test-crypto-tlssession.c +6 -6
@@ -69,10 +69,10 @@ static QCryptoTLSCreds *test_tls_creds_create(QCryptoTLSCredsEndpoint endpoint, Object *creds = object_new_with_props( TYPE_QCRYPTO_TLS_CREDS_X509, parent, - (endpoint == QCRYPTO_TLS_CREDS_ENDPOINT_server ? + (endpoint == QCryptoTLSCredsEndpoint_server ? "testtlscredsserver" : "testtlscredsclient"), &err, - "endpoint", (endpoint == QCRYPTO_TLS_CREDS_ENDPOINT_server ? + "endpoint", (endpoint == QCryptoTLSCredsEndpoint_server ? "server" : "client"), "dir", certdir, "verify-peer", "yes",
@@ -160,13 +160,13 @@ static void test_crypto_tls_session(const void *opaque) CLIENT_CERT_DIR QCRYPTO_TLS_CREDS_X509_CLIENT_KEY) == 0); clientCreds =test_tls_creds_create ( - QCRYPTO_TLS_CREDS_ENDPOINT_client, + QCryptoTLSCredsEndpoint_client,CLIENT_CERT_DIR , &err);g_assert (clientCreds !=NULL ); serverCreds =test_tls_creds_create ( - QCRYPTO_TLS_CREDS_ENDPOINT_server, + QCryptoTLSCredsEndpoint_server,SERVER_CERT_DIR , &err);g_assert (serverCreds !=NULL );
@@ -182,11 +182,11 @@ static void test_crypto_tls_session(const void *opaque)/* Now the real part of the test, setup the sessions */ clientSess =qcrypto_tls_session_new ( clientCreds, data->hostname,NULL , - QCRYPTO_TLS_CREDS_ENDPOINT_client, &err); + QCryptoTLSCredsEndpoint_client, &err); serverSess =qcrypto_tls_session_new ( serverCreds,NULL , data->wildcards ?"tlssessionacl" :NULL , - QCRYPTO_TLS_CREDS_ENDPOINT_server, &err); + QCryptoTLSCredsEndpoint_server, &err);g_assert (clientSess !=NULL );g_assert (serverSess !=NULL );
ui/vnc-auth-vencrypt.c +1 -1
@@ -132,7 +132,7 @@ static int protocol_client_vencrypt_auth(VncState *vs, uint8_t *data, size_t len vs->tls =qcrypto_tls_session_new (vs->vd->tlscreds,NULL , vs->vd->tlsaclname, - QCRYPTO_TLS_CREDS_ENDPOINT_server, + QCryptoTLSCredsEndpoint_server, &err);if (!vs->tls) { VNC_DEBUG("Failed to setup TLS %s\n",
ui/vnc-ws.c +1 -1
@@ -68,7 +68,7 @@ void vncws_tls_handshake_io(void *opaque) vs->tls =qcrypto_tls_session_new (vs->vd->tlscreds,NULL , vs->vd->tlsaclname, - QCRYPTO_TLS_CREDS_ENDPOINT_server, + QCryptoTLSCredsEndpoint_server, &err);if (!vs->tls) { VNC_DEBUG("Failed to setup TLS %s\n",
ui/vnc.c +1 -1
@@ -3634,7 +3634,7 @@ void vnc_display_open(const char *id, Error **errp) }object_ref (OBJECT (vs->tlscreds)); -if (vs->tlscreds->endpoint != QCRYPTO_TLS_CREDS_ENDPOINT_server) { +if (vs->tlscreds->endpoint != QCryptoTLSCredsEndpoint_server) {error_setg (errp,"Expecting TLS credentials with a server endpoint" ); goto fail;
Signature · 1 line
2.4.3
RFC PATCH 5/5 Revert "qapi: allow override of default enum prefix naming"
In reply to Markus ArmbrusterThis reverts commit 351d36e454cddc67a1675740916636a7ccbf1c4b.
The previous commit removed the feature's lone user. The common name mangling should do going forward.
Conflicts:
docs/qapi-code-gen.txt
scripts/qapi-types.py
scripts/qapi.py
tests/Makefile
tests/qapi-schema/qapi-schema-test.out
--- docs/qapi-code-gen.txt | 9 -------- scripts/qapi-introspect.py | 2 +- scripts/qapi-types.py | 6 +++--- scripts/qapi-visit.py | 2 +- scripts/qapi.py | 37 ++++++++++++--------------------- tests/Makefile | 1 - tests/qapi-schema/enum-bad-prefix.err | 1 - tests/qapi-schema/enum-bad-prefix.exit | 1 - tests/qapi-schema/enum-bad-prefix.json | 2 -- tests/qapi-schema/enum-bad-prefix.out | 0 tests/qapi-schema/qapi-schema-test.json | 5 ----- tests/qapi-schema/qapi-schema-test.out | 2 -- tests/qapi-schema/test-qapi.py | 4 +--- 13 files changed, 19 insertions(+), 53 deletions(-) delete mode 100644 tests/qapi-schema/enum-bad-prefix.err delete mode 100644 tests/qapi-schema/enum-bad-prefix.exit delete mode 100644 tests/qapi-schema/enum-bad-prefix.json delete mode 100644 tests/qapi-schema/enum-bad-prefix.out
docs/qapi-code-gen.txt +0 -9
@@ -245,7 +245,6 @@ both fields like this: === Enumeration types === Usage: { 'enum': STRING, 'data': ARRAY-OF-STRING } - { 'enum': STRING, '*prefix': STRING, 'data': ARRAY-OF-STRING } An enumeration type is a dictionary containing a single 'data' key whose value is a list of strings. An example enumeration is:
@@ -257,14 +256,6 @@ useful. The list of strings should be lower case; if an enum name represents multiple words, use '-' between words. The string 'max' is not allowed as an enum value, and values should not be repeated. -FIXME obsolete, rewrite -The enum constants will be named by using a heuristic to turn the -type name into a set of underscore separated words. For the example -above, 'MyEnum' will turn into 'MY_ENUM' giving a constant name -of 'MY_ENUM_VALUE1' for the first value. If the default heuristic -does not result in a desirable name, the optional 'prefix' field -can be used when defining the enum. - The enumeration values are passed as strings over the Client JSON Protocol, but are encoded as C enum integral values in generated code. While the C code starts numbering at 0, it is better to use explicit
scripts/qapi-introspect.py +1 -1
@@ -134,7 +134,7 @@ const char %(c_name)s[] = %(c_string)s; def visit_builtin_type(self, name, info, json_type): self._gen_json(name, 'builtin', {'json-type': json_type}) - def visit_enum_type(self, name, info, values, prefix): + def visit_enum_type(self, name, info, values): self._gen_json(name, 'enum', {'values': values}) def visit_array_type(self, name, info, element_type):
scripts/qapi-types.py +3 -3
@@ -232,9 +232,9 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): self.decl += gen_type_cleanup_decl(name) self.defn += gen_type_cleanup(name) - def visit_enum_type(self, name, info, values, prefix): - self._fwdecl += gen_enum(name, values, prefix) - self._fwdefn += gen_enum_lookup(name, values, prefix) + def visit_enum_type(self, name, info, values): + self._fwdecl += gen_enum(name, values) + self._fwdefn += gen_enum_lookup(name, values) def visit_array_type(self, name, info, element_type): if isinstance(element_type, QAPISchemaBuiltinType):
scripts/qapi-visit.py +1 -1
@@ -346,7 +346,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor): return not (entity.is_implicit() and isinstance(entity, QAPISchemaObjectType)) - def visit_enum_type(self, name, info, values, prefix): + def visit_enum_type(self, name, info, values): self.decl += gen_visit_decl(name, scalar=True) self.defn += gen_visit_enum(name)
scripts/qapi.py +13 -24
@@ -666,15 +666,11 @@ def check_alternate(expr, expr_info): def check_enum(expr, expr_info): name = expr['enum'] members = expr.get('data') - prefix = expr.get('prefix') values = {'MAX': '(automatic)'} if not isinstance(members, list): raise QAPIExprError(expr_info, "Enum '%s' requires an array for 'data'" % name) - if prefix is not None and not isinstance(prefix, str): - raise QAPIExprError(expr_info, - "Enum '%s' requires a string for 'prefix'" % name) for member in members: check_name(expr_info, "Member of enum '%s'" % name, member, enum_member=True)
@@ -732,7 +728,7 @@ def check_exprs(exprs): expr = expr_elem['expr'] info = expr_elem['info'] if 'enum' in expr: - check_keys(expr_elem, 'enum', ['data'], ['prefix']) + check_keys(expr_elem, 'enum', ['data']) add_enum(expr['enum'], info, expr['data']) elif 'union' in expr: check_keys(expr_elem, 'union', ['data'],
@@ -831,7 +827,7 @@ class QAPISchemaVisitor(object): def visit_builtin_type(self, name, info, json_type): pass - def visit_enum_type(self, name, info, values, prefix): + def visit_enum_type(self, name, info, values): pass def visit_array_type(self, name, info, element_type):
@@ -904,13 +900,11 @@ class QAPISchemaBuiltinType(QAPISchemaType): class QAPISchemaEnumType(QAPISchemaType): - def __init__(self, name, info, values, prefix): + def __init__(self, name, info, values): QAPISchemaType.__init__(self, name, info) for v in values: assert isinstance(v, str) - assert prefix is None or isinstance(prefix, str) self.values = values - self.prefix = prefix def check(self, schema): assert len(set(self.values)) == len(self.values)
@@ -923,15 +917,13 @@ class QAPISchemaEnumType(QAPISchemaType): return c_name(self.name) def c_null(self): - return c_enum_const(self.name, (self.values + ['MAX'])[0], - self.prefix) + return c_enum_const(self.name, (self.values + ['MAX'])[0]) def json_type(self): return 'string' def visit(self, visitor): - visitor.visit_enum_type(self.name, self.info, - self.values, self.prefix) + visitor.visit_enum_type(self.name, self.info, self.values) class QAPISchemaArrayType(QAPISchemaType):
@@ -1209,7 +1201,7 @@ class QAPISchema(object): def _make_implicit_enum_type(self, name, info, values): name = name + 'Kind' # Use namespace reserved by add_name() - self._def_entity(QAPISchemaEnumType(name, info, values, None)) + self._def_entity(QAPISchemaEnumType(name, info, values)) return name def _make_array_type(self, element_type, info):
@@ -1230,8 +1222,7 @@ class QAPISchema(object): def _def_enum_type(self, expr, info): name = expr['enum'] data = expr['data'] - prefix = expr.get('prefix') - self._def_entity(QAPISchemaEnumType(name, info, data, prefix)) + self._def_entity(QAPISchemaEnumType(name, info, data)) def _make_member(self, name, typ, info): optional = False
@@ -1362,9 +1353,7 @@ class QAPISchema(object): # Code generation helpers # -def c_enum_const(type_name, const_name, prefix=None): - if prefix is not None: - type_name = prefix +def c_enum_const(type_name, const_name): return c_name(type_name + '_' + const_name) c_name_trans = string.maketrans('.-', '__')
@@ -1477,20 +1466,20 @@ def guardend(name): name=guardname(name)) -def gen_enum_lookup(name, values, prefix=None): +def gen_enum_lookup(name, values): ret = mcgen(''' const char *const %(c_name)s_lookup[] = { ''', c_name=c_name(name)) for value in values: - index = c_enum_const(name, value, prefix) + index = c_enum_const(name, value) ret += mcgen(''' [%(index)s] = "%(value)s", ''', index=index, value=value) - max_index = c_enum_const(name, 'MAX', prefix) + max_index = c_enum_const(name, 'MAX') ret += mcgen(''' [%(max_index)s] = NULL, };
@@ -1499,7 +1488,7 @@ const char *const %(c_name)s_lookup[] = { return ret -def gen_enum(name, values, prefix=None): +def gen_enum(name, values): # append automatically generated _MAX value enum_values = values + ['MAX']
@@ -1514,7 +1503,7 @@ typedef enum %(c_name)s { ret += mcgen(''' %(c_enum)s = %(i)d, ''', - c_enum=c_enum_const(name, value, prefix), + c_enum=c_enum_const(name, value), i=i) i += 1
tests/Makefile +0 -1
@@ -259,7 +259,6 @@ qapi-schema += double-type.json qapi-schema += duplicate-key.json qapi-schema += empty.json qapi-schema += enum-bad-name.json -qapi-schema += enum-bad-prefix.json qapi-schema += enum-clash-member.json qapi-schema += enum-dict-member.json qapi-schema += enum-int-member.json
tests/qapi-schema/enum-bad-prefix.err deleted +0 -1
@@ -1 +0,0 @@ -tests/qapi-schema/enum-bad-prefix.json:2: Enum 'MyEnum' requires a string for 'prefix'
tests/qapi-schema/enum-bad-prefix.exit deleted +0 -1
@@ -1 +0,0 @@ -1
tests/qapi-schema/enum-bad-prefix.json deleted +0 -2
@@ -1,2 +0,0 @@ -# The prefix must be a string type -{ 'enum': 'MyEnum', 'data': [ 'one' ], 'prefix': [ 'fish' ] }
tests/qapi-schema/enum-bad-prefix.out deleted +0 -0
tests/qapi-schema/qapi-schema-test.json +0 -5
@@ -18,11 +18,6 @@ { 'struct': 'Empty1', 'data': { } } { 'struct': 'Empty2', 'base': 'Empty1', 'data': { } } -# for testing override of default naming heuristic -{ 'enum': 'QEnumTwo', - 'prefix': 'QENUM_TWO', - 'data': [ 'value1', 'value2' ] } - # for testing nested structs { 'struct': 'UserDefOne', 'base': 'UserDefZero', # intentional forward reference
tests/qapi-schema/qapi-schema-test.out +0 -2
@@ -99,8 +99,6 @@ object NestedEnumsOne member enum2: EnumOne optional=True member enum3: EnumOne optional=False member enum4: EnumOne optional=True -enum QEnumTwo ['value1', 'value2'] - prefix QENUM_TWO object TestStruct member integer: int optional=False member boolean: bool optional=False
tests/qapi-schema/test-qapi.py +1 -3
@@ -17,10 +17,8 @@ import sys class QAPISchemaTestVisitor(QAPISchemaVisitor): - def visit_enum_type(self, name, info, values, prefix): + def visit_enum_type(self, name, info, values): print 'enum %s %s' % (name, values) - if prefix: - print ' prefix %s' % prefix def visit_object_type(self, name, info, base, members, variants): print 'object %s' % name
Signature · 1 line
2.4.3
PATCH v9 22/27 qapi: Remove outdated tests related to QMP/branch collisions
In reply to Eric BlakeNow that branches are in a separate C namespace, we can remove the restrictions in the parser that claim a branch name would collide with QMP, and delete the negative tests that are no longer problematic. A separate patch can then add positive tests to qapi-schema-test to test that any corner cases will compile correctly.
This reverts the scripts/qapi.py portion of commit 7b2a5c2, now that the assertions that it plugged are no longer possible.
---
v9: no change
v8: retitle and update commit message, finish reversion of 7b2a5c2
v7: new patch (also temporarily appeared in subset B v10)
--- scripts/qapi.py | 11 ++--------- tests/Makefile | 3 --- tests/qapi-schema/flat-union-clash-branch.err | 0 tests/qapi-schema/flat-union-clash-branch.exit | 1 - tests/qapi-schema/flat-union-clash-branch.json | 18 ------------------ tests/qapi-schema/flat-union-clash-branch.out | 14 -------------- tests/qapi-schema/flat-union-clash-type.err | 1 - tests/qapi-schema/flat-union-clash-type.exit | 1 - tests/qapi-schema/flat-union-clash-type.json | 14 -------------- tests/qapi-schema/flat-union-clash-type.out | 0 tests/qapi-schema/union-clash-type.err | 1 - tests/qapi-schema/union-clash-type.exit | 1 - tests/qapi-schema/union-clash-type.json | 9 --------- tests/qapi-schema/union-clash-type.out | 0 14 files changed, 2 insertions(+), 72 deletions(-) delete mode 100644 tests/qapi-schema/flat-union-clash-branch.err delete mode 100644 tests/qapi-schema/flat-union-clash-branch.exit delete mode 100644 tests/qapi-schema/flat-union-clash-branch.json delete mode 100644 tests/qapi-schema/flat-union-clash-branch.out delete mode 100644 tests/qapi-schema/flat-union-clash-type.err delete mode 100644 tests/qapi-schema/flat-union-clash-type.exit delete mode 100644 tests/qapi-schema/flat-union-clash-type.json delete mode 100644 tests/qapi-schema/flat-union-clash-type.out delete mode 100644 tests/qapi-schema/union-clash-type.err delete mode 100644 tests/qapi-schema/union-clash-type.exit delete mode 100644 tests/qapi-schema/union-clash-type.json delete mode 100644 tests/qapi-schema/union-clash-type.out
scripts/qapi.py +2 -9
@@ -548,8 +548,7 @@ def check_union(expr, expr_info): base = expr.get('base') discriminator = expr.get('discriminator') members = expr['data'] - values = {'MAX': '(automatic)', 'KIND': '(automatic)', - 'TYPE': '(automatic)'} + values = {'MAX': '(automatic)'} # Two types of unions, determined by discriminator.
@@ -607,19 +606,13 @@ def check_union(expr, expr_info): " of branch '%s'" % key) # If the discriminator names an enum type, then all members - # of 'data' must also be members of the enum type, which in turn - # must not collide with the discriminator name. + # of 'data' must also be members of the enum type. if enum_define: if key not in enum_define['enum_values']: raise QAPIExprError(expr_info, "Discriminator value '%s' is not found in " "enum '%s'" % (key, enum_define["enum_name"])) - if discriminator in enum_define['enum_values']: - raise QAPIExprError(expr_info, - "Discriminator name '%s' collides with " - "enum value in '%s'" % - (discriminator, enum_define["enum_name"])) # Otherwise, check for conflicts in the generated enum else:
tests/Makefile +0 -3
@@ -277,9 +277,7 @@ qapi-schema += flat-union-bad-base.json qapi-schema += flat-union-bad-discriminator.json qapi-schema += flat-union-base-any.json qapi-schema += flat-union-base-union.json -qapi-schema += flat-union-clash-branch.json qapi-schema += flat-union-clash-member.json -qapi-schema += flat-union-clash-type.json qapi-schema += flat-union-empty.json qapi-schema += flat-union-inline.json qapi-schema += flat-union-int-branch.json
@@ -341,7 +339,6 @@ qapi-schema += union-bad-branch.json qapi-schema += union-base-no-discriminator.json qapi-schema += union-clash-branches.json qapi-schema += union-clash-data.json -qapi-schema += union-clash-type.json qapi-schema += union-empty.json qapi-schema += union-invalid-base.json qapi-schema += union-max.json
tests/qapi-schema/flat-union-clash-branch.err deleted +0 -0
tests/qapi-schema/flat-union-clash-branch.exit deleted +0 -1
@@ -1 +0,0 @@ -0
tests/qapi-schema/flat-union-clash-branch.json deleted +0 -18
@@ -1,18 +0,0 @@ -# Flat union branch name collision -# FIXME: this parses, but then fails to compile due to a duplicate 'c_d' -# (one from the base member, the other from the branch name). We should -# either reject the collision at parse time, or munge the generated branch -# name to allow this to compile. -{ 'enum': 'TestEnum', - 'data': [ 'base', 'c-d' ] } -{ 'struct': 'Base', - 'data': { 'enum1': 'TestEnum', '*c_d': 'str' } } -{ 'struct': 'Branch1', - 'data': { 'string': 'str' } } -{ 'struct': 'Branch2', - 'data': { 'value': 'int' } } -{ 'union': 'TestUnion', - 'base': 'Base', - 'discriminator': 'enum1', - 'data': { 'base': 'Branch1', - 'c-d': 'Branch2' } }
tests/qapi-schema/flat-union-clash-branch.out deleted +0 -14
@@ -1,14 +0,0 @@ -object :empty -object Base - member enum1: TestEnum optional=False - member c_d: str optional=True -object Branch1 - member string: str optional=False -object Branch2 - member value: int optional=False -enum TestEnum ['base', 'c-d'] -object TestUnion - base Base - tag enum1 - case base: Branch1 - case c-d: Branch2
tests/qapi-schema/flat-union-clash-type.err deleted +0 -1
@@ -1 +0,0 @@ -tests/qapi-schema/flat-union-clash-type.json:11: Discriminator name 'type' collides with enum value in 'TestEnum'
tests/qapi-schema/flat-union-clash-type.exit deleted +0 -1
@@ -1 +0,0 @@ -1
tests/qapi-schema/flat-union-clash-type.json deleted +0 -14
@@ -1,14 +0,0 @@ -# Flat union branch 'type' -# Reject this, because we would have a clash in generated C, between the -# outer tag 'type' and the branch name 'type' within the union. -# TODO: We could munge the generated C branch name to let it compile. -{ 'enum': 'TestEnum', - 'data': [ 'type' ] } -{ 'struct': 'Base', - 'data': { 'type': 'TestEnum' } } -{ 'struct': 'Branch1', - 'data': { 'string': 'str' } } -{ 'union': 'TestUnion', - 'base': 'Base', - 'discriminator': 'type', - 'data': { 'type': 'Branch1' } }
tests/qapi-schema/flat-union-clash-type.out deleted +0 -0
tests/qapi-schema/union-clash-type.err deleted +0 -1
@@ -1 +0,0 @@ -tests/qapi-schema/union-clash-type.json:8: Union 'TestUnion' member 'kind' clashes with '(automatic)'
tests/qapi-schema/union-clash-type.exit deleted +0 -1
@@ -1 +0,0 @@ -1
tests/qapi-schema/union-clash-type.json deleted +0 -9
@@ -1,9 +0,0 @@ -# Union branch 'type' -# Reject this, because we would have a clash in generated C, between the -# simple union's implicit tag member 'kind' and the branch name 'kind' -# within the union. -# TODO: Even when the generated C is switched to use 'type' rather than -# 'kind', to match the QMP spelling, the collision should still be detected. -# Or, we could munge the branch name to allow compilation. -{ 'union': 'TestUnion', - 'data': { 'kind': 'int', 'type': 'str' } }
tests/qapi-schema/union-clash-type.out deleted +0 -0
Signature · 1 line
2.4.3
PATCH v9 23/27 qapi: Simplify visiting of alternate types
In reply to Eric BlakePreviously, working with alternates required two lookup arrays and some indirection: for type Foo, we created Foo_qtypes[] which maps each qtype to a value of the generated FooKind enum, then look up that value in FooKind_lookup[] like we do for other union types.
This has a couple of subtle bugs. First, the generator was creating a call with a parameter '(int *) &(*obj)->type' where type is an enum type; this is unsafe if the compiler chooses to store the enum type in a different size than int, where assigning through the wrong size pointer can corrupt data or cause a SIGBUS.
Second, since the values of the FooKind enum start at zero, all entries of the Foo_qtypes[] array that were not explicitly initialized will map to the same branch of the union as the first member of the alternate, rather than triggering a desired failure in visit_get_next_type(). Fortunately, the bug seldom bites; the very next thing the input visitor does is try to parse the incoming JSON with the wrong parser, which normally fails; the output visitor is not used with a C struct in that state, and the dealloc visitor has nothing to clean up (so there is no leak).
However, the second bug IS observable in one case: the behavior of an alternate that contains a 'number' member but no 'int' member differs according to whether the 'number' was first in the qapi definition, and when the input being parsed is an integer; this is because the 'number' parser accepts QTYPE_QINT in addition to the expected QTYPE_QFLOAT. A later patch will worry about fixing alternates to parse all inputs that a non-alternate 'number' would accept, for now this is still marked FIXME, and the test merely updated to point out that new undesired behavior of 'ans' matches the existing undesired behavior of 'asn'.
This patch fixes the validation bug by deleting the indirection, and modifying get_next_type() to directly assign a qtype_code parameter. This in turn fixes the type-casting bug, as we are no longer casting a pointer to enum to a questionable size. There is no longer a need to generate an implicit FooKind enum associated with the alternate type (since the QMP wire format never uses the stringized counterparts of the C union member names); that also means we no longer have a collision with an alternate branch named 'max'. Since visit_get_next_type() does not know which qtypes are expected, the generated visitor is modified to generate an error statement if an unexpected type is encountered.
The code relies on a new QAPISchemaAlternateTypeTag subclass and the use of a new member.c_type() method for generating qapi-types.h; this is because we don't want to expose 'qtype_code' as a built-in type usable from .json files. The new subtype happens to work by keeping tag_member.type as None, although this feels a bit unclean, and may be touched up further in a later patch.
Callers now have to know the QTYPE_* mapping when looking at the discriminator; but so far, only the testsuite was even using the C struct of an alternate types. I considered the possibility of keeping the internal enum FooKind, but initialized differently than most generated arrays, as in:
typedef enum FooKind {
FOO_KIND_A = QTYPE_QDICT,
FOO_KIND_B = QTYPE_QINT,
} FooKind;
to create nicer aliases for knowing when to use foo->a or foo->b when inspecting foo->type; but it turned out to add too much complexity, especially without a client.
There is a user-visible side effect to this change, but I consider it to be an improvement. Previously, the invalid QMP command:
{"execute":"blockdev-add", "arguments":{"options":
{"driver":"raw", "id":"a", "file":true}}}
failed with:
{"error": {"class": "GenericError",
"desc": "Invalid parameter type for 'file', expected: QDict"}}(visit_get_next_type() succeeded, and the error comes from the visit_type_BlockdevOptions() expecting {}; there is no mention of the fact that a string would also work). Now it fails with:
{"error": {"class": "GenericError",
"desc": "Invalid parameter type for 'file', expected: BlockdevRef"}}
(the error when the next type doesn't match any expected types for the overall alternate).
---
v9: rebase to earlier changes, rework commit message to mention second bug fix; move positive test in qapi-schema-test to later patch
v8: no change
v7: rebase onto earlier changes, rework how subtype makes things work
v6: rebase onto tag_member subclass, testsuite, gen_err_check(), and info improvements
--- docs/qapi-code-gen.txt | 3 --- include/qapi/visitor-impl.h | 3 ++- include/qapi/visitor.h | 8 ++++++- qapi/qapi-visit-core.c | 4 ++-- qapi/qmp-input-visitor.c | 4 ++-- scripts/qapi-types.py | 36 +--------------------------- scripts/qapi-visit.py | 14 +++++++---- scripts/qapi.py | 44 +++++++++++++++++++++++++--------- tests/qapi-schema/alternate-empty.out | 1 - tests/qapi-schema/qapi-schema-test.out | 8 ------- tests/test-qmp-input-visitor.c | 31 ++++++++++++------------ tests/test-qmp-output-visitor.c | 4 ++-- 12 files changed, 74 insertions(+), 86 deletions(-)
docs/qapi-code-gen.txt +0 -3
@@ -383,9 +383,6 @@ where each branch of the union names a QAPI type. For example: 'data': { 'definition': 'BlockdevOptions', 'reference': 'str' } } -Just like for a simple union, an implicit C enum 'NameKind' is created -to enumerate the branches for the alternate 'Name'. - Unlike a union, the discriminator string is never passed on the wire for the Client JSON Protocol. Instead, the value's JSON type serves as an implicit discriminator, which in turn means that an alternate
include/qapi/visitor-impl.h +2 -1
@@ -32,7 +32,8 @@ struct Visitorvoid (*type_enum)(Visitor *v,int *obj,const char *const strings[],const char *kind,const char *name,Error **errp); -void (*get_next_type)(Visitor *v,int *kind,const int *qobjects, +/* May be NULL; most useful for input visitors. */ +void (*get_next_type)(Visitor *v,qtype_code *type,const char *name,Error **errp);void (*type_int)(Visitor *v,int64_t *obj,const char *name,Error **errp);
include/qapi/visitor.h +7 -1
@@ -41,7 +41,13 @@ GenericList *visit_next_list(Visitor *v, GenericList **list, Error **errp);void visit_end_list (Visitor *v,Error **errp);void visit_optional (Visitor *v,bool *present,const char *name,Error **errp); -void visit_get_next_type (Visitor *v,int *obj,const int *qtypes, + +/** +* Determine the qtype of the item @name in the current object visit. +* For input visitors, set *@type to the correct qtype of a qapi +* alternate type; for other visitors, leave *@type unchanged. +*/ +void visit_get_next_type (Visitor *v,qtype_code *type,const char *name,Error **errp);void visit_type_enum (Visitor *v,int *obj,const char *const strings[],const char *kind,const char *name,Error **errp);
qapi/qapi-visit-core.c +2 -2
@@ -81,11 +81,11 @@ void visit_optional(Visitor *v, bool *present, const char *name, } } -void visit_get_next_type (Visitor *v,int *obj,const int *qtypes, +void visit_get_next_type (Visitor *v,qtype_code *type,const char *name,Error **errp) {if (v->get_next_type) { - v->get_next_type (v, obj, qtypes, name, errp); + v->get_next_type (v, type, name, errp); } }
qapi/qmp-input-visitor.c +2 -2
@@ -208,7 +208,7 @@ static void qmp_input_end_list(Visitor *v, Error **errp)qmp_input_pop (qiv, errp); } -static void qmp_input_get_next_type (Visitor *v,int *kind,const int *qobjects, +static void qmp_input_get_next_type (Visitor *v,qtype_code *type,const char *name,Error **errp) {QmpInputVisitor *qiv =to_qiv (v);
@@ -218,7 +218,7 @@ static void qmp_input_get_next_type(Visitor *v, int *kind, const int *qobjects,error_setg (errp,QERR_MISSING_PARAMETER , name ? name :"null" );return ; } - *kind = qobjects[qobject_type (qobj)]; + *type =qobject_type (qobj); } static void qmp_input_type_int(Visitor *v, int64_t *obj, const char *name,
scripts/qapi-types.py +1 -35
@@ -47,7 +47,7 @@ def gen_struct_fields(members): ret += mcgen(''' %(c_type)s %(c_name)s; ''', - c_type=memb.type.c_type(), c_name=c_name(memb.name)) + c_type=memb.c_type(), c_name=c_name(memb.name)) return ret
@@ -101,38 +101,6 @@ static inline %(base)s *qapi_%(c_name)s_base(const %(c_name)s *obj) c_name=c_name(name), base=base.c_name()) -def gen_alternate_qtypes_decl(name): - return mcgen(''' - -extern const int %(c_name)s_qtypes[]; -''', - c_name=c_name(name)) - - -def gen_alternate_qtypes(name, variants): - ret = mcgen(''' - -const int %(c_name)s_qtypes[QTYPE_MAX] = { -''', - c_name=c_name(name)) - - for var in variants.variants: - qtype = var.type.alternate_qtype() - assert qtype - - ret += mcgen(''' - [%(qtype)s] = %(enum_const)s, -''', - qtype=qtype, - enum_const=c_enum_const(variants.tag_member.type.name, - var.name)) - - ret += mcgen(''' -}; -''') - return ret - - def gen_variants(variants): # FIXME: What purpose does data serve, besides preventing a union that # has a branch named 'data'? We use it in qapi-visit.py to decide
@@ -257,9 +225,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): def visit_alternate_type(self, name, info, variants): self._fwdecl += gen_fwd_object_or_array(name) - self._fwdefn += gen_alternate_qtypes(name, variants) self.decl += gen_object(name, None, [variants.tag_member], variants) - self.decl += gen_alternate_qtypes_decl(name) self._gen_type_cleanup(name) # If you link code generated from multiple schemata, you want only one
scripts/qapi-visit.py +9 -5
@@ -193,7 +193,7 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error if (err) { goto out; } - visit_get_next_type(v, (int*) &(*obj)->type, %(c_name)s_qtypes, name, &err); + visit_get_next_type(v, &(*obj)->type, name, &err); if (err) { goto out_obj; }
@@ -201,20 +201,22 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error ''', c_name=c_name(name)) + # FIXME: When 'number' but not 'int' is present in the alternate, we + # should allow QTYPE_INT to promote to QTYPE_FLOAT. for var in variants.variants: ret += mcgen(''' case %(case)s: visit_type_%(c_type)s(v, &(*obj)->u.%(c_name)s, name, &err); break; ''', - case=c_enum_const(variants.tag_member.type.name, - var.name), + case=var.type.alternate_qtype(), c_type=var.type.c_name(), c_name=c_name(var.name)) ret += mcgen(''' default: - abort(); + error_setg(&err, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", + "%(name)s"); } out_obj: error_propagate(errp, err);
@@ -223,7 +225,8 @@ out_obj: out: error_propagate(errp, err); } -''') +''', + name=name) return ret
@@ -430,6 +433,7 @@ fdef.write(mcgen(''' fdecl.write(mcgen(''' #include "qapi/visitor.h" +#include "qapi/qmp/qerror.h" #include "%(prefix)sqapi-types.h" ''',
scripts/qapi.py +33 -11
99 lines not on this page · raw message
tests/qapi-schema/alternate-empty.out +0 -1
@@ -1,4 +1,3 @@ object :empty alternate Alt case i: int -enum AltKind ['i']
tests/qapi-schema/qapi-schema-test.out +0 -8
@@ -56,27 +56,21 @@ object :obj-user_def_cmd2-arg alternate AltIntNum case i: int case n: number -enum AltIntNumKind ['i', 'n'] alternate AltNumInt case n: number case i: int -enum AltNumIntKind ['n', 'i'] alternate AltNumStr case n: number case s: str -enum AltNumStrKind ['n', 's'] alternate AltStrBool case s: str case b: bool -enum AltStrBoolKind ['s', 'b'] alternate AltStrInt case s: str case i: int -enum AltStrIntKind ['s', 'i'] alternate AltStrNum case s: str case n: number -enum AltStrNumKind ['s', 'n'] event EVENT_A None event EVENT_B None event EVENT_C :obj-EVENT_C-arg
@@ -112,7 +106,6 @@ alternate UserDefAlternate case uda: UserDefA case s: str case i: int -enum UserDefAlternateKind ['uda', 's', 'i'] object UserDefB member intb: int optional=False member a-b: bool optional=True
@@ -178,7 +171,6 @@ event __ORG.QEMU_X-EVENT __org.qemu_x-Struct alternate __org.qemu_x-Alt case __org.qemu_x-branch: str case b: __org.qemu_x-Base -enum __org.qemu_x-AltKind ['__org.qemu_x-branch', 'b'] object __org.qemu_x-Base member __org.qemu_x-member1: __org.qemu_x-Enum optional=False enum __org.qemu_x-Enum ['__org.qemu_x-value']
tests/test-qmp-input-visitor.c +16 -15
@@ -317,13 +317,13 @@ static void test_visitor_in_alternate(TestInputVisitorData *data, v =visitor_input_test_init (data,"42" );visit_type_UserDefAlternate (v, &tmp,NULL , &error_abort); - g_assert_cmpint(tmp->type, ==, USER_DEF_ALTERNATE_KIND_I); + g_assert_cmpint(tmp->type, ==, QTYPE_QINT); g_assert_cmpint(tmp->u.i, ==, 42);qapi_free_UserDefAlternate (tmp); v =visitor_input_test_init (data,"'string'" );visit_type_UserDefAlternate (v, &tmp,NULL , &error_abort); - g_assert_cmpint(tmp->type, ==, USER_DEF_ALTERNATE_KIND_S); + g_assert_cmpint(tmp->type, ==, QTYPE_QSTRING); g_assert_cmpstr(tmp->u.s, ==, "string");qapi_free_UserDefAlternate (tmp);
@@ -351,36 +351,37 @@ static void test_visitor_in_alternate_number(TestInputVisitorData *data,g_assert (data->err);qapi_free_AltStrBool (asb); -/* FIXME: Order of alternate should not affect semantics; asn should -* parse the same as ans */ +/* FIXME: integer should parse as number */ v =visitor_input_test_init (data,"42" );visit_type_AltStrNum (v, &asn,NULL , &data->err); -/* FIXME g_assert_cmpint(asn->type, == ALT_STR_NUM_KIND_N); */ +/* FIXME g_assert_cmpint(asn->type, ==, QTYPE_QFLOAT); */ /* FIXME g_assert_cmpfloat(asn->u.n, ==, 42); */ g_assert (data->err);qapi_free_AltStrNum (asn); +/* FIXME: integer should parse as number */ v =visitor_input_test_init (data,"42" ); -visit_type_AltNumStr (v, &ans,NULL , &error_abort); - g_assert_cmpint(ans->type, ==, ALT_NUM_STR_KIND_N); - g_assert_cmpfloat(ans->u.n, ==, 42); +visit_type_AltNumStr (v, &ans,NULL , &data->err); +/* FIXME g_assert_cmpint(ans->type, ==, QTYPE_QFLOAT); */ +/* FIXME g_assert_cmpfloat(ans->u.n, ==, 42); */ +g_assert (data->err);qapi_free_AltNumStr (ans); v =visitor_input_test_init (data,"42" );visit_type_AltStrInt (v, &asi,NULL , &error_abort); - g_assert_cmpint(asi->type, ==, ALT_STR_INT_KIND_I); + g_assert_cmpint(asi->type, ==, QTYPE_QINT); g_assert_cmpint(asi->u.i, ==, 42);qapi_free_AltStrInt (asi); v =visitor_input_test_init (data,"42" );visit_type_AltIntNum (v, &ain,NULL , &error_abort); - g_assert_cmpint(ain->type, ==, ALT_INT_NUM_KIND_I); + g_assert_cmpint(ain->type, ==, QTYPE_QINT); g_assert_cmpint(ain->u.i, ==, 42);qapi_free_AltIntNum (ain); v =visitor_input_test_init (data,"42" );visit_type_AltNumInt (v, &ani,NULL , &error_abort); - g_assert_cmpint(ani->type, ==, ALT_NUM_INT_KIND_I); + g_assert_cmpint(ani->type, ==, QTYPE_QINT); g_assert_cmpint(ani->u.i, ==, 42);qapi_free_AltNumInt (ani);
@@ -393,13 +394,13 @@ static void test_visitor_in_alternate_number(TestInputVisitorData *data, v =visitor_input_test_init (data,"42.5" );visit_type_AltStrNum (v, &asn,NULL , &error_abort); - g_assert_cmpint(asn->type, ==, ALT_STR_NUM_KIND_N); + g_assert_cmpint(asn->type, ==, QTYPE_QFLOAT); g_assert_cmpfloat(asn->u.n, ==, 42.5);qapi_free_AltStrNum (asn); v =visitor_input_test_init (data,"42.5" );visit_type_AltNumStr (v, &ans,NULL , &error_abort); - g_assert_cmpint(ans->type, ==, ALT_NUM_STR_KIND_N); + g_assert_cmpint(ans->type, ==, QTYPE_QFLOAT); g_assert_cmpfloat(ans->u.n, ==, 42.5);qapi_free_AltNumStr (ans);
@@ -410,13 +411,13 @@ static void test_visitor_in_alternate_number(TestInputVisitorData *data, v =visitor_input_test_init (data,"42.5" );visit_type_AltIntNum (v, &ain,NULL , &error_abort); - g_assert_cmpint(ain->type, ==, ALT_INT_NUM_KIND_N); + g_assert_cmpint(ain->type, ==, QTYPE_QFLOAT); g_assert_cmpfloat(ain->u.n, ==, 42.5);qapi_free_AltIntNum (ain); v =visitor_input_test_init (data,"42.5" );visit_type_AltNumInt (v, &ani,NULL , &error_abort); - g_assert_cmpint(ani->type, ==, ALT_NUM_INT_KIND_N); + g_assert_cmpint(ani->type, ==, QTYPE_QFLOAT); g_assert_cmpfloat(ani->u.n, ==, 42.5);qapi_free_AltNumInt (ani); }
tests/test-qmp-output-visitor.c +2 -2
@@ -428,7 +428,7 @@ static void test_visitor_out_alternate(TestOutputVisitorData *data,UserDefAlternate *tmp; tmp =g_new0 (UserDefAlternate,1 ); - tmp->type =USER_DEF_ALTERNATE_KIND_I ; + tmp->type =QTYPE_QINT ; tmp->u.i =42 ;visit_type_UserDefAlternate (data->ov, &tmp,NULL , &error_abort);
@@ -441,7 +441,7 @@ static void test_visitor_out_alternate(TestOutputVisitorData *data,qobject_decref (arg); tmp =g_new0 (UserDefAlternate,1 ); - tmp->type =USER_DEF_ALTERNATE_KIND_S ; + tmp->type =QTYPE_QSTRING ; tmp->u.s =g_strdup ("hello" );visit_type_UserDefAlternate (data->ov, &tmp,NULL , &error_abort);
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v9 23/27] qapi: Simplify visiting of alternate types
Quoted 24 lines · Eric Blake
Previously, working with alternates required two lookup arrays and some indirection: for type Foo, we created Foo_qtypes[] which maps each qtype to a value of the generated FooKind enum, then look up that value in FooKind_lookup[] like we do for other union types.
This has a couple of subtle bugs. First, the generator was creating a call with a parameter '(int *) &(*obj)->type' where type is an enum type; this is unsafe if the compiler chooses to store the enum type in a different size than int, where assigning through the wrong size pointer can corrupt data or cause a SIGBUS.
Second, since the values of the FooKind enum start at zero, all entries of the Foo_qtypes[] array that were not explicitly initialized will map to the same branch of the union as the first member of the alternate, rather than triggering a desired failure in
visit_get_next_type(). Fortunately, the bug seldom bites; the very next thing the input visitor does is try to parse the incoming JSON with the wrong parser, which normally fails; the output visitor is not used with a C struct in that state, and the dealloc visitor has nothing to clean up (so there is no leak).
Quoted 4 lines
However, the second bug IS observable in one case: the behavior of an alternate that contains a 'number' member but no 'int' member differs according to whether the 'number' was first in the qapi definition,
This is confusing. If there is a 'number' but no 'int', and the 'number is first, what's second?
Quoted 6 lines
and when the input being parsed is an
integer; this is because the 'number' parser acceptsQTYPE_QINTin addition to the expectedQTYPE_QFLOAT. A later patch will worry about fixing alternates to parse all inputs that a non-alternate 'number' would accept, for now this is still marked FIXME, and the test merely updated to point out that
and tests/test-qmp-input-visitor.c merely updated
Quoted 4 lines
new undesired behavior of 'ans' matches the existing undesired behavior of 'asn'.
This patch fixes the validation bug by deleting the indirection,
What's the validation bug? I guess it's the one involving default-initialized FooKind_lookup[].
Quoted 12 lines
and modifying
get_next_type()to directly assign aqtype_codeparameter. This in turn fixes the type-casting bug, as we are no longer casting a pointer to enum to a questionable size. There is no longer a need to generate an implicit FooKind enum associated with the alternate type (since the QMP wire format never uses the stringized counterparts of the C union member names); that also means we no longer have a collision with an alternate branch named 'max'. Sincevisit_get_next_type()does not know which qtypes are expected, the generated visitor is modified to generate an error statement if an unexpected type is encountered.
Quoted 4 lines
The code relies on a new QAPISchemaAlternateTypeTag subclass and the use of a new
member.c_type()method for generatingqapi-types.h; this is because we don't want to expose 'qtype_code' as a built-in type usable from .json files.
I'd be totally cool with that, actually.
Quoted 3 lines
The new subtype happens to work by keeping tag_member.type as None, although this feels a bit unclean, and may be touched up further in a later patch.
I hate special cases like this one.
Quoted 4 lines
Callers now have to know the QTYPE_* mapping when looking at the discriminator; but so far, only the testsuite was even using the C struct of an alternate types. I considered the possibility of keeping the internal enum FooKind, but initialized differently
Quoted 8 lines
than most generated arrays, as in:
typedef enum FooKind {
FOO_KIND_A=QTYPE_QDICT,
FOO_KIND_B=QTYPE_QINT,
} FooKind;
to create nicer aliases for knowing when to usefoo->aorfoo->bwhen inspectingfoo->type; but it turned out to add too much complexity, especially without a client.
Having to use QTYPE_FOOs seems good enough.
Quoted 73 lines
There is a user-visible side effect to this change, but I consider it to be an improvement. Previously, the invalid QMP command:
{"execute":"blockdev-add", "arguments":{"options":{"driver":"raw", "id":"a", "file":true}}} failed with: {"error": {"class": "GenericError", "desc": "Invalid parameter type for 'file', expected: QDict"}}(
visit_get_next_type()succeeded, and the error comes from thevisit_type_BlockdevOptions()expecting {}; there is no mention of the fact that a string would also work). Now it fails with:
{"error": {"class": "GenericError","desc": "Invalid parameter type for 'file', expected: BlockdevRef"}}(the error when the next type doesn't match any expected types for the overall alternate).
Signed-off-by Eric Blake <[email protected]>---
v9: rebase to earlier changes, rework commit message to mention second bug fix; move positive test in qapi-schema-test to later patch
v8: no change
v7: rebase onto earlier changes, rework how subtype makes things work
v6: rebase ontotag_membersubclass, testsuite,gen_err_check(), and info improvements--- docs/qapi-code-gen.txt | 3 --- include/qapi/visitor-impl.h | 3 ++- include/qapi/visitor.h | 8 ++++++- qapi/qapi-visit-core.c | 4 ++-- qapi/qmp-input-visitor.c | 4 ++-- scripts/qapi-types.py | 36 +--------------------------- scripts/qapi-visit.py | 14 +++++++---- scripts/qapi.py | 44 +++++++++++++++++++++++++--------- tests/qapi-schema/alternate-empty.out | 1 - tests/qapi-schema/qapi-schema-test.out | 8 ------- tests/test-qmp-input-visitor.c | 31 ++++++++++++------------ tests/test-qmp-output-visitor.c | 4 ++-- 12 files changed, 74 insertions(+), 86 deletions(-)docs/qapi-code-gen.txt +0
-3@@ -383,9 +383,6 @@ where each branch of the union names a QAPI type. For example: 'data': { 'definition': 'BlockdevOptions', 'reference': 'str' } } -Just like for a simple union, an implicit C enum 'NameKind' is created -to enumerate the branches for the alternate 'Name'. - Unlike a union, the discriminator string is never passed on the wire for the Client JSON Protocol. Instead, the value's JSON type serves as an implicit discriminator, which in turn means that an alternateinclude/qapi/visitor-impl.h +2
-1@@ -32,7 +32,8 @@ struct Visitorvoid (*type_enum)(Visitor *v,int *obj,const char *const strings[],const char *kind,const char *name,Error **errp); -void (*get_next_type)(Visitor *v,int *kind,const int *qobjects, +/* May be NULL; most useful for input visitors. */ +void (*get_next_type)(Visitor *v,qtype_code *type,const char *name,Error **errp);void (*type_int)(Visitor *v,int64_t *obj,const char *name,Error **errp);include/qapi/visitor.h +0
-0
include/qapi/visitor.h GenericList *visit_next_list(Visitor *v, GenericList **list, Error **errp); · line 48
Quoted 9 lines
include/qapi/visitor.h +5
-1@@ -41,7 +41,13 @@ GenericList *visit_next_list(Visitor *v, GenericList **list, Error **errp);void visit_end_list (Visitor *v,Error **errp);void visit_optional (Visitor *v,bool *present,const char *name,Error **errp); -void visit_get_next_type(Visitor *v, int *obj, const int *qtypes, + +/** +* Determine the qtype of the item @name in the current object visit. +* For input visitors, set *@type to the correct qtype of a qapi +* alternate type; for other visitors, leave *@type unchanged.
Aside: I can't think of a reason for an output visitor to implement this method.
Quoted 133 lines
include/qapi/visitor.h +2
-0+*/ +void visit_get_next_type (Visitor *v,qtype_code *type,const char *name,Error **errp);void visit_type_enum (Visitor *v,int *obj,const char *const strings[],const char *kind,const char *name,Error **errp);qapi/qapi-visit-core.c +2
-2@@ -81,11 +81,11 @@ void visit_optional(Visitor *v, bool *present, const char *name, } } -void visit_get_next_type (Visitor *v,int *obj,const int *qtypes, +void visit_get_next_type (Visitor *v,qtype_code *type,const char *name,Error **errp) {if (v->get_next_type) { - v->get_next_type (v, obj, qtypes, name, errp); + v->get_next_type (v, type, name, errp); } }qapi/qmp-input-visitor.c +2
-2@@ -208,7 +208,7 @@ static void qmp_input_end_list(Visitor *v, Error **errp)qmp_input_pop (qiv, errp); } -static void qmp_input_get_next_type (Visitor *v,int *kind,const int *qobjects, +static void qmp_input_get_next_type (Visitor *v,qtype_code *type,const char *name,Error **errp) {QmpInputVisitor *qiv =to_qiv (v);@@ -218,7 +218,7 @@ static void qmp_input_get_next_type(Visitor *v, int *kind, const int *qobjects,error_setg (errp,QERR_MISSING_PARAMETER , name ? name :"null" );return ; } - *kind = qobjects[qobject_type (qobj)]; + *type =qobject_type (qobj); } static void qmp_input_type_int(Visitor *v, int64_t *obj, const char *name,scripts/qapi-types.py +1
-35@@ -47,7 +47,7 @@ def gen_struct_fields(members): ret += mcgen(''' %(c_type)s %(c_name)s; ''', - c_type=memb.type.c_type(), c_name=c_name(memb.name)) + c_type=memb.c_type(), c_name=c_name(memb.name)) return ret@@ -101,38 +101,6 @@ static inline %(base)s *qapi_%(c_name)s_base(const %(c_name)s *obj) c_name=c_name(name), base=base.c_name()) -def gen_alternate_qtypes_decl(name): - return mcgen(''' - -extern const int %(c_name)s_qtypes[]; -''', - c_name=c_name(name)) - - -def gen_alternate_qtypes(name, variants): - ret = mcgen(''' - -const int %(c_name)s_qtypes[QTYPE_MAX] = { -''', - c_name=c_name(name)) - - for var in variants.variants: - qtype = var.type.alternate_qtype() - assert qtype - - ret += mcgen(''' - [%(qtype)s] = %(enum_const)s, -''', - qtype=qtype, - enum_const=c_enum_const(variants.tag_member.type.name, - var.name)) - - ret += mcgen(''' -}; -''') - return ret - - def gen_variants(variants): # FIXME: What purpose does data serve, besides preventing a union that # has a branch named 'data'? We use it in qapi-visit.py to decide@@ -257,9 +225,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): def visit_alternate_type(self, name, info, variants): self._fwdecl += gen_fwd_object_or_array(name) - self._fwdefn += gen_alternate_qtypes(name, variants) self.decl += gen_object(name, None, [variants.tag_member], variants) - self.decl += gen_alternate_qtypes_decl(name) self._gen_type_cleanup(name) # If you link code generated from multiple schemata, you want only onescripts/qapi-visit.py +3
-2@@ -193,7 +193,7 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error if (err) { goto out; } - visit_get_next_type(v, (int*) &(*obj)->type, %(c_name)s_qtypes, name, &err); + visit_get_next_type(v, &(*obj)->type, name, &err); if (err) { goto out_obj; }@@ -201,20 +201,22 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error ''', c_name=c_name(name)) + # FIXME: When 'number' but not 'int' is present in the alternate, we + # should allow QTYPE_INT to promote to QTYPE_FLOAT. for var in variants.variants: ret += mcgen(''' case %(case)s: visit_type_%(c_type)s(v, &(*obj)->u.%(c_name)s, name, &err); break; ''', - case=c_enum_const(variants.tag_member.type.name,
scripts/qapi-visit.py void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error · line 219
Quoted 10 lines
scripts/qapi-visit.py +3
-2- var.name), + case=var.type.alternate_qtype(), c_type=var.type.c_name(), c_name=c_name(var.name)) ret += mcgen(''' default: - abort(); + error_setg(&err, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", + "%(name)s");
Craptastic error reporting, but it's widely done elsewhere already, and cleaning it up is out of scope.
Quoted 64 lines
scripts/qapi-visit.py +3
-1} out_obj: error_propagate(errp, err);@@ -223,7 +225,8 @@ out_obj: out: error_propagate(errp, err); } -''') +''', + name=name) return ret@@ -430,6 +433,7 @@ fdef.write(mcgen(''' fdecl.write(mcgen(''' #include "qapi/visitor.h" +#include "qapi/qmp/qerror.h" #include "%(prefix)sqapi-types.h" ''',scripts/qapi.py +8
-4@@ -627,15 +627,15 @@ def check_union(expr, expr_info): def check_alternate(expr, expr_info): name = expr['alternate'] members = expr['data'] - values = {'MAX': '(automatic)'} + values = {} types_seen = {} # Check every branch for (key, value) in members.items(): check_name(expr_info, "Member of alternate '%s'" % name, key) - # Check for conflicts in the generated enum - c_key = camel_to_upper(key) + # Check for conflicts in the branch names + c_key = c_name(key) if c_key in values: raise QAPIExprError(expr_info, "Alternate '%s' member '%s' clashes with '%s'"@@ -1029,13 +1029,17 @@ class QAPISchemaObjectTypeMember(object): assert self.name not in seen seen[self.name] = self + def c_type(self): + return self.type.c_type() + class QAPISchemaObjectTypeVariants(object): def __init__(self, tag_name, tag_member, variants): # Flat unions pass tag_name but not tag_member. # Simple unions and alternates pass tag_member but not tag_name. # After check(), tag_member is always set, and tag_name remains - # a reliable witness of being used by a flat union. + # a reliable witness of being used by a flat union, and + # tag_member.type being None is a reliable witness of an alternate. assert bool(tag_member) != bool(tag_name) assert (isinstance(tag_name, str) or isinstance(tag_member, QAPISchemaObjectTypeMember))
scripts/qapi.py class QAPISchemaObjectTypeVariants(object): · line 1060
Quoted 9 lines
scripts/qapi.py +5
-1@@ -1049,7 +1053,11 @@ class QAPISchemaObjectTypeVariants(object): # seen is non-empty for unions, empty for alternates if self.tag_name: # flat union self.tag_member = seen[self.tag_name] - assert isinstance(self.tag_member.type, QAPISchemaEnumType) + if seen: + assert isinstance(self.tag_member.type, QAPISchemaEnumType) + else: + assert isinstance(self.tag_member, QAPISchemaAlternateTypeTag) + assert not self.tag_member.type
Awkward.
Quoted 31 lines
scripts/qapi.py +7
-5for v in self.variants: # Reset seen array for each variant, since qapi names from one # branch do not affect another branch@@ -1062,10 +1070,8 @@ class QAPISchemaObjectTypeVariant(QAPISchemaObjectTypeMember): def check(self, schema, tag_type, seen): QAPISchemaObjectTypeMember.check(self, schema) - assert self.name in tag_type.values - if seen: - # This variant is used within a union; ensure each qapi member - # field does not collide with the union's non-variant members. + if seen: # in a union + assert self.name in tag_type.values self.type.check_clash(schema, seen) # This function exists to support ugly simple union special cases@@ -1087,8 +1093,12 @@ class QAPISchemaAlternateType(QAPISchemaType): self.variants = variants def check(self, schema): - self.variants.tag_member.check(schema) self.variants.check(schema, {}) + # Since we have no enum mapping, we have to check for potential + # case name collisions ourselves. + cases = {} + for var in self.variants.variants: + var.check_clash(cases) def json_type(self): return 'value'
scripts/qapi.py class QAPISchemaAlternateType(QAPISchemaType): · line 1114
Quoted 8 lines
scripts/qapi.py +5
-0@@ -1097,6 +1107,18 @@ class QAPISchemaAlternateType(QAPISchemaType): visitor.visit_alternate_type(self.name, self.info, self.variants) +class QAPISchemaAlternateTypeTag(QAPISchemaObjectTypeMember): + # TODO: This subclass intentionally leaves self.tag_type as None, + # and intentionally has no check() method. It might be easier to + # reason about the overall QAPISchema if we also subclassed + # QAPISchemaBuiltinType to supply an internal-only 'qtype_code' type.
Sure we need to subclass? I do hope an instance will do! Something like
self.the_qtype_code_type = QAPISchemaEnumType(':qtype_code', None,
['NONE', 'QNULL', ...])
in _def_predefineds().
Also avoids the awkward conditional inQAPISchemaObjectTypeVariants.check().
Fewer special cases are worth a bit of scaffolding.
Quoted 11 lines
scripts/qapi.py +7
-0+ def __init__(self): + QAPISchemaObjectTypeMember.__init__(self, 'type', '', False) + + def c_type(self): + return 'qtype_code' + + class QAPISchemaCommand(QAPISchemaEntity): def __init__(self, name, info, arg_type, ret_type, gen, success_response): QAPISchemaEntity.__init__(self, name, info)
scripts/qapi.py class QAPISchema(object): · line 1318
Quoted 8 lines
scripts/qapi.py +1
-1@@ -1290,7 +1312,7 @@ class QAPISchema(object): data = expr['data'] variants = [self._make_variant(key, value) for (key, value) in data.iteritems()] - tag_member = self._make_implicit_tag(name, info, variants) + tag_member = QAPISchemaAlternateTypeTag() self._def_entity( QAPISchemaAlternateType(name, info, QAPISchemaObjectTypeVariants(None,
[Tests snipped...]
PATCH v9 24/27 qapi: Fix alternates that accept 'number' but not 'int'
In reply to Eric BlakeThe QMP input visitor allows integral values to be assigned by promotion to a QTYPE_QFLOAT. However, when parsing an alternate, we did not take this into account, such that an alternate that accepts 'number' but not 'int' would reject integral values.
With this patch, we now have the following desirable table:
alternate has case selected for
'int' 'number' QTYPE_QINT QTYPE_QFLOAT
no no error error
no yes 'number' 'number'
yes no 'int' error
yes yes 'int' 'number'While it is unlikely that we will ever use 'number' in an alternate other than in the testsuite, it never hurts to be more precise in what we allow.
---
v9: rebase to earlier changes
v8: no change
v7: rebase to named .u union
v6: rebase onto earlier testsuite and gen_err_check() improvements
--- include/qapi/visitor-impl.h | 2 +- include/qapi/visitor.h | 3 ++- qapi/qapi-visit-core.c | 4 ++-- qapi/qmp-input-visitor.c | 4 ++++ scripts/qapi-visit.py | 11 +++++++---- tests/test-qmp-input-visitor.c | 16 ++++++---------- 6 files changed, 22 insertions(+), 18 deletions(-)
include/qapi/visitor-impl.h +1 -1
@@ -33,7 +33,7 @@ struct Visitorvoid (*type_enum)(Visitor *v,int *obj,const char *const strings[],const char *kind,const char *name,Error **errp);/* May be NULL; most useful for input visitors. */ -void (*get_next_type)(Visitor *v,qtype_code *type, +void (*get_next_type)(Visitor *v,qtype_code *type,bool promote_int,const char *name,Error **errp);void (*type_int)(Visitor *v,int64_t *obj,const char *name,Error **errp);
include/qapi/visitor.h +2 -1
@@ -46,8 +46,9 @@ void visit_optional(Visitor *v, bool *present, const char *name,* Determine the qtype of the item @name in the current object visit. * For input visitors, set *@type to the correct qtype of a qapi * alternate type; for other visitors, leave *@type unchanged. +* If @promote_int, treat integers as QTYPE_FLOAT. */ -void visit_get_next_type (Visitor *v,qtype_code *type, +void visit_get_next_type (Visitor *v,qtype_code *type,bool promote_int,const char *name,Error **errp);void visit_type_enum (Visitor *v,int *obj,const char *const strings[],const char *kind,const char *name,Error **errp);
qapi/qapi-visit-core.c +2 -2
@@ -81,11 +81,11 @@ void visit_optional(Visitor *v, bool *present, const char *name, } } -void visit_get_next_type (Visitor *v,qtype_code *type, +void visit_get_next_type (Visitor *v,qtype_code *type,bool promote_int,const char *name,Error **errp) {if (v->get_next_type) { - v->get_next_type (v, type, name, errp); + v->get_next_type (v, type, promote_int, name, errp); } }
qapi/qmp-input-visitor.c +4 -0
@@ -209,6 +209,7 @@ static void qmp_input_end_list(Visitor *v, Error **errp) }static void qmp_input_get_next_type (Visitor *v,qtype_code *type, +bool promote_int,const char *name,Error **errp) {QmpInputVisitor *qiv =to_qiv (v);
@@ -219,6 +220,9 @@ static void qmp_input_get_next_type(Visitor *v, qtype_code *type,return ; } *type =qobject_type (qobj); +if (promote_int && *type ==QTYPE_QINT ) { + *type =QTYPE_QFLOAT ; + } } static void qmp_input_type_int(Visitor *v, int64_t *obj, const char *name,
scripts/qapi-visit.py +7 -4
@@ -183,6 +183,11 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s *obj, const char *name, Error def gen_visit_alternate(name, variants): + promote_int = 'true' + for var in variants.variants: + if var.type.alternate_qtype() == 'QTYPE_QINT': + promote_int = 'false' + ret = mcgen(''' void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error **errp)
@@ -193,16 +198,14 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error if (err) { goto out; } - visit_get_next_type(v, &(*obj)->type, name, &err); + visit_get_next_type(v, &(*obj)->type, %(promote_int)s, name, &err); if (err) { goto out_obj; } switch ((*obj)->type) { ''', - c_name=c_name(name)) + c_name=c_name(name), promote_int=promote_int) - # FIXME: When 'number' but not 'int' is present in the alternate, we - # should allow QTYPE_INT to promote to QTYPE_FLOAT. for var in variants.variants: ret += mcgen(''' case %(case)s:
tests/test-qmp-input-visitor.c +6 -10
@@ -351,20 +351,16 @@ static void test_visitor_in_alternate_number(TestInputVisitorData *data,g_assert (data->err);qapi_free_AltStrBool (asb); -/* FIXME: integer should parse as number */ v =visitor_input_test_init (data,"42" ); -visit_type_AltStrNum (v, &asn,NULL , &data->err); -/* FIXME g_assert_cmpint(asn->type, ==, QTYPE_QFLOAT); */ -/* FIXME g_assert_cmpfloat(asn->u.n, ==, 42); */ -g_assert (data->err); +visit_type_AltStrNum (v, &asn,NULL , &error_abort); + g_assert_cmpint(asn->type, ==, QTYPE_QFLOAT); + g_assert_cmpfloat(asn->u.n, ==, 42);qapi_free_AltStrNum (asn); -/* FIXME: integer should parse as number */ v =visitor_input_test_init (data,"42" ); -visit_type_AltNumStr (v, &ans,NULL , &data->err); -/* FIXME g_assert_cmpint(ans->type, ==, QTYPE_QFLOAT); */ -/* FIXME g_assert_cmpfloat(ans->u.n, ==, 42); */ -g_assert (data->err); +visit_type_AltNumStr (v, &ans,NULL , &error_abort); + g_assert_cmpint(ans->type, ==, QTYPE_QFLOAT); + g_assert_cmpfloat(ans->u.n, ==, 42);qapi_free_AltNumStr (ans); v =visitor_input_test_init (data,"42" );
Signature · 1 line
2.4.3
PATCH v9 25/27 qapi: Add positive tests to qapi-schema-test
In reply to Eric BlakeAdd positive tests to qapi-schema-test for things that were made possible by recent patches but which caused compile errors due to collisions prior to that point. The focus is mainly on collisions due to names we have reserved for qapi, even though it is unlikely that anyone will want to abuse these names in actual .json files.
The added tests includes:
Use of a member name ending in 'Kind' or 'List' [1, 4] Use of a type name starting with 'has_' [1, 5] Use of a type named 'u' [1, 6]
Use of a union branch name of 'u' [2, 6]
Use of a union branch name starting with 'has_' [2, 5] Use of an alternate branch name of 'max' [3]
[1] Never broken, but could break if reservations are too strict
[2] Broken prior to commit e4ba22b
[3] Broken prior to previous commit
[4] See reservations in commit 4dc2e69 and 255960d
[5] See reservations in commit 9fb081e
[6] See reservation in commit 5e59baf
Not worth testing here: we no longer have a collision with a member named 'base' (commit ddf2190) or with a branch named 'type' (commit e4ba22b).
---
v9: reorder in series (was 9/17); fewer tests of 'base' and 'type' non-collision; fold in alternate 'max' test; update commit message
v8: new, but collects portions of subset B v10 patches 2, 3, and 16 and subset C v7 patch 6 that were deferred to later.
It might be worth dropping or simplifying this patch, depending on how many corner cases we actually want to test.
--- tests/qapi-schema/qapi-schema-test.json | 16 ++++++++++++++++ tests/qapi-schema/qapi-schema-test.out | 27 +++++++++++++++++++++++++++ 2 files changed, 43 insertions(+)
tests/qapi-schema/qapi-schema-test.json +16 -0
@@ -113,6 +113,22 @@ 'sizes': ['size'], 'any': ['any'] } } +# Even though 'u' and 'has_*' are forbidden as struct member names, they +# should still be valid as a type or union branch name. And although +# '*Kind' and '*List' are forbidden as type names, they should not be +# forbidden as a member or branch name. Flat union branches do not +# collide with base members. +{ 'enum': 'EnumName', 'data': [ 'value1', 'has_a', 'u' ] } +{ 'struct': 'has_a', 'data': { 'MyKind': 'int', 'MyList': ['int'], + 'value1': 'EnumName' } } +{ 'union': 'u', 'data': { 'u': 'uint8', 'myKind': 'has_a', + 'myList': 'has_a', 'has_a': 'has_a' } } +{ 'union': 'UnionName', 'base': 'has_a', 'discriminator': 'value1', + 'data': { 'value1': 'UserDefZero', 'has_a': 'UserDefZero', + 'u': 'UserDefZero' } } +{ 'alternate': 'AltName', 'data': { 'type': 'int', 'u': 'bool', + 'myKind': 'has_a', 'max': 'str' } } + # testing commands { 'command': 'user_def_cmd', 'data': {} } { 'command': 'user_def_cmd1', 'data': {'ud1a': 'UserDefOne'} }
tests/qapi-schema/qapi-schema-test.out +27 -0
@@ -22,6 +22,8 @@ object :obj-guest-get-time-arg member b: int optional=True object :obj-guest-sync-arg member arg: any optional=False +object :obj-has_a-wrapper + member data: has_a optional=False object :obj-int16List-wrapper member data: int16List optional=False object :obj-int32List-wrapper
@@ -46,6 +48,8 @@ object :obj-uint32List-wrapper member data: uint32List optional=False object :obj-uint64List-wrapper member data: uint64List optional=False +object :obj-uint8-wrapper + member data: uint8 optional=False object :obj-uint8List-wrapper member data: uint8List optional=False object :obj-user_def_cmd1-arg
@@ -56,6 +60,11 @@ object :obj-user_def_cmd2-arg alternate AltIntNum case i: int case n: number +alternate AltName + case type: int + case u: bool + case myKind: has_a + case max: str alternate AltNumInt case n: number case i: int
@@ -78,6 +87,7 @@ event EVENT_D :obj-EVENT_D-arg object Empty1 object Empty2 base Empty1 +enum EnumName ['value1', 'has_a', 'u'] enum EnumOne ['value1', 'value2', 'value3'] object EventStructOne member struct1: UserDefOne optional=False
@@ -99,6 +109,12 @@ object TestStruct member integer: int optional=False member boolean: bool optional=False member string: str optional=False +object UnionName + base has_a + tag value1 + case value1: UserDefZero + case has_a: UserDefZero + case u: UserDefZero object UserDefA member boolean: bool optional=False member a_b: int optional=True
@@ -193,6 +209,17 @@ command guest-get-time :obj-guest-get-time-arg -> int gen=True success_response=True command guest-sync :obj-guest-sync-arg -> any gen=True success_response=True +object has_a + member MyKind: int optional=False + member MyList: intList optional=False + member value1: EnumName optional=False +object u + member type: uKind optional=False + case u: :obj-uint8-wrapper + case myKind: :obj-has_a-wrapper + case myList: :obj-has_a-wrapper + case has_a: :obj-has_a-wrapper +enum uKind ['u', 'myKind', 'myList', 'has_a'] command user_def_cmd None -> None gen=True success_response=True command user_def_cmd1 :obj-user_def_cmd1-arg -> None
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v9 25/27] qapi: Add positive tests to qapi-schema-test
Quoted 8 lines · Eric Blake
Add positive tests to qapi-schema-test for things that were made possible by recent patches but which caused compile errors due to collisions prior to that point. The focus is mainly on collisions due to names we have reserved for qapi, even though it is unlikely that anyone will want to abuse these names in actual .json files.
The added tests includes:
Checking sanity aloud:
Quoted 1 line
Use of a member name ending in 'Kind' or 'List' [1, 4]
Reserved for type names, because we generate typedef FOOList for ['FOO'], and FOOKind for a simple union FOO.
Quoted 1 line
Use of a type name starting with '
has_' [1, 5]
Reserved for member names, because we generate has_FOO for an optional member FOO in the same name space.
See below for union branch.
Could additionally test command and event names, but I very much doubt that's worth the bother.
Quoted 2 lines
Use of a type named 'u' [1, 6]
Use of a union branch name of 'u' [2, 6]
Reserved for member names, because we generate u in the same name space for unions.
Quoted 1 line
Use of a union branch name starting with '
has_' [2, 5]
See above.
Quoted 1 line
Use of an alternate branch name of 'max' [3]
I'd prefer keeping "branch name can't be MAX" as artificial restriction just for similarity to unions.
Quoted 7 lines
[1] Never broken, but could break if reservations are too strict
[2] Broken prior to commit e4ba22b
[3] Broken prior to previous commit
[4] See reservations in commit 4dc2e69 and 255960d
[5] See reservations in commit 9fb081e
[6] See reservation in commit 5e59baf
Quoted 5 lines
Not worth testing here: we no longer have a collision with a member named 'base' (commit ddf2190) or with a branch named 'type' (commit e4ba22b).
Signed-off-by Eric Blake <[email protected]>
Patch looks good.
PATCH v9 26/27 qapi: Remove dead visitor code
In reply to Eric BlakeCommit cbc95538 removed unused start_handle() and end_handle(), but forgot got remove their declarations.
Commit 4e27e819 introduced optional visitor callbacks for all sorts of int types, but except for type_uint64 and type_size, none of them have ever been supplied (the generic implementation based on using type_int then bounds-checking works just fine). In the interest of simplicity, it's easier to make the visitor callback interface not have to worry about the other sizes.
---
v9: no change
v8: no change
v7: no change
v6: no change
--- include/qapi/visitor-impl.h | 19 +++---- include/qapi/visitor.h | 3 - qapi/qapi-visit-core.c | 131 +++++++++++++++++--------------------------- 3 files changed, 58 insertions(+), 95 deletions(-)
include/qapi/visitor-impl.h +8 -11
@@ -1,7 +1,7 @@/* * Core Definitions for QAPI Visitor implementations * -* Copyright (C) 2012 Red Hat, Inc. +* Copyright (C) 2012, 2015 Red Hat, Inc. * * Author: Paolo Bonizni <[email protected]> *
@@ -48,18 +48,15 @@ struct Visitorvoid (*optional)(Visitor *v,bool *present,const char *name,Error **errp); -void (*type_uint8)(Visitor *v,uint8_t *obj,const char *name,Error **errp); -void (*type_uint16)(Visitor *v,uint16_t *obj,const char *name,Error **errp); -void (*type_uint32)(Visitor *v,uint32_t *obj,const char *name,Error **errp); -void (*type_uint64)(Visitor *v,uint64_t *obj,const char *name,Error **errp); -void (*type_int8)(Visitor *v,int8_t *obj,const char *name,Error **errp); -void (*type_int16)(Visitor *v,int16_t *obj,const char *name,Error **errp); -void (*type_int32)(Visitor *v,int32_t *obj,const char *name,Error **errp); -void (*type_int64)(Visitor *v,int64_t *obj,const char *name,Error **errp); -/* visit_type_size() falls back to (*type_uint64)() if type_size is unset */ -void (*type_size)(Visitor *v,uint64_t *obj,const char *name,Error **errp);bool (*start_union)(Visitor *v,bool data_present,Error **errp);void (*end_union)(Visitor *v,bool data_present,Error **errp); + +/* Only required to visit uint64 differently than (*type_int)(). */ +void (*type_uint64)(Visitor *v,uint64_t *obj,const char *name, +Error **errp); +/* Only required to visit sizes differently than (*type_uint64)(). */ +void (*type_size)(Visitor *v,uint64_t *obj,const char *name, +Error **errp); }; void input_type_enum(Visitor *v, int *obj, const char * const strings[],
include/qapi/visitor.h +0 -3
@@ -27,9 +27,6 @@ typedef struct GenericListstruct GenericList *next; } GenericList; -void visit_start_handle (Visitor *v,void **obj,const char *kind, -const char *name,Error **errp); -void visit_end_handle (Visitor *v,Error **errp);void visit_start_struct (Visitor *v,void **obj,const char *kind,const char *name,size_t size,Error **errp);void visit_end_struct (Visitor *v,Error **errp);
qapi/qapi-visit-core.c +50 -81
184 lines not on this page · raw message
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v9 26/27] qapi: Remove dead visitor code
Quoted 17 lines · Eric Blake
Commit
cbc95538removed unusedstart_handle()andend_handle(), but forgot got remove their declarations.Commit
4e27e819introduced optional visitor callbacks for all sorts of int types, but except fortype_uint64andtype_size, none of them have ever been supplied (the generic implementation based on usingtype_intthen bounds-checking works just fine). In the interest of simplicity, it's easier to make the visitor callback interface not have to worry about the other sizes.Signed-off-by Eric Blake <[email protected]>---
v9: no change
v8: no change
v7: no change
v6: no change
Quoted 5 lines
--- include/qapi/visitor-impl.h | 19 +++---- include/qapi/visitor.h | 3 - qapi/qapi-visit-core.c | 131 +++++++++++++++++--------------------------- 3 files changed, 58 insertions(+), 95 deletions(-)
Easier to review with whitespace change ignored:
| diff --git a/include/qapi/visitor-impl.h b/include/qapi/visitor-impl.h | index 1d09b7b..370935a 100644 | --- a/include/qapi/visitor-impl.h | +++ b/include/qapi/visitor-impl.h | @@ -1,7 +1,7 @@ | /* | * Core Definitions for QAPI Visitor implementations | * | - * Copyright (C) 2012 Red Hat, Inc. | + * Copyright (C) 2012, 2015 Red Hat, Inc. | * | * Author: Paolo Bonizni <[email protected]> | * | @@ -48,18 +48,15 @@ struct Visitor | void (*optional)(Visitor *v, bool *present, const char *name, | Error **errp); | | - void (*type_uint8)(Visitor *v, uint8_t *obj, const char *name, Error **errp); | - void (*type_uint16)(Visitor *v, uint16_t *obj, const char *name, Error **errp); | - void (*type_uint32)(Visitor *v, uint32_t *obj, const char *name, Error **errp); | - void (*type_uint64)(Visitor *v, uint64_t *obj, const char *name, Error **errp); | - void (*type_int8)(Visitor *v, int8_t *obj, const char *name, Error **errp); | - void (*type_int16)(Visitor *v, int16_t *obj, const char *name, Error **errp); | - void (*type_int32)(Visitor *v, int32_t *obj, const char *name, Error **errp); | - void (*type_int64)(Visitor *v, int64_t *obj, const char *name, Error **errp); | - /* visit_type_size() falls back to (*type_uint64)() if type_size is unset */ | - void (*type_size)(Visitor *v, uint64_t *obj, const char *name, Error **errp); | bool (*start_union)(Visitor *v, bool data_present, Error **errp); | void (*end_union)(Visitor *v, bool data_present, Error **errp); | + | + /* Only required to visit uint64 differently than (*type_int)(). */
If you don't supply it, what happens for uint64_t values that aren't representable as int64_t?
| + void (*type_uint64)(Visitor *v, uint64_t *obj, const char *name,
| + Error **errp);
| + /* Only required to visit sizes differently than (*type_uint64)(). */
| + void (*type_size)(Visitor *v, uint64_t *obj, const char *name,
| + Error **errp);
| };
|
| void input_type_enum(Visitor *v, int *obj, const char * const strings[],
| diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h
| index baea594..67ddd83 100644
| --- a/include/qapi/visitor.h
| +++ b/include/qapi/visitor.h
| @@ -27,9 +27,6 @@ typedef struct GenericList
| struct GenericList *next;
| } GenericList;
|
| -void visit_start_handle(Visitor *v, void **obj, const char *kind,
| - const char *name, Error **errp);
| -void visit_end_handle(Visitor *v, Error **errp);
| void visit_start_struct(Visitor *v, void **obj, const char *kind,
| const char *name, size_t size, Error **errp);
| void visit_end_struct(Visitor *v, Error **errp);
| diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c
| index 884fe94..cbf7780 100644
| --- a/qapi/qapi-visit-core.c
| +++ b/qapi/qapi-visit-core.c
| @@ -104,9 +104,6 @@ void visit_type_uint8(Visitor *v, uint8_t *obj, const char *name, Error **errp)
| {
| int64_t value;
|
| - if (v->type_uint8) {
| - v->type_uint8(v, obj, name, errp);
| - } else {
| value = *obj;
| v->type_int(v, &value, name, errp);
| if (value < 0 || value > UINT8_MAX) {
| @@ -116,15 +113,12 @@ void visit_type_uint8(Visitor *v, uint8_t *obj, const char *name, Error **errp)
| }
| *obj = value;
| }
| -}
|
| -void visit_type_uint16(Visitor *v, uint16_t *obj, const char *name, Error **errp)
| +void visit_type_uint16(Visitor *v, uint16_t *obj, const char *name,
| + Error **errp)
| {
| int64_t value;
|
| - if (v->type_uint16) {
| - v->type_uint16(v, obj, name, errp);
| - } else {
| value = *obj;
| v->type_int(v, &value, name, errp);
| if (value < 0 || value > UINT16_MAX) {
| @@ -134,15 +128,12 @@ void visit_type_uint16(Visitor *v, uint16_t *obj, const char *name, Error **errp
| }
| *obj = value;
| }
| -}
|
| -void visit_type_uint32(Visitor *v, uint32_t *obj, const char *name, Error **errp)
| +void visit_type_uint32(Visitor *v, uint32_t *obj, const char *name,
| + Error **errp)
| {
| int64_t value;
|
| - if (v->type_uint32) {
| - v->type_uint32(v, obj, name, errp);
| - } else {
| value = *obj;
| v->type_int(v, &value, name, errp);
| if (value < 0 || value > UINT32_MAX) {
| @@ -152,9 +143,9 @@ void visit_type_uint32(Visitor *v, uint32_t *obj, const char *name, Error **errp
| }
| *obj = value;
| }
| -}
|
| -void visit_type_uint64(Visitor *v, uint64_t *obj, const char *name, Error **errp)
| +void visit_type_uint64(Visitor *v, uint64_t *obj, const char *name,
| + Error **errp)
| {
| int64_t value;
|
if (v->type_uint64) {
v->type_uint64(v, obj, name, errp);
} else {
value = *obj;
v->type_int(v, &value, name, errp);
*obj = value;
}}
Answering my "what happens" question:
* Input visitor
If your type_int() accepts large positive input values and casts them to the corresponding large negative value, *obj = value will cast them right back, and the sloppiness cancels out.
If it rejects them, they stay rejected.
* Output visitor
You'll output large positive values as the corresponding large negative value.
I doubt not defining this makes much sense. Do we have such visitors?
| @@ -171,9 +162,6 @@ void visit_type_int8(Visitor *v, int8_t *obj, const char *name, Error **errp)
| {
| int64_t value;
|
| - if (v->type_int8) {
| - v->type_int8(v, obj, name, errp);
| - } else {
| value = *obj;
| v->type_int(v, &value, name, errp);
| if (value < INT8_MIN || value > INT8_MAX) {
| @@ -183,15 +171,11 @@ void visit_type_int8(Visitor *v, int8_t *obj, const char *name, Error **errp)
| }
| *obj = value;
| }
| -}
|
| void visit_type_int16(Visitor *v, int16_t *obj, const char *name, Error **errp)
| {
| int64_t value;
|
| - if (v->type_int16) {
| - v->type_int16(v, obj, name, errp);
| - } else {
| value = *obj;
| v->type_int(v, &value, name, errp);
| if (value < INT16_MIN || value > INT16_MAX) {
| @@ -201,15 +185,11 @@ void visit_type_int16(Visitor *v, int16_t *obj, const char *name, Error **errp)
| }
| *obj = value;
| }
| -}
|
| void visit_type_int32(Visitor *v, int32_t *obj, const char *name, Error **errp)
| {
| int64_t value;
|
| - if (v->type_int32) {
| - v->type_int32(v, obj, name, errp);
| - } else {
| value = *obj;
| v->type_int(v, &value, name, errp);
| if (value < INT32_MIN || value > INT32_MAX) {
| @@ -219,29 +199,18 @@ void visit_type_int32(Visitor *v, int32_t *obj, const char *name, Error **errp)
| }
| *obj = value;
| }
| -}
|
| void visit_type_int64(Visitor *v, int64_t *obj, const char *name, Error **errp)
| {
| - if (v->type_int64) {
| - v->type_int64(v, obj, name, errp);
| - } else {
| v->type_int(v, obj, name, errp);
| }
| -}
|
| void visit_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp)
| {
| - int64_t value;
| -
| if (v->type_size) {
| v->type_size(v, obj, name, errp);
| - } else if (v->type_uint64) {
| - v->type_uint64(v, obj, name, errp);
| } else {
| - value = *obj;
| - v->type_int(v, &value, name, errp);
| - *obj = value;
| + visit_type_uint64(v, obj, name, errp);
| }
| }
| This one's problematic, I think. If you supply type_uint64(), but not type_size(), I'd certainly expect type_uint64() to be used. If not, what happens for values that can be represented as uint64_t, but not as int64_t?
Re: [Qemu-devel] [PATCH v9 26/27] qapi: Remove dead visitor code
Quoted 31 lines · Markus Armbruster
Quoted 12 lines · Eric Blake
Commit
cbc95538removed unusedstart_handle()andend_handle(), but forgot got remove their declarations.Commit
4e27e819introduced optional visitor callbacks for all sorts of int types, but except fortype_uint64andtype_size, none of them have ever been supplied (the generic implementation based on usingtype_intthen bounds-checking works just fine). In the interest of simplicity, it's easier to make the visitor callback interface not have to worry about the other sizes.Signed-off-by Eric Blake <[email protected]>| +
| + /* Only required to visit uint64 differently than (*type_int)(). */If you don't supply it, what happens for
uint64_tvalues that aren't representable asint64_t?| + void (*type_uint64)(Visitor *v,
uint64_t*obj, const char *name,Answering my "what happens" question:
* Input visitor
If your
type_int()accepts large positive input values and casts them to the corresponding large negative value, *obj = value will cast them right back, and the sloppiness cancels out.
Quoted 8 lines
If it rejects them, they stay rejected.
* Output visitor
You'll output large positive values as the corresponding large negative value.
I doubt not defining this makes much sense. Do we have such visitors?
Yes (qapi-dealloc-visitor.c gets away with it, but qmp-input-visitor.c, qmp-output-visitor.c, string-input-visitor.c, and string-output-visitor.c are all afflicted). But we shouldn't. For my next spin of this patch, I'll first add another patch that guarantees that all visitors have both signed and unsigned int handled correctly.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH v9 27/27 qapi: Simplify visits of optional fields
In reply to Eric BlakeNone of the visitor callbacks would set an error when testing if an optional field was present; make this part of the interface contract by eliminating the errp argument. Then, for less code, reflect the determined boolean value back to the caller instead of making the caller read the boolean after the fact.
The resulting generated code has a nice diff:
|- visit_optional(v, &has_fdset_id, "fdset-id", &err);
|- if (err) {
|- goto out;
|- }
|- if (has_fdset_id) {
|+ if (visit_optional(v, &has_fdset_id, "fdset-id")) {
| visit_type_int(v, &fdset_id, "fdset-id", &err);
| if (err) {
| goto out;
| }
| }---
v9: no change
v8: no change
v7: rebase to no member.c_name()
v6: rebase onto earlier testsuite and gen_err_check() improvements
--- include/qapi/visitor-impl.h | 5 ++--- include/qapi/visitor.h | 10 ++++++++-- qapi/opts-visitor.c | 2 +- qapi/qapi-visit-core.c | 6 +++--- qapi/qmp-input-visitor.c | 3 +-- qapi/string-input-visitor.c | 3 +-- scripts/qapi.py | 7 +------ 7 files changed, 17 insertions(+), 19 deletions(-)
include/qapi/visitor-impl.h +2 -3
@@ -44,9 +44,8 @@ struct Visitorvoid (*type_any)(Visitor *v,QObject **obj,const char *name,Error **errp); -/* May be NULL */ -void (*optional)(Visitor *v,bool *present,const char *name, -Error **errp); +/* May be NULL; most useful for input visitors. */ +void (*optional)(Visitor *v,bool *present,const char *name);bool (*start_union)(Visitor *v,bool data_present,Error **errp);void (*end_union)(Visitor *v,bool data_present,Error **errp);
include/qapi/visitor.h +8 -2
@@ -36,8 +36,14 @@ void visit_end_implicit_struct(Visitor *v, Error **errp);void visit_start_list (Visitor *v,const char *name,Error **errp);GenericList *visit_next_list (Visitor *v,GenericList **list,Error **errp);void visit_end_list (Visitor *v,Error **errp); -void visit_optional (Visitor *v,bool *present,const char *name, -Error **errp); + +/** +* Check if an optional member @name of an object needs visiting. +* For input visitors, set *@present according to whether the +* corresponding visit_type_*() needs calling; for other visitors, +* leave *@present unchanged. Return *@present for convenience. +*/ +bool visit_optional (Visitor *v,bool *present,const char *name);/** * Determine the qtype of the item @name in the current object visit.
qapi/opts-visitor.c +1 -1
@@ -488,7 +488,7 @@ opts_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp)static void -opts_optional (Visitor *v,bool *present,const char *name,Error **errp) +opts_optional (Visitor *v,bool *present,const char *name) {OptsVisitor *ov =DO_UPCAST (OptsVisitor, visitor, v);
qapi/qapi-visit-core.c +3 -3
@@ -73,12 +73,12 @@ void visit_end_union(Visitor *v, bool data_present, Error **errp) } } -void visit_optional (Visitor *v,bool *present,const char *name, -Error **errp) +bool visit_optional (Visitor *v,bool *present,const char *name) {if (v->optional) { - v->optional (v, present, name, errp); + v->optional (v, present, name); } +return *present; } void visit_get_next_type(Visitor *v, qtype_code *type, bool promote_int,
qapi/qmp-input-visitor.c +1 -2
@@ -304,8 +304,7 @@ static void qmp_input_type_any(Visitor *v, QObject **obj, const char *name, *obj = qobj; } -static void qmp_input_optional (Visitor *v,bool *present,const char *name, -Error **errp) +static void qmp_input_optional (Visitor *v,bool *present,const char *name) {QmpInputVisitor *qiv =to_qiv (v);QObject *qobj =qmp_input_get_object (qiv, name, true);
qapi/string-input-visitor.c +1 -2
@@ -299,8 +299,7 @@ static void parse_type_number(Visitor *v, double *obj, const char *name, *obj = val; } -static void parse_optional (Visitor *v,bool *present,const char *name, -Error **errp) +static void parse_optional (Visitor *v,bool *present,const char *name) {StringInputVisitor *siv =DO_UPCAST (StringInputVisitor, visitor, v);
scripts/qapi.py +1 -6
@@ -1620,15 +1620,10 @@ def gen_visit_fields(members, prefix='', need_cast=False, skiperr=False): for memb in members: if memb.optional: ret += mcgen(''' - visit_optional(v, &%(prefix)shas_%(c_name)s, "%(name)s", %(errp)s); + if (visit_optional(v, &%(prefix)shas_%(c_name)s, "%(name)s")) { ''', prefix=prefix, c_name=c_name(memb.name), name=memb.name, errp=errparg) - ret += gen_err_check(skiperr=skiperr) - ret += mcgen(''' - if (%(prefix)shas_%(c_name)s) { -''', - prefix=prefix, c_name=c_name(memb.name)) push_indent() # Ugly: sometimes we need to cast away const
Signature · 1 line
2.4.3
Quoted 12 lines · Eric Blake
No pending prerequisites; based on qemu.git master
Also available as a tag at this location:
git fetchgit://repo.or.cz/qemu/ericb.gitqapi-cleanupv9cand will soon be part of my branch with the rest of the v5 series, at:
http://repo.or.cz/qemu/ericb.git/shortlog/refs/heads/qapiv9 notes:
More patches added, and several reorganized. Lots of new patches from Markus, although not in the order originally proposed.
Quoted 7 lines
The first 8 patches are fairly straightforward, and could probably be taken as-is. Patch 9 is a rewrite of v8 4/17, but in the opposite direction (document that no sorting is done, rather than attempting to sort), so it may need further fine-tuning. Patches 12-21 represents a fusion of Markus' and my attempts to rewrite v5 7/17 into a more-reviewable set of patches, and caused further churn later in the series.
Hard freeze is next week.
PATCH 01-07+09 are simple cleanups, bug fixes tests and documentation, which makes them obvious candidates for 2.5.
PATCH 08 is a feature, but harmless enough. I still don't like it much, but I said I'll take it. Best before the hard freeze, though.
The remainder of the series doesn't feel like post hard freeze material. What do you think?
I don't have the complete picture of your queue. Please double-check whether you got anything in it that affects introspection, because changing introspection will become super awkward as soon as 2.5 is out.
Quoted 7 lines
Patch 23 still uses tag_member.type == None; I ran out of time to work on Markus' idea of providing an instance of QAPISchemaBuiltinType to fill the role for '
qtype_code' without being exposed through .json files and without breaking the invariant of a valid member.type aftercheck(), and wanted to get the rest of the series started under revew. So I may need a followup patch or even a v10 of the later half of this series after exploring that idea more.
I'll continue reviewing meanwhile.
Quoted 24 lines · Markus Armbruster
Quoted 12 lines · Eric Blake
No pending prerequisites; based on qemu.git master
Also available as a tag at this location:
git fetchgit://repo.or.cz/qemu/ericb.gitqapi-cleanupv9cand will soon be part of my branch with the rest of the v5 series, at:
http://repo.or.cz/qemu/ericb.git/shortlog/refs/heads/qapiv9 notes:
More patches added, and several reorganized. Lots of new patches from Markus, although not in the order originally proposed.Quoted 7 lines
The first 8 patches are fairly straightforward, and could probably be taken as-is. Patch 9 is a rewrite of v8 4/17, but in the opposite direction (document that no sorting is done, rather than attempting to sort), so it may need further fine-tuning. Patches 12-21 represents a fusion of Markus' and my attempts to rewrite v5 7/17 into a more-reviewable set of patches, and caused further churn later in the series.
Hard freeze is next week.
Quoted 8 lines
PATCH 01-07+09 are simple cleanups, bug fixes tests and documentation, which makes them obvious candidates for 2.5.
PATCH 08 is a feature, but harmless enough. I still don't like it much, but I said I'll take it. Best before the hard freeze, though.
The remainder of the series doesn't feel like post hard freeze material. What do you think?
My patches _were_ posted prior to soft freeze, even if the initial review did not happen then; so on that grounds, you can continue to take as much as you want until hard freeze actually happens. But it gets harder and harder to justify, and the process definitely changes when hard freeze hits (no features, regardless of when they were first posted, but only bug fixes).
So it sounds like we won't get all of my qapi queue in 2.5. My goal had originally been to get netdev_add to be fully introspectible, but that's still more than 20 patches away; and the status quo of learning about the netdev_add command being less than perfect isn't a regression per se. So you are right that the later patches in my series can probably wait until 2.6. I'm fine with your judgment on where you want to draw the line of what will make soft freeze.
Quoted 4 lines
I don't have the complete picture of your queue. Please double-check whether you got anything in it that affects introspection, because changing introspection will become super awkward as soon as 2.5 is out.
Patches 8 and 9 in this series have to make 2.5 (and we're in agreement that while patch 9 is not quite baked in this v9 spin, we should still have plenty of time to get it done before hard freeze). The only other pending patch I have previously posted from my queue that touches qapi-introspect.py does not actually change introspection output:
http://repo.or.cz/qemu/ericb.git/commitdiff/5c25f6eb95, first posted at:
https://lists.gnu.org/archive/html/qemu-devel/2015-09/msg05441.html
so we should be fine on that front. Introspection itself is fine, and the bulk of my focus has been on cleanups to the internals and extensions of the internals to allow netdev_add to be introspectible.
I can certainly browse through my pending queue to double-check if any of the patches there qualify as bug fixes that are safe even during hard freeze, and focus on hoisting them to the front of the review queue, once we get 1-9 of this series ready for pull. And obviously that should mean user-triggerable bugs under existing .json files (patches like 24/27 that fix design bugs in the generator, but which don't affect any user besides the testsuite, aren't hard-freeze material - either it makes soft freeze or it defers to 2.6).
Quoted 11 lines
Quoted 8 lines
Patch 23 still uses tag_member.type == None; I ran out of time to work on Markus' idea of providing an instance of QAPISchemaBuiltinType to fill the role for '
qtype_code' without being exposed through .json files and without breaking the invariant of a valid member.type aftercheck(), and wanted to get the rest of the series started under revew. So I may need a followup patch or even a v10 of the later half of this series after exploring that idea more.I'll continue reviewing meanwhile.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 34 lines · Eric Blake
Quoted 24 lines · Markus Armbruster
Quoted 12 lines · Eric Blake
No pending prerequisites; based on qemu.git master
Also available as a tag at this location:
git fetchgit://repo.or.cz/qemu/ericb.gitqapi-cleanupv9cand will soon be part of my branch with the rest of the v5 series, at:
http://repo.or.cz/qemu/ericb.git/shortlog/refs/heads/qapiv9 notes:
More patches added, and several reorganized. Lots of new patches from Markus, although not in the order originally proposed.Quoted 7 lines
The first 8 patches are fairly straightforward, and could probably be taken as-is. Patch 9 is a rewrite of v8 4/17, but in the opposite direction (document that no sorting is done, rather than attempting to sort), so it may need further fine-tuning. Patches 12-21 represents a fusion of Markus' and my attempts to rewrite v5 7/17 into a more-reviewable set of patches, and caused further churn later in the series.
Hard freeze is next week.
Quoted 8 lines
PATCH 01-07+09 are simple cleanups, bug fixes tests and documentation, which makes them obvious candidates for 2.5.
PATCH 08 is a feature, but harmless enough. I still don't like it much, but I said I'll take it. Best before the hard freeze, though.
The remainder of the series doesn't feel like post hard freeze material. What do you think?
Quoted 6 lines
My patches _were_ posted prior to soft freeze, even if the initial review did not happen then; so on that grounds, you can continue to take as much as you want until hard freeze actually happens. But it gets harder and harder to justify, and the process definitely changes when hard freeze hits (no features, regardless of when they were first posted, but only bug fixes).
We're on the same page.
Quoted 7 lines
So it sounds like we won't get all of my qapi queue in 2.5. My goal had originally been to get
netdev_addto be fully introspectible, but that's still more than 20 patches away; and the status quo of learning about thenetdev_addcommand being less than perfect isn't a regression per se. So you are right that the later patches in my series can probably wait until 2.6. I'm fine with your judgment on where you want to draw the line of what will make soft freeze.
It would've been nice to get through the complete queue, but I'm a horribly picky reviewer. On the plus side, it hasn't been just for making patches prettier; we've found quite a few additional things to improve.
Quoted 10 lines
Quoted 3 lines
I don't have the complete picture of your queue. Please double-check whether you got anything in it that affects introspection, because changing introspection will become super awkward as soon as 2.5 is out.
Patches 8 and 9 in this series have to make 2.5 (and we're in agreement that while patch 9 is not quite baked in this v9 spin, we should still have plenty of time to get it done before hard freeze). The only other pending patch I have previously posted from my queue that touches
qapi-introspect.pydoes not actually change introspection output:
Quoted 6 lines
http://repo.or.cz/qemu/ericb.git/commitdiff/5c25f6eb95, first posted at:
https://lists.gnu.org/archive/html/qemu-devel/2015-09/msg05441.htmlso we should be fine on that front. Introspection itself is fine, and the bulk of my focus has been on cleanups to the internals and extensions of the internals to allow
netdev_addto be introspectible.
That's reassuring.
Quoted 8 lines
I can certainly browse through my pending queue to double-check if any of the patches there qualify as bug fixes that are safe even during hard freeze, and focus on hoisting them to the front of the review queue, once we get 1-9 of this series ready for pull. And obviously that should mean user-triggerable bugs under existing .json files (patches like 24/27 that fix design bugs in the generator, but which don't affect any user besides the testsuite, aren't hard-freeze material - either it makes soft freeze or it defers to 2.6).
Your choice. I probably wouldn't, because I figure that bug fixes that impact users are pretty unlikely. Fixes for stuff that breaks when you do certain things in a schema we don't currently do are not critical, and delaying them to the next cycle is just fine with me.
[...]
Got through, puh! Most patches are basically fine, but there are a few open questions.