diff mbox series

[v8,2/7] block/io: refactor coroutine wrappers

Message ID 20200915164411.20590-3-vsementsov@virtuozzo.com
State New
Headers show
Series coroutines: generate wrapper code | expand

Commit Message

Vladimir Sementsov-Ogievskiy Sept. 15, 2020, 4:44 p.m. UTC
Most of our coroutine wrappers already follow this convention:

We have 'coroutine_fn bdrv_co_<something>(<normal argument list>)' as
the core function, and a wrapper 'bdrv_<something>(<same argument
list>)' which does parameters packing and call bdrv_run_co().

The only outsiders are the bdrv_prwv_co and
bdrv_common_block_status_above wrappers. Let's refactor them to behave
as the others, it simplifies further conversion of coroutine wrappers.

This patch adds indirection layer, but it will be compensated by
further commit, which will drop bdrv_co_prwv together with is_write
logic, to keep read and write path separate.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
 block/io.c | 60 +++++++++++++++++++++++++++++-------------------------
 1 file changed, 32 insertions(+), 28 deletions(-)

Comments

Eric Blake Sept. 23, 2020, 7:41 p.m. UTC | #1
On 9/15/20 11:44 AM, Vladimir Sementsov-Ogievskiy wrote:
> Most of our coroutine wrappers already follow this convention:

> 

> We have 'coroutine_fn bdrv_co_<something>(<normal argument list>)' as

> the core function, and a wrapper 'bdrv_<something>(<same argument

> list>)' which does parameters packing and call bdrv_run_co().

> 

> The only outsiders are the bdrv_prwv_co and

> bdrv_common_block_status_above wrappers. Let's refactor them to behave

> as the others, it simplifies further conversion of coroutine wrappers.

> 

> This patch adds indirection layer, but it will be compensated by


adds an

> further commit, which will drop bdrv_co_prwv together with is_write

> logic, to keep read and write path separate.


keep the

> 

> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>

> Reviewed-by: Eric Blake <eblake@redhat.com>


R-b stands.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
Philippe Mathieu-Daudé Sept. 24, 2020, 8:27 a.m. UTC | #2
On 9/15/20 6:44 PM, Vladimir Sementsov-Ogievskiy wrote:
> Most of our coroutine wrappers already follow this convention:

> 

> We have 'coroutine_fn bdrv_co_<something>(<normal argument list>)' as

> the core function, and a wrapper 'bdrv_<something>(<same argument

> list>)' which does parameters packing and call bdrv_run_co().

> 

> The only outsiders are the bdrv_prwv_co and

> bdrv_common_block_status_above wrappers. Let's refactor them to behave

> as the others, it simplifies further conversion of coroutine wrappers.

> 

> This patch adds indirection layer, but it will be compensated by

> further commit, which will drop bdrv_co_prwv together with is_write

> logic, to keep read and write path separate.

> 

> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>

> Reviewed-by: Eric Blake <eblake@redhat.com>

> ---

>  block/io.c | 60 +++++++++++++++++++++++++++++-------------------------

>  1 file changed, 32 insertions(+), 28 deletions(-)


Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Stefan Hajnoczi Sept. 24, 2020, 11:24 a.m. UTC | #3
On Tue, Sep 15, 2020 at 07:44:06PM +0300, Vladimir Sementsov-Ogievskiy wrote:
> Most of our coroutine wrappers already follow this convention:

> 

> We have 'coroutine_fn bdrv_co_<something>(<normal argument list>)' as

> the core function, and a wrapper 'bdrv_<something>(<same argument

> list>)' which does parameters packing and call bdrv_run_co().

> 

> The only outsiders are the bdrv_prwv_co and

> bdrv_common_block_status_above wrappers. Let's refactor them to behave

> as the others, it simplifies further conversion of coroutine wrappers.

> 

> This patch adds indirection layer, but it will be compensated by

> further commit, which will drop bdrv_co_prwv together with is_write

> logic, to keep read and write path separate.

> 

> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>

> Reviewed-by: Eric Blake <eblake@redhat.com>

> ---

>  block/io.c | 60 +++++++++++++++++++++++++++++-------------------------

>  1 file changed, 32 insertions(+), 28 deletions(-)


Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
diff mbox series

Patch

diff --git a/block/io.c b/block/io.c
index ad3a51ed53..2e2c89ce31 100644
--- a/block/io.c
+++ b/block/io.c
@@ -933,27 +933,31 @@  typedef struct RwCo {
     BdrvRequestFlags flags;
 } RwCo;
 
+static int coroutine_fn bdrv_co_prwv(BdrvChild *child, int64_t offset,
+                                     QEMUIOVector *qiov, bool is_write,
+                                     BdrvRequestFlags flags)
+{
+    if (is_write) {
+        return bdrv_co_pwritev(child, offset, qiov->size, qiov, flags);
+    } else {
+        return bdrv_co_preadv(child, offset, qiov->size, qiov, flags);
+    }
+}
+
 static int coroutine_fn bdrv_rw_co_entry(void *opaque)
 {
     RwCo *rwco = opaque;
 
-    if (!rwco->is_write) {
-        return bdrv_co_preadv(rwco->child, rwco->offset,
-                              rwco->qiov->size, rwco->qiov,
-                              rwco->flags);
-    } else {
-        return bdrv_co_pwritev(rwco->child, rwco->offset,
-                               rwco->qiov->size, rwco->qiov,
-                               rwco->flags);
-    }
+    return bdrv_co_prwv(rwco->child, rwco->offset, rwco->qiov,
+                        rwco->is_write, rwco->flags);
 }
 
 /*
  * Process a vectored synchronous request using coroutines
  */
-static int bdrv_prwv_co(BdrvChild *child, int64_t offset,
-                        QEMUIOVector *qiov, bool is_write,
-                        BdrvRequestFlags flags)
+static int bdrv_prwv(BdrvChild *child, int64_t offset,
+                     QEMUIOVector *qiov, bool is_write,
+                     BdrvRequestFlags flags)
 {
     RwCo rwco = {
         .child = child,
@@ -971,8 +975,7 @@  int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset,
 {
     QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, NULL, bytes);
 
-    return bdrv_prwv_co(child, offset, &qiov, true,
-                        BDRV_REQ_ZERO_WRITE | flags);
+    return bdrv_prwv(child, offset, &qiov, true, BDRV_REQ_ZERO_WRITE | flags);
 }
 
 /*
@@ -1021,7 +1024,7 @@  int bdrv_preadv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov)
 {
     int ret;
 
-    ret = bdrv_prwv_co(child, offset, qiov, false, 0);
+    ret = bdrv_prwv(child, offset, qiov, false, 0);
     if (ret < 0) {
         return ret;
     }
@@ -1045,7 +1048,7 @@  int bdrv_pwritev(BdrvChild *child, int64_t offset, QEMUIOVector *qiov)
 {
     int ret;
 
-    ret = bdrv_prwv_co(child, offset, qiov, true, 0);
+    ret = bdrv_prwv(child, offset, qiov, true, 0);
     if (ret < 0) {
         return ret;
     }
@@ -2465,14 +2468,15 @@  early_out:
     return ret;
 }
 
-static int coroutine_fn bdrv_co_block_status_above(BlockDriverState *bs,
-                                                   BlockDriverState *base,
-                                                   bool want_zero,
-                                                   int64_t offset,
-                                                   int64_t bytes,
-                                                   int64_t *pnum,
-                                                   int64_t *map,
-                                                   BlockDriverState **file)
+static int coroutine_fn
+bdrv_co_common_block_status_above(BlockDriverState *bs,
+                                  BlockDriverState *base,
+                                  bool want_zero,
+                                  int64_t offset,
+                                  int64_t bytes,
+                                  int64_t *pnum,
+                                  int64_t *map,
+                                  BlockDriverState **file)
 {
     BlockDriverState *p;
     int ret = 0;
@@ -2510,10 +2514,10 @@  static int coroutine_fn bdrv_block_status_above_co_entry(void *opaque)
 {
     BdrvCoBlockStatusData *data = opaque;
 
-    return bdrv_co_block_status_above(data->bs, data->base,
-                                      data->want_zero,
-                                      data->offset, data->bytes,
-                                      data->pnum, data->map, data->file);
+    return bdrv_co_common_block_status_above(data->bs, data->base,
+                                             data->want_zero,
+                                             data->offset, data->bytes,
+                                             data->pnum, data->map, data->file);
 }
 
 /*