block-coroutine-wrapper.py: support BlockBackend first argument
authorVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Wed, 6 Oct 2021 13:17:12 +0000 (15:17 +0200)
committerEric Blake <eblake@redhat.com>
Fri, 15 Oct 2021 20:51:33 +0000 (15:51 -0500)
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20211006131718.214235-7-vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
block/coroutines.h
scripts/block-coroutine-wrapper.py

index 514d169d23d6a20ef0be3ca856253206728cfd60..35a6c49857824ec9357da5005ff07e81f4f71c95 100644 (file)
@@ -27,6 +27,9 @@
 
 #include "block/block_int.h"
 
+/* For blk_bs() in generated block/block-gen.c */
+#include "sysemu/block-backend.h"
+
 int coroutine_fn bdrv_co_check(BlockDriverState *bs,
                                BdrvCheckResult *res, BdrvCheckMode fix);
 int coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, Error **errp);
index 85dbeb9ecf9c84abe042157ceace70ebb7a38d00..08be813407b636aec129bae27ec25b0436cda0ec 100644 (file)
@@ -100,12 +100,20 @@ def snake_to_camel(func_name: str) -> str:
 def gen_wrapper(func: FuncDecl) -> str:
     assert not '_co_' in func.name
     assert func.return_type == 'int'
-    assert func.args[0].type in ['BlockDriverState *', 'BdrvChild *']
+    assert func.args[0].type in ['BlockDriverState *', 'BdrvChild *',
+                                 'BlockBackend *']
 
     subsystem, subname = func.name.split('_', 1)
 
     name = f'{subsystem}_co_{subname}'
-    bs = 'bs' if func.args[0].type == 'BlockDriverState *' else 'child->bs'
+
+    t = func.args[0].type
+    if t == 'BlockDriverState *':
+        bs = 'bs'
+    elif t == 'BdrvChild *':
+        bs = 'child->bs'
+    else:
+        bs = 'blk_bs(blk)'
     struct_name = snake_to_camel(name)
 
     return f"""\