[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 27/56] block/block-copy: introduce block_copy_set_copy_opts()
From: |
Hanna Reitz |
Subject: |
[PULL 27/56] block/block-copy: introduce block_copy_set_copy_opts() |
Date: |
Wed, 1 Sep 2021 17:15:50 +0200 |
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
We'll need a possibility to set compress and use_copy_range options
after initialization of the state. So make corresponding part of
block_copy_state_new() separate and public.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20210824083856.17408-8-vsementsov@virtuozzo.com>
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
---
include/block/block-copy.h | 3 +++
block/block-copy.c | 49 ++++++++++++++++++++++----------------
2 files changed, 32 insertions(+), 20 deletions(-)
diff --git a/include/block/block-copy.h b/include/block/block-copy.h
index 734389d32a..dca6c4ce36 100644
--- a/include/block/block-copy.h
+++ b/include/block/block-copy.h
@@ -28,6 +28,9 @@ BlockCopyState *block_copy_state_new(BdrvChild *source,
BdrvChild *target,
int64_t cluster_size, bool use_copy_range,
bool compress, Error **errp);
+/* Function should be called prior any actual copy request */
+void block_copy_set_copy_opts(BlockCopyState *s, bool use_copy_range,
+ bool compress);
void block_copy_set_progress_meter(BlockCopyState *s, ProgressMeter *pm);
void block_copy_state_free(BlockCopyState *s);
diff --git a/block/block-copy.c b/block/block-copy.c
index 58b4345a5a..e83870ff81 100644
--- a/block/block-copy.c
+++ b/block/block-copy.c
@@ -315,6 +315,33 @@ static uint32_t block_copy_max_transfer(BdrvChild *source,
BdrvChild *target)
target->bs->bl.max_transfer));
}
+void block_copy_set_copy_opts(BlockCopyState *s, bool use_copy_range,
+ bool compress)
+{
+ /* Keep BDRV_REQ_SERIALISING set (or not set) in block_copy_state_new() */
+ s->write_flags = (s->write_flags & BDRV_REQ_SERIALISING) |
+ (compress ? BDRV_REQ_WRITE_COMPRESSED : 0);
+
+ if (s->max_transfer < s->cluster_size) {
+ /*
+ * copy_range does not respect max_transfer. We don't want to bother
+ * with requests smaller than block-copy cluster size, so fallback to
+ * buffered copying (read and write respect max_transfer on their
+ * behalf).
+ */
+ s->method = COPY_READ_WRITE_CLUSTER;
+ } else if (compress) {
+ /* Compression supports only cluster-size writes and no copy-range. */
+ s->method = COPY_READ_WRITE_CLUSTER;
+ } else {
+ /*
+ * If copy range enabled, start with COPY_RANGE_SMALL, until first
+ * successful copy_range (look at block_copy_do_copy).
+ */
+ s->method = use_copy_range ? COPY_RANGE_SMALL : COPY_READ_WRITE;
+ }
+}
+
BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target,
int64_t cluster_size, bool use_copy_range,
bool compress, Error **errp)
@@ -353,32 +380,14 @@ BlockCopyState *block_copy_state_new(BdrvChild *source,
BdrvChild *target,
.copy_bitmap = copy_bitmap,
.cluster_size = cluster_size,
.len = bdrv_dirty_bitmap_size(copy_bitmap),
- .write_flags = (is_fleecing ? BDRV_REQ_SERIALISING : 0) |
- (compress ? BDRV_REQ_WRITE_COMPRESSED : 0),
+ .write_flags = (is_fleecing ? BDRV_REQ_SERIALISING : 0),
.mem = shres_create(BLOCK_COPY_MAX_MEM),
.max_transfer = QEMU_ALIGN_DOWN(
block_copy_max_transfer(source, target),
cluster_size),
};
- if (s->max_transfer < cluster_size) {
- /*
- * copy_range does not respect max_transfer. We don't want to bother
- * with requests smaller than block-copy cluster size, so fallback to
- * buffered copying (read and write respect max_transfer on their
- * behalf).
- */
- s->method = COPY_READ_WRITE_CLUSTER;
- } else if (compress) {
- /* Compression supports only cluster-size writes and no copy-range. */
- s->method = COPY_READ_WRITE_CLUSTER;
- } else {
- /*
- * If copy range enabled, start with COPY_RANGE_SMALL, until first
- * successful copy_range (look at block_copy_do_copy).
- */
- s->method = use_copy_range ? COPY_RANGE_SMALL : COPY_READ_WRITE;
- }
+ block_copy_set_copy_opts(s, use_copy_range, compress);
ratelimit_init(&s->rate_limit);
qemu_co_mutex_init(&s->lock);
--
2.31.1
- [PULL 16/56] docs/devel/testing: add -p option to the debug section of QEMU iotests, (continued)
- [PULL 16/56] docs/devel/testing: add -p option to the debug section of QEMU iotests, Hanna Reitz, 2021/09/01
- [PULL 17/56] block/monitor: Consolidate hmp_handle_error calls to reduce redundant code, Hanna Reitz, 2021/09/01
- [PULL 18/56] raw-format: drop WRITE and RESIZE child perms when possible, Hanna Reitz, 2021/09/01
- [PULL 19/56] iotests: use with-statement for open() calls, Hanna Reitz, 2021/09/01
- [PULL 20/56] iotests: use subprocess.DEVNULL instead of open("/dev/null"), Hanna Reitz, 2021/09/01
- [PULL 21/56] block: introduce bdrv_replace_child_bs(), Hanna Reitz, 2021/09/01
- [PULL 23/56] qdev-properties: PropertyInfo: add realized_set_allowed field, Hanna Reitz, 2021/09/01
- [PULL 24/56] qdev: allow setting drive property for realized device, Hanna Reitz, 2021/09/01
- [PULL 25/56] block: rename backup-top to copy-before-write, Hanna Reitz, 2021/09/01
- [PULL 26/56] block-copy: move detecting fleecing scheme to block-copy, Hanna Reitz, 2021/09/01
- [PULL 27/56] block/block-copy: introduce block_copy_set_copy_opts(),
Hanna Reitz <=
- [PULL 28/56] block/backup: set copy_range and compress after filter insertion, Hanna Reitz, 2021/09/01
- [PULL 32/56] block/copy-before-write: use file child instead of backing, Hanna Reitz, 2021/09/01
- [PULL 29/56] block/backup: move cluster size calculation to block-copy, Hanna Reitz, 2021/09/01
- [PULL 34/56] block/copy-before-write: introduce cbw_init(), Hanna Reitz, 2021/09/01
- [PULL 22/56] block: introduce blk_replace_bs, Hanna Reitz, 2021/09/01
- [PULL 31/56] block/copy-before-write: drop extra bdrv_unref on failure path, Hanna Reitz, 2021/09/01
- [PULL 30/56] block/copy-before-write: relax permission requirements when no parents, Hanna Reitz, 2021/09/01
- [PULL 33/56] block/copy-before-write: bdrv_cbw_append(): replace child at last, Hanna Reitz, 2021/09/01
- [PULL 38/56] block/copy-before-write: cbw_init(): use options, Hanna Reitz, 2021/09/01
- [PULL 36/56] block/copy-before-write: cbw_init(): use file child after attaching, Hanna Reitz, 2021/09/01