We have a very frequent pattern of creating coroutine from function
with several arguments:
- create structure to pack parameters
- create _entry function to call original function taking parameters
from struct
- do different magic to handle completion: set ret to NOT_DONE or
EINPROGRESS or use separate bool field
- fill the struct and create coroutine from _entry function and this
struct as a parameter
- do coroutine enter and BDRV_POLL_WHILE loop
Let's reduce code duplication by generating coroutine wrappers.
This patch adds scripts/block-coroutine-wrapper.py together with some
friends, which will generate functions with declared prototypes marked
by 'generated_co_wrapper' specifier.
The usage of new code generation is as follows:
1. define somewhere
int coroutine_fn bdrv_co_NAME(...) {...}
function
2. declare in some header file
int generated_co_wrapper bdrv_NAME(...);
function with same list of parameters. (you'll need to include
"block/generated-co-wrapper.h" to get the specifier)
3. both declarations should be available through block/coroutines.h
header.
4. add header with generated_co_wrapper declaration into
COROUTINE_HEADERS list in Makefile
Still, no function is now marked, this work is for the following
commit.
Signed-off-by: Vladimir Sementsov-Ogievskiy<vsementsov@virtuozzo.com>
---
docs/devel/block-coroutine-wrapper.rst | 54 +++++++
block/block-gen.h | 49 +++++++
include/block/block.h | 10 ++
block/meson.build | 8 ++
scripts/block-coroutine-wrapper.py | 187 +++++++++++++++++++++++++
5 files changed, 308 insertions(+)
create mode 100644 docs/devel/block-coroutine-wrapper.rst
create mode 100644 block/block-gen.h
create mode 100755 scripts/block-coroutine-wrapper.py