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

qapi: Only input visitors can actually fail

The previous few commits have made this more obvious, and removed the
one exception. Time to clarify the documentation, and drop dead error
checking.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200424084338.26803-13-armbru@redhat.com>

+35 -48
+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
+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",
+4
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);
+24 -16
include/qapi/visitor.h
··· 82 82 * Each function also takes the customary @errp argument (see 83 83 * qapi/error.h for details), for reporting any errors (such as if a 84 84 * member @name is not present, or is present but not the specified 85 - * type). 85 + * type). Only input visitors can fail. 86 86 * 87 87 * If an error is detected during visit_type_FOO() with an input 88 88 * visitor, then *@obj will be set to NULL for pointer types, and left ··· 164 164 * 165 165 * <example> 166 166 * Foo *f = ...obtain populated object... 167 - * Error *err = NULL; 168 167 * Visitor *v; 169 168 * Type *result; 170 169 * 171 170 * v = FOO_visitor_new(..., &result); 172 - * visit_type_Foo(v, NULL, &f, &err); 173 - * if (err) { 174 - * ...handle error... 175 - * } else { 176 - * visit_complete(v, &result); 177 - * ...use result... 178 - * } 171 + * visit_type_Foo(v, NULL, &f, &error_abort); 172 + * visit_complete(v, &result); 179 173 * visit_free(v); 174 + * ...use result... 180 175 * </example> 181 176 * 182 177 * It is also possible to use the visitors to do a virtual walk, where ··· 289 284 * case @size is ignored. 290 285 * 291 286 * On failure, set *@obj to NULL and store an error through @errp. 287 + * Can happen only when @v is an input visitor. 292 288 * 293 289 * After visit_start_struct() succeeds, the caller may visit its 294 290 * members one after the other, passing the member's name and address ··· 305 301 /* 306 302 * Prepare for completing an object visit. 307 303 * 308 - * On failure, store an error through @errp. 304 + * On failure, store an error through @errp. Can happen only when @v 305 + * is an input visitor. 309 306 * 310 307 * Should be called prior to visit_end_struct() if all other 311 308 * intermediate visit steps were successful, to allow the visitor one ··· 342 339 * ignored. 343 340 * 344 341 * On failure, set *@list to NULL and store an error through @errp. 342 + * Can happen only when @v is an input visitor. 345 343 * 346 344 * After visit_start_list() succeeds, the caller may visit its members 347 345 * one after the other. A real visit (where @list is non-NULL) uses ··· 375 373 /* 376 374 * Prepare for completing a list visit. 377 375 * 378 - * On failure, store an error through @errp. 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 ··· 411 410 * (*@obj)->type. Other visitors leave @obj unchanged. 412 411 * 413 412 * On failure, set *@obj to NULL and store an error through @errp. 413 + * Can happen only when @v is an input visitor. 414 414 * 415 415 * If successful, this must be paired with visit_end_alternate() with 416 416 * the same @obj to clean up, even if visiting the contents of the ··· 465 465 * visitors produce text output. The mapping between enumeration 466 466 * values and strings is done by the visitor core, using @lookup. 467 467 * 468 - * On failure, store an error through @errp. 468 + * On failure, store an error through @errp. Can happen only when @v 469 + * is an input visitor. 469 470 * 470 471 * May call visit_type_str() under the hood, and the enum visit may 471 472 * fail even if the corresponding string visit succeeded; this implies 472 - * 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. 473 475 */ 474 476 void visit_type_enum(Visitor *v, const char *name, int *obj, 475 477 const QEnumLookup *lookup, Error **errp); ··· 495 497 * @obj must be non-NULL. Input visitors set *@obj to the value; 496 498 * other visitors will leave *@obj unchanged. 497 499 * 498 - * On failure, store an error through @errp. 500 + * On failure, store an error through @errp. Can happen only when @v 501 + * is an input visitor. 499 502 */ 500 503 void visit_type_int(Visitor *v, const char *name, int64_t *obj, Error **errp); 501 504 ··· 573 576 * @obj must be non-NULL. Input visitors set *@obj to the value; 574 577 * other visitors will leave *@obj unchanged. 575 578 * 576 - * On failure, store an error through @errp. 579 + * On failure, store an error through @errp. Can happen only when @v 580 + * is an input visitor. 577 581 */ 578 582 void visit_type_bool(Visitor *v, const char *name, bool *obj, Error **errp); 579 583 ··· 592 596 * into @obj for use by an output visitor. 593 597 * 594 598 * On failure, set *@obj to NULL and store an error through @errp. 599 + * Can happen only when @v is an input visitor. 595 600 * 596 601 * FIXME: Callers that try to output NULL *obj should not be allowed. 597 602 */ ··· 607 612 * other visitors will leave *@obj unchanged. Visitors should 608 613 * document if infinity or NaN are not permitted. 609 614 * 610 - * On failure, store an error through @errp. 615 + * On failure, store an error through @errp. Can happen only when @v 616 + * is an input visitor. 611 617 */ 612 618 void visit_type_number(Visitor *v, const char *name, double *obj, 613 619 Error **errp); ··· 623 629 * for output visitors. 624 630 * 625 631 * On failure, set *@obj to NULL and store an error through @errp. 632 + * Can happen only when @v is an input visitor. 626 633 * 627 634 * Note that some kinds of input can't express arbitrary QObject. 628 635 * E.g. the visitor returned by qobject_input_visitor_new_keyval() ··· 640 647 * other visitors ignore *@obj. 641 648 * 642 649 * On failure, set *@obj to NULL and store an error through @errp. 650 + * Can happen only when @v is an input visitor. 643 651 */ 644 652 void visit_type_null(Visitor *v, const char *name, QNull **obj, 645 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);