qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2020-04-30' into staging

QAPI patches for 2020-04-30

# gpg: Signature made Thu 30 Apr 2020 06:29:18 BST
# gpg: using RSA key 354BC8B3D7EB2A6B68674E5F3870B400EB918653
# gpg: issuer "armbru@redhat.com"
# gpg: Good signature from "Markus Armbruster <armbru@redhat.com>" [full]
# gpg: aka "Markus Armbruster <armbru@pond.sub.org>" [full]
# Primary key fingerprint: 354B C8B3 D7EB 2A6B 6867 4E5F 3870 B400 EB91 8653

* remotes/armbru/tags/pull-qapi-2020-04-30:
qapi: Generate simpler marshalling code when no arguments
qapi: Disallow qmp_marshal_FOO(NULL, ...)
qom: Simplify object_property_get_enum()
qapi: Only input visitors can actually fail
qapi: Assert non-input visitors see only valid alternate tags
qapi: Clean up visitor's recovery from input with invalid type
qapi: Assert non-input visitors see only valid narrow integers
qapi: Assert output visitors see only valid enum values
qapi: Fix Visitor contract for start_alternate()
qapi: Assert incomplete object occurs only in dealloc visitor
qapi: Polish prose in visitor.h
qapi: Document @errp usage more thoroughly in visitor.h
qapi: Fix typo in visit_start_list()'s contract
qapi: Fix the virtual walk example in visitor.h's big comment
qapi: Belatedly update visitor.h's big comment for QAPI modules
qemu-option: Clean up after the previous commit
qobject: Eliminate qdict_iter(), use qdict_first(), qdict_next()
qobject: Eliminate qlist_iter(), use QLIST_FOREACH_ENTRY() instead
qobject: Factor out helper json_pretty_newline()
qobject: Clean up QLIST_FOREACH_ENTRY()

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

+271 -419
+1 -8
block.c
··· 2982 2982 BlockDriverState *bdrv_open_blockdev_ref(BlockdevRef *ref, Error **errp) 2983 2983 { 2984 2984 BlockDriverState *bs = NULL; 2985 - Error *local_err = NULL; 2986 2985 QObject *obj = NULL; 2987 2986 QDict *qdict = NULL; 2988 2987 const char *reference = NULL; ··· 2995 2994 assert(ref->type == QTYPE_QDICT); 2996 2995 2997 2996 v = qobject_output_visitor_new(&obj); 2998 - visit_type_BlockdevOptions(v, NULL, &options, &local_err); 2999 - if (local_err) { 3000 - error_propagate(errp, local_err); 3001 - goto fail; 3002 - } 2997 + visit_type_BlockdevOptions(v, NULL, &options, &error_abort); 3003 2998 visit_complete(v, &obj); 3004 2999 3005 3000 qdict = qobject_to(QDict, obj); ··· 3017 3012 3018 3013 bs = bdrv_open_inherit(NULL, reference, qdict, 0, NULL, NULL, errp); 3019 3014 obj = NULL; 3020 - 3021 - fail: 3022 3015 qobject_unref(obj); 3023 3016 visit_free(v); 3024 3017 return bs;
+1 -8
block/sheepdog.c
··· 1854 1854 Visitor *v; 1855 1855 QObject *obj = NULL; 1856 1856 QDict *qdict; 1857 - Error *local_err = NULL; 1858 1857 int ret; 1859 1858 1860 1859 v = qobject_output_visitor_new(&obj); 1861 - visit_type_BlockdevOptionsSheepdog(v, NULL, &location, &local_err); 1860 + visit_type_BlockdevOptionsSheepdog(v, NULL, &location, &error_abort); 1862 1861 visit_free(v); 1863 - 1864 - if (local_err) { 1865 - error_propagate(errp, local_err); 1866 - qobject_unref(obj); 1867 - return -EINVAL; 1868 - } 1869 1862 1870 1863 qdict = qobject_to(QDict, obj); 1871 1864 qdict_flatten(qdict);
+2 -14
blockdev.c
··· 3725 3725 QObject *obj; 3726 3726 Visitor *v = qobject_output_visitor_new(&obj); 3727 3727 QDict *qdict; 3728 - Error *local_err = NULL; 3729 3728 3730 - visit_type_BlockdevOptions(v, NULL, &options, &local_err); 3731 - if (local_err) { 3732 - error_propagate(errp, local_err); 3733 - goto fail; 3734 - } 3735 - 3729 + visit_type_BlockdevOptions(v, NULL, &options, &error_abort); 3736 3730 visit_complete(v, &obj); 3737 3731 qdict = qobject_to(QDict, obj); 3738 3732 ··· 3760 3754 AioContext *ctx; 3761 3755 QObject *obj; 3762 3756 Visitor *v = qobject_output_visitor_new(&obj); 3763 - Error *local_err = NULL; 3764 3757 BlockReopenQueue *queue; 3765 3758 QDict *qdict; 3766 3759 ··· 3777 3770 } 3778 3771 3779 3772 /* Put all options in a QDict and flatten it */ 3780 - visit_type_BlockdevOptions(v, NULL, &options, &local_err); 3781 - if (local_err) { 3782 - error_propagate(errp, local_err); 3783 - goto fail; 3784 - } 3785 - 3773 + visit_type_BlockdevOptions(v, NULL, &options, &error_abort); 3786 3774 visit_complete(v, &obj); 3787 3775 qdict = qobject_to(QDict, obj); 3788 3776
+3 -1
docs/devel/qapi-code-gen.txt
··· 1446 1446 goto out; 1447 1447 } 1448 1448 if (!*obj) { 1449 + /* incomplete */ 1450 + assert(visit_is_dealloc(v)); 1449 1451 goto out_obj; 1450 1452 } 1451 1453 visit_type_UserDefOne_members(v, *obj, &err); ··· 1577 1579 void qmp_marshal_my_command(QDict *args, QObject **ret, Error **errp) 1578 1580 { 1579 1581 Error *err = NULL; 1580 - UserDefOne *retval; 1581 1582 Visitor *v; 1583 + UserDefOne *retval; 1582 1584 q_obj_my_command_arg arg = {0}; 1583 1585 1584 1586 v = qobject_input_visitor_new(QOBJECT(args));
+1 -1
hw/core/machine-hmp-cmds.c
··· 113 113 114 114 while (m) { 115 115 v = string_output_visitor_new(false, &str); 116 - visit_type_uint16List(v, NULL, &m->value->host_nodes, NULL); 116 + visit_type_uint16List(v, NULL, &m->value->host_nodes, &error_abort); 117 117 monitor_printf(mon, "memory backend: %s\n", m->value->id); 118 118 monitor_printf(mon, " size: %" PRId64 "\n", m->value->size); 119 119 monitor_printf(mon, " merge: %s\n",
-3
include/qapi/qmp/qdict.h
··· 40 40 int qdict_haskey(const QDict *qdict, const char *key); 41 41 QObject *qdict_get(const QDict *qdict, const char *key); 42 42 bool qdict_is_equal(const QObject *x, const QObject *y); 43 - void qdict_iter(const QDict *qdict, 44 - void (*iter)(const char *key, QObject *obj, void *opaque), 45 - void *opaque); 46 43 const QDictEntry *qdict_first(const QDict *qdict); 47 44 const QDictEntry *qdict_next(const QDict *qdict, const QDictEntry *entry); 48 45 void qdict_destroy_obj(QObject *obj);
+4 -6
include/qapi/qmp/qlist.h
··· 34 34 void qlist_append_null(QList *qlist); 35 35 void qlist_append_str(QList *qlist, const char *value); 36 36 37 - #define QLIST_FOREACH_ENTRY(qlist, var) \ 38 - for ((var) = ((qlist)->head.tqh_first); \ 39 - (var); \ 40 - (var) = ((var)->next.tqe_next)) 37 + #define QLIST_FOREACH_ENTRY(qlist, var) \ 38 + for ((var) = QTAILQ_FIRST(&(qlist)->head); \ 39 + (var); \ 40 + (var) = QTAILQ_NEXT((var), next)) 41 41 42 42 static inline QObject *qlist_entry_obj(const QListEntry *entry) 43 43 { ··· 47 47 QList *qlist_new(void); 48 48 QList *qlist_copy(QList *src); 49 49 void qlist_append_obj(QList *qlist, QObject *obj); 50 - void qlist_iter(const QList *qlist, 51 - void (*iter)(QObject *obj, void *opaque), void *opaque); 52 50 QObject *qlist_pop(QList *qlist); 53 51 QObject *qlist_peek(QList *qlist); 54 52 int qlist_empty(const QList *qlist);
+6 -3
include/qapi/visitor-impl.h
··· 43 43 44 44 struct Visitor 45 45 { 46 + /* 47 + * Only input visitors may fail! 48 + */ 49 + 46 50 /* Must be set to visit structs */ 47 51 void (*start_struct)(Visitor *v, const char *name, void **obj, 48 52 size_t size, Error **errp); ··· 67 71 /* Must be set */ 68 72 void (*end_list)(Visitor *v, void **list); 69 73 70 - /* Must be set by input and dealloc visitors to visit alternates; 71 - * optional for output visitors. */ 74 + /* Must be set by input and clone visitors to visit alternates */ 72 75 void (*start_alternate)(Visitor *v, const char *name, 73 76 GenericAlternate **obj, size_t size, 74 77 Error **errp); 75 78 76 - /* Optional, needed for dealloc visitor */ 79 + /* Optional */ 77 80 void (*end_alternate)(Visitor *v, void **obj); 78 81 79 82 /* Must be set */
+110 -82
include/qapi/visitor.h
··· 25 25 * for doing work at each node of a QAPI graph; it can also be used 26 26 * for a virtual walk, where there is no actual QAPI C struct. 27 27 * 28 - * There are four kinds of visitor classes: input visitors (QObject, 29 - * string, and QemuOpts) parse an external representation and build 30 - * the corresponding QAPI graph, output visitors (QObject and string) take 31 - * a completed QAPI graph and generate an external representation, the 32 - * dealloc visitor can take a QAPI graph (possibly partially 33 - * constructed) and recursively free its resources, and the clone 34 - * visitor performs a deep clone of one QAPI object to another. While 35 - * the dealloc and QObject input/output visitors are general, the string, 36 - * QemuOpts, and clone visitors have some implementation limitations; 37 - * see the documentation for each visitor for more details on what it 38 - * supports. Also, see visitor-impl.h for the callback contracts 39 - * implemented by each visitor, and docs/devel/qapi-code-gen.txt for more 40 - * about the QAPI code generator. 28 + * There are four kinds of visitors: input visitors (QObject, string, 29 + * and QemuOpts) parse an external representation and build the 30 + * corresponding QAPI object, output visitors (QObject and string) 31 + * take a QAPI object and generate an external representation, the 32 + * dealloc visitor takes a QAPI object (possibly partially 33 + * constructed) and recursively frees it, and the clone visitor 34 + * performs a deep clone of a QAPI object. 35 + * 36 + * While the dealloc and QObject input/output visitors are general, 37 + * the string, QemuOpts, and clone visitors have some implementation 38 + * limitations; see the documentation for each visitor for more 39 + * details on what it supports. Also, see visitor-impl.h for the 40 + * callback contracts implemented by each visitor, and 41 + * docs/devel/qapi-code-gen.txt for more about the QAPI code 42 + * generator. 41 43 * 42 44 * All of the visitors are created via: 43 45 * ··· 45 47 * 46 48 * A visitor should be used for exactly one top-level visit_type_FOO() 47 49 * or virtual walk; if that is successful, the caller can optionally 48 - * call visit_complete() (for now, useful only for output visits, but 49 - * safe to call on all visits). Then, regardless of success or 50 - * failure, the user should call visit_free() to clean up resources. 51 - * It is okay to free the visitor without completing the visit, if 52 - * some other error is detected in the meantime. 50 + * call visit_complete() (useful only for output visits, but safe to 51 + * call on all visits). Then, regardless of success or failure, the 52 + * user should call visit_free() to clean up resources. It is okay to 53 + * free the visitor without completing the visit, if some other error 54 + * is detected in the meantime. 55 + * 56 + * The clone and dealloc visitor should not be used directly outside 57 + * of QAPI code. Use the qapi_free_FOO() and QAPI_CLONE() instead, 58 + * described below. 53 59 * 54 60 * All QAPI types have a corresponding function with a signature 55 61 * roughly compatible with this: ··· 58 64 * 59 65 * where T is FOO for scalar types, and FOO * otherwise. The scalar 60 66 * visitors are declared here; the remaining visitors are generated in 61 - * qapi-visit.h. 67 + * qapi-visit-MODULE.h. 62 68 * 63 69 * The @name parameter of visit_type_FOO() describes the relation 64 70 * between this QAPI value and its parent container. When visiting ··· 68 74 * alternate, @name should equal the name used for visiting the 69 75 * alternate. 70 76 * 71 - * The visit_type_FOO() functions expect a non-null @obj argument; 72 - * they allocate *@obj during input visits, leave it unchanged on 73 - * output visits, and recursively free any resources during a dealloc 74 - * visit. Each function also takes the customary @errp argument (see 77 + * The visit_type_FOO() functions take a non-null @obj argument; they 78 + * allocate *@obj during input visits, leave it unchanged during 79 + * output and clone visits, and free it (recursively) during a dealloc 80 + * visit. 81 + * 82 + * Each function also takes the customary @errp argument (see 75 83 * qapi/error.h for details), for reporting any errors (such as if a 76 84 * member @name is not present, or is present but not the specified 77 - * type). 85 + * type). Only input visitors can fail. 78 86 * 79 87 * If an error is detected during visit_type_FOO() with an input 80 - * visitor, then *@obj will be NULL for pointer types, and left 81 - * unchanged for scalar types. Using an output or clone visitor with 82 - * an incomplete object has undefined behavior (other than a special 83 - * case for visit_type_str() treating NULL like ""), while the dealloc 84 - * visitor safely handles incomplete objects. Since input visitors 85 - * never produce an incomplete object, such an object is possible only 86 - * by manual construction. 88 + * visitor, then *@obj will be set to NULL for pointer types, and left 89 + * unchanged for scalar types. 90 + * 91 + * Using an output or clone visitor with an incomplete object has 92 + * undefined behavior (other than a special case for visit_type_str() 93 + * treating NULL like ""), while the dealloc visitor safely handles 94 + * incomplete objects. Since input visitors never produce an 95 + * incomplete object, such an object is possible only by manual 96 + * construction. 87 97 * 88 98 * For the QAPI object types (structs, unions, and alternates), there 89 - * is an additional generated function in qapi-visit.h compatible 90 - * with: 99 + * is an additional generated function in qapi-visit-MODULE.h 100 + * compatible with: 91 101 * 92 102 * void visit_type_FOO_members(Visitor *v, FOO *obj, Error **errp); 93 103 * 94 104 * for visiting the members of a type without also allocating the QAPI 95 105 * struct. 96 106 * 97 - * Additionally, in qapi-types.h, all QAPI pointer types (structs, 98 - * unions, alternates, and lists) have a generated function compatible 107 + * Additionally, QAPI pointer types (structs, unions, alternates, and 108 + * lists) have a generated function in qapi-types-MODULE.h compatible 99 109 * with: 100 110 * 101 111 * void qapi_free_FOO(FOO *obj); 102 112 * 103 - * where behaves like free() in that @obj may be NULL. Such objects 104 - * may also be used with the following macro, provided alongside the 105 - * clone visitor: 113 + * Does nothing when @obj is NULL. 114 + * 115 + * Such objects may also be used with macro 106 116 * 107 117 * Type *QAPI_CLONE(Type, src); 108 118 * 109 - * in order to perform a deep clone of @src. Because of the generated 110 - * qapi_free functions and the QAPI_CLONE() macro, the clone and 111 - * dealloc visitor should not be used directly outside of QAPI code. 119 + * in order to perform a deep clone of @src. 112 120 * 113 - * QAPI types can also inherit from a base class; when this happens, a 114 - * function is generated for easily going from the derived type to the 115 - * base type: 121 + * For QAPI types can that inherit from a base type, a function is 122 + * generated for going from the derived type to the base type: 116 123 * 117 124 * BASE *qapi_CHILD_base(CHILD *obj); 118 125 * 119 - * For a real QAPI struct, typical input usage involves: 126 + * Typical input visitor usage involves: 120 127 * 121 128 * <example> 122 129 * Foo *f; ··· 153 160 * qapi_free_FooList(l); 154 161 * </example> 155 162 * 156 - * Similarly, typical output usage is: 163 + * Typical output visitor usage: 157 164 * 158 165 * <example> 159 166 * Foo *f = ...obtain populated object... 160 - * Error *err = NULL; 161 167 * Visitor *v; 162 168 * Type *result; 163 169 * 164 170 * v = FOO_visitor_new(..., &result); 165 - * visit_type_Foo(v, NULL, &f, &err); 166 - * if (err) { 167 - * ...handle error... 168 - * } else { 169 - * visit_complete(v, &result); 170 - * ...use result... 171 - * } 171 + * visit_type_Foo(v, NULL, &f, &error_abort); 172 + * visit_complete(v, &result); 172 173 * visit_free(v); 174 + * ...use result... 173 175 * </example> 174 176 * 175 - * When visiting a real QAPI struct, this file provides several 176 - * helpers that rely on in-tree information to control the walk: 177 - * visit_optional() for the 'has_member' field associated with 178 - * optional 'member' in the C struct; and visit_next_list() for 179 - * advancing through a FooList linked list. Similarly, the 180 - * visit_is_input() helper makes it possible to write code that is 181 - * visitor-agnostic everywhere except for cleanup. Only the generated 182 - * visit_type functions need to use these helpers. 183 - * 184 177 * It is also possible to use the visitors to do a virtual walk, where 185 - * no actual QAPI struct is present. In this situation, decisions 178 + * no actual QAPI object is present. In this situation, decisions 186 179 * about what needs to be walked are made by the calling code, and 187 180 * structured visits are split between pairs of start and end methods 188 181 * (where the end method must be called if the start function ··· 215 208 * goto outlist; 216 209 * } 217 210 * outlist: 211 + * if (!err) { 212 + * visit_check_list(v, &err); 213 + * } 218 214 * visit_end_list(v, NULL); 219 215 * if (!err) { 220 216 * visit_check_struct(v, &err); ··· 222 218 * outobj: 223 219 * visit_end_struct(v, NULL); 224 220 * out: 225 - * error_propagate(errp, err); 226 221 * visit_free(v); 227 222 * </example> 223 + * 224 + * This file provides helpers for use by the generated 225 + * visit_type_FOO(): visit_optional() for the 'has_member' field 226 + * associated with optional 'member' in the C struct, 227 + * visit_next_list() for advancing through a FooList linked list, and 228 + * visit_is_input() for cleaning up on failure. 228 229 */ 229 230 230 231 /*** Useful types ***/ ··· 282 283 * into *@obj. @obj may also be NULL for a virtual walk, in which 283 284 * case @size is ignored. 284 285 * 285 - * @errp obeys typical error usage, and reports failures such as a 286 - * member @name is not present, or present but not an object. On 287 - * error, input visitors set *@obj to NULL. 286 + * On failure, set *@obj to NULL and store an error through @errp. 287 + * Can happen only when @v is an input visitor. 288 288 * 289 289 * After visit_start_struct() succeeds, the caller may visit its 290 290 * members one after the other, passing the member's name and address ··· 301 301 /* 302 302 * Prepare for completing an object visit. 303 303 * 304 - * @errp obeys typical error usage, and reports failures such as 305 - * unparsed keys remaining in the input stream. 304 + * On failure, store an error through @errp. Can happen only when @v 305 + * is an input visitor. 306 306 * 307 307 * Should be called prior to visit_end_struct() if all other 308 308 * intermediate visit steps were successful, to allow the visitor one ··· 338 338 * allow @list to be NULL for a virtual walk, in which case @size is 339 339 * ignored. 340 340 * 341 - * @errp obeys typical error usage, and reports failures such as a 342 - * member @name is not present, or present but not a list. On error, 343 - * input visitors set *@list to NULL. 341 + * On failure, set *@list to NULL and store an error through @errp. 342 + * Can happen only when @v is an input visitor. 344 343 * 345 344 * After visit_start_list() succeeds, the caller may visit its members 346 - * one after the other. A real visit (where @obj is non-NULL) uses 345 + * one after the other. A real visit (where @list is non-NULL) uses 347 346 * visit_next_list() for traversing the linked list, while a virtual 348 - * visit (where @obj is NULL) uses other means. For each list 347 + * visit (where @list is NULL) uses other means. For each list 349 348 * element, call the appropriate visit_type_FOO() with name set to 350 349 * NULL and obj set to the address of the value member of the list 351 350 * element. Finally, visit_end_list() needs to be called with the ··· 374 373 /* 375 374 * Prepare for completing a list visit. 376 375 * 377 - * @errp obeys typical error usage, and reports failures such as 378 - * unvisited list tail remaining in the input stream. 376 + * On failure, store an error through @errp. Can happen only when @v 377 + * is an input visitor. 379 378 * 380 379 * Should be called prior to visit_end_list() if all other 381 380 * intermediate visit steps were successful, to allow the visitor one ··· 407 406 * 408 407 * @obj must not be NULL. Input and clone visitors use @size to 409 408 * determine how much memory to allocate into *@obj, then determine 410 - * the qtype of the next thing to be visited, stored in (*@obj)->type. 411 - * Other visitors will leave @obj unchanged. 409 + * the qtype of the next thing to be visited, and store it in 410 + * (*@obj)->type. Other visitors leave @obj unchanged. 411 + * 412 + * On failure, set *@obj to NULL and store an error through @errp. 413 + * Can happen only when @v is an input visitor. 412 414 * 413 415 * If successful, this must be paired with visit_end_alternate() with 414 416 * the same @obj to clean up, even if visiting the contents of the ··· 461 463 * 462 464 * Currently, all input visitors parse text input, and all output 463 465 * visitors produce text output. The mapping between enumeration 464 - * values and strings is done by the visitor core, using @strings; it 465 - * should be the ENUM_lookup array from visit-types.h. 466 + * values and strings is done by the visitor core, using @lookup. 467 + * 468 + * On failure, store an error through @errp. Can happen only when @v 469 + * is an input visitor. 466 470 * 467 471 * May call visit_type_str() under the hood, and the enum visit may 468 472 * fail even if the corresponding string visit succeeded; this implies 469 - * that visit_type_str() must have no unwelcome side effects. 473 + * that an input visitor's visit_type_str() must have no unwelcome 474 + * side effects. 470 475 */ 471 476 void visit_type_enum(Visitor *v, const char *name, int *obj, 472 477 const QEnumLookup *lookup, Error **errp); ··· 476 481 */ 477 482 bool visit_is_input(Visitor *v); 478 483 484 + /* 485 + * Check if visitor is a dealloc visitor. 486 + */ 487 + bool visit_is_dealloc(Visitor *v); 488 + 479 489 /*** Visiting built-in types ***/ 480 490 481 491 /* ··· 486 496 * 487 497 * @obj must be non-NULL. Input visitors set *@obj to the value; 488 498 * other visitors will leave *@obj unchanged. 499 + * 500 + * On failure, store an error through @errp. Can happen only when @v 501 + * is an input visitor. 489 502 */ 490 503 void visit_type_int(Visitor *v, const char *name, int64_t *obj, Error **errp); 491 504 ··· 562 575 * 563 576 * @obj must be non-NULL. Input visitors set *@obj to the value; 564 577 * other visitors will leave *@obj unchanged. 578 + * 579 + * On failure, store an error through @errp. Can happen only when @v 580 + * is an input visitor. 565 581 */ 566 582 void visit_type_bool(Visitor *v, const char *name, bool *obj, Error **errp); 567 583 ··· 579 595 * It is safe to cast away const when preparing a (const char *) value 580 596 * into @obj for use by an output visitor. 581 597 * 598 + * On failure, set *@obj to NULL and store an error through @errp. 599 + * Can happen only when @v is an input visitor. 600 + * 582 601 * FIXME: Callers that try to output NULL *obj should not be allowed. 583 602 */ 584 603 void visit_type_str(Visitor *v, const char *name, char **obj, Error **errp); ··· 592 611 * @obj must be non-NULL. Input visitors set *@obj to the value; 593 612 * other visitors will leave *@obj unchanged. Visitors should 594 613 * document if infinity or NaN are not permitted. 614 + * 615 + * On failure, store an error through @errp. Can happen only when @v 616 + * is an input visitor. 595 617 */ 596 618 void visit_type_number(Visitor *v, const char *name, double *obj, 597 619 Error **errp); ··· 606 628 * other visitors will leave *@obj unchanged. *@obj must be non-NULL 607 629 * for output visitors. 608 630 * 631 + * On failure, set *@obj to NULL and store an error through @errp. 632 + * Can happen only when @v is an input visitor. 633 + * 609 634 * Note that some kinds of input can't express arbitrary QObject. 610 635 * E.g. the visitor returned by qobject_input_visitor_new_keyval() 611 636 * can't create numbers or booleans, only strings. ··· 620 645 * 621 646 * @obj must be non-NULL. Input visitors set *@obj to the value; 622 647 * other visitors ignore *@obj. 648 + * 649 + * On failure, set *@obj to NULL and store an error through @errp. 650 + * Can happen only when @v is an input visitor. 623 651 */ 624 652 void visit_type_null(Visitor *v, const char *name, QNull **obj, 625 653 Error **errp);
+2 -1
monitor/hmp-cmds.c
··· 334 334 Visitor *v; 335 335 char *str; 336 336 v = string_output_visitor_new(false, &str); 337 - visit_type_uint32List(v, NULL, &info->postcopy_vcpu_blocktime, NULL); 337 + visit_type_uint32List(v, NULL, &info->postcopy_vcpu_blocktime, 338 + &error_abort); 338 339 visit_complete(v, &str); 339 340 monitor_printf(mon, "postcopy vcpu blocktime: %s\n", str); 340 341 g_free(str);
+4 -1
monitor/qmp.c
··· 322 322 { 323 323 QList *cap_list = qlist_new(); 324 324 QObject *ver = NULL; 325 + QDict *args; 325 326 QMPCapability cap; 326 327 327 - qmp_marshal_query_version(NULL, &ver, NULL); 328 + args = qdict_new(); 329 + qmp_marshal_query_version(args, &ver, NULL); 330 + qobject_unref(args); 328 331 329 332 for (cap = 0; cap < QMP_CAPABILITY__MAX; cap++) { 330 333 if (mon->capab_offered[cap]) {
-7
qapi/qapi-dealloc-visitor.c
··· 34 34 } 35 35 } 36 36 37 - static void qapi_dealloc_start_alternate(Visitor *v, const char *name, 38 - GenericAlternate **obj, size_t size, 39 - Error **errp) 40 - { 41 - } 42 - 43 37 static void qapi_dealloc_end_alternate(Visitor *v, void **obj) 44 38 { 45 39 if (obj) { ··· 123 117 v->visitor.type = VISITOR_DEALLOC; 124 118 v->visitor.start_struct = qapi_dealloc_start_struct; 125 119 v->visitor.end_struct = qapi_dealloc_end_struct; 126 - v->visitor.start_alternate = qapi_dealloc_start_alternate; 127 120 v->visitor.end_alternate = qapi_dealloc_end_alternate; 128 121 v->visitor.start_list = qapi_dealloc_start_list; 129 122 v->visitor.next_list = qapi_dealloc_next_list;
+11 -9
qapi/qapi-visit-core.c
··· 142 142 return v->type == VISITOR_INPUT; 143 143 } 144 144 145 + bool visit_is_dealloc(Visitor *v) 146 + { 147 + return v->type == VISITOR_DEALLOC; 148 + } 149 + 145 150 void visit_type_int(Visitor *v, const char *name, int64_t *obj, Error **errp) 146 151 { 147 152 assert(obj); ··· 155 160 Error *err = NULL; 156 161 uint64_t value = *obj; 157 162 163 + assert(v->type == VISITOR_INPUT || value <= max); 164 + 158 165 v->type_uint64(v, name, &value, &err); 159 166 if (err) { 160 167 error_propagate(errp, err); 161 168 } else if (value > max) { 169 + assert(v->type == VISITOR_INPUT); 162 170 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, 163 171 name ? name : "null", type); 164 172 } else { ··· 214 222 Error *err = NULL; 215 223 int64_t value = *obj; 216 224 225 + assert(v->type == VISITOR_INPUT || (value >= min && value <= max)); 226 + 217 227 v->type_int64(v, name, &value, &err); 218 228 if (err) { 219 229 error_propagate(errp, err); 220 230 } else if (value < min || value > max) { 231 + assert(v->type == VISITOR_INPUT); 221 232 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, 222 233 name ? name : "null", type); 223 234 } else { ··· 335 346 { 336 347 int value = *obj; 337 348 char *enum_str; 338 - 339 - /* 340 - * TODO why is this an error, not an assertion? If assertion: 341 - * delete, and rely on qapi_enum_lookup() 342 - */ 343 - if (value < 0 || value >= lookup->size) { 344 - error_setg(errp, QERR_INVALID_PARAMETER, name ? name : "null"); 345 - return; 346 - } 347 349 348 350 enum_str = (char *)qapi_enum_lookup(lookup, value); 349 351 visit_type_str(v, name, &enum_str, errp);
+11 -10
qapi/qobject-input-visitor.c
··· 203 203 return qstring_get_str(qstr); 204 204 } 205 205 206 - static void qdict_add_key(const char *key, QObject *obj, void *opaque) 207 - { 208 - GHashTable *h = opaque; 209 - g_hash_table_insert(h, (gpointer) key, NULL); 210 - } 211 - 212 206 static const QListEntry *qobject_input_push(QObjectInputVisitor *qiv, 213 207 const char *name, 214 208 QObject *obj, void *qapi) 215 209 { 216 210 GHashTable *h; 217 211 StackObject *tos = g_new0(StackObject, 1); 212 + QDict *qdict = qobject_to(QDict, obj); 213 + QList *qlist = qobject_to(QList, obj); 214 + const QDictEntry *entry; 218 215 219 216 assert(obj); 220 217 tos->name = name; 221 218 tos->obj = obj; 222 219 tos->qapi = qapi; 223 220 224 - if (qobject_type(obj) == QTYPE_QDICT) { 221 + if (qdict) { 225 222 h = g_hash_table_new(g_str_hash, g_str_equal); 226 - qdict_iter(qobject_to(QDict, obj), qdict_add_key, h); 223 + for (entry = qdict_first(qdict); 224 + entry; 225 + entry = qdict_next(qdict, entry)) { 226 + g_hash_table_insert(h, (void *)qdict_entry_key(entry), NULL); 227 + } 227 228 tos->h = h; 228 229 } else { 229 - assert(qobject_type(obj) == QTYPE_QLIST); 230 - tos->entry = qlist_first(qobject_to(QList, obj)); 230 + assert(qlist); 231 + tos->entry = qlist_first(qlist); 231 232 tos->index = -1; 232 233 } 233 234
-19
qobject/qdict.c
··· 298 298 return qstr ? qstring_get_str(qstr) : NULL; 299 299 } 300 300 301 - /** 302 - * qdict_iter(): Iterate over all the dictionary's stored values. 303 - * 304 - * This function allows the user to provide an iterator, which will be 305 - * called for each stored value in the dictionary. 306 - */ 307 - void qdict_iter(const QDict *qdict, 308 - void (*iter)(const char *key, QObject *obj, void *opaque), 309 - void *opaque) 310 - { 311 - int i; 312 - QDictEntry *entry; 313 - 314 - for (i = 0; i < QDICT_BUCKET_MAX; i++) { 315 - QLIST_FOREACH(entry, &qdict->table[i], next) 316 - iter(entry->key, entry->value, opaque); 317 - } 318 - } 319 - 320 301 static QDictEntry *qdict_next_entry(const QDict *qdict, int first_bucket) 321 302 { 322 303 int i;
+38 -69
qobject/qjson.c
··· 149 149 return qdict; 150 150 } 151 151 152 - typedef struct ToJsonIterState 153 - { 154 - int indent; 155 - int pretty; 156 - int count; 157 - QString *str; 158 - } ToJsonIterState; 159 - 160 152 static void to_json(const QObject *obj, QString *str, int pretty, int indent); 161 153 162 - static void to_json_dict_iter(const char *key, QObject *obj, void *opaque) 163 - { 164 - ToJsonIterState *s = opaque; 165 - QString *qkey; 166 - int j; 167 - 168 - if (s->count) { 169 - qstring_append(s->str, s->pretty ? "," : ", "); 170 - } 171 - 172 - if (s->pretty) { 173 - qstring_append(s->str, "\n"); 174 - for (j = 0 ; j < s->indent ; j++) 175 - qstring_append(s->str, " "); 176 - } 177 - 178 - qkey = qstring_from_str(key); 179 - to_json(QOBJECT(qkey), s->str, s->pretty, s->indent); 180 - qobject_unref(qkey); 181 - 182 - qstring_append(s->str, ": "); 183 - to_json(obj, s->str, s->pretty, s->indent); 184 - s->count++; 185 - } 186 - 187 - static void to_json_list_iter(QObject *obj, void *opaque) 154 + static void json_pretty_newline(QString *str, bool pretty, int indent) 188 155 { 189 - ToJsonIterState *s = opaque; 190 - int j; 156 + int i; 191 157 192 - if (s->count) { 193 - qstring_append(s->str, s->pretty ? "," : ", "); 158 + if (pretty) { 159 + qstring_append(str, "\n"); 160 + for (i = 0; i < indent; i++) { 161 + qstring_append(str, " "); 162 + } 194 163 } 195 - 196 - if (s->pretty) { 197 - qstring_append(s->str, "\n"); 198 - for (j = 0 ; j < s->indent ; j++) 199 - qstring_append(s->str, " "); 200 - } 201 - 202 - to_json(obj, s->str, s->pretty, s->indent); 203 - s->count++; 204 164 } 205 165 206 166 static void to_json(const QObject *obj, QString *str, int pretty, int indent) ··· 273 233 break; 274 234 } 275 235 case QTYPE_QDICT: { 276 - ToJsonIterState s; 277 236 QDict *val = qobject_to(QDict, obj); 237 + const char *comma = pretty ? "," : ", "; 238 + const char *sep = ""; 239 + const QDictEntry *entry; 240 + QString *qkey; 278 241 279 - s.count = 0; 280 - s.str = str; 281 - s.indent = indent + 1; 282 - s.pretty = pretty; 283 242 qstring_append(str, "{"); 284 - qdict_iter(val, to_json_dict_iter, &s); 285 - if (pretty) { 286 - int j; 287 - qstring_append(str, "\n"); 288 - for (j = 0 ; j < indent ; j++) 289 - qstring_append(str, " "); 243 + 244 + for (entry = qdict_first(val); 245 + entry; 246 + entry = qdict_next(val, entry)) { 247 + qstring_append(str, sep); 248 + json_pretty_newline(str, pretty, indent + 1); 249 + 250 + qkey = qstring_from_str(qdict_entry_key(entry)); 251 + to_json(QOBJECT(qkey), str, pretty, indent + 1); 252 + qobject_unref(qkey); 253 + 254 + qstring_append(str, ": "); 255 + to_json(qdict_entry_value(entry), str, pretty, indent + 1); 256 + sep = comma; 290 257 } 258 + 259 + json_pretty_newline(str, pretty, indent); 291 260 qstring_append(str, "}"); 292 261 break; 293 262 } 294 263 case QTYPE_QLIST: { 295 - ToJsonIterState s; 296 264 QList *val = qobject_to(QList, obj); 265 + const char *comma = pretty ? "," : ", "; 266 + const char *sep = ""; 267 + QListEntry *entry; 297 268 298 - s.count = 0; 299 - s.str = str; 300 - s.indent = indent + 1; 301 - s.pretty = pretty; 302 269 qstring_append(str, "["); 303 - qlist_iter(val, (void *)to_json_list_iter, &s); 304 - if (pretty) { 305 - int j; 306 - qstring_append(str, "\n"); 307 - for (j = 0 ; j < indent ; j++) 308 - qstring_append(str, " "); 270 + 271 + QLIST_FOREACH_ENTRY(val, entry) { 272 + qstring_append(str, sep); 273 + json_pretty_newline(str, pretty, indent + 1); 274 + to_json(qlist_entry_obj(entry), str, pretty, indent + 1); 275 + sep = comma; 309 276 } 277 + 278 + json_pretty_newline(str, pretty, indent); 310 279 qstring_append(str, "]"); 311 280 break; 312 281 }
+12 -32
qobject/qlist.c
··· 34 34 return qlist; 35 35 } 36 36 37 - static void qlist_copy_elem(QObject *obj, void *opaque) 38 - { 39 - QList *dst = opaque; 40 - 41 - qobject_ref(obj); 42 - qlist_append_obj(dst, obj); 43 - } 44 - 45 37 QList *qlist_copy(QList *src) 46 38 { 47 39 QList *dst = qlist_new(); 48 - 49 - qlist_iter(src, qlist_copy_elem, dst); 40 + QListEntry *entry; 41 + QObject *elt; 50 42 43 + QLIST_FOREACH_ENTRY(src, entry) { 44 + elt = qlist_entry_obj(entry); 45 + qobject_ref(elt); 46 + qlist_append_obj(dst, elt); 47 + } 51 48 return dst; 52 49 } 53 50 ··· 86 83 qlist_append(qlist, qnull()); 87 84 } 88 85 89 - /** 90 - * qlist_iter(): Iterate over all the list's stored values. 91 - * 92 - * This function allows the user to provide an iterator, which will be 93 - * called for each stored value in the list. 94 - */ 95 - void qlist_iter(const QList *qlist, 96 - void (*iter)(QObject *obj, void *opaque), void *opaque) 97 - { 98 - QListEntry *entry; 99 - 100 - QTAILQ_FOREACH(entry, &qlist->head, next) 101 - iter(entry->value, opaque); 102 - } 103 - 104 86 QObject *qlist_pop(QList *qlist) 105 87 { 106 88 QListEntry *entry; ··· 137 119 return QTAILQ_EMPTY(&qlist->head); 138 120 } 139 121 140 - static void qlist_size_iter(QObject *obj, void *opaque) 141 - { 142 - size_t *count = opaque; 143 - (*count)++; 144 - } 145 - 146 122 size_t qlist_size(const QList *qlist) 147 123 { 148 124 size_t count = 0; 149 - qlist_iter(qlist, qlist_size_iter, &count); 125 + QListEntry *entry; 126 + 127 + QLIST_FOREACH_ENTRY(qlist, entry) { 128 + count++; 129 + } 150 130 return count; 151 131 } 152 132
+1 -3
qom/object.c
··· 1550 1550 } 1551 1551 visit_complete(v, &str); 1552 1552 visit_free(v); 1553 - v = string_input_visitor_new(str); 1554 - visit_type_enum(v, name, &ret, enumprop->lookup, errp); 1555 1553 1554 + ret = qapi_enum_parse(enumprop->lookup, str, -1, errp); 1556 1555 g_free(str); 1557 - visit_free(v); 1558 1556 1559 1557 return ret; 1560 1558 }
+23 -37
scripts/qapi/commands.py
··· 104 104 %(proto)s 105 105 { 106 106 Error *err = NULL; 107 + Visitor *v; 107 108 ''', 108 109 proto=build_marshal_proto(name)) 109 110 ··· 114 115 c_type=ret_type.c_type()) 115 116 116 117 if have_args: 117 - visit_members = ('visit_type_%s_members(v, &arg, &err);' 118 - % arg_type.c_name()) 119 118 ret += mcgen(''' 120 - Visitor *v; 121 119 %(c_name)s arg = {0}; 122 - 123 120 ''', 124 121 c_name=arg_type.c_name()) 125 - else: 126 - visit_members = '' 127 - ret += mcgen(''' 128 - Visitor *v = NULL; 129 122 130 - if (args) { 131 - ''') 132 - push_indent() 123 + ret += mcgen(''' 133 124 134 - ret += mcgen(''' 135 125 v = qobject_input_visitor_new(QOBJECT(args)); 136 126 visit_start_struct(v, NULL, NULL, 0, &err); 137 127 if (err) { 138 128 goto out; 139 129 } 140 - %(visit_members)s 130 + ''') 131 + 132 + if have_args: 133 + ret += mcgen(''' 134 + visit_type_%(c_arg_type)s_members(v, &arg, &err); 141 135 if (!err) { 142 136 visit_check_struct(v, &err); 143 137 } 138 + ''', 139 + c_arg_type=arg_type.c_name()) 140 + else: 141 + ret += mcgen(''' 142 + visit_check_struct(v, &err); 143 + ''') 144 + 145 + ret += mcgen(''' 144 146 visit_end_struct(v, NULL); 145 147 if (err) { 146 148 goto out; 147 149 } 148 - ''', 149 - visit_members=visit_members) 150 - 151 - if not have_args: 152 - pop_indent() 153 - ret += mcgen(''' 154 - } 155 150 ''') 156 151 157 152 ret += gen_call(name, arg_type, boxed, ret_type) ··· 163 158 visit_free(v); 164 159 ''') 165 160 161 + ret += mcgen(''' 162 + v = qapi_dealloc_visitor_new(); 163 + visit_start_struct(v, NULL, NULL, 0, NULL); 164 + ''') 165 + 166 166 if have_args: 167 - visit_members = ('visit_type_%s_members(v, &arg, NULL);' 168 - % arg_type.c_name()) 169 - else: 170 - visit_members = '' 171 167 ret += mcgen(''' 172 - if (args) { 173 - ''') 174 - push_indent() 168 + visit_type_%(c_arg_type)s_members(v, &arg, NULL); 169 + ''', 170 + c_arg_type=arg_type.c_name()) 175 171 176 172 ret += mcgen(''' 177 - v = qapi_dealloc_visitor_new(); 178 - visit_start_struct(v, NULL, NULL, 0, NULL); 179 - %(visit_members)s 180 173 visit_end_struct(v, NULL); 181 174 visit_free(v); 182 - ''', 183 - visit_members=visit_members) 184 - 185 - if not have_args: 186 - pop_indent() 187 - ret += mcgen(''' 188 - } 189 175 ''') 190 176 191 177 ret += mcgen('''
+8
scripts/qapi/visit.py
··· 189 189 goto out; 190 190 } 191 191 if (!*obj) { 192 + /* incomplete */ 193 + assert(visit_is_dealloc(v)); 192 194 goto out_obj; 193 195 } 194 196 switch ((*obj)->type) { ··· 230 232 case QTYPE_NONE: 231 233 abort(); 232 234 default: 235 + assert(visit_is_input(v)); 233 236 error_setg(&err, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", 234 237 "%(name)s"); 238 + /* Avoid passing invalid *obj to qapi_free_%(c_name)s() */ 239 + g_free(*obj); 240 + *obj = NULL; 235 241 } 236 242 out_obj: 237 243 visit_end_alternate(v, (void **)obj); ··· 260 266 goto out; 261 267 } 262 268 if (!*obj) { 269 + /* incomplete */ 270 + assert(visit_is_dealloc(v)); 263 271 goto out_obj; 264 272 } 265 273 visit_type_%(c_name)s_members(v, *obj, &err);
+14 -23
tests/check-qlist.c
··· 61 61 qobject_unref(qlist); 62 62 } 63 63 64 - static int iter_called; 65 - static const int iter_max = 42; 66 - 67 - static void iter_func(QObject *obj, void *opaque) 68 - { 69 - QNum *qi; 70 - int64_t val; 71 - 72 - g_assert(opaque == NULL); 73 - 74 - qi = qobject_to(QNum, obj); 75 - g_assert(qi != NULL); 76 - 77 - g_assert(qnum_get_try_int(qi, &val)); 78 - g_assert_cmpint(val, >=, 0); 79 - g_assert_cmpint(val, <=, iter_max); 80 - 81 - iter_called++; 82 - } 83 - 84 64 static void qlist_iter_test(void) 85 65 { 66 + const int iter_max = 42; 86 67 int i; 87 68 QList *qlist; 69 + QListEntry *entry; 70 + QNum *qi; 71 + int64_t val; 88 72 89 73 qlist = qlist_new(); 90 74 91 75 for (i = 0; i < iter_max; i++) 92 76 qlist_append_int(qlist, i); 93 77 94 - iter_called = 0; 95 - qlist_iter(qlist, iter_func, NULL); 78 + i = 0; 79 + QLIST_FOREACH_ENTRY(qlist, entry) { 80 + qi = qobject_to(QNum, qlist_entry_obj(entry)); 81 + g_assert(qi != NULL); 96 82 97 - g_assert(iter_called == iter_max); 83 + g_assert(qnum_get_try_int(qi, &val)); 84 + g_assert_cmpint(val, ==, i); 85 + i++; 86 + } 87 + 88 + g_assert(i == iter_max); 98 89 99 90 qobject_unref(qlist); 100 91 }
-39
tests/test-qobject-output-visitor.c
··· 141 141 } 142 142 } 143 143 144 - static void test_visitor_out_enum_errors(TestOutputVisitorData *data, 145 - const void *unused) 146 - { 147 - EnumOne i, bad_values[] = { ENUM_ONE__MAX, -1 }; 148 - 149 - for (i = 0; i < ARRAY_SIZE(bad_values) ; i++) { 150 - Error *err = NULL; 151 - 152 - visit_type_EnumOne(data->ov, "unused", &bad_values[i], &err); 153 - error_free_or_abort(&err); 154 - visitor_reset(data); 155 - } 156 - } 157 - 158 - 159 144 static void test_visitor_out_struct(TestOutputVisitorData *data, 160 145 const void *unused) 161 146 { ··· 233 218 234 219 qapi_free_UserDefTwo(ud2); 235 220 } 236 - 237 - static void test_visitor_out_struct_errors(TestOutputVisitorData *data, 238 - const void *unused) 239 - { 240 - EnumOne bad_values[] = { ENUM_ONE__MAX, -1 }; 241 - UserDefOne u = {0}; 242 - UserDefOne *pu = &u; 243 - int i; 244 - 245 - for (i = 0; i < ARRAY_SIZE(bad_values) ; i++) { 246 - Error *err = NULL; 247 - 248 - u.has_enum1 = true; 249 - u.enum1 = bad_values[i]; 250 - visit_type_UserDefOne(data->ov, "unused", &pu, &err); 251 - error_free_or_abort(&err); 252 - visitor_reset(data); 253 - } 254 - } 255 - 256 221 257 222 static void test_visitor_out_list(TestOutputVisitorData *data, 258 223 const void *unused) ··· 821 786 &out_visitor_data, test_visitor_out_no_string); 822 787 output_visitor_test_add("/visitor/output/enum", 823 788 &out_visitor_data, test_visitor_out_enum); 824 - output_visitor_test_add("/visitor/output/enum-errors", 825 - &out_visitor_data, test_visitor_out_enum_errors); 826 789 output_visitor_test_add("/visitor/output/struct", 827 790 &out_visitor_data, test_visitor_out_struct); 828 791 output_visitor_test_add("/visitor/output/struct-nested", 829 792 &out_visitor_data, test_visitor_out_struct_nested); 830 - output_visitor_test_add("/visitor/output/struct-errors", 831 - &out_visitor_data, test_visitor_out_struct_errors); 832 793 output_visitor_test_add("/visitor/output/list", 833 794 &out_visitor_data, test_visitor_out_list); 834 795 output_visitor_test_add("/visitor/output/any",
-19
tests/test-string-output-visitor.c
··· 203 203 } 204 204 } 205 205 206 - static void test_visitor_out_enum_errors(TestOutputVisitorData *data, 207 - const void *unused) 208 - { 209 - EnumOne i, bad_values[] = { ENUM_ONE__MAX, -1 }; 210 - 211 - for (i = 0; i < ARRAY_SIZE(bad_values) ; i++) { 212 - Error *err = NULL; 213 - 214 - visit_type_EnumOne(data->ov, "unused", &bad_values[i], &err); 215 - error_free_or_abort(&err); 216 - } 217 - } 218 - 219 206 static void 220 207 output_visitor_test_add(const char *testpath, 221 208 TestOutputVisitorData *data, ··· 260 247 &out_visitor_data, test_visitor_out_enum, false); 261 248 output_visitor_test_add("/string-visitor/output/enum-human", 262 249 &out_visitor_data, test_visitor_out_enum, true); 263 - output_visitor_test_add("/string-visitor/output/enum-errors", 264 - &out_visitor_data, test_visitor_out_enum_errors, 265 - false); 266 - output_visitor_test_add("/string-visitor/output/enum-errors-human", 267 - &out_visitor_data, test_visitor_out_enum_errors, 268 - true); 269 250 output_visitor_test_add("/string-visitor/output/intList", 270 251 &out_visitor_data, test_visitor_out_intList, false); 271 252 output_visitor_test_add("/string-visitor/output/intList-human",
+19 -24
util/qemu-option.c
··· 965 965 assert(opts); 966 966 } 967 967 968 - typedef struct OptsFromQDictState { 969 - QemuOpts *opts; 970 - Error **errp; 971 - } OptsFromQDictState; 972 - 973 - static void qemu_opts_from_qdict_1(const char *key, QObject *obj, void *opaque) 968 + static void qemu_opts_from_qdict_entry(QemuOpts *opts, 969 + const QDictEntry *entry, 970 + Error **errp) 974 971 { 975 - OptsFromQDictState *state = opaque; 972 + const char *key = qdict_entry_key(entry); 973 + QObject *obj = qdict_entry_value(entry); 976 974 char buf[32], *tmp = NULL; 977 975 const char *value; 978 976 979 - if (!strcmp(key, "id") || *state->errp) { 977 + if (!strcmp(key, "id")) { 980 978 return; 981 979 } 982 980 ··· 997 995 return; 998 996 } 999 997 1000 - qemu_opt_set(state->opts, key, value, state->errp); 998 + qemu_opt_set(opts, key, value, errp); 1001 999 g_free(tmp); 1002 1000 } 1003 1001 ··· 1010 1008 QemuOpts *qemu_opts_from_qdict(QemuOptsList *list, const QDict *qdict, 1011 1009 Error **errp) 1012 1010 { 1013 - OptsFromQDictState state; 1014 1011 Error *local_err = NULL; 1015 1012 QemuOpts *opts; 1013 + const QDictEntry *entry; 1016 1014 1017 1015 opts = qemu_opts_create(list, qdict_get_try_str(qdict, "id"), 1, 1018 1016 &local_err); ··· 1023 1021 1024 1022 assert(opts != NULL); 1025 1023 1026 - state.errp = &local_err; 1027 - state.opts = opts; 1028 - qdict_iter(qdict, qemu_opts_from_qdict_1, &state); 1029 - if (local_err) { 1030 - error_propagate(errp, local_err); 1031 - qemu_opts_del(opts); 1032 - return NULL; 1024 + for (entry = qdict_first(qdict); 1025 + entry; 1026 + entry = qdict_next(qdict, entry)) { 1027 + qemu_opts_from_qdict_entry(opts, entry, &local_err); 1028 + if (local_err) { 1029 + error_propagate(errp, local_err); 1030 + qemu_opts_del(opts); 1031 + return NULL; 1032 + } 1033 1033 } 1034 1034 1035 1035 return opts; ··· 1048 1048 1049 1049 while (entry != NULL) { 1050 1050 Error *local_err = NULL; 1051 - OptsFromQDictState state = { 1052 - .errp = &local_err, 1053 - .opts = opts, 1054 - }; 1055 1051 1056 1052 next = qdict_next(qdict, entry); 1057 1053 1058 1054 if (find_desc_by_name(opts->list->desc, entry->key)) { 1059 - qemu_opts_from_qdict_1(entry->key, entry->value, &state); 1055 + qemu_opts_from_qdict_entry(opts, entry, &local_err); 1060 1056 if (local_err) { 1061 1057 error_propagate(errp, local_err); 1062 1058 return; 1063 - } else { 1064 - qdict_del(qdict, entry->key); 1065 1059 } 1060 + qdict_del(qdict, entry->key); 1066 1061 } 1067 1062 1068 1063 entry = next;