diff mbox

[4/6] block-backend: Add blk_aio_copy_range

Message ID 20180608060417.10170-5-famz@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Fam Zheng June 8, 2018, 6:04 a.m. UTC
Signed-off-by: Fam Zheng <famz@redhat.com>
---
 block/block-backend.c          | 36 ++++++++++++++++++++++++++++++++++
 include/sysemu/block-backend.h |  4 ++++
 2 files changed, 40 insertions(+)

Comments

Stefan Hajnoczi June 15, 2018, 3:26 p.m. UTC | #1
On Fri, Jun 08, 2018 at 02:04:15PM +0800, Fam Zheng wrote:

Why is a new _aio_ interface needed?  Aren't the copy_range callers
coroutines?

> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
>  block/block-backend.c          | 36 ++++++++++++++++++++++++++++++++++
>  include/sysemu/block-backend.h |  4 ++++
>  2 files changed, 40 insertions(+)
> 
> diff --git a/block/block-backend.c b/block/block-backend.c
> index e20a204bee..36d928e13d 100644
> --- a/block/block-backend.c
> +++ b/block/block-backend.c
> @@ -1213,6 +1213,14 @@ typedef struct BlkRwCo {
>              unsigned long int req;
>              void *buf;
>          } ioctl;
> +
> +        struct {
> +            BlockBackend *dst_blk;
> +            int64_t src_off;
> +            int64_t dst_off;
> +            int bytes;
> +            BdrvRequestFlags flags;
> +        } copy_range;
>      };
>  
>  } BlkRwCo;
> @@ -1505,6 +1513,34 @@ BlockAIOCB *blk_aio_pwritev(BlockBackend *blk, int64_t offset,
>      return blk_aio_prwv(blk, &rwco, blk_aio_write_entry, cb, opaque);
>  }
>  
> +static void blk_aio_copy_range_entry(void *opaque)
> +{
> +    BlkAioEmAIOCB *acb = opaque;
> +    BlkRwCo *rwco = &acb->rwco;
> +
> +    rwco->ret = blk_co_copy_range(rwco->blk, rwco->copy_range.src_off,
> +                                  rwco->copy_range.dst_blk,
> +                                  rwco->copy_range.dst_off,
> +                                  rwco->copy_range.bytes,
> +                                  rwco->copy_range.flags);
> +    blk_aio_complete(acb);
> +}
> +
> +BlockAIOCB *blk_aio_copy_range(BlockBackend *src, int64_t src_offset,
> +                               BlockBackend *dst, int64_t dst_offset,
> +                               uint64_t bytes, BdrvRequestFlags flags,
> +                               BlockCompletionFunc *cb, void *opaque)
> +{
> +    BlkRwCo rwco = (BlkRwCo) {
> +        .copy_range.src_off = src_offset,
> +        .copy_range.dst_blk = dst,
> +        .copy_range.dst_off = dst_offset,
> +        .copy_range.bytes = bytes,
> +        .copy_range.flags = flags,
> +    };
> +    return blk_aio_prwv(src, &rwco, blk_aio_copy_range_entry, cb, opaque);
> +}
> +
>  static void blk_aio_flush_entry(void *opaque)
>  {
>      BlkAioEmAIOCB *acb = opaque;
> diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h
> index 8d03d493c2..ea121eac3f 100644
> --- a/include/sysemu/block-backend.h
> +++ b/include/sysemu/block-backend.h
> @@ -147,6 +147,10 @@ BlockAIOCB *blk_aio_flush(BlockBackend *blk,
>                            BlockCompletionFunc *cb, void *opaque);
>  BlockAIOCB *blk_aio_pdiscard(BlockBackend *blk, int64_t offset, int bytes,
>                               BlockCompletionFunc *cb, void *opaque);
> +BlockAIOCB *blk_aio_copy_range(BlockBackend *src, int64_t src_offset,
> +                               BlockBackend *dst, int64_t dst_offset,
> +                               uint64_t bytes, BdrvRequestFlags flags,
> +                               BlockCompletionFunc *cb, void *opaque);
>  void blk_aio_cancel(BlockAIOCB *acb);
>  void blk_aio_cancel_async(BlockAIOCB *acb);
>  int blk_co_ioctl(BlockBackend *blk, unsigned long int req, void *buf);
> -- 
> 2.17.0
>
diff mbox

Patch

diff --git a/block/block-backend.c b/block/block-backend.c
index e20a204bee..36d928e13d 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -1213,6 +1213,14 @@  typedef struct BlkRwCo {
             unsigned long int req;
             void *buf;
         } ioctl;
+
+        struct {
+            BlockBackend *dst_blk;
+            int64_t src_off;
+            int64_t dst_off;
+            int bytes;
+            BdrvRequestFlags flags;
+        } copy_range;
     };
 
 } BlkRwCo;
@@ -1505,6 +1513,34 @@  BlockAIOCB *blk_aio_pwritev(BlockBackend *blk, int64_t offset,
     return blk_aio_prwv(blk, &rwco, blk_aio_write_entry, cb, opaque);
 }
 
+static void blk_aio_copy_range_entry(void *opaque)
+{
+    BlkAioEmAIOCB *acb = opaque;
+    BlkRwCo *rwco = &acb->rwco;
+
+    rwco->ret = blk_co_copy_range(rwco->blk, rwco->copy_range.src_off,
+                                  rwco->copy_range.dst_blk,
+                                  rwco->copy_range.dst_off,
+                                  rwco->copy_range.bytes,
+                                  rwco->copy_range.flags);
+    blk_aio_complete(acb);
+}
+
+BlockAIOCB *blk_aio_copy_range(BlockBackend *src, int64_t src_offset,
+                               BlockBackend *dst, int64_t dst_offset,
+                               uint64_t bytes, BdrvRequestFlags flags,
+                               BlockCompletionFunc *cb, void *opaque)
+{
+    BlkRwCo rwco = (BlkRwCo) {
+        .copy_range.src_off = src_offset,
+        .copy_range.dst_blk = dst,
+        .copy_range.dst_off = dst_offset,
+        .copy_range.bytes = bytes,
+        .copy_range.flags = flags,
+    };
+    return blk_aio_prwv(src, &rwco, blk_aio_copy_range_entry, cb, opaque);
+}
+
 static void blk_aio_flush_entry(void *opaque)
 {
     BlkAioEmAIOCB *acb = opaque;
diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h
index 8d03d493c2..ea121eac3f 100644
--- a/include/sysemu/block-backend.h
+++ b/include/sysemu/block-backend.h
@@ -147,6 +147,10 @@  BlockAIOCB *blk_aio_flush(BlockBackend *blk,
                           BlockCompletionFunc *cb, void *opaque);
 BlockAIOCB *blk_aio_pdiscard(BlockBackend *blk, int64_t offset, int bytes,
                              BlockCompletionFunc *cb, void *opaque);
+BlockAIOCB *blk_aio_copy_range(BlockBackend *src, int64_t src_offset,
+                               BlockBackend *dst, int64_t dst_offset,
+                               uint64_t bytes, BdrvRequestFlags flags,
+                               BlockCompletionFunc *cb, void *opaque);
 void blk_aio_cancel(BlockAIOCB *acb);
 void blk_aio_cancel_async(BlockAIOCB *acb);
 int blk_co_ioctl(BlockBackend *blk, unsigned long int req, void *buf);