Features/CoroutineFnCleanup
Hand-written wrappers for coroutine functions
- bdrv_pread/bdrv_pwrite have different calling convention than bdrv_co_pread/bdrv_co_pwrite [Alberto]
- Fix using Coccinelle
- Switch bdrv_pread/bdrv_pwrite to generated_co_wrapper
- Missing bdrv_co_pwrite_sync, bdrv_co_pwrite_zeroes
- Adjust code in block/io.c and introduce generated_co_wrapper
- Use generated_co_wrapper for block-backend.c too, removing the need for declarations in block/coroutines.h [Alberto]
- Probably more will be found with custom matching tools (see below)
Converting callbacks to coroutines
- bdrv_inactivate, which does I/O, can be converted to a coroutine_fn callback. It is only implemented by qcow2, so it can be called from bdrv_close instead of qcow2_close. The call in bdrv_inactivate_recurse would go through a generated_co_wrapper in block/coroutines.h, e.g. bdrv_do_inactivate_one.
- It should be possible to convert bdrv_snapshot_goto too. Likewise, bdrv_snapshot_goto would call a generated_co_wrapper, e.g. bdrv_do_snapshot_goto.
Annotations
- Add coroutine_mixed_fn annotation; functions that call qemu_in_coroutine(). Leaves are:
- all generated_co_wrapper functions
- bdrv_create
- bdrv_can_store_new_dirty_bitmap, bdrv_remove_persistent_dirty_bitmap
- bdrv_drain_all_begin, bdrv_do_drained_begin, bdrv_do_drained_end
- qio_channel_readv_full_all_eof, qio_channel_writev_full
- qcow2_open, qcow2_has_zero_init
- bdrv_qed_open
- qmp_dispatch
- nvme_get_free_req
- schedule_next_request
- Detect call from non-coroutine_fn/coroutine_mixed_fn to coroutine_fn (libclang/clang-tidy)
- Remove coroutine_fn from callee, or add it to caller (check against https://patchew.org/QEMU/20220509103019.215041-1-pbonzini@redhat.com/)
- Possibly add fixit to rewrite
- Detect call from coroutine_fn to generated_co_wrapper (libclang/clang-tidy)
- Use _co_ version instead.
- Possibly add fixit to rewrite
- Detect call from non-coroutine_fn to coroutine_mixed_fn (libclang/clang-tidy)
- Change caller to coroutine_mixed_fn too
- If there is none, coroutine_mixed_fn can be changed to coroutine_fn
Clang-query examples
Invoking clang-query:
- Change definition of coroutine_fn to #define coroutine_fn __attribute__((annotate("coroutine")))
- Invoke clang-query -p build-path block/io.c
Example of clang-query uses:
- match functionDecl(allOf(unless(hasAttr("attr::Annotate")),hasDescendant(callExpr(callee(hasAttr("attr::Annotate"))).bind("callee"))))
- call from non-coroutine_fn to coroutine_fn (doesn't actually check the string in the annotate attribute)
- match varDecl(hasType(namedDecl(hasName("BlockDriver"))), hasInitializer(anything()))
- declaration of BlockDriver struct, with initializer
- match functionDecl(isExpansionInMainFile(), forEachDescendant(callExpr(callee(unless(functionDecl()))).bind("call"))).bind("root")'
- indirect call
Clang references
https://devblogs.microsoft.com/cppblog/exploring-clang-tooling-part-1-extending-clang-tidy/