diff mbox

[5/6] block: Add backing passthrough implementations for copy_range

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

Commit Message

Fam Zheng June 8, 2018, 6:04 a.m. UTC
Similar to bdrv_co_block_status_from_backing we add the two passthrough
callbacks for copy_range. This will be used by the block driver filters
so that they can support copy offloading.

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 block/io.c                | 24 ++++++++++++++++++++++++
 include/block/block_int.h | 22 ++++++++++++++++++++++
 2 files changed, 46 insertions(+)

Comments

Stefan Hajnoczi June 15, 2018, 3:30 p.m. UTC | #1
On Fri, Jun 08, 2018 at 02:04:16PM +0800, Fam Zheng wrote:
> +int coroutine_fn bdrv_co_copy_range_from_backing(BlockDriverState *bs,
> +                                                 BdrvChild *src, uint64_t src_offset,
> +                                                 BdrvChild *dst, uint64_t dst_offset,
> +                                                 uint64_t bytes, BdrvRequestFlags flags)
> +{
> +    if (!src->bs) {
> +        return -ENOMEDIUM;
> +    }
> +    return bdrv_co_copy_range_from(src->bs->backing, src_offset, dst,
> +                                   dst_offset, bytes, flags);
> +}
> +
> +int coroutine_fn bdrv_co_copy_range_to_backing(BlockDriverState *bs,
> +                                               BdrvChild *src, uint64_t src_offset,
> +                                               BdrvChild *dst, uint64_t dst_offset,
> +                                               uint64_t bytes, BdrvRequestFlags flags)
> +{
> +    if (!dst->bs) {
> +        return -ENOMEDIUM;
> +    }
> +    return bdrv_co_copy_range_to(src, src_offset, dst->bs->backing,
> +                                 dst_offset, bytes, flags);
> +}

If src->bs or dst->bs were NULL, then bdrv_co_copy_range() would have
already crashed in bdrv_inc_in_flight(src/dst_bs).  Should
.bdrv_co_copy_range_to/from() implementations really check for
ENOMEDIUM?
diff mbox

Patch

diff --git a/block/io.c b/block/io.c
index d8039793c2..d1559c9cd5 100644
--- a/block/io.c
+++ b/block/io.c
@@ -1900,6 +1900,30 @@  int coroutine_fn bdrv_co_block_status_from_backing(BlockDriverState *bs,
     return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID;
 }
 
+int coroutine_fn bdrv_co_copy_range_from_backing(BlockDriverState *bs,
+                                                 BdrvChild *src, uint64_t src_offset,
+                                                 BdrvChild *dst, uint64_t dst_offset,
+                                                 uint64_t bytes, BdrvRequestFlags flags)
+{
+    if (!src->bs) {
+        return -ENOMEDIUM;
+    }
+    return bdrv_co_copy_range_from(src->bs->backing, src_offset, dst,
+                                   dst_offset, bytes, flags);
+}
+
+int coroutine_fn bdrv_co_copy_range_to_backing(BlockDriverState *bs,
+                                               BdrvChild *src, uint64_t src_offset,
+                                               BdrvChild *dst, uint64_t dst_offset,
+                                               uint64_t bytes, BdrvRequestFlags flags)
+{
+    if (!dst->bs) {
+        return -ENOMEDIUM;
+    }
+    return bdrv_co_copy_range_to(src, src_offset, dst->bs->backing,
+                                 dst_offset, bytes, flags);
+}
+
 /*
  * Returns the allocation status of the specified sectors.
  * Drivers not implementing the functionality are assumed to not support
diff --git a/include/block/block_int.h b/include/block/block_int.h
index 2c51cd420f..b488d74c1b 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -1118,6 +1118,28 @@  int coroutine_fn bdrv_co_block_status_from_backing(BlockDriverState *bs,
                                                    int64_t *pnum,
                                                    int64_t *map,
                                                    BlockDriverState **file);
+
+/*
+ * Default implementation for drivers to pass bdrv_co_copy_range_from() to
+ * their backing file.
+ */
+int coroutine_fn bdrv_co_copy_range_from_backing(BlockDriverState *bs,
+                                                 BdrvChild *src, uint64_t src_offset,
+                                                 BdrvChild *dst, uint64_t dst_offset,
+                                                 uint64_t bytes,
+                                                 BdrvRequestFlags flags);
+
+
+/*
+ * Default implementation for drivers to pass bdrv_co_copy_range_to() to their
+ * backing file.
+ */
+int coroutine_fn bdrv_co_copy_range_to_backing(BlockDriverState *bs,
+                                               BdrvChild *src, uint64_t src_offset,
+                                               BdrvChild *dst, uint64_t dst_offset,
+                                               uint64_t bytes,
+                                               BdrvRequestFlags flags);
+
 const char *bdrv_get_parent_name(const BlockDriverState *bs);
 void blk_dev_change_media_cb(BlockBackend *blk, bool load, Error **errp);
 bool blk_dev_has_removable_media(BlockBackend *blk);