aboutsummaryrefslogtreecommitdiff
path: root/docs/devel
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2020-10-06 12:15:59 +0100
committerPeter Maydell <peter.maydell@linaro.org>2020-10-06 12:15:59 +0100
commitd7c5b788295426c1ef48a9ffc3432c51220f69ba (patch)
tree9c7d200421b5fb4fa92a5a761532a21b6bfdb2f7 /docs/devel
parent36d9c2883e55c863b622b99f0ebb5143f0001401 (diff)
parent9ab5741164b1727d22f69fe7001382baf0d56977 (diff)
downloadqemu-d7c5b788295426c1ef48a9ffc3432c51220f69ba.zip
qemu-d7c5b788295426c1ef48a9ffc3432c51220f69ba.tar.gz
qemu-d7c5b788295426c1ef48a9ffc3432c51220f69ba.tar.bz2
Merge remote-tracking branch 'remotes/stefanha-gitlab/tags/block-pull-request' into staging
Pull request v2: * Removed clang-format call from scripts/block-coroutine-wrapper.py. This avoids the issue with clang version incompatibility. It could be added back in the future but the code is readable without reformatting and it also makes the build less dependent on the environment. # gpg: Signature made Mon 05 Oct 2020 16:42:28 BST # gpg: using RSA key 8695A8BFD3F97CDAAC35775A9CA4ABB381AB73C8 # gpg: Good signature from "Stefan Hajnoczi <stefanha@redhat.com>" [full] # gpg: aka "Stefan Hajnoczi <stefanha@gmail.com>" [full] # Primary key fingerprint: 8695 A8BF D3F9 7CDA AC35 775A 9CA4 ABB3 81AB 73C8 * remotes/stefanha-gitlab/tags/block-pull-request: util/vfio-helpers: Rework the IOVA allocator to avoid IOVA reserved regions util/vfio-helpers: Collect IOVA reserved regions docs: add 'io_uring' option to 'aio' param in qemu-options.hx include/block/block.h: drop non-ascii quotation mark block/io: refactor save/load vmstate block: drop bdrv_prwv block: generate coroutine-wrapper code scripts: add block-coroutine-wrapper.py block: declare some coroutine functions in block/coroutines.h block/io: refactor coroutine wrappers block: return error-code from bdrv_invalidate_cache block/nvme: Replace magic value by SCALE_MS definition block/nvme: Use register definitions from 'block/nvme.h' block/nvme: Drop NVMeRegs structure, directly use NvmeBar block/nvme: Reduce I/O registers scope block/nvme: Map doorbells pages write-only util/vfio-helpers: Pass page protections to qemu_vfio_pci_map_bar() Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'docs/devel')
-rw-r--r--docs/devel/block-coroutine-wrapper.rst54
-rw-r--r--docs/devel/index.rst1
2 files changed, 55 insertions, 0 deletions
diff --git a/docs/devel/block-coroutine-wrapper.rst b/docs/devel/block-coroutine-wrapper.rst
new file mode 100644
index 0000000..4128519
--- /dev/null
+++ b/docs/devel/block-coroutine-wrapper.rst
@@ -0,0 +1,54 @@
+=======================
+block-coroutine-wrapper
+=======================
+
+A lot of functions in QEMU block layer (see ``block/*``) can only be
+called in coroutine context. Such functions are normally marked by the
+coroutine_fn specifier. Still, sometimes we need to call them from
+non-coroutine context; for this we need to start a coroutine, run the
+needed function from it and wait for the coroutine to finish in a
+BDRV_POLL_WHILE() loop. To run a coroutine we need a function with one
+void* argument. So for each coroutine_fn function which needs a
+non-coroutine interface, we should define a structure to pack the
+parameters, define a separate function to unpack the parameters and
+call the original function and finally define a new interface function
+with same list of arguments as original one, which will pack the
+parameters into a struct, create a coroutine, run it and wait in
+BDRV_POLL_WHILE() loop. It's boring to create such wrappers by hand,
+so we have a script to generate them.
+
+Usage
+=====
+
+Assume we have defined the ``coroutine_fn`` function
+``bdrv_co_foo(<some args>)`` and need a non-coroutine interface for it,
+called ``bdrv_foo(<same args>)``. In this case the script can help. To
+trigger the generation:
+
+1. You need ``bdrv_foo`` declaration somewhere (for example, in
+ ``block/coroutines.h``) with the ``generated_co_wrapper`` mark,
+ like this:
+
+.. code-block:: c
+
+ int generated_co_wrapper bdrv_foo(<some args>);
+
+2. You need to feed this declaration to block-coroutine-wrapper script.
+ For this, add the .h (or .c) file with the declaration to the
+ ``input: files(...)`` list of ``block_gen_c`` target declaration in
+ ``block/meson.build``
+
+You are done. During the build, coroutine wrappers will be generated in
+``<BUILD_DIR>/block/block-gen.c``.
+
+Links
+=====
+
+1. The script location is ``scripts/block-coroutine-wrapper.py``.
+
+2. Generic place for private ``generated_co_wrapper`` declarations is
+ ``block/coroutines.h``, for public declarations:
+ ``include/block/block.h``
+
+3. The core API of generated coroutine wrappers is placed in
+ (not generated) ``block/block-gen.h``
diff --git a/docs/devel/index.rst b/docs/devel/index.rst
index c34b43e..5fda2d3 100644
--- a/docs/devel/index.rst
+++ b/docs/devel/index.rst
@@ -32,3 +32,4 @@ Contents:
s390-dasd-ipl
clocks
qom
+ block-coroutine-wrapper