15.09.2020 19:44, Vladimir Sementsov-Ogievskiy wrote:
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<vsement...@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
Also needed:
diff --git a/docs/devel/index.rst b/docs/devel/index.rst
index 04773ce076..cb0abe1e69 100644
--- a/docs/devel/index.rst
+++ b/docs/devel/index.rst
@@ -31,3 +31,4 @@ Contents:
reset
s390-dasd-ipl
clocks
+ block-coroutine-wrapper
--
Best regards,
Vladimir