Make image fleecing more usable
Subsystems (2)
v2 cover Make image fleecing more usable
Hi all!
That continues "[PATCH RFC DRAFT 00/11] Make image fleecing more usable" and supersedes "[PATCH v2 for-6.2 0/6] push backup with fleecing"
Supersedes: <[email protected]>
Supersedes: <[email protected]>
There several improvements to fleecing scheme:
1. support bitmap in copy-before-write filter
2. introduce fleecing block driver, which opens the door for a lot of image fleecing improvements.
See "block: introduce fleecing block driver" commit message for details.
3. support "push backup with fleecing" scheme, when backup job is a client of common fleecing scheme. That helps when writes to final backup target are slow and we don't want guest writes hang waiting for copy-before-write operations to final target.
Vladimir Sementsov-Ogievskiy (19):
block/block-copy: move copy_bitmap initialization to
block_copy_state_new()
block/dirty-bitmap: bdrv_merge_dirty_bitmap(): add return value block/block-copy: block_copy_state_new(): add bitmap parameter block/copy-before-write: add bitmap open parameter block/block-copy: add block_copy_reset()
block: intoduce reqlist
block/dirty-bitmap: introduce bdrv_dirty_bitmap_status() block/reqlist: add reqlist_wait_all()
block: introduce FleecingState class
block: introduce fleecing block driver block/copy-before-write: support fleecing block driver block/block-copy: add write-unchanged mode block/copy-before-write: use write-unchanged in fleecing mode iotests/image-fleecing: add test-case for fleecing format node iotests.py: add qemu_io_pipe_and_status() iotests/image-fleecing: add test case with bitmap
block: blk_root(): return non-const pointer
qapi: backup: add immutable-source parameter iotests/image-fleecing: test push backup with fleecing
qapi/block-core.json | 39 ++- block/fleecing.h | 151 ++++++++++++ include/block/block-copy.h | 4 +- include/block/block_int.h | 1 + include/block/dirty-bitmap.h | 4 +- include/block/reqlist.h | 75 ++++++ include/qemu/hbitmap.h | 11 + include/sysemu/block-backend.h | 2 +- block/backup.c | 61 ++++- block/block-backend.c | 2 +- block/block-copy.c | 157 +++++------- block/copy-before-write.c | 70 +++++- block/dirty-bitmap.c | 15 +- block/fleecing-drv.c | 260 ++++++++++++++++++++ block/fleecing.c | 182 ++++++++++++++ block/monitor/bitmap-qmp-cmds.c | 5 +- block/replication.c | 2 +- block/reqlist.c | 84 +++++++ blockdev.c | 1 + util/hbitmap.c | 36 +++ MAINTAINERS | 7 +- block/meson.build | 3 + tests/qemu-iotests/iotests.py | 4 + tests/qemu-iotests/tests/image-fleecing | 178 +++++++++++--- tests/qemu-iotests/tests/image-fleecing.out | 221 ++++++++++++++++- 25 files changed, 1420 insertions(+), 155 deletions(-) create mode 100644 block/fleecing.h create mode 100644 include/block/reqlist.h create mode 100644 block/fleecing-drv.c create mode 100644 block/fleecing.c create mode 100644 block/reqlist.c
Signature · 1 line
2.29.2
PATCH v2 1/19 block/block-copy: move copy_bitmap initialization to block_copy_state_new()
We are going to complicate bitmap initialization in the further commit. And in future, backup job will be able to work without filter (when source is immutable), so we'll need same bitmap initialization in copy-before-write filter and in backup job. So, it's reasonable to do it in block-copy.
Note that for now cbw_open() is the only caller of block_copy_state_new().
--- block/block-copy.c | 1 + block/copy-before-write.c | 4 ---- 2 files changed, 1 insertion(+), 4 deletions(-)
block/block-copy.c +1 -0
@@ -401,6 +401,7 @@ BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target,return NULL ; }bdrv_disable_dirty_bitmap (copy_bitmap); +bdrv_set_dirty_bitmap (copy_bitmap,0 ,bdrv_dirty_bitmap_size (copy_bitmap));/* * If source is in backing chain of target assume that target is going to be
block/copy-before-write.c +0 -4
@@ -148,7 +148,6 @@ static int cbw_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) {BDRVCopyBeforeWriteState *s = bs->opaque; -BdrvDirtyBitmap *copy_bitmap; bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY,
@@ -176,9 +175,6 @@ static int cbw_open(BlockDriverState *bs, QDict *options, int flags,return -EINVAL ; } - copy_bitmap =block_copy_dirty_bitmap (s->bcs); -bdrv_set_dirty_bitmap (copy_bitmap,0 ,bdrv_dirty_bitmap_size (copy_bitmap)); -return 0 ; }
Signature · 1 line
2.29.2
PATCH v2 2/19 block/dirty-bitmap: bdrv_merge_dirty_bitmap(): add return value
In reply to Vladimir Sementsov-OgievskiyThat simplifies handling failure in existing code and in further new usage of bdrv_merge_dirty_bitmap().
--- include/block/dirty-bitmap.h | 2 +- block/dirty-bitmap.c | 9 +++++++-- block/monitor/bitmap-qmp-cmds.c | 5 +---- 3 files changed, 9 insertions(+), 7 deletions(-)
include/block/dirty-bitmap.h +1 -1
@@ -77,7 +77,7 @@ void bdrv_dirty_bitmap_set_persistence(BdrvDirtyBitmap *bitmap, bool persistent);void bdrv_dirty_bitmap_set_inconsistent (BdrvDirtyBitmap *bitmap);void bdrv_dirty_bitmap_set_busy (BdrvDirtyBitmap *bitmap,bool busy); -void bdrv_merge_dirty_bitmap (BdrvDirtyBitmap *dest,const BdrvDirtyBitmap *src, +bool bdrv_merge_dirty_bitmap (BdrvDirtyBitmap *dest,const BdrvDirtyBitmap *src,HBitmap **backup,Error **errp);void bdrv_dirty_bitmap_skip_store (BdrvDirtyBitmap *bitmap,bool skip);bool bdrv_dirty_bitmap_get (BdrvDirtyBitmap *bitmap,int64_t offset);
block/dirty-bitmap.c +7 -2
@@ -880,11 +880,14 @@ bool bdrv_dirty_bitmap_next_dirty_area(BdrvDirtyBitmap *bitmap,* Ensures permissions on bitmaps are reasonable; use for public API. * * @backup: If provided, make a copy of dest here prior to merge. +* +* Returns true on success, false on failure. In case of failure bitmaps are +* untouched. */ -void bdrv_merge_dirty_bitmap (BdrvDirtyBitmap *dest,const BdrvDirtyBitmap *src, +bool bdrv_merge_dirty_bitmap (BdrvDirtyBitmap *dest,const BdrvDirtyBitmap *src,HBitmap **backup,Error **errp) { -bool ret; +bool ret = false;bdrv_dirty_bitmaps_lock (dest->bs);if (src->bs != dest->bs) {
@@ -912,6 +915,8 @@ out:if (src->bs != dest->bs) {bdrv_dirty_bitmaps_unlock (src->bs); } + +return ret; }/**
block/monitor/bitmap-qmp-cmds.c +1 -4
@@ -259,7 +259,6 @@ BdrvDirtyBitmap *block_dirty_bitmap_merge(const char *node, const char *target,BlockDriverState *bs;BdrvDirtyBitmap *dst, *src, *anon;BlockDirtyBitmapMergeSourceList *lst; -Error *local_err =NULL ; dst =block_dirty_bitmap_lookup (node, target, &bs, errp);if (!dst) {
@@ -297,9 +296,7 @@ BdrvDirtyBitmap *block_dirty_bitmap_merge(const char *node, const char *target,abort (); } -bdrv_merge_dirty_bitmap (anon, src,NULL , &local_err); -if (local_err) { -error_propagate (errp, local_err); +if (!bdrv_merge_dirty_bitmap (anon, src,NULL , errp)) { dst =NULL ; goto out; }
Signature · 1 line
2.29.2
PATCH v2 3/19 block/block-copy: block_copy_state_new(): add bitmap parameter
In reply to Vladimir Sementsov-OgievskiyThis will be used in the following commit to bring "incremental" mode to copy-before-write filter.
--- include/block/block-copy.h | 2 +- block/block-copy.c | 14 ++++++++++++-- block/copy-before-write.c | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-)
include/block/block-copy.h +1 -1
@@ -25,7 +25,7 @@ typedef struct BlockCopyState BlockCopyState;typedef struct BlockCopyCallState BlockCopyCallState ;BlockCopyState *block_copy_state_new (BdrvChild *source,BdrvChild *target, -Error **errp); +BdrvDirtyBitmap *bitmap,Error **errp);/* Function should be called prior any actual copy request */ void block_copy_set_copy_opts(BlockCopyState *s, bool use_copy_range,
block/block-copy.c +12 -2
@@ -383,8 +383,9 @@ static int64_t block_copy_calculate_cluster_size(BlockDriverState *target, }BlockCopyState *block_copy_state_new (BdrvChild *source,BdrvChild *target, -Error **errp) +BdrvDirtyBitmap *bitmap,Error **errp) { +ERRP_GUARD ();BlockCopyState *s;int64_t cluster_size;BdrvDirtyBitmap *copy_bitmap;
@@ -401,7 +402,16 @@ BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target,return NULL ; }bdrv_disable_dirty_bitmap (copy_bitmap); -bdrv_set_dirty_bitmap (copy_bitmap,0 ,bdrv_dirty_bitmap_size (copy_bitmap)); +if (bitmap) { +if (!bdrv_merge_dirty_bitmap (copy_bitmap, bitmap,NULL , errp)) { +error_prepend (errp,"Failed to merge bitmap '%s' to internal " +"copy-bitmap: " ,bdrv_dirty_bitmap_name (bitmap)); +return NULL ; + } + }else { +bdrv_set_dirty_bitmap (copy_bitmap,0 , +bdrv_dirty_bitmap_size (copy_bitmap)); + }/* * If source is in backing chain of target assume that target is going to be
block/copy-before-write.c +1 -1
@@ -169,7 +169,7 @@ static int cbw_open(BlockDriverState *bs, QDict *options, int flags, ((BDRV_REQ_FUA |BDRV_REQ_MAY_UNMAP |BDRV_REQ_NO_FALLBACK ) & bs->file->bs->supported_zero_flags); - s->bcs =block_copy_state_new (bs->file, s->target, errp); + s->bcs =block_copy_state_new (bs->file, s->target,NULL , errp);if (!s->bcs) {error_prepend (errp,"Cannot create block-copy-state: " );return -EINVAL ;
Signature · 1 line
2.29.2
PATCH v2 4/19 block/copy-before-write: add bitmap open parameter
In reply to Vladimir Sementsov-OgievskiyThis brings "incremental" mode to copy-before-write filter: user can specify bitmap so that filter will copy only "dirty" areas.
--- qapi/block-core.json | 10 +++++++++- block/copy-before-write.c | 30 +++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-)
qapi/block-core.json +9 -1
@@ -4063,11 +4063,19 @@ # # @target: The target for copy-before-write operations. # +# @bitmap: If specified, copy-before-write filter will do +# copy-before-write operations only for dirty regions of the +# bitmap. Bitmap size must be equal to length of file and +# target child of the filter. Note also, that bitmap is used +# only to initialize internal bitmap of the process, so further +# modifications (or removing) of specified bitmap doesn't +# influence the filter. +# # Since: 6.2 ## { 'struct': 'BlockdevOptionsCbw', 'base': 'BlockdevOptionsGenericFormat', - 'data': { 'target': 'BlockdevRef' } } + 'data': { 'target': 'BlockdevRef', '*bitmap': 'BlockDirtyBitmap' } } ## # @BlockdevOptions:
block/copy-before-write.c +29 -1
@@ -148,6 +148,7 @@ static int cbw_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) {BDRVCopyBeforeWriteState *s = bs->opaque; +BdrvDirtyBitmap *bitmap =NULL ; bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY,
@@ -162,6 +163,33 @@ static int cbw_open(BlockDriverState *bs, QDict *options, int flags,return -EINVAL ; } +if (qdict_haskey (options,"bitmap.node" ) || +qdict_haskey (options,"bitmap.name" )) + { +const char *bitmap_node, *bitmap_name; + +if (!qdict_haskey (options,"bitmap.node" )) { +error_setg (errp,"bitmap.node is not specified" ); +return -EINVAL ; + } + +if (!qdict_haskey (options,"bitmap.name" )) { +error_setg (errp,"bitmap.name is not specified" ); +return -EINVAL ; + } + + bitmap_node =qdict_get_str (options,"bitmap.node" ); + bitmap_name =qdict_get_str (options,"bitmap.name" ); +qdict_del (options,"bitmap.node" ); +qdict_del (options,"bitmap.name" ); + + bitmap =block_dirty_bitmap_lookup (bitmap_node, bitmap_name,NULL , + errp); +if (!bitmap) { +return -EINVAL ; + } + } + bs->total_sectors = bs->file->bs->total_sectors; bs->supported_write_flags =BDRV_REQ_WRITE_UNCHANGED | (BDRV_REQ_FUA & bs->file->bs->supported_write_flags);
@@ -169,7 +197,7 @@ static int cbw_open(BlockDriverState *bs, QDict *options, int flags, ((BDRV_REQ_FUA |BDRV_REQ_MAY_UNMAP |BDRV_REQ_NO_FALLBACK ) & bs->file->bs->supported_zero_flags); - s->bcs =block_copy_state_new (bs->file, s->target,NULL , errp); + s->bcs =block_copy_state_new (bs->file, s->target, bitmap, errp);if (!s->bcs) {error_prepend (errp,"Cannot create block-copy-state: " );return -EINVAL ;
Signature · 1 line
2.29.2
PATCH v2 5/19 block/block-copy: add block_copy_reset()
In reply to Vladimir Sementsov-OgievskiySplit block_copy_reset() out of block_copy_reset_unallocated() to be used separately later.
--- include/block/block-copy.h | 1 + block/block-copy.c | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-)
include/block/block-copy.h +1 -0
@@ -34,6 +34,7 @@ void block_copy_set_progress_meter(BlockCopyState *s, ProgressMeter *pm);void block_copy_state_free (BlockCopyState *s); +void block_copy_reset (BlockCopyState *s,int64_t offset,int64_t bytes);int64_t block_copy_reset_unallocated (BlockCopyState *s,int64_t offset,int64_t *count);
block/block-copy.c +13 -8
@@ -689,6 +689,18 @@ static int block_copy_is_cluster_allocated(BlockCopyState *s, int64_t offset, } } +void block_copy_reset (BlockCopyState *s,int64_t offset,int64_t bytes) +{ +QEMU_LOCK_GUARD (&s->lock); + +bdrv_reset_dirty_bitmap (s->copy_bitmap, offset, bytes); +if (s->progress) { +progress_set_remaining (s->progress, +bdrv_get_dirty_count (s->copy_bitmap) + + s->in_flight_bytes); + } +} +/* * Reset bits in copy_bitmap starting at offset if they represent unallocated * data in the image. May reset subsequent contiguous bits.
@@ -709,14 +721,7 @@ int64_t block_copy_reset_unallocated(BlockCopyState *s, bytes = clusters * s->cluster_size;if (!ret) { -qemu_co_mutex_lock (&s->lock); -bdrv_reset_dirty_bitmap (s->copy_bitmap, offset, bytes); -if (s->progress) { -progress_set_remaining (s->progress, -bdrv_get_dirty_count (s->copy_bitmap) + - s->in_flight_bytes); - } -qemu_co_mutex_unlock (&s->lock); +block_copy_reset (s, offset, bytes); } *count = bytes;
Signature · 1 line
2.29.2
PATCH v2 6/19 block: intoduce reqlist
In reply to Vladimir Sementsov-OgievskiySplit intersecting-requests functionality out of block-copy to be reused in copy-before-write filter.
Note: while being here, fix tiny typo in MAINTAINERS.
--- include/block/reqlist.h | 67 +++++++++++++++++++++++ block/block-copy.c | 116 +++++++++++++--------------------------- block/reqlist.c | 76 ++++++++++++++++++++++++++ MAINTAINERS | 4 +- block/meson.build | 1 + 5 files changed, 184 insertions(+), 80 deletions(-) create mode 100644 include/block/reqlist.h create mode 100644 block/reqlist.c
include/block/reqlist.h new file +67 -0
@@ -0,0 +1,67 @@ +/* +* reqlist API +* +* Copyright (C) 2013 Proxmox Server Solutions +* Copyright (c) 2021 Virtuozzo International GmbH. +* +* Authors: +* Dietmar Maurer ([email protected]) +* Vladimir Sementsov-Ogievskiy <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef REQLIST_H +#define REQLIST_H + +#include "qemu/coroutine.h" + +/* +* The API is not thread-safe and shouldn't be. The struct is public to be part +* of other structures and protected by third-party locks, see +* block/block-copy.c for example. +*/ + +typedef struct BlockReq { +int64_t offset; +int64_t bytes; + +CoQueue wait_queue;/* coroutines blocked on this req */ +QLIST_ENTRY (BlockReq) list; +}BlockReq ; + +typedef QLIST_HEAD(, BlockReq) BlockReqList; + +/* +* Initialize new request and add it to the list. Caller should be sure that +* there are no conflicting requests in the list. +*/ +void reqlist_init_req (BlockReqList *reqs,BlockReq *req,int64_t offset, +int64_t bytes); +/* Search for request in the list intersecting with @offset/@bytes area. */ +BlockReq *reqlist_find_conflict (BlockReqList *reqs,int64_t offset, +int64_t bytes); + +/* +* If there are no intersecting requests return false. Otherwise, wait for the +* first found intersecting request to finish and return true. +* +* @lock is passed to qemu_co_queue_wait() +* False return value proves that lock was NOT released. +*/ +bool coroutine_fn reqlist_wait_one(BlockReqList *reqs, int64_t offset, +int64_t bytes,CoMutex *lock); + +/* +* Shrink request and wake all waiting coroutines (may be some of them are not +* intersecting with shrunk request). +*/ +void coroutine_fn reqlist_shrink_req(BlockReq *req, int64_t new_bytes); + +/* +* Remove request and wake all waiting coroutines. Do not release any memory. +*/ +void coroutine_fn reqlist_remove_req(BlockReq *req); + +#endif /* REQLIST_H */
block/block-copy.c +37 -79
252 lines not on this page · raw message
block/reqlist.c new file +76 -0
76 lines not on this page · raw message
MAINTAINERS +3 -1
@@ -2336,7 +2336,9 @@ F: block/stream.c F: block/mirror.c F: qapi/job.json F: block/block-copy.c -F: include/block/block-copy.c +F: include/block/block-copy.h +F: block/reqlist.c +F: include/block/reqlist.h F: block/copy-before-write.h F: block/copy-before-write.c F: include/block/aio_task.h
block/meson.build +1 -0
@@ -32,6 +32,7 @@ block_ss.add(files( 'qcow2.c', 'quorum.c', 'raw-format.c', + 'reqlist.c', 'snapshot.c', 'throttle-groups.c', 'throttle.c',
Signature · 1 line
2.29.2
PATCH v2 7/19 block/dirty-bitmap: introduce bdrv_dirty_bitmap_status()
In reply to Vladimir Sementsov-OgievskiyAdd a convenient function similar with bdrv_block_status() to get status of dirty bitmap.
--- include/block/dirty-bitmap.h | 2 ++ include/qemu/hbitmap.h | 11 +++++++++++ block/dirty-bitmap.c | 6 ++++++ util/hbitmap.c | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+)
include/block/dirty-bitmap.h +2 -0
@@ -115,6 +115,8 @@ int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap *bitmap, int64_t offset,bool bdrv_dirty_bitmap_next_dirty_area (BdrvDirtyBitmap *bitmap,int64_t start,int64_t end,int64_t max_dirty_count,int64_t *dirty_start,int64_t *dirty_count); +void bdrv_dirty_bitmap_status (BdrvDirtyBitmap *bitmap,int64_t offset, +int64_t bytes,bool *is_dirty,int64_t *count);BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap_locked (BdrvDirtyBitmap *bitmap,Error **errp);
include/qemu/hbitmap.h +11 -0
@@ -340,6 +340,17 @@ bool hbitmap_next_dirty_area(const HBitmap *hb, int64_t start, int64_t end,int64_t max_dirty_count, int64_t *dirty_start, int64_t *dirty_count); +/* +* bdrv_dirty_bitmap_status: +* @hb: The HBitmap to operate on +* @start: the offset to start from +* @end: end of requested area +* @is_dirty: is bitmap dirty at @offset +* @pnum: how many bits has same value starting from @offset +*/ +void hbitmap_status (const HBitmap *hb,int64_t offset,int64_t bytes, +bool *is_dirty,int64_t *pnum); +/** * hbitmap_iter_next: * @hbi: HBitmapIter to operate on.
block/dirty-bitmap.c +6 -0
@@ -875,6 +875,12 @@ bool bdrv_dirty_bitmap_next_dirty_area(BdrvDirtyBitmap *bitmap, dirty_start, dirty_count); } +void bdrv_dirty_bitmap_status (BdrvDirtyBitmap *bitmap,int64_t offset, +int64_t bytes,bool *is_dirty,int64_t *count) +{ +hbitmap_status (bitmap->bitmap, offset, bytes, is_dirty, count); +} +/** * bdrv_merge_dirty_bitmap: merge src into dest. * Ensures permissions on bitmaps are reasonable; use for public API.
util/hbitmap.c +36 -0
@@ -301,6 +301,42 @@ bool hbitmap_next_dirty_area(const HBitmap *hb, int64_t start, int64_t end,return true; } +void hbitmap_status (const HBitmap *hb,int64_t start,int64_t count, +bool *is_dirty,int64_t *pnum) +{ +int64_t next_dirty, next_zero; + +assert (start >=0 ); +assert (count >0 ); +assert (start + count <= hb->orig_size); + + next_dirty =hbitmap_next_dirty (hb, start, count); +if (next_dirty ==-1 ) { + *pnum = count; + *is_dirty = false; +return ; + } + +if (next_dirty > start) { + *pnum = next_dirty - start; + *is_dirty = false; +return ; + } + +assert (next_dirty == start); + + next_zero =hbitmap_next_zero (hb, start, count); +if (next_zero ==-1 ) { + *pnum = count; + *is_dirty = true; +return ; + } + +assert (next_zero > start); + *pnum = next_zero - start; + *is_dirty = false; +} +bool hbitmap_empty (const HBitmap *hb) {return hb->count ==0 ;
Signature · 1 line
2.29.2
PATCH v2 8/19 block/reqlist: add reqlist_wait_all()
In reply to Vladimir Sementsov-OgievskiyAdd function to wait for all intersecting requests. To be used in the further commit.
--- include/block/reqlist.h | 8 ++++++++ block/reqlist.c | 8 ++++++++ 2 files changed, 16 insertions(+)
include/block/reqlist.h +8 -0
@@ -53,6 +53,14 @@ BlockReq *reqlist_find_conflict(BlockReqList *reqs, int64_t offset, bool coroutine_fn reqlist_wait_one(BlockReqList *reqs, int64_t offset,int64_t bytes,CoMutex *lock); +/* +* Wait for all intersecting requests. It just calls reqlist_wait_one() in a +* loops, caller is responsible to stop producing new requests in this region +* in parallel, otherwise reqlist_wait_all() may never return. +*/ +void coroutine_fn reqlist_wait_all(BlockReqList *reqs, int64_t offset, +int64_t bytes,CoMutex *lock); +/* * Shrink request and wake all waiting coroutines (may be some of them are not * intersecting with shrunk request).
block/reqlist.c +8 -0
@@ -57,6 +57,14 @@ bool coroutine_fn reqlist_wait_one(BlockReqList *reqs, int64_t offset,return true; } +void coroutine_fn reqlist_wait_all(BlockReqList *reqs, int64_t offset, +int64_t bytes,CoMutex *lock) +{ +while (reqlist_wait_one (reqs, offset, bytes, lock)) { +/* continue */ + } +} + void coroutine_fn reqlist_shrink_req(BlockReq *req, int64_t new_bytes) {if (new_bytes == req->bytes) {
Signature · 1 line
2.29.2
PATCH v2 9/19 block: introduce FleecingState class
In reply to Vladimir Sementsov-OgievskiyFleecingState represents state shared between copy-before-write filter and upcoming fleecing block driver.
--- block/fleecing.h | 135 ++++++++++++++++++++++++++++++++++ block/fleecing.c | 182 ++++++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 2 + block/meson.build | 1 + 4 files changed, 320 insertions(+) create mode 100644 block/fleecing.h create mode 100644 block/fleecing.c
block/fleecing.h new file +135 -0
@@ -0,0 +1,135 @@ +/* +* FleecingState +* +* The common state of image fleecing, shared between copy-before-write filter +* and fleecing block driver. +* +* Copyright (c) 2021 Virtuozzo International GmbH. +* +* Author: +* Sementsov-Ogievskiy Vladimir <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +* +* +* Fleecing scheme looks as follows: +* +* [guest blk] [nbd export] +* | | +* |root | +* v v +* [copy-before-write]--target-->[fleecing drv] +* | / | +* |file / |file +* v / v +* [active disk]<--source-----/ [temp disk] +* +* Note that "active disk" is also called just "source" and "temp disk" is also +* called "target". +* +* What happens here: +* +* copy-before-write filter performs copy-before-write operations: on guest +* write we should copy old data to target child before rewriting. Note that we +* write this data through fleecing driver: it saves a possibility to implement +* a kind of cache in fleecing driver in future. +* +* Fleecing user is nbd export: it can read from fleecing node, which guarantees +* a snapshot-view for fleecing user. Fleecing user may also do discard +* operations. +* +* FleecingState is responsible for most of the fleecing logic: +* +* 1. Fleecing read. Handle reads of fleecing user: we should decide where from +* to read, from source node or from copy-before-write target node. In former +* case we need to synchronize with guest writes. See fleecing_read_lock() and +* fleecing_read_unlock() functionality. +* +* 2. Guest write synchronization (part of [1] actually). See +* fleecing_mark_done_and_wait_readers() +* +* 3. Fleecing discard. Used by fleecing user when corresponding area is already +* copied. Fleecing user may discard the area which is not needed anymore, that +* should result in: +* - discarding data to free disk space +* - clear bits in copy-bitmap of block-copy, to avoid extra copy-before-write +* operations +* - clear bits in access-bitmap of FleecingState, to avoid further wrong +* access +* +* Still, FleecingState doesn't own any block children, so all real io +* operations (reads, writes and discards) are done by copy-before-write filter +* and fleecing block driver. +*/ + +#ifndef FLEECING_H +#define FLEECING_H + +#include "block/block_int.h" +#include "block/block-copy.h" +#include "block/reqlist.h" + +typedef struct FleecingState FleecingState ; + +/* +* Create FleecingState. +* +* @bcs: link to block-copy owned by copy-before-write filter. +* +* @fleecing_node: should be fleecing block driver node. Used to create some +* bitmaps in it. +*/ +FleecingState *fleecing_new (BlockCopyState *bcs, +BlockDriverState *fleecing_node, +Error **errp); + +/* Free the state. Doesn't free block-copy state (@bcs) */ +void fleecing_free (FleecingState *s); + +/* +* Convenient function for thous who want to do fleecing read. +* +* If requested region starts in "done" area, i.e. data is already copied to +* copy-before-write target node, req is set to NULL, pnum is set to available +* bytes to read from target. User is free to read @pnum bytes from target. +* Still, user is responsible for concurrent discards on target. +* +* If requests region starts in "not done" area, i.e. we have to read from +* source node directly, than @pnum bytes of source node are frozen and +* guaranteed not be rewritten until user calls cbw_snapshot_read_unlock(). +* +* Returns 0 on success and -EACCES when try to read non-dirty area of +* access_bitmap. +*/ +int fleecing_read_lock (FleecingState *f,int64_t offset, +int64_t bytes,const BlockReq **req,int64_t *pnum); +/* Called as closing pair for fleecing_read_lock() */ +void fleecing_read_unlock (FleecingState *f,const BlockReq *req); + +/* +* Called when fleecing user doesn't need the region anymore (for example the +* region is successfully read and backed up somewhere). +* This prevents extra copy-before-write operations in this area in future. +* Next fleecing read from this area will fail with -EACCES. +*/ +void fleecing_discard (FleecingState *f,int64_t offset,int64_t bytes); + +/* +* Called by copy-before-write filter after successful copy-before-write +* operation to synchronize with parallel fleecing reads. +*/ +void fleecing_mark_done_and_wait_readers (FleecingState *f,int64_t offset, +int64_t bytes); + +#endif /* FLEECING_H */
block/fleecing.c new file +182 -0
182 lines not on this page · raw message
MAINTAINERS +2 -0
@@ -2341,6 +2341,8 @@ F: block/reqlist.c F: include/block/reqlist.h F: block/copy-before-write.h F: block/copy-before-write.c +F: block/fleecing.h +F: block/fleecing.c F: include/block/aio_task.h F: block/aio_task.c F: util/qemu-co-shared-resource.c
block/meson.build +1 -0
@@ -18,6 +18,7 @@ block_ss.add(files( 'crypto.c', 'dirty-bitmap.c', 'filter-compress.c', + 'fleecing.c', 'io.c', 'mirror.c', 'nbd.c',
Signature · 1 line
2.29.2
PATCH v2 10/19 block: introduce fleecing block driver
In reply to Vladimir Sementsov-OgievskiyIntroduce a new driver, that works in pair with copy-before-write to improve fleecing.
Without fleecing driver, old fleecing scheme looks as follows:
[guest]
|
|root
v
[copy-before-write] -----> [temp.qcow2] <--- [nbd export]
| target | |file |backing v |
[active disk] <-------------+
With fleecing driver, new scheme is:
[guest]
|
|root
v
[copy-before-write] -----> [fleecing] <--- [nbd export]
| target | | |file | |file v | v [active disk]<--source------+ [temp.img]
Benefits of new scheme:
1. Access control: if remote client try to read data that not covered by original dirty bitmap used on copy-before-write open, client gets -EACCES.
2. Discard support: if remote client do DISCARD, this additionally to discarding data in temp.img informs block-copy process to not copy these clusters. Next read from discarded area will return -EACCES. This is significant thing: when fleecing user reads data that was not yet copied to temp.img, we can avoid copying it on further guest write.
3. Synchronisation between client reads and block-copy write is more
efficient: it doesn't block intersecting block-copy write during client read.
4. We don't rely on backing feature: active disk should not be backing of temp image, so we avoid some permission-related difficulties and temp image now is not required to support backing, it may be simple raw image.
Note that now nobody calls fleecing_drv_activate(), so new driver is actually unusable. It's a work for the following patch: support fleecing block driver in copy-before-write filter driver.
--- qapi/block-core.json | 17 ++- block/fleecing.h | 16 +++ block/fleecing-drv.c | 260 +++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + block/meson.build | 1 + 5 files changed, 294 insertions(+), 1 deletion(-) create mode 100644 block/fleecing-drv.c
qapi/block-core.json +16 -1
@@ -2826,13 +2826,14 @@ # @blkreplay: Since 4.2 # @compress: Since 5.0 # @copy-before-write: Since 6.2 +# @fleecing: Since 6.2 # # Since: 2.9 ## { 'enum': 'BlockdevDriver', 'data': [ 'blkdebug', 'blklogwrites', 'blkreplay', 'blkverify', 'bochs', 'cloop', 'compress', 'copy-before-write', 'copy-on-read', 'dmg', - 'file', 'ftp', 'ftps', 'gluster', + 'file', 'fleecing', 'ftp', 'ftps', 'gluster', {'name': 'host_cdrom', 'if': 'defined(HAVE_HOST_BLOCK_DEVICE)' }, {'name': 'host_device', 'if': 'defined(HAVE_HOST_BLOCK_DEVICE)' }, 'http', 'https', 'iscsi',
@@ -4077,6 +4078,19 @@ 'base': 'BlockdevOptionsGenericFormat', 'data': { 'target': 'BlockdevRef', '*bitmap': 'BlockDirtyBitmap' } } +## +# @BlockdevOptionsFleecing: +# +# Driver that works in pair with copy-before-write to make fleecing scheme. +# +# @source: source node of fleecing +# +# Since: 6.2 +## +{ 'struct': 'BlockdevOptionsFleecing', + 'base': 'BlockdevOptionsGenericFormat', + 'data': { 'source': 'str' } } + ## # @BlockdevOptions: #
@@ -4133,6 +4147,7 @@ 'copy-on-read':'BlockdevOptionsCor', 'dmg': 'BlockdevOptionsGenericFormat', 'file': 'BlockdevOptionsFile', + 'fleecing': 'BlockdevOptionsFleecing', 'ftp': 'BlockdevOptionsCurlFtp', 'ftps': 'BlockdevOptionsCurlFtps', 'gluster': 'BlockdevOptionsGluster',
block/fleecing.h +16 -0
@@ -80,6 +80,9 @@#include "block/block-copy.h" #include "block/reqlist.h" + +/* fleecing.c */ +typedef struct FleecingState FleecingState ;/*
@@ -132,4 +135,17 @@ void fleecing_discard(FleecingState *f, int64_t offset, int64_t bytes);void fleecing_mark_done_and_wait_readers (FleecingState *f,int64_t offset,int64_t bytes); + +/* fleecing-drv.c */ + +/* Returns true if @bs->drv is fleecing block driver */ +bool is_fleecing_drv (BlockDriverState *bs); + +/* +* Normally FleecingState is created by copy-before-write filter. Then +* copy-before-write filter calls fleecing_drv_activate() to share FleecingState +* with fleecing block driver. +*/ +void fleecing_drv_activate (BlockDriverState *bs,FleecingState *fleecing); +#endif /* FLEECING_H */
block/fleecing-drv.c new file +260 -0
260 lines not on this page · raw message
MAINTAINERS +1 -0
@@ -2343,6 +2343,7 @@ F: block/copy-before-write.h F: block/copy-before-write.c F: block/fleecing.h F: block/fleecing.c +F: block/fleecing-drv.c F: include/block/aio_task.h F: block/aio_task.c F: util/qemu-co-shared-resource.c
block/meson.build +1 -0
@@ -19,6 +19,7 @@ block_ss.add(files( 'dirty-bitmap.c', 'filter-compress.c', 'fleecing.c', + 'fleecing-drv.c', 'io.c', 'mirror.c', 'nbd.c',
Signature · 1 line
2.29.2
Re: [PATCH v2 10/19] block: introduce fleecing block driver
Quoted 84 lines · Vladimir Sementsov-Ogievskiy
Introduce a new driver, that works in pair with copy-before-write to improve fleecing.
Without fleecing driver, old fleecing scheme looks as follows:
[guest]
|
|root
v
[copy-before-write] -----> [temp.qcow2] <--- [nbd export]| target | |file |backing v |[active disk] <-------------+
With fleecing driver, new scheme is:
[guest]
|
|root
v
[copy-before-write] -----> [fleecing] <--- [nbd export]| target | | |file | |file v | v [active disk]<--source------+ [temp.img]Benefits of new scheme:
1. Access control: if remote client try to read data that not covered by original dirty bitmap used on copy-before-write open, client gets
-EACCES.2. Discard support: if remote client do DISCARD, this additionally to discarding data in temp.img informs block-copy process to not copy these clusters. Next read from discarded area will return
-EACCES. This is significant thing: when fleecing user reads data that was not yet copied to temp.img, we can avoid copying it on further guest write.3. Synchronisation between client reads and block-copy write is more
efficient: it doesn't block intersecting block-copy write during client read.4. We don't rely on backing feature: active disk should not be backing of temp image, so we avoid some permission-related difficulties and temp image now is not required to support backing, it may be simple raw image.
Note that now nobody calls
fleecing_drv_activate(), so new driver is actually unusable. It's a work for the following patch: support fleecing block driver in copy-before-write filter driver.Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- qapi/block-core.json | 17 ++- block/fleecing.h | 16 +++ block/fleecing-drv.c | 260 +++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + block/meson.build | 1 + 5 files changed, 294 insertions(+), 1 deletion(-) create mode 100644 block/fleecing-drv.cqapi/block-core.json +2
-1@@ -2826,13 +2826,14 @@ # @blkreplay: Since 4.2 # @compress: Since 5.0 # @copy-before-write: Since 6.2 +# @fleecing: Since 6.2 # # Since: 2.9 ## { 'enum': 'BlockdevDriver', 'data': [ 'blkdebug', 'blklogwrites', 'blkreplay', 'blkverify', 'bochs', 'cloop', 'compress', 'copy-before-write', 'copy-on-read', 'dmg', - 'file', 'ftp', 'ftps', 'gluster', + 'file', 'fleecing', 'ftp', 'ftps', 'gluster', {'name': 'host_cdrom', 'if': 'defined(HAVE_HOST_BLOCK_DEVICE)' }, {'name': 'host_device', 'if': 'defined(HAVE_HOST_BLOCK_DEVICE)' }, 'http', 'https', 'iscsi',
qapi/block-core.json line 4084
Quoted 7 lines
qapi/block-core.json +4
-0@@ -4077,6 +4078,19 @@ 'base': 'BlockdevOptionsGenericFormat', 'data': { 'target': 'BlockdevRef', '*bitmap': 'BlockDirtyBitmap' } } +## +# @BlockdevOptionsFleecing: +# +# Driver that works in pair with copy-before-write to make fleecing scheme.
This is really terse. Do we explain the driver's intended use anywhere?
I'd suggest s/to make fleecing scheme/to make a fleecing scheme/, except it doesn't make much sense to me either way :)
qapi/block-core.json line 4086
Quoted 2 lines
qapi/block-core.json +2
-0+# +# @source: source node of fleecing
We usually say "node name of ...".
Quoted 18 lines
qapi/block-core.json +8
-0+# +# Since: 6.2 +## +{ 'struct': 'BlockdevOptionsFleecing', + 'base': 'BlockdevOptionsGenericFormat', + 'data': { 'source': 'str' } } + ## # @BlockdevOptions: #@@ -4133,6 +4147,7 @@ 'copy-on-read':'BlockdevOptionsCor', 'dmg': 'BlockdevOptionsGenericFormat', 'file': 'BlockdevOptionsFile', + 'fleecing': 'BlockdevOptionsFleecing', 'ftp': 'BlockdevOptionsCurlFtp', 'ftps': 'BlockdevOptionsCurlFtps', 'gluster': 'BlockdevOptionsGluster',
[...]
Re: [PATCH v2 10/19] block: introduce fleecing block driver
Quoted 89 lines · Markus Armbruster
Quoted 87 lines · Vladimir Sementsov-Ogievskiy
Introduce a new driver, that works in pair with copy-before-write to improve fleecing.
Without fleecing driver, old fleecing scheme looks as follows:
[guest]
|
|root
v
[copy-before-write] -----> [temp.qcow2] <--- [nbd export]| target | |file |backing v |[active disk] <-------------+
With fleecing driver, new scheme is:
[guest]
|
|root
v
[copy-before-write] -----> [fleecing] <--- [nbd export]| target | | |file | |file v | v [active disk]<--source------+ [temp.img]Benefits of new scheme:
1. Access control: if remote client try to read data that not covered by original dirty bitmap used on copy-before-write open, client gets
-EACCES.2. Discard support: if remote client do DISCARD, this additionally to discarding data in temp.img informs block-copy process to not copy these clusters. Next read from discarded area will return
-EACCES. This is significant thing: when fleecing user reads data that was not yet copied to temp.img, we can avoid copying it on further guest write.3. Synchronisation between client reads and block-copy write is more
efficient: it doesn't block intersecting block-copy write during client read.4. We don't rely on backing feature: active disk should not be backing of temp image, so we avoid some permission-related difficulties and temp image now is not required to support backing, it may be simple raw image.
Note that now nobody calls
fleecing_drv_activate(), so new driver is actually unusable. It's a work for the following patch: support fleecing block driver in copy-before-write filter driver.Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- qapi/block-core.json | 17 ++- block/fleecing.h | 16 +++ block/fleecing-drv.c | 260 +++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + block/meson.build | 1 + 5 files changed, 294 insertions(+), 1 deletion(-)create mode 100644
block/fleecing-drv.cqapi/block-core.json +2
-1@@ -2826,13 +2826,14 @@ # @blkreplay: Since 4.2 # @compress: Since 5.0 # @copy-before-write: Since 6.2 +# @fleecing: Since 6.2 # # Since: 2.9 ## { 'enum': 'BlockdevDriver', 'data': [ 'blkdebug', 'blklogwrites', 'blkreplay', 'blkverify', 'bochs', 'cloop', 'compress', 'copy-before-write', 'copy-on-read', 'dmg', - 'file', 'ftp', 'ftps', 'gluster', + 'file', 'fleecing', 'ftp', 'ftps', 'gluster', {'name': 'host_cdrom', 'if': 'defined(HAVE_HOST_BLOCK_DEVICE)' }, {'name': 'host_device', 'if': 'defined(HAVE_HOST_BLOCK_DEVICE)' }, 'http', 'https', 'iscsi',@@ -4077,6 +4078,19 @@ 'base': 'BlockdevOptionsGenericFormat', 'data': { 'target': 'BlockdevRef', '*bitmap': 'BlockDirtyBitmap' } }
Quoted 6 lines
qapi/block-core.json line 4084
Quoted 4 lines
qapi/block-core.json +4
-0+## +# @BlockdevOptionsFleecing: +# +# Driver that works in pair with copy-before-write to make fleecing scheme.This is really terse. Do we explain the driver's intended use anywhere?
Hmm. I can duplicate here the ASII art from commit message together with some explanations.
Quoted 8 lines
I'd suggest s/to make fleecing scheme/to make a fleecing scheme/, except it doesn't make much sense to me either way :)
qapi/block-core.json line 4086
Quoted 2 lines
qapi/block-core.json +2
-0+# +# @source: source node of fleecingWe usually say "node name of ...".
OK
Quoted 22 lines
Quoted 19 lines
qapi/block-core.json +8
-0+# +# Since: 6.2 +## +{ 'struct': 'BlockdevOptionsFleecing', + 'base': 'BlockdevOptionsGenericFormat', + 'data': { 'source': 'str' } } + ## # @BlockdevOptions: #@@ -4133,6 +4147,7 @@ 'copy-on-read':'BlockdevOptionsCor', 'dmg': 'BlockdevOptionsGenericFormat', 'file': 'BlockdevOptionsFile', + 'fleecing': 'BlockdevOptionsFleecing', 'ftp': 'BlockdevOptionsCurlFtp', 'ftps': 'BlockdevOptionsCurlFtps', 'gluster': 'BlockdevOptionsGluster',[...]
Signature · 2 lines
Best regards, Vladimir
PATCH v2 11/19 block/copy-before-write: support fleecing block driver
In reply to Vladimir Sementsov-OgievskiyThe last step to make new fleecing scheme work (see block/fleecing.h for descritption) is to update copy-before-write filter:
If we detect that unfiltered target child is fleecing block driver, we do:
- initialize shared FleecingState
- activate fleecing block driver with it
- do guest write synchronization with help of fleecing_mark_done_and_wait_readers() function
--- block/copy-before-write.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-)
block/copy-before-write.c +26 -1
@@ -33,10 +33,13 @@#include "block/block-copy.h" #include "block/copy-before-write.h" +#include "block/fleecing.h" typedef struct BDRVCopyBeforeWriteState {BlockCopyState *bcs;BdrvChild *target; + +FleecingState *fleecing; }BDRVCopyBeforeWriteState ; static coroutine_fn int cbw_co_preadv(
@@ -50,6 +53,7 @@ static coroutine_fn int cbw_do_copy_before_write(BlockDriverState *bs, uint64_t offset, uint64_t bytes, BdrvRequestFlags flags) { BDRVCopyBeforeWriteState *s = bs->opaque; +int ret;uint64_t off, end;int64_t cluster_size =block_copy_cluster_size (s->bcs);
@@ -60,7 +64,16 @@ static coroutine_fn int cbw_do_copy_before_write(BlockDriverState *bs, off =QEMU_ALIGN_DOWN (offset, cluster_size); end =QEMU_ALIGN_UP (offset + bytes, cluster_size); -return block_copy (s->bcs, off, end - off, true); + ret =block_copy (s->bcs, off, end - off, true); +if (ret <0 ) { +return ret; + } + +if (s->fleecing) { +fleecing_mark_done_and_wait_readers (s->fleecing, off, end - off); + } + +return 0 ; } static int coroutine_fn cbw_co_pdiscard(BlockDriverState *bs,
@@ -149,6 +162,7 @@ static int cbw_open(BlockDriverState *bs, QDict *options, int flags, {BDRVCopyBeforeWriteState *s = bs->opaque;BdrvDirtyBitmap *bitmap =NULL ; +BlockDriverState *unfiltered_target; bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY,
@@ -162,6 +176,7 @@ static int cbw_open(BlockDriverState *bs, QDict *options, int flags,if (!s->target) {return -EINVAL ; } + unfiltered_target =bdrv_skip_filters (s->target->bs);if (qdict_haskey (options,"bitmap.node" ) ||qdict_haskey (options,"bitmap.name" ))
@@ -203,6 +218,14 @@ static int cbw_open(BlockDriverState *bs, QDict *options, int flags,return -EINVAL ; } +if (is_fleecing_drv (unfiltered_target)) { + s->fleecing =fleecing_new (s->bcs, unfiltered_target, errp); +if (!s->fleecing) { +return -EINVAL ; + } +fleecing_drv_activate (unfiltered_target, s->fleecing); + } +return 0 ; }
@@ -210,6 +233,8 @@ static void cbw_close(BlockDriverState *bs) {BDRVCopyBeforeWriteState *s = bs->opaque; +fleecing_free (s->fleecing); + s->fleecing =NULL ;block_copy_state_free (s->bcs); s->bcs =NULL ; }
Signature · 1 line
2.29.2
PATCH v2 12/19 block/block-copy: add write-unchanged mode
In reply to Vladimir Sementsov-OgievskiyWe are going to implement push backup with fleecing scheme. This means that backup job will be a fleecing user and therefore will not need separate copy-before-write filter. Instead it will consider source as constant unchanged drive. Of course backup will want to unshare writes on source for this case. But we want to do copy-before-write operations. Still these operations may be considered as write-unchanged. Add corresponding option to block-copy now, to use in the following commit.
--- include/block/block-copy.h | 3 ++- block/block-copy.c | 9 ++++++--- block/copy-before-write.c | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-)
include/block/block-copy.h +2 -1
@@ -25,7 +25,8 @@ typedef struct BlockCopyState BlockCopyState;typedef struct BlockCopyCallState BlockCopyCallState ;BlockCopyState *block_copy_state_new (BdrvChild *source,BdrvChild *target, -BdrvDirtyBitmap *bitmap,Error **errp); +BdrvDirtyBitmap *bitmap, +bool write_unchanged,Error **errp);/* Function should be called prior any actual copy request */ void block_copy_set_copy_opts(BlockCopyState *s, bool use_copy_range,
block/block-copy.c +6 -3
@@ -279,7 +279,8 @@ 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 ) | + s->write_flags = (s->write_flags & + (BDRV_REQ_SERIALISING |BDRV_REQ_WRITE_UNCHANGED )) | (compress ?BDRV_REQ_WRITE_COMPRESSED :0 );if (s->max_transfer < s->cluster_size) {
@@ -340,7 +341,8 @@ static int64_t block_copy_calculate_cluster_size(BlockDriverState *target, }BlockCopyState *block_copy_state_new (BdrvChild *source,BdrvChild *target, -BdrvDirtyBitmap *bitmap,Error **errp) +BdrvDirtyBitmap *bitmap, +bool write_unchanged,Error **errp) {ERRP_GUARD ();BlockCopyState *s;
@@ -393,7 +395,8 @@ 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), + .write_flags = (is_fleecing ?BDRV_REQ_SERIALISING :0 ) | + (write_unchanged ? BDRV_REQ_WRITE_UNCHANGED : 0), .mem = shres_create(BLOCK_COPY_MAX_MEM), .max_transfer = QEMU_ALIGN_DOWN( block_copy_max_transfer(source, target),
block/copy-before-write.c +1 -1
@@ -212,7 +212,7 @@ static int cbw_open(BlockDriverState *bs, QDict *options, int flags, ((BDRV_REQ_FUA |BDRV_REQ_MAY_UNMAP |BDRV_REQ_NO_FALLBACK ) & bs->file->bs->supported_zero_flags); - s->bcs =block_copy_state_new (bs->file, s->target, bitmap, errp); + s->bcs =block_copy_state_new (bs->file, s->target, bitmap, false, errp);if (!s->bcs) {error_prepend (errp,"Cannot create block-copy-state: " );return -EINVAL ;
Signature · 1 line
2.29.2
PATCH v2 13/19 block/copy-before-write: use write-unchanged in fleecing mode
In reply to Vladimir Sementsov-OgievskiyAs announced in previous commit, we need use write-unchanged operations for fleecing, so that fleecing client may unshare writes if needed.
--- block/copy-before-write.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
block/copy-before-write.c +11 -2
@@ -132,6 +132,8 @@ static void cbw_child_perm(BlockDriverState *bs, BdrvChild *c, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared) { + BDRVCopyBeforeWriteState *s = bs->opaque; +if (!(role &BDRV_CHILD_FILTERED )) {/* * Target child
@@ -142,7 +144,7 @@ static void cbw_child_perm(BlockDriverState *bs, BdrvChild *c,* only upfront. */ *nshared =BLK_PERM_ALL & ~BLK_PERM_RESIZE ; - *nperm =BLK_PERM_WRITE ; + *nperm = s->fleecing ?BLK_PERM_WRITE_UNCHANGED :BLK_PERM_WRITE ; }else {/* Source child */ bdrv_default_perms(bs, c, role, reopen_queue,
@@ -212,7 +214,14 @@ static int cbw_open(BlockDriverState *bs, QDict *options, int flags, ((BDRV_REQ_FUA |BDRV_REQ_MAY_UNMAP |BDRV_REQ_NO_FALLBACK ) & bs->file->bs->supported_zero_flags); - s->bcs =block_copy_state_new (bs->file, s->target, bitmap, false, errp); +/* +* For fleecing scheme set parameter write_unchanged=true, as our +* copy-before-write operations will actually be write-unchanged. As well we +* take write-unchanged permission instead of write, which is important for +* backup with immutable_source=true to work as fleecing client. +*/ + s->bcs =block_copy_state_new (bs->file, s->target, bitmap, +is_fleecing_drv (unfiltered_target), errp);if (!s->bcs) {error_prepend (errp,"Cannot create block-copy-state: " );return -EINVAL ;
Signature · 1 line
2.29.2
PATCH v2 14/19 iotests/image-fleecing: add test-case for fleecing format node
In reply to Vladimir Sementsov-Ogievskiy--- tests/qemu-iotests/tests/image-fleecing | 67 +++++++++++++------ tests/qemu-iotests/tests/image-fleecing.out | 74 ++++++++++++++++++++- 2 files changed, 121 insertions(+), 20 deletions(-)
tests/qemu-iotests/tests/image-fleecing +48 -19
@@ -48,12 +48,17 @@ remainder = [('0xd5', '0x108000', '32k'), # Right-end of partial-left [1] ('0xdc', '32M', '32k'), # Left-end of partial-right [2] ('0xcd', '0x3ff0000', '64k')] # patterns[3] -def do_test(use_cbw, base_img_path, fleece_img_path, nbd_sock_path, vm): +def do_test(use_cbw, use_fleecing_filter, base_img_path, + fleece_img_path, nbd_sock_path, vm): log('--- Setting up images ---') log('') assert qemu_img('create', '-f', iotests.imgfmt, base_img_path, '64M') == 0 - assert qemu_img('create', '-f', 'qcow2', fleece_img_path, '64M') == 0 + if use_fleecing_filter: + assert use_cbw + assert qemu_img('create', '-f', 'raw', fleece_img_path, '64M') == 0 + else: + assert qemu_img('create', '-f', 'qcow2', fleece_img_path, '64M') == 0 for p in patterns: qemu_io('-f', iotests.imgfmt,
@@ -80,24 +85,39 @@ def do_test(use_cbw, base_img_path, fleece_img_path, nbd_sock_path, vm): log('') - # create tmp_node backed by src_node - log(vm.qmp('blockdev-add', { - 'driver': 'qcow2', - 'node-name': tmp_node, - 'file': { + if use_fleecing_filter: + log(vm.qmp('blockdev-add', { + 'node-name': tmp_node, 'driver': 'file', 'filename': fleece_img_path, - }, - 'backing': src_node, - })) + })) + else: + # create tmp_node backed by src_node + log(vm.qmp('blockdev-add', { + 'driver': 'qcow2', + 'node-name': tmp_node, + 'file': { + 'driver': 'file', + 'filename': fleece_img_path, + }, + 'backing': src_node, + })) # Establish CBW from source to fleecing node if use_cbw: + if use_fleecing_filter: + log(vm.qmp('blockdev-add', { + 'driver': 'fleecing', + 'node-name': 'fl-fleecing', + 'file': tmp_node, + 'source': src_node, + })) + log(vm.qmp('blockdev-add', { 'driver': 'copy-before-write', 'node-name': 'fl-cbw', 'file': src_node, - 'target': tmp_node + 'target': 'fl-fleecing' if use_fleecing_filter else tmp_node })) log(vm.qmp('qom-set', path=qom_path, property='drive', value='fl-cbw'))
@@ -108,16 +128,18 @@ def do_test(use_cbw, base_img_path, fleece_img_path, nbd_sock_path, vm): target=tmp_node, sync='none')) + export_node = 'fl-fleecing' if use_fleecing_filter else tmp_node + log('') log('--- Setting up NBD Export ---') log('') - nbd_uri = 'nbd+unix:///%s?socket=%s' % (tmp_node, nbd_sock_path) + nbd_uri = 'nbd+unix:///%s?socket=%s' % (export_node, nbd_sock_path) log(vm.qmp('nbd-server-start', {'addr': { 'type': 'unix', 'data': { 'path': nbd_sock_path } } })) - log(vm.qmp('nbd-server-add', device=tmp_node)) + log(vm.qmp('nbd-server-add', device=export_node)) log('') log('--- Sanity Check ---')
@@ -150,16 +172,19 @@ def do_test(use_cbw, base_img_path, fleece_img_path, nbd_sock_path, vm): log('--- Cleanup ---') log('') + log(vm.qmp('nbd-server-stop')) + if use_cbw: log(vm.qmp('qom-set', path=qom_path, property='drive', value=src_node)) log(vm.qmp('blockdev-del', node_name='fl-cbw')) + if use_fleecing_filter: + log(vm.qmp('blockdev-del', node_name='fl-fleecing')) else: log(vm.qmp('block-job-cancel', device='fleecing')) e = vm.event_wait('BLOCK_JOB_CANCELLED') assert e is not None log(e, filters=[iotests.filter_qmp_event]) - log(vm.qmp('nbd-server-stop')) log(vm.qmp('blockdev-del', node_name=tmp_node)) vm.shutdown()
@@ -176,17 +201,21 @@ def do_test(use_cbw, base_img_path, fleece_img_path, nbd_sock_path, vm): log('Done') -def test(use_cbw): +def test(use_cbw, use_fleecing_filter): with iotests.FilePath('base.img') as base_img_path, \ iotests.FilePath('fleece.img') as fleece_img_path, \ iotests.FilePath('nbd.sock', base_dir=iotests.sock_dir) as nbd_sock_path, \ iotests.VM() as vm: - do_test(use_cbw, base_img_path, fleece_img_path, nbd_sock_path, vm) + do_test(use_cbw, use_fleecing_filter, base_img_path, + fleece_img_path, nbd_sock_path, vm) log('=== Test backup(sync=none) based fleecing ===\n') -test(False) +test(False, False) + +log('=== Test cbw-filter based fleecing ===\n') +test(True, False) -log('=== Test filter based fleecing ===\n') -test(True) +log('=== Test fleecing-format based fleecing ===\n') +test(True, True)
tests/qemu-iotests/tests/image-fleecing.out +73 -1
101 lines not on this page · raw message
Signature · 1 line
2.29.2
PATCH v2 15/19 iotests.py: add qemu_io_pipe_and_status()
In reply to Vladimir Sementsov-OgievskiyAdd helper that returns both status and output, to be used in the following commit
--- tests/qemu-iotests/iotests.py | 4 ++++ 1 file changed, 4 insertions(+)
tests/qemu-iotests/iotests.py +4 -0
@@ -206,6 +206,10 @@ def qemu_io(*args): args = qemu_io_args + list(args) return qemu_tool_pipe_and_status('qemu-io', args)[0] +def qemu_io_pipe_and_status(*args): + args = qemu_io_args + list(args) + return qemu_tool_pipe_and_status('qemu-io', args) + def qemu_io_log(*args): result = qemu_io(*args) log(result, filters=[filter_testfiles, filter_qemu_io])
Signature · 1 line
2.29.2
PATCH v2 16/19 iotests/image-fleecing: add test case with bitmap
In reply to Vladimir Sementsov-OgievskiyNote that reads zero areas (not dirty in the bitmap) fails, that's correct.
--- tests/qemu-iotests/tests/image-fleecing | 32 ++++++-- tests/qemu-iotests/tests/image-fleecing.out | 84 +++++++++++++++++++++ 2 files changed, 108 insertions(+), 8 deletions(-)
tests/qemu-iotests/tests/image-fleecing +24 -8
@@ -23,7 +23,7 @@ # Creator/Owner: John Snow <[email protected]> import iotests -from iotests import log, qemu_img, qemu_io, qemu_io_silent +from iotests import log, qemu_img, qemu_io, qemu_io_silent, qemu_io_pipe_and_status iotests.script_initialize( supported_fmts=['qcow2', 'qcow', 'qed', 'vmdk', 'vhdx', 'raw'],
@@ -49,11 +49,15 @@ remainder = [('0xd5', '0x108000', '32k'), # Right-end of partial-left [1] ('0xcd', '0x3ff0000', '64k')] # patterns[3] def do_test(use_cbw, use_fleecing_filter, base_img_path, - fleece_img_path, nbd_sock_path, vm): + fleece_img_path, nbd_sock_path, vm, + bitmap=False): log('--- Setting up images ---') log('') assert qemu_img('create', '-f', iotests.imgfmt, base_img_path, '64M') == 0 + if bitmap: + assert qemu_img('bitmap', '--add', base_img_path, 'bitmap0') == 0 + if use_fleecing_filter: assert use_cbw assert qemu_img('create', '-f', 'raw', fleece_img_path, '64M') == 0
@@ -113,12 +117,17 @@ def do_test(use_cbw, use_fleecing_filter, base_img_path, 'source': src_node, })) - log(vm.qmp('blockdev-add', { + fl_cbw = { 'driver': 'copy-before-write', 'node-name': 'fl-cbw', 'file': src_node, 'target': 'fl-fleecing' if use_fleecing_filter else tmp_node - })) + } + + if bitmap: + fl_cbw['bitmap'] = {'node': src_node, 'name': 'bitmap0'} + + log(vm.qmp('blockdev-add', fl_cbw)) log(vm.qmp('qom-set', path=qom_path, property='drive', value='fl-cbw')) else:
@@ -148,7 +157,9 @@ def do_test(use_cbw, use_fleecing_filter, base_img_path, for p in patterns + zeroes: cmd = 'read -P%s %s %s' % p log(cmd) - assert qemu_io_silent('-r', '-f', 'raw', '-c', cmd, nbd_uri) == 0 + out, ret = qemu_io_pipe_and_status('-r', '-f', 'raw', '-c', cmd, nbd_uri) + if ret != 0: + print(out) log('') log('--- Testing COW ---')
@@ -166,7 +177,9 @@ def do_test(use_cbw, use_fleecing_filter, base_img_path, for p in patterns + zeroes: cmd = 'read -P%s %s %s' % p log(cmd) - assert qemu_io_silent('-r', '-f', 'raw', '-c', cmd, nbd_uri) == 0 + out, ret = qemu_io_pipe_and_status('-r', '-f', 'raw', '-c', cmd, nbd_uri) + if ret != 0: + print(out) log('') log('--- Cleanup ---')
@@ -201,14 +214,14 @@ def do_test(use_cbw, use_fleecing_filter, base_img_path, log('Done') -def test(use_cbw, use_fleecing_filter): +def test(use_cbw, use_fleecing_filter, bitmap=False): with iotests.FilePath('base.img') as base_img_path, \ iotests.FilePath('fleece.img') as fleece_img_path, \ iotests.FilePath('nbd.sock', base_dir=iotests.sock_dir) as nbd_sock_path, \ iotests.VM() as vm: do_test(use_cbw, use_fleecing_filter, base_img_path, - fleece_img_path, nbd_sock_path, vm) + fleece_img_path, nbd_sock_path, vm, bitmap=bitmap) log('=== Test backup(sync=none) based fleecing ===\n')
@@ -219,3 +232,6 @@ test(True, False) log('=== Test fleecing-format based fleecing ===\n') test(True, True) + +log('=== Test fleecing-format based fleecing with bitmap ===\n') +test(True, True, bitmap=True)
tests/qemu-iotests/tests/image-fleecing.out +84 -0
90 lines not on this page · raw message
Signature · 1 line
2.29.2
PATCH v2 17/19 block: blk_root(): return non-const pointer
In reply to Vladimir Sementsov-OgievskiyIn the following patch we'll want to pass blk children to block-copy. Const pointers are not enough. So, return non const pointer from blk_root().
--- include/sysemu/block-backend.h | 2 +- block/block-backend.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
include/sysemu/block-backend.h +1 -1
@@ -271,7 +271,7 @@ int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in, int bytes, BdrvRequestFlags read_flags, BdrvRequestFlags write_flags); -const BdrvChild *blk_root (BlockBackend *blk); +BdrvChild *blk_root (BlockBackend *blk);int blk_make_empty (BlockBackend *blk,Error **errp);
block/block-backend.c +1 -1
@@ -2463,7 +2463,7 @@ int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in, bytes, read_flags, write_flags); } -const BdrvChild *blk_root (BlockBackend *blk) +BdrvChild *blk_root (BlockBackend *blk) {return blk->root; }
Signature · 1 line
2.29.2
PATCH v2 18/19 qapi: backup: add immutable-source parameter
In reply to Vladimir Sementsov-OgievskiyWe are on the way to implement internal-backup with fleecing scheme, which includes backup job copying from fleecing block driver node (which is target of copy-before-write filter) to final target of backup. This job doesn't need own filter, as fleecing block driver node is a kind of snapshot, it's immutable from reader point of view.
Let's add a parameter for backup to not insert filter but instead unshare writes on source. This way backup job becomes a simple copying process.
--- qapi/block-core.json | 12 +++++++- include/block/block_int.h | 1 + block/backup.c | 61 +++++++++++++++++++++++++++++++++++---- block/replication.c | 2 +- blockdev.c | 1 + 5 files changed, 70 insertions(+), 7 deletions(-)
qapi/block-core.json +11 -1
@@ -1391,6 +1391,15 @@ # above node specified by @drive. If this option is not given, # a node name is autogenerated. (Since: 4.2) # +# @immutable-source: If true, assume source is immutable and don't insert filter +# as no copy-before-write operations are needed. It will +# fail if there are existing writers on source node, as well, +# any attempt to add writer to source node during backup will +# fail. @filter-node-name must not be set. +# If false, insert copy-before-write filter above source node +# (see also @filter-node-name parameter). +# Default is false. (Since 6.2) +# # @x-perf: Performance options. (Since 6.0) # # Note: @on-source-error and @on-target-error only affect background
@@ -1407,7 +1416,8 @@ '*on-source-error': 'BlockdevOnError', '*on-target-error': 'BlockdevOnError', '*auto-finalize': 'bool', '*auto-dismiss': 'bool', - '*filter-node-name': 'str', '*x-perf': 'BackupPerf' } } + '*filter-node-name': 'str', '*immutable-source': 'bool', + '*x-perf': 'BackupPerf' } } ## # @DriveBackup:
include/block/block_int.h +1 -0
@@ -1284,6 +1284,7 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,BitmapSyncMode bitmap_mode, bool compress, const char *filter_node_name, + bool immutable_source, BackupPerf *perf, BlockdevOnError on_source_error, BlockdevOnError on_target_error,
block/backup.c +56 -5
115 lines not on this page · raw message
block/replication.c +1 -1
@@ -590,7 +590,7 @@ static void replication_start(ReplicationState *rs, ReplicationMode mode, s->backup_job =backup_job_create (NULL , s->secondary_disk->bs, s->hidden_disk->bs,0 ,MIRROR_SYNC_MODE_NONE ,NULL ,0 , false,NULL , - &perf, + false, &perf,BLOCKDEV_ON_ERROR_REPORT ,BLOCKDEV_ON_ERROR_REPORT ,JOB_INTERNAL , backup_job_completed, bs,NULL , &local_err);
blockdev.c +1 -0
@@ -2911,6 +2911,7 @@ static BlockJob *do_backup_common(BackupCommon *backup, backup->sync, bmap, backup->bitmap_mode, backup->compress, backup->filter_node_name, + backup->immutable_source, &perf, backup->on_source_error, backup->on_target_error,
Signature · 1 line
2.29.2
Re: [PATCH v2 18/19] qapi: backup: add immutable-source parameter
Quoted 24 lines · Vladimir Sementsov-Ogievskiy
We are on the way to implement internal-backup with fleecing scheme, which includes backup job copying from fleecing block driver node (which is target of copy-before-write filter) to final target of backup. This job doesn't need own filter, as fleecing block driver node is a kind of snapshot, it's immutable from reader point of view.
Let's add a parameter for backup to not insert filter but instead unshare writes on source. This way backup job becomes a simple copying process.
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- qapi/block-core.json | 12 +++++++- include/block/block_int.h | 1 + block/backup.c | 61 +++++++++++++++++++++++++++++++++++---- block/replication.c | 2 +- blockdev.c | 1 + 5 files changed, 70 insertions(+), 7 deletions(-)qapi/block-core.json +0
-0
qapi/block-core.json line 1394
Quoted 4 lines
qapi/block-core.json +1
-0@@ -1391,6 +1391,15 @@ # above node specified by @drive. If this option is not given, # a node name is autogenerated. (Since: 4.2) # +# @immutable-source: If true, assume source is immutable and don't insert filter
Suggest comma after immutable.
qapi/block-core.json line 1398
Quoted 4 lines
qapi/block-core.json +4
-0+# as no copy-before-write operations are needed. It will +# fail if there are existing writers on source node, as well, +# any attempt to add writer to source node during backup will +# fail. @filter-node-name must not be set.
Suggest to split the sentence like "... fail if there are existing writers on source node. Any attempt ... will also fail."
Quoted 17 lines
qapi/block-core.json +6
-1+# If false, insert copy-before-write filter above source node +# (see also @filter-node-name parameter). +# Default is false. (Since 6.2) +# # @x-perf: Performance options. (Since 6.0) # # Note: @on-source-error and @on-target-error only affect background@@ -1407,7 +1416,8 @@ '*on-source-error': 'BlockdevOnError', '*on-target-error': 'BlockdevOnError', '*auto-finalize': 'bool', '*auto-dismiss': 'bool', - '*filter-node-name': 'str', '*x-perf': 'BackupPerf' } } + '*filter-node-name': 'str', '*immutable-source': 'bool', + '*x-perf': 'BackupPerf' } } ## # @DriveBackup:
[...]
PATCH v2 19/19 iotests/image-fleecing: test push backup with fleecing
In reply to Vladimir Sementsov-OgievskiyAdd test for push backup with fleecing:
- start fleecing with copy-before-write filter
- start a backup job from temporary fleecing node to actual backup target
--- tests/qemu-iotests/tests/image-fleecing | 121 ++++++++++++++------ tests/qemu-iotests/tests/image-fleecing.out | 63 ++++++++++ 2 files changed, 152 insertions(+), 32 deletions(-)
tests/qemu-iotests/tests/image-fleecing +89 -32
@@ -48,9 +48,15 @@ remainder = [('0xd5', '0x108000', '32k'), # Right-end of partial-left [1] ('0xdc', '32M', '32k'), # Left-end of partial-right [2] ('0xcd', '0x3ff0000', '64k')] # patterns[3] -def do_test(use_cbw, use_fleecing_filter, base_img_path, - fleece_img_path, nbd_sock_path, vm, +def do_test(vm, use_cbw, use_fleecing_filter, base_img_path, + fleece_img_path, nbd_sock_path=None, + target_img_path=None, bitmap=False): + push_backup = target_img_path is not None + assert (nbd_sock_path is not None) != push_backup + if push_backup: + assert use_cbw + log('--- Setting up images ---') log('')
@@ -64,6 +70,9 @@ def do_test(use_cbw, use_fleecing_filter, base_img_path, else: assert qemu_img('create', '-f', 'qcow2', fleece_img_path, '64M') == 0 + if push_backup: + assert qemu_img('create', '-f', 'qcow2', target_img_path, '64M') == 0 + for p in patterns: qemu_io('-f', iotests.imgfmt, '-c', 'write -P%s %s %s' % p, base_img_path)
@@ -139,27 +148,45 @@ def do_test(use_cbw, use_fleecing_filter, base_img_path, export_node = 'fl-fleecing' if use_fleecing_filter else tmp_node - log('') - log('--- Setting up NBD Export ---') - log('') + if push_backup: + log('') + log('--- Starting actual backup ---') + log('') - nbd_uri = 'nbd+unix:///%s?socket=%s' % (export_node, nbd_sock_path) - log(vm.qmp('nbd-server-start', - {'addr': { 'type': 'unix', - 'data': { 'path': nbd_sock_path } } })) + log(vm.qmp('blockdev-add', **{ + 'driver': iotests.imgfmt, + 'node-name': 'target', + 'file': { + 'driver': 'file', + 'filename': target_img_path + } + })) + log(vm.qmp('blockdev-backup', device=export_node, + sync='full', target='target', + immutable_source=True, + job_id='push-backup', speed=1)) + else: + log('') + log('--- Setting up NBD Export ---') + log('') - log(vm.qmp('nbd-server-add', device=export_node)) + nbd_uri = 'nbd+unix:///%s?socket=%s' % (export_node, nbd_sock_path) + log(vm.qmp('nbd-server-start', + {'addr': { 'type': 'unix', + 'data': { 'path': nbd_sock_path } } })) - log('') - log('--- Sanity Check ---') - log('') + log(vm.qmp('nbd-server-add', device=export_node)) - for p in patterns + zeroes: - cmd = 'read -P%s %s %s' % p - log(cmd) - out, ret = qemu_io_pipe_and_status('-r', '-f', 'raw', '-c', cmd, nbd_uri) - if ret != 0: - print(out) + log('') + log('--- Sanity Check ---') + log('') + + for p in patterns + zeroes: + cmd = 'read -P%s %s %s' % p + log(cmd) + out, ret = qemu_io_pipe_and_status('-r', '-f', 'raw', '-c', cmd, nbd_uri) + if ret != 0: + print(out) log('') log('--- Testing COW ---')
@@ -170,6 +197,20 @@ def do_test(use_cbw, use_fleecing_filter, base_img_path, log(cmd) log(vm.hmp_qemu_io(qom_path, cmd, qdev=True)) + if push_backup: + # Check that previous operations were done during backup, not after + result = vm.qmp('query-block-jobs') + if len(result['return']) != 1: + log('Backup finished too fast, COW is not tested') + + result = vm.qmp('block-job-set-speed', device='push-backup', speed=0) + assert result == {'return': {}} + + log(vm.event_wait(name='BLOCK_JOB_COMPLETED', + match={'data': {'device': 'push-backup'}}), + filters=[iotests.filter_qmp_event]) + log(vm.qmp('blockdev-del', node_name='target')) + log('') log('--- Verifying Data ---') log('')
@@ -177,15 +218,19 @@ def do_test(use_cbw, use_fleecing_filter, base_img_path, for p in patterns + zeroes: cmd = 'read -P%s %s %s' % p log(cmd) - out, ret = qemu_io_pipe_and_status('-r', '-f', 'raw', '-c', cmd, nbd_uri) - if ret != 0: - print(out) + if push_backup: + assert qemu_io_silent('-r', '-c', cmd, target_img_path) == 0 + else: + out, ret = qemu_io_pipe_and_status('-r', '-f', 'raw', '-c', cmd, nbd_uri) + if ret != 0: + print(out) log('') log('--- Cleanup ---') log('') - log(vm.qmp('nbd-server-stop')) + if not push_backup: + log(vm.qmp('nbd-server-stop')) if use_cbw: log(vm.qmp('qom-set', path=qom_path, property='drive', value=src_node))
@@ -214,24 +259,36 @@ def do_test(use_cbw, use_fleecing_filter, base_img_path, log('Done') -def test(use_cbw, use_fleecing_filter, bitmap=False): +def test(use_cbw, use_fleecing_filter, + nbd_sock_path=None, target_img_path=None, bitmap=False): with iotests.FilePath('base.img') as base_img_path, \ iotests.FilePath('fleece.img') as fleece_img_path, \ - iotests.FilePath('nbd.sock', - base_dir=iotests.sock_dir) as nbd_sock_path, \ iotests.VM() as vm: - do_test(use_cbw, use_fleecing_filter, base_img_path, - fleece_img_path, nbd_sock_path, vm, bitmap=bitmap) + do_test(vm, use_cbw, use_fleecing_filter, base_img_path, + fleece_img_path, nbd_sock_path, target_img_path, + bitmap=bitmap) + +def test_pull(use_cbw, use_fleecing_filter, bitmap=False): + with iotests.FilePath('nbd.sock', + base_dir=iotests.sock_dir) as nbd_sock_path: + test(use_cbw, use_fleecing_filter, nbd_sock_path, None, bitmap=bitmap) + +def test_push(): + with iotests.FilePath('target.img') as target_img_path: + test(True, True, None, target_img_path) log('=== Test backup(sync=none) based fleecing ===\n') -test(False, False) +test_pull(False, False) log('=== Test cbw-filter based fleecing ===\n') -test(True, False) +test_pull(True, False) log('=== Test fleecing-format based fleecing ===\n') -test(True, True) +test_pull(True, True) log('=== Test fleecing-format based fleecing with bitmap ===\n') -test(True, True, bitmap=True) +test_pull(True, True, bitmap=True) + +log('=== Test push backup with fleecing ===\n') +test_push()
tests/qemu-iotests/tests/image-fleecing.out +63 -0
66 lines not on this page · raw message
Signature · 1 line
2.29.2
ping )
Quoted 76 lines · Vladimir Sementsov-Ogievskiy
Hi all!
That continues "[PATCH RFC DRAFT 00/11] Make image fleecing more usable" and supersedes "[PATCH v2 for-6.2 0/6] push backup with fleecing"
Supersedes: <[email protected]>
Supersedes: <[email protected]>There several improvements to fleecing scheme:
1. support bitmap in copy-before-write filter
2. introduce fleecing block driver, which opens the door for a lot of image fleecing improvements.
See "block: introduce fleecing block driver" commit message for details.3. support "push backup with fleecing" scheme, when backup job is a client of common fleecing scheme. That helps when writes to final backup target are slow and we don't want guest writes hang waiting for copy-before-write operations to final target.
Vladimir Sementsov-Ogievskiy (19):
block/block-copy: movecopy_bitmapinitialization to
block_copy_state_new()
block/dirty-bitmap:bdrv_merge_dirty_bitmap(): add return valueblock/block-copy:block_copy_state_new(): add bitmap parameterblock/copy-before-write: add bitmap open parameterblock/block-copy: addblock_copy_reset()
block: intoduce reqlist
block/dirty-bitmap: introducebdrv_dirty_bitmap_status()block/reqlist: addreqlist_wait_all()
block: introduce FleecingState class
block: introduce fleecing block driverblock/copy-before-write: support fleecing block driverblock/block-copy: add write-unchanged modeblock/copy-before-write: use write-unchanged in fleecing mode iotests/image-fleecing: add test-case for fleecing format nodeiotests.py: addqemu_io_pipe_and_status()iotests/image-fleecing: add test case with bitmap
block:blk_root(): return non-const pointer
qapi: backup: add immutable-source parameter iotests/image-fleecing: test push backup with fleecingqapi/block-core.json | 39 ++- block/fleecing.h | 151 ++++++++++++ include/block/block-copy.h | 4 +- include/block/block_int.h | 1 + include/block/dirty-bitmap.h | 4 +- include/block/reqlist.h | 75 ++++++ include/qemu/hbitmap.h | 11 + include/sysemu/block-backend.h | 2 +- block/backup.c | 61 ++++- block/block-backend.c | 2 +- block/block-copy.c | 157 +++++------- block/copy-before-write.c | 70 +++++- block/dirty-bitmap.c | 15 +- block/fleecing-drv.c | 260 ++++++++++++++++++++ block/fleecing.c | 182 ++++++++++++++ block/monitor/bitmap-qmp-cmds.c | 5 +- block/replication.c | 2 +- block/reqlist.c | 84 +++++++ blockdev.c | 1 + util/hbitmap.c | 36 +++ MAINTAINERS | 7 +- block/meson.build | 3 + tests/qemu-iotests/iotests.py | 4 + tests/qemu-iotests/tests/image-fleecing | 178 +++++++++++--- tests/qemu-iotests/tests/image-fleecing.out | 221 ++++++++++++++++- 25 files changed, 1420 insertions(+), 155 deletions(-)create mode 100644
block/fleecing.h
create mode 100644include/block/reqlist.h
create mode 100644block/fleecing-drv.c
create mode 100644block/fleecing.c
create mode 100644block/reqlist.c
Signature · 2 lines
Best regards, Vladimir