Paolo Bonzini <pbonz...@redhat.com> writes: > Coroutine commands have to be declared as coroutine_fn, but the
Reminder, because I had to look this up... A "coroutine command" is a command that has flag coroutine set, like so: { 'command': 'block_resize', 'data': { '*device': 'str', '*node-name': 'str', 'size': 'int' }, --> 'coroutine': true, 'allow-preconfig': true } This flag means "safe to run in coroutine context". The QMP dispatcher runs in coroutine context (except for OOB commands, but let's ignore those). It executes coroutine commands directly, and the others in a bottom half outside coroutine context. See commit 04f22362f1 "qapi: Add a 'coroutine' flag for commands" and commit 9ce44e2ce2 "qmp: Move dispatcher to a coroutine". Only two coroutine commands exist so far. > marker does not show up in the qapi-comands-* headers; likewise, the > marshaling function calls the command and therefore must be coroutine_fn. > Static analysis would want coroutine_fn to match between prototype and > declaration, because in principle coroutines might be compiled to a > completely different calling convention. So we would like to add the > marker to the header. > > Unfortunately, doing so causes lots of files to fail to compile because > they do not include qemu/coroutine.h; which in principle is legitimate > because the files could be only dealing with non-coroutine commands. > There are three ways to deal with this: > > - include qemu/coroutine.h in all the files that include the qapi-commands-* > headers. This would be a large change and in many case unnecessary, > because only very few files deal with coroutine commands > > - include qemu/coroutine.h from the headers themselves. This is > ugly for the same reason, and also because headers-including-headers > make it harder to avoid world rebuilds Headers should be self-contained, i.e. include everything they need to compile (except for qemu/osdep.h, which the .c include first). The first way would violate this. > - only define the affected prototypes if coroutine_fn is defined, > meaning that the .c file has already included qemu/coroutine.h. > This is what the patch goes for. Why can't we include qemu/coroutine.h only when the header actually needs it? I.e. when it declares a coroutine command. > Signed-off-by: Paolo Bonzini <pbonz...@redhat.com>