qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v8 4/7] scripts: add block-coroutine-wrapper.py


From: Vladimir Sementsov-Ogievskiy
Subject: Re: [PATCH v8 4/7] scripts: add block-coroutine-wrapper.py
Date: Tue, 15 Sep 2020 23:02:28 +0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0

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<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


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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]