Block patches
The following changes since commit 31ee895047bdcf7387e3570cbd2a473c6f744b08:
Merge remote-tracking branch 'remotes/jasowang/tags/net-pull-request' into staging (2021-01-25 15:56:13 +0000)
are available in the Git repository at:
https://github.com/XanClic/qemu.git tags/pull-block-2021-01-26
for you to fetch changes up to bb24cdc5efee580e81f71c5ff0fd980f2cc179d0:
iotests/178: Pass value to invalid option (2021-01-26 14:36:37 +0100)
----------------------------------------------------------------
Block patches:
- Make backup block jobs use asynchronous requests with the block-copy module
- Use COR filter node for stream block jobs
- Make coroutine-sigaltstack’s qemu_coroutine_new() function thread-safe
- Report error string when file locking fails with an unexpected errno
- iotest fixes, additions, and some refactoring
----------------------------------------------------------------
Alberto Garcia (1):
iotests: Add test for the regression fixed in c8bf9a9169
Andrey Shinkevich (10):
copy-on-read: support preadv/pwritev_part functions
block: add API function to insert a node
copy-on-read: add filter drop function
qapi: add filter-node-name to block-stream
qapi: copy-on-read filter: add 'bottom' option
iotests: add #310 to test bottom node in COR driver
block: include supported_read_flags into BDS structure
copy-on-read: skip non-guest reads if no copy needed
stream: rework backing-file changing
block: apply COR-filter to block-stream jobs
David Edmondson (1):
block: report errno when flock fcntl fails
Max Reitz (14):
iotests.py: Assume a couple of variables as given iotests/297: Rewrite in Python and extend reach
iotests: Move try_remove to iotests.py iotests/129: Remove test images in tearDown() iotests/129: Do not check @busy iotests/129: Use throttle node iotests/129: Actually test a commit job iotests/129: Limit mirror job's buffer size iotests/129: Clean up pylint and mypy complaints iotests/300: Clean up pylint and mypy complaints
coroutine-sigaltstack: Add SIGUSR2 mutex iotests/129: Limit backup's max-chunk/max-workers iotests/118: Drop 'change' test iotests/178: Pass value to invalid option
Vladimir Sementsov-Ogievskiy (27):
iotests: fix _check_o_direct
qapi: block-stream: add "bottom" argument
iotests: 30: prepare to COR filter insertion by stream job block/stream: add s->target_bs
qapi: backup: add perf.use-copy-range parameter block/block-copy: More explicit call_state block/block-copy: implement block_copy_async block/block-copy: add max_chunk and max_workers parameters block/block-copy: add list of all call-states block/block-copy: add ratelimit to block-copy block/block-copy: add block_copy_cancel
blockjob: add set_speed to BlockJobDriver
job: call job_enter from job_pause
qapi: backup: add max-chunk and max-workers to x-perf struct
iotests: 56: prepare for backup over block-copy
iotests: 185: prepare for backup over block-copy
iotests: 219: prepare for backup over block-copy
iotests: 257: prepare for backup over block-copy block/block-copy: make progress_bytes_callback optional block/backup: drop extra gotos from backup_run()
backup: move to block-copy
qapi: backup: disable copy_range by default block/block-copy: drop unused block_copy_set_progress_callback() block/block-copy: drop unused argument of block_copy() simplebench/bench_block_job: use correct shebang line with python3
simplebench: bench_block_job: add cmd_options argument
simplebench: add bench-backup.py
qapi/block-core.json | 66 +++++- block/backup-top.h | 1 + block/copy-on-read.h | 32 +++ include/block/block-copy.h | 61 ++++- include/block/block.h | 10 +- include/block/block_int.h | 15 +- include/block/blockjob_int.h | 2 + block.c | 25 ++ block/backup-top.c | 6 +- block/backup.c | 233 ++++++++++++------- block/block-copy.c | 227 +++++++++++++++--- block/copy-on-read.c | 184 ++++++++++++++- block/file-posix.c | 38 ++- block/io.c | 10 +- block/monitor/block-hmp-cmds.c | 7 +- block/replication.c | 2 + block/stream.c | 185 +++++++++------ blockdev.c | 83 +++++-- blockjob.c | 6 + job.c | 3 + util/coroutine-sigaltstack.c | 9 + scripts/simplebench/bench-backup.py | 167 ++++++++++++++ scripts/simplebench/bench-example.py | 2 +- scripts/simplebench/bench_block_job.py | 13 +- tests/qemu-iotests/030 | 12 +- tests/qemu-iotests/056 | 9 +- tests/qemu-iotests/109.out | 24 ++ tests/qemu-iotests/118 | 20 +- tests/qemu-iotests/118.out | 4 +- tests/qemu-iotests/124 | 8 +- tests/qemu-iotests/129 | 79 ++++--- tests/qemu-iotests/141.out | 2 +- tests/qemu-iotests/178 | 2 +- tests/qemu-iotests/178.out.qcow2 | 2 +- tests/qemu-iotests/178.out.raw | 2 +- tests/qemu-iotests/185 | 3 +- tests/qemu-iotests/185.out | 3 +- tests/qemu-iotests/219 | 13 +- tests/qemu-iotests/245 | 20 +- tests/qemu-iotests/257 | 1 + tests/qemu-iotests/257.out | 306 ++++++++++++------------- tests/qemu-iotests/297 | 112 +++++++-- tests/qemu-iotests/297.out | 5 +- tests/qemu-iotests/300 | 19 +- tests/qemu-iotests/310 | 117 ++++++++++ tests/qemu-iotests/310.out | 15 ++ tests/qemu-iotests/313 | 104 +++++++++ tests/qemu-iotests/313.out | 29 +++ tests/qemu-iotests/common.rc | 7 +- tests/qemu-iotests/group | 2 + tests/qemu-iotests/iotests.py | 37 +-- 51 files changed, 1797 insertions(+), 547 deletions(-) create mode 100644 block/copy-on-read.h create mode 100755 scripts/simplebench/bench-backup.py create mode 100755 tests/qemu-iotests/310 create mode 100644 tests/qemu-iotests/310.out create mode 100755 tests/qemu-iotests/313 create mode 100644 tests/qemu-iotests/313.out
Signature · 1 line
2.29.2
[PULL 01/53] iotests: fix _check_o_direct
From: Vladimir Sementsov-Ogievskiy <[email protected]>
Unfortunately commit "iotests: handle tmpfs" breaks running iotests with -nbd -nocache, as _check_o_direct tries to create $TEST_IMG.test_o_direct, but in case of nbd TEST_IMG is something like nbd+unix:///... , and test fails with message
qemu-img: nbd+unix:///?socket[...]test_o_direct: Protocol driver
'nbd' does not support image creation, and opening the image
failed: Failed to connect to '/tmp/tmp.[...]/nbd/test_o_direct': No such file or directory
Use TEST_DIR instead.
Message-Id: <[email protected]>
--- tests/qemu-iotests/common.rc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
tests/qemu-iotests/common.rc +4 -3
@@ -821,9 +821,10 @@ _supported_cache_modes() # Check whether the filesystem supports O_DIRECT _check_o_direct() { - $QEMU_IMG create -f raw "$TEST_IMG".test_o_direct 1M > /dev/null - out=$($QEMU_IO -f raw -t none -c quit "$TEST_IMG".test_o_direct 2>&1) - rm -f "$TEST_IMG".test_o_direct + testfile="$TEST_DIR"/_check_o_direct + $QEMU_IMG create -f raw "$testfile" 1M > /dev/null + out=$($QEMU_IO -f raw -t none -c quit "$testfile" 2>&1) + rm -f "$testfile" [[ "$out" != *"O_DIRECT"* ]] }
Signature · 1 line
2.29.2
[PULL 02/53] copy-on-read: support preadv/pwritev_part functions
In reply to Max ReitzFrom: Andrey Shinkevich <[email protected]>
Add support for the recently introduced functionsbdrv_co_preadv_part()
andbdrv_co_pwritev_part()
to the COR-filter driver.
Message-Id: <[email protected]>
--- block/copy-on-read.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-)
block/copy-on-read.c +16 -12
@@ -74,21 +74,25 @@ static int64_t cor_getlength(BlockDriverState *bs) } -static int coroutine_fn cor_co_preadv(BlockDriverState *bs, -uint64_t offset,uint64_t bytes, -QEMUIOVector *qiov,int flags) +static int coroutine_fn cor_co_preadv_part(BlockDriverState *bs, +uint64_t offset,uint64_t bytes, +QEMUIOVector *qiov, +size_t qiov_offset, +int flags) { -return bdrv_co_preadv (bs->file, offset, bytes, qiov, - flags |BDRV_REQ_COPY_ON_READ ); +return bdrv_co_preadv_part (bs->file, offset, bytes, qiov, qiov_offset, + flags |BDRV_REQ_COPY_ON_READ ); } -static int coroutine_fn cor_co_pwritev(BlockDriverState *bs, -uint64_t offset,uint64_t bytes, -QEMUIOVector *qiov,int flags) +static int coroutine_fn cor_co_pwritev_part(BlockDriverState *bs, +uint64_t offset, +uint64_t bytes, +QEMUIOVector *qiov, +size_t qiov_offset,int flags) { - -return bdrv_co_pwritev (bs->file, offset, bytes, qiov, flags); +return bdrv_co_pwritev_part (bs->file, offset, bytes, qiov, qiov_offset, + flags); }
@@ -137,8 +141,8 @@ static BlockDriver bdrv_copy_on_read = { .bdrv_getlength = cor_getlength, - .bdrv_co_preadv = cor_co_preadv, - .bdrv_co_pwritev = cor_co_pwritev, + .bdrv_co_preadv_part = cor_co_preadv_part, + .bdrv_co_pwritev_part = cor_co_pwritev_part, .bdrv_co_pwrite_zeroes = cor_co_pwrite_zeroes, .bdrv_co_pdiscard = cor_co_pdiscard, .bdrv_co_pwritev_compressed = cor_co_pwritev_compressed,
Signature · 1 line
2.29.2
[PULL 04/53] copy-on-read: add filter drop function
In reply to Max ReitzFrom: Andrey Shinkevich <[email protected]>
Provide API for the COR-filter removal. Also, drop the filter child permissions for an inactive state when the filter node is being removed.
To insert the filter, the block generic layer function bdrv_insert_node() can be used.
The new function bdrv_cor_filter_drop() may be considered as an intermediate solution before the QEMU permission update system has overhauled. Then we are able to implement the API function bdrv_remove_node() on the block generic layer.
Message-Id: <[email protected]>
--- block/copy-on-read.h | 32 +++++++++++++++++++++++++ block/copy-on-read.c | 56 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 block/copy-on-read.h
block/copy-on-read.h new file +32 -0
@@ -0,0 +1,32 @@ +/* +* Copy-on-read filter block driver +* +* The filter driver performs Copy-On-Read (COR) operations +* +* Copyright (c) 2018-2020 Virtuozzo International GmbH. +* +* Author: +* Andrey Shinkevich <[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/>. +*/ + +#ifndef BLOCK_COPY_ON_READ +#define BLOCK_COPY_ON_READ + +#include "block/block_int.h" + +void bdrv_cor_filter_drop (BlockDriverState *cor_filter_bs); + +#endif /* BLOCK_COPY_ON_READ */
block/copy-on-read.c +56 -0
91 lines not on this page · raw message
Signature · 1 line
2.29.2
[PULL 11/53] qapi: block-stream: add "bottom" argument
In reply to Max ReitzFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
The code already don't freeze base node and we try to make it prepared for the situation when base node is changed during the operation. In other words, block-stream doesn't own base node.
Let's introduce a new interface which should replace the current one, which will in better relations with the code. Specifying bottom node instead of base, and requiring it to be non-filter gives us the following benefits:
- drop difference between above_base and base_overlay, which will be renamed to just bottom, when old interface dropped
- clean way to work with parallel streams/commits on the same backing chain, which otherwise become a problem when we introduce a filter for stream job
- cleaner interface. Nobody will surprised the fact that base node may disappear during block-stream, when there is no word about "base" in the interface.
Message-Id: <[email protected]>
--- qapi/block-core.json | 12 ++++--- include/block/block_int.h | 1 + block/monitor/block-hmp-cmds.c | 3 +- block/stream.c | 50 +++++++++++++++++++--------- blockdev.c | 59 ++++++++++++++++++++++++++++------ 5 files changed, 94 insertions(+), 31 deletions(-)
qapi/block-core.json +8 -4
@@ -2517,10 +2517,14 @@ # @device: the device or node name of the top image # # @base: the common backing file name. -# It cannot be set if @base-node is also set. +# It cannot be set if @base-node or @bottom is also set. # # @base-node: the node name of the backing file. -# It cannot be set if @base is also set. (Since 2.8) +# It cannot be set if @base or @bottom is also set. (Since 2.8) +# +# @bottom: the last node in the chain that should be streamed into +# top. It cannot be set if @base or @base-node is also set. +# It cannot be filter node. (Since 6.0) # # @backing-file: The backing file string to write into the top # image. This filename is not validated.
@@ -2576,8 +2580,8 @@ ## { 'command': 'block-stream', 'data': { '*job-id': 'str', 'device': 'str', '*base': 'str', - '*base-node': 'str', '*backing-file': 'str', '*speed': 'int', - '*on-error': 'BlockdevOnError', + '*base-node': 'str', '*backing-file': 'str', '*bottom': 'str', + '*speed': 'int', '*on-error': 'BlockdevOnError', '*filter-node-name': 'str', '*auto-finalize': 'bool', '*auto-dismiss': 'bool' } }
include/block/block_int.h +1 -0
@@ -1161,6 +1161,7 @@ int is_windows_drive(const char *filename);*/ void stream_start(const char *job_id, BlockDriverState *bs, BlockDriverState *base, const char *backing_file_str, + BlockDriverState *bottom, int creation_flags, int64_t speed, BlockdevOnError on_error, const char *filter_node_name,
block/monitor/block-hmp-cmds.c +2 -1
@@ -507,7 +507,8 @@ void hmp_block_stream(Monitor *mon, const QDict *qdict)int64_t speed =qdict_get_try_int (qdict,"speed" ,0 );qmp_block_stream (true, device, device, base !=NULL , base, false,NULL , - false,NULL ,qdict_haskey (qdict,"speed" ), speed, true, + false,NULL , false,NULL , +qdict_haskey (qdict,"speed" ), speed, true,BLOCKDEV_ON_ERROR_REPORT , false,NULL , false, false, false, false, &error);
block/stream.c +34 -16
65 lines not on this page · raw message
blockdev.c +49 -10
94 lines not on this page · raw message
Signature · 1 line
2.29.2
[PULL 03/53] block: add API function to insert a node
In reply to Max ReitzFrom: Andrey Shinkevich <[email protected]>
Provide API for insertion a node to backing chain.
Message-Id: <[email protected]>
--- include/block/block.h | 2 ++ block.c | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+)
include/block/block.h +2 -0
@@ -358,6 +358,8 @@ void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top, Error **errp);void bdrv_replace_node (BlockDriverState *from,BlockDriverState *to,Error **errp); +BlockDriverState *bdrv_insert_node (BlockDriverState *bs,QDict *node_options, +int flags,Error **errp);int bdrv_parse_aio (const char *mode,int *flags);int bdrv_parse_cache_mode (const char *mode,int *flags,bool *writethrough);
block.c +25 -0
@@ -4660,6 +4660,31 @@ static void bdrv_delete(BlockDriverState *bs)g_free (bs); } +BlockDriverState *bdrv_insert_node (BlockDriverState *bs,QDict *node_options, +int flags,Error **errp) +{ +BlockDriverState *new_node_bs; +Error *local_err =NULL ; + + new_node_bs =bdrv_open (NULL ,NULL , node_options, flags, errp); +if (new_node_bs ==NULL ) { +error_prepend (errp,"Could not create node: " ); +return NULL ; + } + +bdrv_drained_begin (bs); +bdrv_replace_node (bs, new_node_bs, &local_err); +bdrv_drained_end (bs); + +if (local_err) { +bdrv_unref (new_node_bs); +error_propagate (errp, local_err); +return NULL ; + } + +return new_node_bs; +} +/* * Run consistency checks on an image *
Signature · 1 line
2.29.2
[PULL 14/53] block: apply COR-filter to block-stream jobs
In reply to Max ReitzFrom: Andrey Shinkevich <[email protected]>
This patch completes the series with the COR-filter applied to block-stream operations.
Adding the filter makes it possible in future implement discarding copied regions in backing files during the block-stream job, to reduce the disk overuse (we need control on permissions).
Also, the filter now is smart enough to do copy-on-read with specified base, so we have benefit on guest reads even when doing block-stream of the part of the backing chain.
Several iotests are slightly modified due to filter insertion.
Message-Id: <[email protected]>
--- block/stream.c | 105 ++++++++++++++++++++++--------------- tests/qemu-iotests/030 | 8 +-- tests/qemu-iotests/141.out | 2 +- tests/qemu-iotests/245 | 20 ++++--- 4 files changed, 80 insertions(+), 55 deletions(-)
block/stream.c +62 -43
@@ -17,8 +17,10 @@#include "block/blockjob_int.h" #include "qapi/error.h" #include "qapi/qmp/qerror.h" +#include "qapi/qmp/qdict.h" #include "qemu/ratelimit.h" #include "sysemu/block-backend.h" +#include "block/copy-on-read.h" enum {/*
@@ -33,11 +35,11 @@ typedef struct StreamBlockJob {BlockJob common;BlockDriverState *base_overlay;/* COW overlay (stream from this) */ BlockDriverState *above_base;/* Node directly above the base */ +BlockDriverState *cor_filter_bs;BlockDriverState *target_bs;BlockdevOnError on_error;char *backing_file_str;bool bs_read_only; -bool chain_frozen; } StreamBlockJob; static int coroutine_fn stream_populate(BlockBackend *blk,
@@ -45,17 +47,7 @@ static int coroutine_fn stream_populate(BlockBackend *blk, {assert (bytes <SIZE_MAX ); -return blk_co_preadv (blk, offset, bytes,NULL , -BDRV_REQ_COPY_ON_READ |BDRV_REQ_PREFETCH ); -} - -static void stream_abort (Job *job) -{ -StreamBlockJob *s =container_of (job, StreamBlockJob, common.job); - -if (s->chain_frozen) { -bdrv_unfreeze_backing_chain (s->target_bs, s->above_base); - } +return blk_co_preadv (blk, offset, bytes,NULL ,BDRV_REQ_PREFETCH ); }static int stream_prepare (Job *job)
@@ -67,8 +59,9 @@ static int stream_prepare(Job *job)Error *local_err =NULL ;int ret =0 ; -bdrv_unfreeze_backing_chain (s->target_bs, s->above_base); - s->chain_frozen = false; +/* We should drop filter at this point, as filter hold the backing chain */ +bdrv_cor_filter_drop (s->cor_filter_bs); + s->cor_filter_bs =NULL ;if (bdrv_cow_child (unfiltered_bs)) {const char *base_id =NULL , *base_fmt =NULL ;
@@ -94,6 +87,11 @@ static void stream_clean(Job *job)StreamBlockJob *s =container_of (job, StreamBlockJob, common.job);BlockJob *bjob = &s->common; +if (s->cor_filter_bs) { +bdrv_cor_filter_drop (s->cor_filter_bs); + s->cor_filter_bs =NULL ; + } +/* Reopen the image back in read-only mode if necessary */ if (s->bs_read_only) {/* Give up write permissions before making it read-only */
@@ -109,7 +107,6 @@ static int coroutine_fn stream_run(Job *job, Error **errp)StreamBlockJob *s =container_of (job, StreamBlockJob, common.job);BlockBackend *blk = s->common.blk;BlockDriverState *unfiltered_bs =bdrv_skip_filters (s->target_bs); -bool enable_cor = !bdrv_cow_child (s->base_overlay);int64_t len;int64_t offset =0 ;uint64_t delay_ns =0 ;
@@ -127,15 +124,6 @@ static int coroutine_fn stream_run(Job *job, Error **errp) }job_progress_set_remaining (&s->common.job, len); -/* Turn on copy-on-read for the whole block device so that guest read -* requests help us make progress. Only do this when copying the entire -* backing chain since the copy-on-read operation does not take base into -* account. -*/ -if (enable_cor) { -bdrv_enable_copy_on_read (s->target_bs); - } -for ( ; offset < len; offset += n) {bool copy;int ret;
@@ -194,10 +182,6 @@ static int coroutine_fn stream_run(Job *job, Error **errp) } } -if (enable_cor) { -bdrv_disable_copy_on_read (s->target_bs); - } -/* Do not remove the backing file if an error was there but ignored. */ return error; }
@@ -209,7 +193,6 @@ static const BlockJobDriver stream_job_driver = { .free = block_job_free, .run = stream_run, .prepare = stream_prepare, - .abort = stream_abort, .clean = stream_clean, .user_resume = block_job_user_resume, },
@@ -228,7 +211,9 @@ void stream_start(const char *job_id, BlockDriverState *bs,bool bs_read_only;int basic_flags =BLK_PERM_CONSISTENT_READ |BLK_PERM_WRITE_UNCHANGED ;BlockDriverState *base_overlay; +BlockDriverState *cor_filter_bs =NULL ;BlockDriverState *above_base; +QDict *opts;assert (!(base && bottom));assert (!(backing_file_str && bottom));
@@ -266,30 +251,62 @@ void stream_start(const char *job_id, BlockDriverState *bs, } } -if (bdrv_freeze_backing_chain (bs, above_base, errp) <0 ) { -return ; - } -/* Make sure that the image is opened in read-write mode */ bs_read_only =bdrv_is_read_only (bs);if (bs_read_only) { -if (bdrv_reopen_set_read_only (bs, false, errp) !=0 ) { - bs_read_only = false; - goto fail; +int ret; +/* Hold the chain during reopen */ +if (bdrv_freeze_backing_chain (bs, above_base, errp) <0 ) { +return ; + } + + ret =bdrv_reopen_set_read_only (bs, false, errp); + +/* failure, or cor-filter will hold the chain */ +bdrv_unfreeze_backing_chain (bs, above_base); + +if (ret <0 ) { +return ; } } -/* Prevent concurrent jobs trying to modify the graph structure here, we -* already have our own plans. Also don't allow resize as the image size is -* queried only at the job start and then cached. */ - s =block_job_create (job_id, &stream_job_driver,NULL , bs, - basic_flags |BLK_PERM_GRAPH_MOD , + opts =qdict_new (); + +qdict_put_str (opts,"driver" ,"copy-on-read" ); +qdict_put_str (opts,"file" ,bdrv_get_node_name (bs)); +/* Pass the base_overlay node name as 'bottom' to COR driver */ +qdict_put_str (opts,"bottom" , base_overlay->node_name); +if (filter_node_name) { +qdict_put_str (opts,"node-name" , filter_node_name); + } + + cor_filter_bs =bdrv_insert_node (bs, opts,BDRV_O_RDWR , errp); +if (!cor_filter_bs) { + goto fail; + } + +if (!filter_node_name) { + cor_filter_bs->implicit = true; + } + + s =block_job_create (job_id, &stream_job_driver,NULL , cor_filter_bs, +BLK_PERM_CONSISTENT_READ , basic_flags |BLK_PERM_WRITE , speed, creation_flags,NULL ,NULL , errp);if (!s) { goto fail; } +/* +* Prevent concurrent jobs trying to modify the graph structure here, we +* already have our own plans. Also don't allow resize as the image size is +* queried only at the job start and then cached. +*/ +if (block_job_add_bdrv (&s->common,"active node" , bs,0 , + basic_flags |BLK_PERM_WRITE , &error_abort)) { + goto fail; + } +/* Block all intermediate nodes between bs and base, because they will * disappear from the chain after this operation. The streaming job reads * every block only once, assuming that it doesn't change, so forbid writes
@@ -310,9 +327,9 @@ void stream_start(const char *job_id, BlockDriverState *bs, s->base_overlay = base_overlay; s->above_base = above_base; s->backing_file_str =g_strdup (backing_file_str); + s->cor_filter_bs = cor_filter_bs; s->target_bs = bs; s->bs_read_only = bs_read_only; - s->chain_frozen = true; s->on_error = on_error;trace_stream_start (bs, base, s);
@@ -320,8 +337,10 @@ void stream_start(const char *job_id, BlockDriverState *bs,return ; fail: +if (cor_filter_bs) { +bdrv_cor_filter_drop (cor_filter_bs); + }if (bs_read_only) {bdrv_reopen_set_read_only (bs, true,NULL ); } -bdrv_unfreeze_backing_chain (bs, above_base); }
tests/qemu-iotests/030 +5 -3
@@ -279,12 +279,14 @@ class TestParallelOps(iotests.QMPTestCase): self.assert_no_active_block_jobs() # Set a speed limit to make sure that this job blocks the rest - result = self.vm.qmp('block-stream', device='node4', job_id='stream-node4', base=self.imgs[1], speed=1024*1024) + result = self.vm.qmp('block-stream', device='node4', + job_id='stream-node4', base=self.imgs[1], + filter_node_name='stream-filter', speed=1024*1024) self.assert_qmp(result, 'return', {}) result = self.vm.qmp('block-stream', device='node5', job_id='stream-node5', base=self.imgs[2]) self.assert_qmp(result, 'error/desc', - "Node 'node4' is busy: block device is in use by block job: stream") + "Node 'stream-filter' is busy: block device is in use by block job: stream") result = self.vm.qmp('block-stream', device='node3', job_id='stream-node3', base=self.imgs[2]) self.assert_qmp(result, 'error/desc',
@@ -297,7 +299,7 @@ class TestParallelOps(iotests.QMPTestCase): # block-commit should also fail if it touches nodes used by the stream job result = self.vm.qmp('block-commit', device='drive0', base=self.imgs[4], job_id='commit-node4') self.assert_qmp(result, 'error/desc', - "Node 'node4' is busy: block device is in use by block job: stream") + "Node 'stream-filter' is busy: block device is in use by block job: stream") result = self.vm.qmp('block-commit', device='drive0', base=self.imgs[1], top=self.imgs[3], job_id='commit-node1') self.assert_qmp(result, 'error/desc',
tests/qemu-iotests/141.out +1 -1
@@ -165,7 +165,7 @@ wrote 1048576/1048576 bytes at offset 0 {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "running", "id": "job0"}} {'execute': 'blockdev-del', 'arguments': {'node-name': 'drv0'}} -{"error": {"class": "GenericError", "desc": "Node drv0 is in use"}} +{"error": {"class": "GenericError", "desc": "Node 'drv0' is busy: block device is in use by block job: stream"}} {'execute': 'block-job-cancel', 'arguments': {'device': 'job0'}} {"return": {}}
tests/qemu-iotests/245 +12 -8
@@ -893,20 +893,24 @@ class TestBlockdevReopen(iotests.QMPTestCase): # hd1 <- hd0 result = self.vm.qmp('block-stream', conv_keys = True, job_id = 'stream0', - device = 'hd1', auto_finalize = False) + device = 'hd1', filter_node_name='cor', + auto_finalize = False) self.assert_qmp(result, 'return', {}) - # We can't reopen with the original options because that would - # make hd1 read-only and block-stream requires it to be read-write - # (Which error message appears depends on whether the stream job is - # already done with copying at this point.) + # We can't reopen with the original options because there is a filter + # inserted by stream job above hd1. self.reopen(opts, {}, - ["Can't set node 'hd1' to r/o with copy-on-read enabled", - "Cannot make block node read-only, there is a writer on it"]) + "Cannot change the option 'backing.backing.file.node-name'") + + # We can't reopen hd1 to read-only, as block-stream requires it to be + # read-write + self.reopen(opts['backing'], {'read-only': True}, + "Cannot make block node read-only, there is a writer on it") # We can't remove hd2 while the stream job is ongoing opts['backing']['backing'] = None - self.reopen(opts, {'backing.read-only': False}, "Cannot change 'backing' link from 'hd1' to 'hd2'") + self.reopen(opts['backing'], {'read-only': False}, + "Cannot change 'backing' link from 'hd1' to 'hd2'") # We can detach hd1 from hd0 because it doesn't affect the stream job opts['backing'] = None
Signature · 1 line
2.29.2
Re: [PULL 14/53] block: apply COR-filter to block-stream jobs
Hi Andrey,
Quoted 28 lines · Max Reitz
From: Andrey Shinkevich <[email protected]>
This patch completes the series with the COR-filter applied to block-stream operations.
Adding the filter makes it possible in future implement discarding copied regions in backing files during the block-stream job, to reduce the disk overuse (we need control on permissions).
Also, the filter now is smart enough to do copy-on-read with specified base, so we have benefit on guest reads even when doing block-stream of the part of the backing chain.
Several iotests are slightly modified due to filter insertion.
Signed-off-by Andrey Shinkevich <[email protected]>Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>Message-Id: <[email protected]>
Reviewed-by Max Reitz <[email protected]>Signed-off-by Max Reitz <[email protected]>--- block/stream.c | 105 ++++++++++++++++++++++--------------- tests/qemu-iotests/030 | 8 +-- tests/qemu-iotests/141.out | 2 +- tests/qemu-iotests/245 | 20 ++++--- 4 files changed, 80 insertions(+), 55 deletions(-)block/stream.c +0
-0
...
Quoted 36 lines
block/stream.c +14
-7@@ -228,7 +211,9 @@ void stream_start(const char *job_id, BlockDriverState *bs,bool bs_read_only;int basic_flags =BLK_PERM_CONSISTENT_READ |BLK_PERM_WRITE_UNCHANGED ;BlockDriverState *base_overlay; +BlockDriverState *cor_filter_bs =NULL ;BlockDriverState *above_base; +QDict *opts;assert (!(base && bottom));assert (!(backing_file_str && bottom));@@ -266,30 +251,62 @@ void stream_start(const char *job_id, BlockDriverState *bs, } } -if (bdrv_freeze_backing_chain (bs, above_base, errp) <0 ) { -return ; - } -/* Make sure that the image is opened in read-write mode */ bs_read_only =bdrv_is_read_only (bs);if (bs_read_only) { -if (bdrv_reopen_set_read_only (bs, false, errp) !=0 ) { - bs_read_only = false; - goto fail; +int ret; +/* Hold the chain during reopen */ +if (bdrv_freeze_backing_chain (bs, above_base, errp) <0 ) { +return ; + } + + ret =bdrv_reopen_set_read_only (bs, false, errp); + +/* failure, or cor-filter will hold the chain */ +bdrv_unfreeze_backing_chain (bs, above_base); + +if (ret <0 ) {
block/stream.c void stream_start(const char *job_id, BlockDriverState *bs, · line 273
Quoted 10 lines
block/stream.c +2
-5+return ; } } -/* Prevent concurrent jobs trying to modify the graph structure here, we -* already have our own plans. Also don't allow resize as the image size is -* queried only at the job start and then cached. */ - s = block_job_create(job_id, &stream_job_driver, NULL, bs, - basic_flags | BLK_PERM_GRAPH_MOD, + opts =qdict_new ();
Coverity reported (CID 1445793) that this resource could be leaked...
block/stream.c void stream_start(const char *job_id, BlockDriverState *bs, · line 284
Quoted 11 lines
block/stream.c +11
-0+ +qdict_put_str (opts,"driver" ,"copy-on-read" ); +qdict_put_str (opts,"file" ,bdrv_get_node_name (bs)); +/* Pass the base_overlay node name as 'bottom' to COR driver */ +qdict_put_str (opts,"bottom" , base_overlay->node_name); +if (filter_node_name) { +qdict_put_str (opts,"node-name" , filter_node_name); + } + + cor_filter_bs =bdrv_insert_node (bs, opts,BDRV_O_RDWR , errp); +if (!cor_filter_bs) {
... probably here.
Should we call g_free(opts) here?
Quoted 51 lines
block/stream.c +23
-2+ goto fail; + } + +if (!filter_node_name) { + cor_filter_bs->implicit = true; + } + + s =block_job_create (job_id, &stream_job_driver,NULL , cor_filter_bs, +BLK_PERM_CONSISTENT_READ , basic_flags |BLK_PERM_WRITE , speed, creation_flags,NULL ,NULL , errp);if (!s) { goto fail; } +/* +* Prevent concurrent jobs trying to modify the graph structure here, we +* already have our own plans. Also don't allow resize as the image size is +* queried only at the job start and then cached. +*/ +if (block_job_add_bdrv (&s->common,"active node" , bs,0 , + basic_flags |BLK_PERM_WRITE , &error_abort)) { + goto fail; + } +/* Block all intermediate nodes between bs and base, because they will * disappear from the chain after this operation. The streaming job reads * every block only once, assuming that it doesn't change, so forbid writes @@ -310,9 +327,9 @@ void stream_start(const char *job_id, BlockDriverState *bs, s->base_overlay = base_overlay; s->above_base = above_base; s->backing_file_str =g_strdup (backing_file_str); + s->cor_filter_bs = cor_filter_bs; s->target_bs = bs; s->bs_read_only = bs_read_only; - s->chain_frozen = true; s->on_error = on_error;trace_stream_start (bs, base, s);@@ -320,8 +337,10 @@ void stream_start(const char *job_id, BlockDriverState *bs,return ; fail: +if (cor_filter_bs) { +bdrv_cor_filter_drop (cor_filter_bs); + }if (bs_read_only) {bdrv_reopen_set_read_only (bs, true,NULL ); } -bdrv_unfreeze_backing_chain (bs, above_base); }
...
Re: [PULL 14/53] block: apply COR-filter to block-stream jobs
Quoted 95 lines · Philippe Mathieu-Daudé
Hi Andrey,
Quoted 28 lines · Max Reitz
From: Andrey Shinkevich <[email protected]>
This patch completes the series with the COR-filter applied to block-stream operations.
Adding the filter makes it possible in future implement discarding copied regions in backing files during the block-stream job, to reduce the disk overuse (we need control on permissions).
Also, the filter now is smart enough to do copy-on-read with specified base, so we have benefit on guest reads even when doing block-stream of the part of the backing chain.
Several iotests are slightly modified due to filter insertion.
Signed-off-by Andrey Shinkevich <[email protected]>Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>Message-Id: <[email protected]>
Reviewed-by Max Reitz <[email protected]>Signed-off-by Max Reitz <[email protected]>--- block/stream.c | 105 ++++++++++++++++++++++--------------- tests/qemu-iotests/030 | 8 +-- tests/qemu-iotests/141.out | 2 +- tests/qemu-iotests/245 | 20 ++++--- 4 files changed, 80 insertions(+), 55 deletions(-)block/stream.c +0
-0...
Quoted 36 lines
block/stream.c +14
-7@@ -228,7 +211,9 @@ void stream_start(const char *job_id, BlockDriverState *bs,bool bs_read_only;int basic_flags =BLK_PERM_CONSISTENT_READ |BLK_PERM_WRITE_UNCHANGED ;BlockDriverState *base_overlay; +BlockDriverState *cor_filter_bs =NULL ;BlockDriverState *above_base; +QDict *opts;assert (!(base && bottom));assert (!(backing_file_str && bottom));@@ -266,30 +251,62 @@ void stream_start(const char *job_id, BlockDriverState *bs, } } -if (bdrv_freeze_backing_chain (bs, above_base, errp) <0 ) { -return ; - } -/* Make sure that the image is opened in read-write mode */ bs_read_only =bdrv_is_read_only (bs);if (bs_read_only) { -if (bdrv_reopen_set_read_only (bs, false, errp) !=0 ) { - bs_read_only = false; - goto fail; +int ret; +/* Hold the chain during reopen */ +if (bdrv_freeze_backing_chain (bs, above_base, errp) <0 ) { +return ; + } + + ret =bdrv_reopen_set_read_only (bs, false, errp); + +/* failure, or cor-filter will hold the chain */ +bdrv_unfreeze_backing_chain (bs, above_base); + +if (ret <0 ) {block/stream.c void stream_start(const char *job_id, BlockDriverState *bs, · line 273
Quoted 10 lines
block/stream.c +2
-5+return ; } } -/* Prevent concurrent jobs trying to modify the graph structure here, we -* already have our own plans. Also don't allow resize as the image size is -* queried only at the job start and then cached. */ - s = block_job_create(job_id, &stream_job_driver, NULL, bs, - basic_flags | BLK_PERM_GRAPH_MOD, + opts =qdict_new ();Coverity reported (CID 1445793) that this resource could be leaked...
block/stream.c void stream_start(const char *job_id, BlockDriverState *bs, · line 284
Quoted 11 lines
block/stream.c +11
-0+ +qdict_put_str (opts,"driver" ,"copy-on-read" ); +qdict_put_str (opts,"file" ,bdrv_get_node_name (bs)); +/* Pass the base_overlay node name as 'bottom' to COR driver */ +qdict_put_str (opts,"bottom" , base_overlay->node_name); +if (filter_node_name) { +qdict_put_str (opts,"node-name" , filter_node_name); + } + + cor_filter_bs =bdrv_insert_node (bs, opts,BDRV_O_RDWR , errp); +if (!cor_filter_bs) {... probably here.
Quoted 1 line
Should we call
g_free(opts)here?
Actually, not..
bdrv_insert_node() calls bdrv_open() which eats options even on failure.
I see, CID already marked false-positive?
Quoted 55 lines
Quoted 52 lines
block/stream.c +23
-2+ goto fail; + } + +if (!filter_node_name) { + cor_filter_bs->implicit = true; + } + + s =block_job_create (job_id, &stream_job_driver,NULL , cor_filter_bs, +BLK_PERM_CONSISTENT_READ , basic_flags |BLK_PERM_WRITE , speed, creation_flags,NULL ,NULL , errp);if (!s) { goto fail; } +/* +* Prevent concurrent jobs trying to modify the graph structure here, we +* already have our own plans. Also don't allow resize as the image size is +* queried only at the job start and then cached. +*/ +if (block_job_add_bdrv (&s->common,"active node" , bs,0 , + basic_flags |BLK_PERM_WRITE , &error_abort)) { + goto fail; + } +/* Block all intermediate nodes between bs and base, because they will * disappear from the chain after this operation. The streaming job reads * every block only once, assuming that it doesn't change, so forbid writes @@ -310,9 +327,9 @@ void stream_start(const char *job_id, BlockDriverState *bs, s->base_overlay = base_overlay; s->above_base = above_base; s->backing_file_str =g_strdup (backing_file_str); + s->cor_filter_bs = cor_filter_bs; s->target_bs = bs; s->bs_read_only = bs_read_only; - s->chain_frozen = true; s->on_error = on_error;trace_stream_start (bs, base, s);@@ -320,8 +337,10 @@ void stream_start(const char *job_id, BlockDriverState *bs,return ; fail: +if (cor_filter_bs) { +bdrv_cor_filter_drop (cor_filter_bs); + }if (bs_read_only) {bdrv_reopen_set_read_only (bs, true,NULL ); } -bdrv_unfreeze_backing_chain (bs, above_base); }...
Signature · 2 lines
Best regards, Vladimir
Re: [PULL 14/53] block: apply COR-filter to block-stream jobs
Quoted 97 lines · Vladimir Sementsov-Ogievskiy
Quoted 96 lines · Philippe Mathieu-Daudé
Hi Andrey,
Quoted 28 lines · Max Reitz
From: Andrey Shinkevich <[email protected]>
This patch completes the series with the COR-filter applied to block-stream operations.
Adding the filter makes it possible in future implement discarding copied regions in backing files during the block-stream job, to reduce the disk overuse (we need control on permissions).
Also, the filter now is smart enough to do copy-on-read with specified base, so we have benefit on guest reads even when doing block-stream of the part of the backing chain.
Several iotests are slightly modified due to filter insertion.
Signed-off-by Andrey Shinkevich <[email protected]>Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>Message-Id: <[email protected]>
Reviewed-by Max Reitz <[email protected]>Signed-off-by Max Reitz <[email protected]>---
block/stream.c | 105 ++++++++++++++++++++++--------------- tests/qemu-iotests/030 | 8 +-- tests/qemu-iotests/141.out | 2 +-
tests/qemu-iotests/245 | 20 ++++---4 files changed, 80 insertions(+), 55 deletions(-)block/stream.c +0
-0...
Quoted 40 lines
block/stream.c +15
-8@@ -228,7 +211,9 @@ void stream_start(const char *job_id,BlockDriverState *bs, bool bs_read_only; int basic_flags = BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED; BlockDriverState *base_overlay; + BlockDriverState *cor_filter_bs = NULL; BlockDriverState *above_base; + QDict *opts; assert(!(base && bottom)); assert(!(backing_file_str && bottom));@@ -266,30 +251,62 @@ void stream_start(const char *job_id,BlockDriverState *bs, } } - if (bdrv_freeze_backing_chain(bs, above_base, errp) < 0) { - return; - } - /* Make sure that the image is opened in read-write mode */ bs_read_only = bdrv_is_read_only(bs); if (bs_read_only) { - if (bdrv_reopen_set_read_only(bs, false, errp) != 0) { - bs_read_only = false; - goto fail; + int ret; + /* Hold the chain during reopen */ + if (bdrv_freeze_backing_chain(bs, above_base, errp) < 0) { + return; + } + + ret = bdrv_reopen_set_read_only(bs, false, errp); + + /* failure, or cor-filter will hold the chain */ + bdrv_unfreeze_backing_chain(bs, above_base); + + if (ret < 0) { + return; } } - /* Prevent concurrent jobs trying to modify the graph structureQuoted 7 lines
here, we
- * already have our own plans. Also don't allow resize as the image size is
- * queried only at the job start and then cached. */ - s = block_job_create(job_id,&stream_job_driver, NULL, bs, -basic_flags|BLK_PERM_GRAPH_MOD, + opts =qdict_new();Coverity reported (CID 1445793) that this resource could be leaked...
block/stream.c void stream_start(const char *job_id, BlockDriverState *bs, · line 284
Quoted 11 lines
block/stream.c +11
-0+ + qdict_put_str(opts, "driver", "copy-on-read"); + qdict_put_str(opts, "file", bdrv_get_node_name(bs)); + /* Pass the base_overlay node name as 'bottom' to COR driver */ + qdict_put_str(opts, "bottom", base_overlay->node_name); + if (filter_node_name) { + qdict_put_str(opts, "node-name", filter_node_name); + } + + cor_filter_bs = bdrv_insert_node(bs, opts, BDRV_O_RDWR, errp); + if (!cor_filter_bs) {... probably here.
Quoted 8 lines
Quoted 1 line
Should we call
g_free(opts)here?Actually, not..
bdrv_insert_node()callsbdrv_open()which eats options even on failure.I see, CID already marked false-positive?
Yes, I did that.
This isn’t the first time Coverity has reported a failed bdrv_open() call would leak the options QDict. Perhaps someone™ should look into why it likes to thinks that, but so far I haven’t been sufficiently bothered by it.
Max
Re: [PULL 14/53] block: apply COR-filter to block-stream jobs
Quoted 100 lines · Max Reitz
Quoted 99 lines · Vladimir Sementsov-Ogievskiy
Quoted 98 lines · Philippe Mathieu-Daudé
Hi Andrey,
Quoted 29 lines · Max Reitz
From: Andrey Shinkevich <[email protected]>
This patch completes the series with the COR-filter applied to block-stream operations.
Adding the filter makes it possible in future implement discarding copied regions in backing files during the block-stream job, to reduce the disk overuse (we need control on permissions).
Also, the filter now is smart enough to do copy-on-read with specified base, so we have benefit on guest reads even when doing block-stream of the part of the backing chain.
Several iotests are slightly modified due to filter insertion.
Signed-off-by Andrey Shinkevich <[email protected]>Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>Message-Id: <[email protected]>
Reviewed-by Max Reitz <[email protected]>Signed-off-by Max Reitz <[email protected]>---
block/stream.c | 105
++++++++++++++++++++++---------------
tests/qemu-iotests/030 | 8 +--
tests/qemu-iotests/141.out | 2 +-
tests/qemu-iotests/245 | 20 ++++---4 files changed, 80 insertions(+), 55 deletions(-)block/stream.c +0
-0...
Quoted 41 lines
block/stream.c +0
-0@@ -228,7 +211,9 @@ void stream_start(const char *job_id,BlockDriverState *bs, bool bs_read_only;int
basic_flags=BLK_PERM_CONSISTENT_READ|BLK_PERM_WRITE_UNCHANGED;
BlockDriverState*base_overlay;
+ BlockDriverState*cor_filter_bs= NULL; BlockDriverState*above_base;
+ QDict *opts;
assert(!(base && bottom));assert(!(backing_file_str && bottom));block/stream.c +13
-8@@ -266,30 +251,62 @@ void stream_start(const char *job_id,BlockDriverState *bs, } } - if (bdrv_freeze_backing_chain(bs, above_base, errp) < 0) { - return; - } - /* Make sure that the image is opened in read-write mode */ bs_read_only = bdrv_is_read_only(bs); if (bs_read_only) { - if (bdrv_reopen_set_read_only(bs, false, errp) != 0) { - bs_read_only = false; - goto fail; + int ret; + /* Hold the chain during reopen */ + if (bdrv_freeze_backing_chain(bs, above_base, errp) < 0) { + return; + } + + ret = bdrv_reopen_set_read_only(bs, false, errp); + + /* failure, or cor-filter will hold the chain */ + bdrv_unfreeze_backing_chain(bs, above_base); + + if (ret < 0) { + return; } } - /* Prevent concurrent jobs trying to modify the graph structureQuoted 7 lines
here, we
- * already have our own plans. Also don't allow resize as the image size is
- * queried only at the job start and then cached. */ - s = block_job_create(job_id,&stream_job_driver, NULL, bs, -basic_flags|BLK_PERM_GRAPH_MOD, + opts =qdict_new();Coverity reported (CID 1445793) that this resource could be leaked...
block/stream.c void stream_start(const char *job_id, BlockDriverState *bs, · line 284
Quoted 11 lines
block/stream.c +11
-0+ + qdict_put_str(opts, "driver", "copy-on-read"); + qdict_put_str(opts, "file", bdrv_get_node_name(bs)); + /* Pass the base_overlay node name as 'bottom' to COR driver */ + qdict_put_str(opts, "bottom", base_overlay->node_name); + if (filter_node_name) { + qdict_put_str(opts, "node-name", filter_node_name); + } + + cor_filter_bs = bdrv_insert_node(bs, opts, BDRV_O_RDWR, errp); + if (!cor_filter_bs) {... probably here.
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Should we call
g_free(opts)here?Actually, not..
bdrv_insert_node()callsbdrv_open()which eats options even on failure.
Ah OK.
Quoted 4 lines
Quoted 2 lines
I see, CID already marked false-positive?
Yes, I did that.
Thanks Max!
Quoted 8 lines
This isn’t the first time Coverity has reported a failed
bdrv_open()call would leak the options QDict. Perhaps someone™ should look into why it likes to thinks that, but so far I haven’t been sufficiently bothered by it.Max
[PULL 07/53] iotests: add #310 to test bottom node in COR driver
In reply to Max ReitzFrom: Andrey Shinkevich <[email protected]>
The test case #310 is similar to #216 by Max Reitz. The difference is that the test #310 involves a bottom node to the COR filter driver.
Message-Id: <[email protected]>
--- tests/qemu-iotests/310 | 117 +++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/310.out | 15 +++++ tests/qemu-iotests/group | 1 + 3 files changed, 133 insertions(+) create mode 100755 tests/qemu-iotests/310 create mode 100644 tests/qemu-iotests/310.out
tests/qemu-iotests/310 new file +117 -0
@@ -0,0 +1,117 @@ +#!/usr/bin/env python3 +# group: rw quick +# +# Copy-on-read tests using a COR filter with a bottom node +# +# Copyright (C) 2018 Red Hat, Inc. +# Copyright (c) 2020 Virtuozzo International GmbH +# +# 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/>. +# + +import iotests +from iotests import log, qemu_img, qemu_io_silent + +# Need backing file support +iotests.script_initialize(supported_fmts=['qcow2'], + supported_platforms=['linux']) + +log('') +log('=== Copy-on-read across nodes ===') +log('') + +# This test is similar to the 216 one by Max Reitz <[email protected]> +# The difference is that this test case involves a bottom node to the +# COR filter driver. + +with iotests.FilePath('base.img') as base_img_path, \ + iotests.FilePath('mid.img') as mid_img_path, \ + iotests.FilePath('top.img') as top_img_path, \ + iotests.VM() as vm: + + log('--- Setting up images ---') + log('') + + assert qemu_img('create', '-f', iotests.imgfmt, base_img_path, '64M') == 0 + assert qemu_io_silent(base_img_path, '-c', 'write -P 1 0M 1M') == 0 + assert qemu_io_silent(base_img_path, '-c', 'write -P 1 3M 1M') == 0 + assert qemu_img('create', '-f', iotests.imgfmt, '-b', base_img_path, + '-F', iotests.imgfmt, mid_img_path) == 0 + assert qemu_io_silent(mid_img_path, '-c', 'write -P 3 2M 1M') == 0 + assert qemu_io_silent(mid_img_path, '-c', 'write -P 3 4M 1M') == 0 + assert qemu_img('create', '-f', iotests.imgfmt, '-b', mid_img_path, + '-F', iotests.imgfmt, top_img_path) == 0 + assert qemu_io_silent(top_img_path, '-c', 'write -P 2 1M 1M') == 0 + +# 0 1 2 3 4 +# top 2 +# mid 3 3 +# base 1 1 + + log('Done') + + log('') + log('--- Doing COR ---') + log('') + + vm.launch() + + log(vm.qmp('blockdev-add', + node_name='node0', + driver='copy-on-read', + bottom='node2', + file={ + 'driver': iotests.imgfmt, + 'file': { + 'driver': 'file', + 'filename': top_img_path + }, + 'backing': { + 'node-name': 'node2', + 'driver': iotests.imgfmt, + 'file': { + 'driver': 'file', + 'filename': mid_img_path + }, + 'backing': { + 'driver': iotests.imgfmt, + 'file': { + 'driver': 'file', + 'filename': base_img_path + } + }, + } + })) + + # Trigger COR + log(vm.qmp('human-monitor-command', + command_line='qemu-io node0 "read 0 5M"')) + + vm.shutdown() + + log('') + log('--- Checking COR result ---') + log('') + + # Detach backing to check that we can read the data from the top level now + assert qemu_img('rebase', '-u', '-b', '', '-f', iotests.imgfmt, + top_img_path) == 0 + + assert qemu_io_silent(top_img_path, '-c', 'read -P 0 0 1M') == 0 + assert qemu_io_silent(top_img_path, '-c', 'read -P 2 1M 1M') == 0 + assert qemu_io_silent(top_img_path, '-c', 'read -P 3 2M 1M') == 0 + assert qemu_io_silent(top_img_path, '-c', 'read -P 0 3M 1M') == 0 + assert qemu_io_silent(top_img_path, '-c', 'read -P 3 4M 1M') == 0 + + log('Done')
tests/qemu-iotests/310.out new file +15 -0
@@ -0,0 +1,15 @@ + +=== Copy-on-read across nodes === + +--- Setting up images --- + +Done + +--- Doing COR --- + +{"return": {}} +{"return": ""} + +--- Checking COR result --- + +Done
tests/qemu-iotests/group +1 -0
@@ -318,4 +318,5 @@ 307 rw quick export 308 rw 309 rw auto quick +310 rw quick 312 rw quick
Signature · 1 line
2.29.2
[PULL 05/53] qapi: add filter-node-name to block-stream
In reply to Max ReitzFrom: Andrey Shinkevich <[email protected]>
Provide the possibility to pass the 'filter-node-name' parameter to the block-stream job as it is done for the commit block job.
Message-Id: <[email protected]>
--- qapi/block-core.json | 6 ++++++ include/block/block_int.h | 7 ++++++- block/monitor/block-hmp-cmds.c | 4 ++-- block/stream.c | 4 +++- blockdev.c | 4 +++- 5 files changed, 20 insertions(+), 5 deletions(-)
qapi/block-core.json +6 -0
@@ -2543,6 +2543,11 @@ # 'stop' and 'enospc' can only be used if the block device # supports io-status (see BlockInfo). Since 1.3. # +# @filter-node-name: the node name that should be assigned to the +# filter driver that the stream job inserts into the graph +# above @device. If this option is not given, a node name is +# autogenerated. (Since: 6.0) +# # @auto-finalize: When false, this job will wait in a PENDING state after it has # finished its work, waiting for @block-job-finalize before # making any block graph changes.
@@ -2573,6 +2578,7 @@ 'data': { '*job-id': 'str', 'device': 'str', '*base': 'str', '*base-node': 'str', '*backing-file': 'str', '*speed': 'int', '*on-error': 'BlockdevOnError', + '*filter-node-name': 'str', '*auto-finalize': 'bool', '*auto-dismiss': 'bool' } } ##
include/block/block_int.h +6 -1
@@ -1143,6 +1143,9 @@ int is_windows_drive(const char *filename);* See @BlockJobCreateFlags * @speed: The maximum speed, in bytes per second, or 0 for unlimited. * @on_error: The action to take upon error. +* @filter_node_name: The node name that should be assigned to the filter +* driver that the stream job inserts into the graph above +* @bs. NULL means that a node name should be autogenerated. * @errp: Error object. * * Start a streaming operation on @bs. Clusters that are unallocated
@@ -1155,7 +1158,9 @@ int is_windows_drive(const char *filename);void stream_start (const char *job_id,BlockDriverState *bs,BlockDriverState *base,const char *backing_file_str,int creation_flags,int64_t speed, -BlockdevOnError on_error,Error **errp); +BlockdevOnError on_error, +const char *filter_node_name, +Error **errp);/** * commit_start:
block/monitor/block-hmp-cmds.c +2 -2
@@ -508,8 +508,8 @@ void hmp_block_stream(Monitor *mon, const QDict *qdict)qmp_block_stream (true, device, device, base !=NULL , base, false,NULL , false,NULL ,qdict_haskey (qdict,"speed" ), speed, true, -BLOCKDEV_ON_ERROR_REPORT , false, false, false, false, - &error); +BLOCKDEV_ON_ERROR_REPORT , false,NULL , false, false, false, + false, &error);hmp_handle_error (mon, error); }
block/stream.c +3 -1
@@ -221,7 +221,9 @@ static const BlockJobDriver stream_job_driver = {void stream_start (const char *job_id,BlockDriverState *bs,BlockDriverState *base,const char *backing_file_str,int creation_flags,int64_t speed, -BlockdevOnError on_error,Error **errp) +BlockdevOnError on_error, +const char *filter_node_name, +Error **errp) {StreamBlockJob *s;BlockDriverState *iter;
blockdev.c +3 -1
@@ -2502,6 +2502,7 @@ void qmp_block_stream(bool has_job_id, const char *job_id, const char *device, bool has_backing_file, const char *backing_file, bool has_speed, int64_t speed, bool has_on_error, BlockdevOnError on_error, + bool has_filter_node_name, const char *filter_node_name, bool has_auto_finalize, bool auto_finalize, bool has_auto_dismiss, bool auto_dismiss, Error **errp)
@@ -2584,7 +2585,8 @@ void qmp_block_stream(bool has_job_id, const char *job_id, const char *device, }stream_start (has_job_id ? job_id :NULL , bs, base_bs, base_name, - job_flags, has_speed ? speed :0 , on_error, &local_err); + job_flags, has_speed ? speed :0 , on_error, + filter_node_name, &local_err);if (local_err) {error_propagate (errp, local_err); goto out;
Signature · 1 line
2.29.2
[PULL 06/53] qapi: copy-on-read filter: add 'bottom' option
In reply to Max ReitzFrom: Andrey Shinkevich <[email protected]>
Add an option to limit copy-on-read operations to specified sub-chain of backing-chain, to make copy-on-read filter useful for block-stream job.
[vsementsov: change subject, modified to freeze the chain,
do some fixes]
Message-Id: <[email protected]>
--- qapi/block-core.json | 20 ++++++++- block/copy-on-read.c | 98 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 115 insertions(+), 3 deletions(-)
qapi/block-core.json +19 -1
@@ -3959,6 +3959,24 @@ 'data': { 'throttle-group': 'str', 'file' : 'BlockdevRef' } } + +## +# @BlockdevOptionsCor: +# +# Driver specific block device options for the copy-on-read driver. +# +# @bottom: The name of a non-filter node (allocation-bearing layer) that +# limits the COR operations in the backing chain (inclusive), so +# that no data below this node will be copied by this filter. +# If option is absent, the limit is not applied, so that data +# from all backing layers may be copied. +# +# Since: 6.0 +## +{ 'struct': 'BlockdevOptionsCor', + 'base': 'BlockdevOptionsGenericFormat', + 'data': { '*bottom': 'str' } } + ## # @BlockdevOptions: #
@@ -4011,7 +4029,7 @@ 'bochs': 'BlockdevOptionsGenericFormat', 'cloop': 'BlockdevOptionsGenericFormat', 'compress': 'BlockdevOptionsGenericFormat', - 'copy-on-read':'BlockdevOptionsGenericFormat', + 'copy-on-read':'BlockdevOptionsCor', 'dmg': 'BlockdevOptionsGenericFormat', 'file': 'BlockdevOptionsFile', 'ftp': 'BlockdevOptionsCurlFtp',
block/copy-on-read.c +96 -2
146 lines not on this page · raw message
Signature · 1 line
2.29.2
[PULL 12/53] iotests: 30: prepare to COR filter insertion by stream job
In reply to Max ReitzFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
test_stream_parallel run parallel stream jobs, intersecting so that top of one is base of another. It's OK now, but it would be a problem if insert the filter, as one job will want to use another job's filter as above_base node.
Correct thing to do is move to new interface: "bottom" argument instead of base. This guarantees that jobs don't intersect by their actions.
Message-Id: <[email protected]>
--- tests/qemu-iotests/030 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tests/qemu-iotests/030 +3 -1
@@ -246,7 +246,9 @@ class TestParallelOps(iotests.QMPTestCase): node_name = 'node%d' % i job_id = 'stream-%s' % node_name pending_jobs.append(job_id) - result = self.vm.qmp('block-stream', device=node_name, job_id=job_id, base=self.imgs[i-2], speed=1024) + result = self.vm.qmp('block-stream', device=node_name, + job_id=job_id, bottom=f'node{i-1}', + speed=1024) self.assert_qmp(result, 'return', {}) for job in pending_jobs:
Signature · 1 line
2.29.2
[PULL 17/53] iotests: Move try_remove to iotests.py
In reply to Max ReitzMessage-Id: <[email protected]>
--- tests/qemu-iotests/124 | 8 +------- tests/qemu-iotests/iotests.py | 11 +++++++---- 2 files changed, 8 insertions(+), 11 deletions(-)
tests/qemu-iotests/124 +1 -7
@@ -23,6 +23,7 @@ import os import iotests +from iotests import try_remove def io_write_patterns(img, patterns):
@@ -30,13 +31,6 @@ def io_write_patterns(img, patterns): iotests.qemu_io('-c', 'write -P%s %s %s' % pattern, img) -def try_remove(img): - try: - os.remove(img) - except OSError: - pass - - def transaction_action(action, **kwargs): return { 'type': action,
tests/qemu-iotests/iotests.py +7 -4
@@ -515,12 +515,15 @@ class FilePath: return False +def try_remove(img): + try: + os.remove(img) + except OSError: + pass + def file_path_remover(): for path in reversed(file_path_remover.paths): - try: - os.remove(path) - except OSError: - pass + try_remove(path) def file_path(*names, base_dir=test_dir):
Signature · 1 line
2.29.2
[PULL 16/53] iotests/297: Rewrite in Python and extend reach
In reply to Max ReitzInstead of checking iotests.py only, check all Python files in the qemu-iotests/ directory. Of course, most of them do not pass, so there is an extensive skip list for now. (The only files that do pass are 209, 254, 283, and iotests.py.)
(Alternatively, we could have the opposite, i.e. an explicit list of files that we do want to check, but I think it is better to check files by default.)
Unless started in debug mode (./check -d), the output has no information on which files are tested, so we will not have a problem e.g. with backports, where some files may be missing when compared to upstream.
Besides the technical rewrite, some more things are changed:
- For the pylint invocation, PYTHONPATH is adjusted. This mirrors setting MYPYPATH for mypy.
- Also, MYPYPATH is now derived from PYTHONPATH, so that we include paths set by the environment. Maybe at some point we want to let the check script add '../../python/' to PYTHONPATH so that iotests.py does not need to do that.
- Passing --notes=FIXME,XXX to pylint suppresses warnings for TODO comments. TODO is fine, we do not need 297 to complain about such comments.
- The "Success" line from mypy's output is suppressed, because (A) it does not add useful information, and (B) it would leak information about the files having been tested to the reference output, which we decidedly do not want.
Message-Id: <[email protected]>
--- tests/qemu-iotests/297 | 112 +++++++++++++++++++++++++++++-------- tests/qemu-iotests/297.out | 5 +- 2 files changed, 92 insertions(+), 25 deletions(-)
tests/qemu-iotests/297 +90 -22
@@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env python3 # group: meta # # Copyright (C) 2020 Red Hat, Inc.
@@ -16,30 +16,98 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -seq=$(basename $0) -echo "QA output created by $seq" +import os +import re +import shutil +import subprocess +import sys -status=1 # failure is the default! +import iotests -# get standard environment -. ./common.rc -if ! type -p "pylint-3" > /dev/null; then - _notrun "pylint-3 not found" -fi -if ! type -p "mypy" > /dev/null; then - _notrun "mypy not found" -fi +# TODO: Empty this list! +SKIP_FILES = ( + '030', '040', '041', '044', '045', '055', '056', '057', '065', '093', + '096', '118', '124', '129', '132', '136', '139', '147', '148', '149', + '151', '152', '155', '163', '165', '169', '194', '196', '199', '202', + '203', '205', '206', '207', '208', '210', '211', '212', '213', '216', + '218', '219', '222', '224', '228', '234', '235', '236', '237', '238', + '240', '242', '245', '246', '248', '255', '256', '257', '258', '260', + '262', '264', '266', '274', '277', '280', '281', '295', '296', '298', + '299', '300', '302', '303', '304', '307', + 'nbd-fault-injector.py', 'qcow2.py', 'qcow2_format.py', 'qed.py' +) -pylint-3 --score=n iotests.py -MYPYPATH=../../python/ mypy --warn-unused-configs --disallow-subclassing-any \ - --disallow-any-generics --disallow-incomplete-defs \ - --disallow-untyped-decorators --no-implicit-optional \ - --warn-redundant-casts --warn-unused-ignores \ - --no-implicit-reexport iotests.py +def is_python_file(filename): + if not os.path.isfile(filename): + return False -# success, all done -echo "*** done" -rm -f $seq.full -status=0 + if filename.endswith('.py'): + return True + + with open(filename) as f: + try: + first_line = f.readline() + return re.match('^#!.*python', first_line) is not None + except UnicodeDecodeError: # Ignore binary files + return False + + +def run_linters(): + files = [filename for filename in (set(os.listdir('.')) - set(SKIP_FILES)) + if is_python_file(filename)] + + iotests.logger.debug('Files to be checked:') + iotests.logger.debug(', '.join(sorted(files))) + + print('=== pylint ===') + sys.stdout.flush() + + # Todo notes are fine, but fixme's or xxx's should probably just be + # fixed (in tests, at least) + env = os.environ.copy() + qemu_module_path = os.path.join(os.path.dirname(__file__), + '..', '..', 'python') + try: + env['PYTHONPATH'] += os.pathsep + qemu_module_path + except KeyError: + env['PYTHONPATH'] = qemu_module_path + subprocess.run(('pylint-3', '--score=n', '--notes=FIXME,XXX', *files), + env=env, check=False) + + print('=== mypy ===') + sys.stdout.flush() + + # We have to call mypy separately for each file. Otherwise, it + # will interpret all given files as belonging together (i.e., they + # may not both define the same classes, etc.; most notably, they + # must not both define the __main__ module). + env['MYPYPATH'] = env['PYTHONPATH'] + for filename in files: + p = subprocess.run(('mypy', + '--warn-unused-configs', + '--disallow-subclassing-any', + '--disallow-any-generics', + '--disallow-incomplete-defs', + '--disallow-untyped-decorators', + '--no-implicit-optional', + '--warn-redundant-casts', + '--warn-unused-ignores', + '--no-implicit-reexport', + filename), + env=env, + check=False, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + universal_newlines=True) + + if p.returncode != 0: + print(p.stdout) + + +for linter in ('pylint-3', 'mypy'): + if shutil.which(linter) is None: + iotests.notrun(f'{linter} not found') + +iotests.script_main(run_linters)
tests/qemu-iotests/297.out +2 -3
@@ -1,3 +1,2 @@ -QA output created by 297 -Success: no issues found in 1 source file -*** done +=== pylint === +=== mypy ===
Signature · 1 line
2.29.2
[PULL 08/53] block: include supported_read_flags into BDS structure
In reply to Max ReitzFrom: Andrey Shinkevich <[email protected]>
Add the new member supported_read_flags to the BlockDriverState structure. It will control the flags set for copy-on-read operations. Make the block generic layer evaluate supported read flags before they go to a block driver.
Message-Id: <[email protected]>
--- include/block/block_int.h | 4 ++++ block/io.c | 10 ++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-)
include/block/block_int.h +4 -0
@@ -881,6 +881,10 @@ struct BlockDriverState {/* I/O Limits */ BlockLimits bl; +/* +* Flags honored during pread +*/ +unsigned int supported_read_flags;/* Flags honored during pwrite (so far: BDRV_REQ_FUA, * BDRV_REQ_WRITE_UNCHANGED). * If a driver does not support BDRV_REQ_WRITE_UNCHANGED, those
block/io.c +8 -2
@@ -1453,6 +1453,9 @@ static int coroutine_fn bdrv_aligned_preadv(BdrvChild *child,if (flags &BDRV_REQ_COPY_ON_READ ) {int64_t pnum; +/* The flag BDRV_REQ_COPY_ON_READ has reached its addressee */ + flags &= ~BDRV_REQ_COPY_ON_READ ; + ret =bdrv_is_allocated (bs, offset, bytes, &pnum);if (ret <0 ) { goto out;
@@ -1474,9 +1477,11 @@ static int coroutine_fn bdrv_aligned_preadv(BdrvChild *child, goto out; } +assert (!(flags & ~bs->supported_read_flags)); + max_bytes =ROUND_UP (MAX (0 , total_bytes - offset), align);if (bytes <= max_bytes && bytes <= max_transfer) { - ret =bdrv_driver_preadv (bs, offset, bytes, qiov, qiov_offset,0 ); + ret =bdrv_driver_preadv (bs, offset, bytes, qiov, qiov_offset, flags); goto out; }
@@ -1489,7 +1494,8 @@ static int coroutine_fn bdrv_aligned_preadv(BdrvChild *child, ret =bdrv_driver_preadv (bs, offset + bytes - bytes_remaining, num, qiov, - qiov_offset + bytes - bytes_remaining,0 ); + qiov_offset + bytes - bytes_remaining, + flags); max_bytes -= num; }else { num = bytes_remaining;
Signature · 1 line
2.29.2
[PULL 18/53] iotests/129: Remove test images in tearDown()
In reply to Max ReitzMessage-Id: <[email protected]>
--- tests/qemu-iotests/129 | 2 ++ 1 file changed, 2 insertions(+)
tests/qemu-iotests/129 +2 -0
@@ -48,6 +48,8 @@ class TestStopWithBlockJob(iotests.QMPTestCase): result = self.vm.qmp("block_set_io_throttle", conv_keys=False, **params) self.vm.shutdown() + for img in (self.test_img, self.target_img, self.base_img): + iotests.try_remove(img) def do_test_stop(self, cmd, **args): """Test 'stop' while block job is running on a throttled drive.
Signature · 1 line
2.29.2
[PULL 13/53] block/stream: add s->target_bs
In reply to Max ReitzFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
Add a direct link to target bs for convenience and to simplify following commit which will insert COR filter above target bs.
This is a part of original commit written by Andrey.
Message-Id: <[email protected]>
--- block/stream.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-)
block/stream.c +10 -13
@@ -33,6 +33,7 @@ typedef struct StreamBlockJob {BlockJob common;BlockDriverState *base_overlay;/* COW overlay (stream from this) */ BlockDriverState *above_base;/* Node directly above the base */ +BlockDriverState *target_bs;BlockdevOnError on_error;char *backing_file_str;bool bs_read_only;
@@ -53,23 +54,20 @@ static void stream_abort(Job *job)StreamBlockJob *s =container_of (job, StreamBlockJob, common.job);if (s->chain_frozen) { -BlockJob *bjob = &s->common; -bdrv_unfreeze_backing_chain (blk_bs (bjob->blk), s->above_base); +bdrv_unfreeze_backing_chain (s->target_bs, s->above_base); } }static int stream_prepare (Job *job) {StreamBlockJob *s =container_of (job, StreamBlockJob, common.job); -BlockJob *bjob = &s->common; -BlockDriverState *bs =blk_bs (bjob->blk); -BlockDriverState *unfiltered_bs =bdrv_skip_filters (bs); +BlockDriverState *unfiltered_bs =bdrv_skip_filters (s->target_bs);BlockDriverState *base =bdrv_filter_or_cow_bs (s->above_base);BlockDriverState *unfiltered_base =bdrv_skip_filters (base);Error *local_err =NULL ;int ret =0 ; -bdrv_unfreeze_backing_chain (bs, s->above_base); +bdrv_unfreeze_backing_chain (s->target_bs, s->above_base); s->chain_frozen = false;if (bdrv_cow_child (unfiltered_bs)) {
@@ -95,13 +93,12 @@ static void stream_clean(Job *job) {StreamBlockJob *s =container_of (job, StreamBlockJob, common.job);BlockJob *bjob = &s->common; -BlockDriverState *bs =blk_bs (bjob->blk);/* Reopen the image back in read-only mode if necessary */ if (s->bs_read_only) {/* Give up write permissions before making it read-only */ blk_set_perm (bjob->blk,0 ,BLK_PERM_ALL , &error_abort); -bdrv_reopen_set_read_only (bs, true,NULL ); +bdrv_reopen_set_read_only (s->target_bs, true,NULL ); }g_free (s->backing_file_str);
@@ -111,8 +108,7 @@ static int coroutine_fn stream_run(Job *job, Error **errp) {StreamBlockJob *s =container_of (job, StreamBlockJob, common.job);BlockBackend *blk = s->common.blk; -BlockDriverState *bs =blk_bs (blk); -BlockDriverState *unfiltered_bs =bdrv_skip_filters (bs); +BlockDriverState *unfiltered_bs =bdrv_skip_filters (s->target_bs);bool enable_cor = !bdrv_cow_child (s->base_overlay);int64_t len;int64_t offset =0 ;
@@ -125,7 +121,7 @@ static int coroutine_fn stream_run(Job *job, Error **errp)return 0 ; } - len =bdrv_getlength (bs); + len =bdrv_getlength (s->target_bs);if (len <0 ) {return len; }
@@ -137,7 +133,7 @@ static int coroutine_fn stream_run(Job *job, Error **errp)* account. */ if (enable_cor) { -bdrv_enable_copy_on_read (bs); +bdrv_enable_copy_on_read (s->target_bs); }for ( ; offset < len; offset += n) {
@@ -199,7 +195,7 @@ static int coroutine_fn stream_run(Job *job, Error **errp) }if (enable_cor) { -bdrv_disable_copy_on_read (bs); +bdrv_disable_copy_on_read (s->target_bs); }/* Do not remove the backing file if an error was there but ignored. */
@@ -314,6 +310,7 @@ void stream_start(const char *job_id, BlockDriverState *bs, s->base_overlay = base_overlay; s->above_base = above_base; s->backing_file_str =g_strdup (backing_file_str); + s->target_bs = bs; s->bs_read_only = bs_read_only; s->chain_frozen = true;
Signature · 1 line
2.29.2
[PULL 22/53] iotests/129: Limit mirror job's buffer size
In reply to Max ReitzIssuing 'stop' on the VM drains all nodes. If the mirror job has many large requests in flight, this may lead to significant I/O that looks a bit like 'stop' would make the job try to complete (which is what 129 should verify not to happen).
We can limit the I/O in flight by limiting the buffer size, so mirror will make very little progress during the 'stop' drain.
(We do not need to do anything about commit, which has a buffer size of 512 kB by default; or backup, which goes cluster by cluster. Once we have asynchronous requests for backup, that will change, but then we can fine-tune the backup job to only perform a single request on a very small chunk, too.)
Message-Id: <[email protected]>
--- tests/qemu-iotests/129 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qemu-iotests/129 +1 -1
@@ -68,7 +68,7 @@ class TestStopWithBlockJob(iotests.QMPTestCase): def test_drive_mirror(self): self.do_test_stop("drive-mirror", device="drive0", target=self.target_img, format=iotests.imgfmt, - sync="full") + sync="full", buf_size=65536) def test_drive_backup(self): self.do_test_stop("drive-backup", device="drive0",
Signature · 1 line
2.29.2
[PULL 10/53] stream: rework backing-file changing
In reply to Max ReitzFrom: Andrey Shinkevich <[email protected]>
Stream in stream_prepare calls bdrv_change_backing_file() to change backing-file in the metadata of bs.
It may use either backing-file parameter given by user or just take filename of base on job start.
Backing file format is determined by base on job finish.
There are some problems with this design, we solve only two by this patch:
1. Consider scenario with backing-file unset. Current concept of stream supports changing of the base during the job (we don't freeze link to the base). So, we should not save base filename at job start,
- let's determine name of the base on job finish.
2. Using direct base to determine filename and format is not very good:
base node may be a filter, so its filename may be JSON, and format_name is not good for storing into qcow2 metadata as backing file format.
- let's use unfiltered_base
Message-Id: <[email protected]>
--- block/stream.c | 9 +++++---- blockdev.c | 8 +------- 2 files changed, 6 insertions(+), 11 deletions(-)
block/stream.c +5 -4
@@ -65,6 +65,7 @@ static int stream_prepare(Job *job)BlockDriverState *bs =blk_bs (bjob->blk);BlockDriverState *unfiltered_bs =bdrv_skip_filters (bs);BlockDriverState *base =bdrv_filter_or_cow_bs (s->above_base); +BlockDriverState *unfiltered_base =bdrv_skip_filters (base);Error *local_err =NULL ;int ret =0 ;
@@ -73,10 +74,10 @@ static int stream_prepare(Job *job)if (bdrv_cow_child (unfiltered_bs)) {const char *base_id =NULL , *base_fmt =NULL ; -if (base) { - base_id = s->backing_file_str; -if (base->drv) { - base_fmt = base->drv->format_name; +if (unfiltered_base) { + base_id = s->backing_file_str ?: unfiltered_base->filename; +if (unfiltered_base->drv) { + base_fmt = unfiltered_base->drv->format_name; } }bdrv_set_backing_hd (unfiltered_bs, base, &local_err);
blockdev.c +1 -7
@@ -2511,7 +2511,6 @@ void qmp_block_stream(bool has_job_id, const char *job_id, const char *device,BlockDriverState *base_bs =NULL ;AioContext *aio_context;Error *local_err =NULL ; -const char *base_name =NULL ;int job_flags =JOB_DEFAULT ;if (!has_on_error) {
@@ -2539,7 +2538,6 @@ void qmp_block_stream(bool has_job_id, const char *job_id, const char *device, goto out; }assert (bdrv_get_aio_context (base_bs) == aio_context); - base_name = base; }if (has_base_node) {
@@ -2554,7 +2552,6 @@ void qmp_block_stream(bool has_job_id, const char *job_id, const char *device, }assert (bdrv_get_aio_context (base_bs) == aio_context);bdrv_refresh_filename (base_bs); - base_name = base_bs->filename; }/* Check for op blockers in the whole chain between bs and base */
@@ -2574,9 +2571,6 @@ void qmp_block_stream(bool has_job_id, const char *job_id, const char *device, goto out; } -/* backing_file string overrides base bs filename */ - base_name = has_backing_file ? backing_file : base_name; -if (has_auto_finalize && !auto_finalize) { job_flags |=JOB_MANUAL_FINALIZE ; }
@@ -2584,7 +2578,7 @@ void qmp_block_stream(bool has_job_id, const char *job_id, const char *device, job_flags |=JOB_MANUAL_DISMISS ; } -stream_start (has_job_id ? job_id :NULL , bs, base_bs, base_name, +stream_start (has_job_id ? job_id :NULL , bs, base_bs, backing_file, job_flags, has_speed ? speed :0 , on_error, filter_node_name, &local_err);if (local_err) {
Signature · 1 line
2.29.2
[PULL 25/53] coroutine-sigaltstack: Add SIGUSR2 mutex
In reply to Max ReitzDisposition (action) for any given signal is global for the process. When two threads run coroutine-sigaltstack's qemu_coroutine_new() concurrently, they may interfere with each other: One of them may revert the SIGUSR2 handler to SIG_DFL, between the other thread (a) setting up coroutine_trampoline() as the handler and (b) raising SIGUSR2. That SIGUSR2 will then terminate the QEMU process abnormally.
We have to ensure that only one thread at a time can modify the process-global SIGUSR2 handler. To do so, wrap the whole section where that is done in a mutex.
Alternatively, we could for example have the SIGUSR2 handler always be coroutine_trampoline(), so there would be no need to invoke sigaction() in qemu_coroutine_new(). Laszlo has posted a patch to do so here:
https://lists.nongnu.org/archive/html/qemu-devel/2021-01/msg05962.html
However, given that coroutine-sigaltstack is more of a fallback implementation for platforms that do not support ucontext, that change may be a bit too invasive to be comfortable with it. The mutex proposed here may negatively impact performance, but the change is much simpler.
Message-Id: <[email protected]>
--- util/coroutine-sigaltstack.c | 9 +++++++++ 1 file changed, 9 insertions(+)
util/coroutine-sigaltstack.c +9 -0
@@ -157,6 +157,7 @@ Coroutine *qemu_coroutine_new(void)sigset_t sigs;sigset_t osigs;sigjmp_buf old_env; +static pthread_mutex_t sigusr2_mutex =PTHREAD_MUTEX_INITIALIZER ;/* The way to manipulate stack is with the sigaltstack function. We * prepare a stack, with it delivering a signal to ourselves and then
@@ -186,6 +187,12 @@ Coroutine *qemu_coroutine_new(void) sa.sa_handler = coroutine_trampoline;sigfillset (&sa.sa_mask); sa.sa_flags =SA_ONSTACK ; + +/* +* sigaction() is a process-global operation. We must not run +* this code in multiple threads at once. +*/ +pthread_mutex_lock (&sigusr2_mutex);if (sigaction (SIGUSR2 , &sa, &osa) !=0 ) {abort (); }
@@ -234,6 +241,8 @@ Coroutine *qemu_coroutine_new(void)* Restore the old SIGUSR2 signal handler and mask */ sigaction (SIGUSR2 , &osa,NULL ); +pthread_mutex_unlock (&sigusr2_mutex); +pthread_sigmask (SIG_SETMASK , &osigs,NULL );/*
Signature · 1 line
2.29.2
[PULL 09/53] copy-on-read: skip non-guest reads if no copy needed
In reply to Max ReitzFrom: Andrey Shinkevich <[email protected]>
If the flag BDRV_REQ_PREFETCH was set, skip idling read/write operations in COR-driver. It can be taken into account for the COR-algorithms optimization. That check is being made during the block stream job by the moment.
Add the BDRV_REQ_PREFETCH flag to the supported_read_flags of the COR-filter.
block: Modify the comment for the flag BDRV_REQ_PREFETCH as we are going to use it alone and pass it to the COR-filter driver for further processing.
Message-Id: <[email protected]>
--- include/block/block.h | 8 +++++--- block/copy-on-read.c | 14 ++++++++++---- 2 files changed, 15 insertions(+), 7 deletions(-)
include/block/block.h +5 -3
@@ -72,9 +72,11 @@ typedef enum {BDRV_REQ_NO_FALLBACK =0x100 ,/* -* BDRV_REQ_PREFETCH may be used only together with BDRV_REQ_COPY_ON_READ -* on read request and means that caller doesn't really need data to be -* written to qiov parameter which may be NULL. +* BDRV_REQ_PREFETCH makes sense only in the context of copy-on-read +* (i.e., together with the BDRV_REQ_COPY_ON_READ flag or when a COR +* filter is involved), in which case it signals that the COR operation +* need not read the data into memory (qiov) but only ensure they are +* copied to the top layer (i.e., that COR operation is done). */ BDRV_REQ_PREFETCH = 0x200,
block/copy-on-read.c +10 -4
@@ -50,6 +50,8 @@ static int cor_open(BlockDriverState *bs, QDict *options, int flags,return -EINVAL ; } + bs->supported_read_flags =BDRV_REQ_PREFETCH ; + bs->supported_write_flags =BDRV_REQ_WRITE_UNCHANGED | (BDRV_REQ_FUA & bs->file->bs->supported_write_flags);
@@ -172,10 +174,14 @@ static int coroutine_fn cor_co_preadv_part(BlockDriverState *bs, } } - ret =bdrv_co_preadv_part (bs->file, offset, n, qiov, qiov_offset, - local_flags); -if (ret <0 ) { -return ret; +/* Skip if neither read nor write are needed */ +if ((local_flags & (BDRV_REQ_PREFETCH |BDRV_REQ_COPY_ON_READ )) != +BDRV_REQ_PREFETCH ) { + ret =bdrv_co_preadv_part (bs->file, offset, n, qiov, qiov_offset, + local_flags); +if (ret <0 ) { +return ret; + } } offset += n;
Signature · 1 line
2.29.2
[PULL 23/53] iotests/129: Clean up pylint and mypy complaints
In reply to Max ReitzAnd consequentially drop it from 297's skip list.
Message-Id: <[email protected]>
--- tests/qemu-iotests/129 | 4 ++-- tests/qemu-iotests/297 | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
tests/qemu-iotests/129 +2 -2
@@ -21,7 +21,6 @@ import os import iotests -import time class TestStopWithBlockJob(iotests.QMPTestCase): test_img = os.path.join(iotests.test_dir, 'test.img')
@@ -33,7 +32,8 @@ class TestStopWithBlockJob(iotests.QMPTestCase): iotests.qemu_img('create', '-f', iotests.imgfmt, self.base_img, "1G") iotests.qemu_img('create', '-f', iotests.imgfmt, self.test_img, "-b", self.base_img, '-F', iotests.imgfmt) - iotests.qemu_io('-f', iotests.imgfmt, '-c', 'write -P0x5d 1M 128M', self.test_img) + iotests.qemu_io('-f', iotests.imgfmt, '-c', 'write -P0x5d 1M 128M', + self.test_img) self.vm = iotests.VM() self.vm.add_object('throttle-group,id=tg0,x-bps-total=1024')
tests/qemu-iotests/297 +1 -1
@@ -28,7 +28,7 @@ import iotests # TODO: Empty this list! SKIP_FILES = ( '030', '040', '041', '044', '045', '055', '056', '057', '065', '093', - '096', '118', '124', '129', '132', '136', '139', '147', '148', '149', + '096', '118', '124', '132', '136', '139', '147', '148', '149', '151', '152', '155', '163', '165', '169', '194', '196', '199', '202', '203', '205', '206', '207', '208', '210', '211', '212', '213', '216', '218', '219', '222', '224', '228', '234', '235', '236', '237', '238',
Signature · 1 line
2.29.2
[PULL 20/53] iotests/129: Use throttle node
In reply to Max ReitzThrottling on the BB has not affected block jobs in a while, so it is possible that one of the jobs in 129 finishes before the VM is stopped. We can fix that by running the job from a throttle node.
Message-Id: <[email protected]>
--- tests/qemu-iotests/129 | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-)
tests/qemu-iotests/129 +13 -24
@@ -33,20 +33,18 @@ class TestStopWithBlockJob(iotests.QMPTestCase): iotests.qemu_img('create', '-f', iotests.imgfmt, self.test_img, "-b", self.base_img, '-F', iotests.imgfmt) iotests.qemu_io('-f', iotests.imgfmt, '-c', 'write -P0x5d 1M 128M', self.test_img) - self.vm = iotests.VM().add_drive(self.test_img) + self.vm = iotests.VM() + self.vm.add_object('throttle-group,id=tg0,x-bps-total=1024') + + source_drive = 'driver=throttle,' \ + 'throttle-group=tg0,' \ + f'file.driver={iotests.imgfmt},' \ + f'file.file.filename={self.test_img}' + + self.vm.add_drive(None, source_drive) self.vm.launch() def tearDown(self): - params = {"device": "drive0", - "bps": 0, - "bps_rd": 0, - "bps_wr": 0, - "iops": 0, - "iops_rd": 0, - "iops_wr": 0, - } - result = self.vm.qmp("block_set_io_throttle", conv_keys=False, - **params) self.vm.shutdown() for img in (self.test_img, self.target_img, self.base_img): iotests.try_remove(img)
@@ -54,33 +52,24 @@ class TestStopWithBlockJob(iotests.QMPTestCase): def do_test_stop(self, cmd, **args): """Test 'stop' while block job is running on a throttled drive. The 'stop' command shouldn't drain the job""" - params = {"device": "drive0", - "bps": 1024, - "bps_rd": 0, - "bps_wr": 0, - "iops": 0, - "iops_rd": 0, - "iops_wr": 0, - } - result = self.vm.qmp("block_set_io_throttle", conv_keys=False, - **params) - self.assert_qmp(result, 'return', {}) result = self.vm.qmp(cmd, **args) self.assert_qmp(result, 'return', {}) + result = self.vm.qmp("stop") self.assert_qmp(result, 'return', {}) result = self.vm.qmp("query-block-jobs") + self.assert_qmp(result, 'return[0]/status', 'running') self.assert_qmp(result, 'return[0]/ready', False) def test_drive_mirror(self): self.do_test_stop("drive-mirror", device="drive0", - target=self.target_img, + target=self.target_img, format=iotests.imgfmt, sync="full") def test_drive_backup(self): self.do_test_stop("drive-backup", device="drive0", - target=self.target_img, + target=self.target_img, format=iotests.imgfmt, sync="full") def test_block_commit(self):
Signature · 1 line
2.29.2
[PULL 28/53] block/block-copy: implement block_copy_async
In reply to Max ReitzFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
We'll need async block-copy invocation to use in backup directly.
Message-Id: <[email protected]>
--- include/block/block-copy.h | 29 ++++++++++++++ block/block-copy.c | 81 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 106 insertions(+), 4 deletions(-)
include/block/block-copy.h +29 -0
@@ -19,7 +19,9 @@#include "qemu/co-shared-resource.h" typedef void (*ProgressBytesCallbackFunc )(int64_t bytes,void *opaque); +typedef void (*BlockCopyAsyncCallbackFunc )(void *opaque);typedef struct BlockCopyState BlockCopyState ; +typedef struct BlockCopyCallState BlockCopyCallState ; BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target, int64_t cluster_size, bool use_copy_range,
@@ -41,6 +43,33 @@ int64_t block_copy_reset_unallocated(BlockCopyState *s, int coroutine_fn block_copy(BlockCopyState *s, int64_t offset, int64_t bytes,bool *error_is_read); +/* +* Run block-copy in a coroutine, create corresponding BlockCopyCallState +* object and return pointer to it. Never returns NULL. +* +* Caller is responsible to call block_copy_call_free() to free +* BlockCopyCallState object. +*/ +BlockCopyCallState *block_copy_async (BlockCopyState *s, +int64_t offset,int64_t bytes, +BlockCopyAsyncCallbackFunc cb, +void *cb_opaque); + +/* +* Free finished BlockCopyCallState. Trying to free running +* block-copy will crash. +*/ +void block_copy_call_free (BlockCopyCallState *call_state); + +/* +* Note, that block-copy call is marked finished prior to calling +* the callback. +*/ +bool block_copy_call_finished (BlockCopyCallState *call_state); +bool block_copy_call_succeeded (BlockCopyCallState *call_state); +bool block_copy_call_failed (BlockCopyCallState *call_state); +int block_copy_call_status (BlockCopyCallState *call_state,bool *error_is_read); +BdrvDirtyBitmap *block_copy_dirty_bitmap (BlockCopyState *s);void block_copy_set_skip_unallocated (BlockCopyState *s,bool skip);
block/block-copy.c +77 -4
110 lines not on this page · raw message
Signature · 1 line
2.29.2
[PULL 15/53] iotests.py: Assume a couple of variables as given
In reply to Max ReitzThere are a couple of environment variables that we fetch with os.environ.get() without supplying a default. Clearly they are required and expected to be set by the ./check script (as evidenced by execute_setup_common(), which checks for test_dir and qemu_default_machine to be set, and aborts if they are not).
Using .get() this way has the disadvantage of returning an Optional[str] type, which mypy will complain about when tests just assume these values to be str.
Use [] instead, which raises a KeyError for environment variables that are not set. When this exception is raised, catch it and move the abort code from execute_setup_common() there.
Drop the 'assert iotests.sock_dir is not None' from iotest 300, because that sort of thing is precisely what this patch wants to prevent.
Message-Id: <[email protected]>
--- tests/qemu-iotests/300 | 1 - tests/qemu-iotests/iotests.py | 26 +++++++++++++------------- 2 files changed, 13 insertions(+), 14 deletions(-)
tests/qemu-iotests/300 +0 -1
@@ -28,7 +28,6 @@ import qemu BlockBitmapMapping = List[Dict[str, Union[str, List[Dict[str, str]]]]] -assert iotests.sock_dir is not None mig_sock = os.path.join(iotests.sock_dir, 'mig_sock')
tests/qemu-iotests/iotests.py +13 -13
@@ -75,12 +75,20 @@ qemu_opts = os.environ.get('QEMU_OPTIONS', '').strip().split(' ') imgfmt = os.environ.get('IMGFMT', 'raw') imgproto = os.environ.get('IMGPROTO', 'file') -test_dir = os.environ.get('TEST_DIR') -sock_dir = os.environ.get('SOCK_DIR') output_dir = os.environ.get('OUTPUT_DIR', '.') -cachemode = os.environ.get('CACHEMODE') -aiomode = os.environ.get('AIOMODE') -qemu_default_machine = os.environ.get('QEMU_DEFAULT_MACHINE') + +try: + test_dir = os.environ['TEST_DIR'] + sock_dir = os.environ['SOCK_DIR'] + cachemode = os.environ['CACHEMODE'] + aiomode = os.environ['AIOMODE'] + qemu_default_machine = os.environ['QEMU_DEFAULT_MACHINE'] +except KeyError: + # We are using these variables as proxies to indicate that we're + # not being run via "check". There may be other things set up by + # "check" that individual test cases rely on. + sys.stderr.write('Please run this test via the "check" script\n') + sys.exit(os.EX_USAGE) socket_scm_helper = os.environ.get('SOCKET_SCM_HELPER', 'socket_scm_helper')
@@ -1286,14 +1294,6 @@ def execute_setup_common(supported_fmts: Sequence[str] = (), """ # Note: Python 3.6 and pylint do not like 'Collection' so use 'Sequence'. - # We are using TEST_DIR and QEMU_DEFAULT_MACHINE as proxies to - # indicate that we're not being run via "check". There may be - # other things set up by "check" that individual test cases rely - # on. - if test_dir is None or qemu_default_machine is None: - sys.stderr.write('Please run this test via the "check" script\n') - sys.exit(os.EX_USAGE) - debug = '-d' in sys.argv if debug: sys.argv.remove('-d')
Signature · 1 line
2.29.2
[PULL 24/53] iotests/300: Clean up pylint and mypy complaints
In reply to Max ReitzAnd consequentially drop it from 297's skip list.
Message-Id: <[email protected]>
--- tests/qemu-iotests/297 | 2 +- tests/qemu-iotests/300 | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-)
tests/qemu-iotests/297 +1 -1
@@ -34,7 +34,7 @@ SKIP_FILES = ( '218', '219', '222', '224', '228', '234', '235', '236', '237', '238', '240', '242', '245', '246', '248', '255', '256', '257', '258', '260', '262', '264', '266', '274', '277', '280', '281', '295', '296', '298', - '299', '300', '302', '303', '304', '307', + '299', '302', '303', '304', '307', 'nbd-fault-injector.py', 'qcow2.py', 'qcow2_format.py', 'qed.py' )
tests/qemu-iotests/300 +15 -3
@@ -23,7 +23,11 @@ import os import random import re from typing import Dict, List, Optional, Union + import iotests + +# Import qemu after iotests.py has amended sys.path +# pylint: disable=wrong-import-order import qemu BlockBitmapMapping = List[Dict[str, Union[str, List[Dict[str, str]]]]]
@@ -111,10 +115,14 @@ class TestDirtyBitmapMigration(iotests.QMPTestCase): If @msg is None, check that there has not been any error. """ self.vm_b.shutdown() + + log = self.vm_b.get_log() + assert log is not None # Loaded after shutdown + if msg is None: - self.assertNotIn('qemu-system-', self.vm_b.get_log()) + self.assertNotIn('qemu-system-', log) else: - self.assertIn(msg, self.vm_b.get_log()) + self.assertIn(msg, log) @staticmethod def mapping(node_name: str, node_alias: str,
@@ -446,9 +454,13 @@ class TestBlockBitmapMappingErrors(TestDirtyBitmapMigration): # Check for the error in the source's log self.vm_a.shutdown() + + log = self.vm_a.get_log() + assert log is not None # Loaded after shutdown + self.assertIn(f"Cannot migrate bitmap '{name}' on node " f"'{self.src_node_name}': Name is longer than 255 bytes", - self.vm_a.get_log()) + log) # Expect abnormal shutdown of the destination VM because of # the failed migration
Signature · 1 line
2.29.2
[PULL 19/53] iotests/129: Do not check @busy
In reply to Max Reitz@busy is false when the job is paused, which happens all the time because that is how jobs yield (e.g. for mirror at least since commit 565ac01f8d3).
Back when 129 was added (2015), perhaps there was no better way of checking whether the job was still actually running. Now we have the @status field (as of 58b295ba52c, i.e. 2018), which can give us exactly that information.
Message-Id: <[email protected]>
--- tests/qemu-iotests/129 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qemu-iotests/129 +1 -1
@@ -70,7 +70,7 @@ class TestStopWithBlockJob(iotests.QMPTestCase): result = self.vm.qmp("stop") self.assert_qmp(result, 'return', {}) result = self.vm.qmp("query-block-jobs") - self.assert_qmp(result, 'return[0]/busy', True) + self.assert_qmp(result, 'return[0]/status', 'running') self.assert_qmp(result, 'return[0]/ready', False) def test_drive_mirror(self):
Signature · 1 line
2.29.2
[PULL 32/53] block/block-copy: add block_copy_cancel
In reply to Max ReitzFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
Add function to cancel running async block-copy call. It will be used in backup.
Message-Id: <[email protected]>
--- include/block/block-copy.h | 13 +++++++++++++ block/block-copy.c | 24 +++++++++++++++++++----- 2 files changed, 32 insertions(+), 5 deletions(-)
include/block/block-copy.h +13 -0
@@ -74,11 +74,24 @@ void block_copy_call_free(BlockCopyCallState *call_state);bool block_copy_call_finished (BlockCopyCallState *call_state);bool block_copy_call_succeeded (BlockCopyCallState *call_state);bool block_copy_call_failed (BlockCopyCallState *call_state); +bool block_copy_call_cancelled (BlockCopyCallState *call_state);int block_copy_call_status (BlockCopyCallState *call_state,bool *error_is_read);void block_copy_set_speed (BlockCopyState *s,uint64_t speed);void block_copy_kick (BlockCopyCallState *call_state); +/* +* Cancel running block-copy call. +* +* Cancel leaves block-copy state valid: dirty bits are correct and you may use +* cancel + <run block_copy with same parameters> to emulate pause/resume. +* +* Note also, that the cancel is async: it only marks block-copy call to be +* cancelled. So, the call may be cancelled (block_copy_call_cancelled() reports +* true) but not yet finished (block_copy_call_finished() reports false). +*/ +void block_copy_call_cancel (BlockCopyCallState *call_state); +BdrvDirtyBitmap *block_copy_dirty_bitmap (BlockCopyState *s);void block_copy_set_skip_unallocated (BlockCopyState *s,bool skip);
block/block-copy.c +19 -5
@@ -51,6 +51,7 @@ typedef struct BlockCopyCallState {int ret;bool finished;QemuCoSleepState *sleep_state; +bool cancelled;/* OUT parameters */ bool error_is_read;
@@ -594,7 +595,7 @@ block_copy_dirty_clusters(BlockCopyCallState *call_state)assert (QEMU_IS_ALIGNED (offset, s->cluster_size));assert (QEMU_IS_ALIGNED (bytes, s->cluster_size)); -while (bytes &&aio_task_pool_status (aio) ==0 ) { +while (bytes &&aio_task_pool_status (aio) ==0 && !call_state->cancelled) {BlockCopyTask *task;int64_t status_bytes;
@@ -707,7 +708,7 @@ static int coroutine_fn block_copy_common(BlockCopyCallState *call_state) do { ret = block_copy_dirty_clusters(call_state); - if (ret == 0) { + if (ret == 0 && !call_state->cancelled) { ret = block_copy_wait_one(call_state->s, call_state->offset, call_state->bytes); }
@@ -721,7 +722,7 @@ static int coroutine_fn block_copy_common(BlockCopyCallState *call_state)* 2. We have waited for some intersecting block-copy request * It may have failed and produced new dirty bits. */ - }while (ret >0 ); + }while (ret >0 && !call_state->cancelled); call_state->finished = true;
@@ -801,12 +802,19 @@ bool block_copy_call_finished(BlockCopyCallState *call_state)bool block_copy_call_succeeded (BlockCopyCallState *call_state) { -return call_state->finished && call_state->ret ==0 ; +return call_state->finished && !call_state->cancelled && + call_state->ret ==0 ; }bool block_copy_call_failed (BlockCopyCallState *call_state) { -return call_state->finished && call_state->ret <0 ; +return call_state->finished && !call_state->cancelled && + call_state->ret <0 ; +} + +bool block_copy_call_cancelled (BlockCopyCallState *call_state) +{ +return call_state->cancelled; }int block_copy_call_status (BlockCopyCallState *call_state,bool *error_is_read)
@@ -818,6 +826,12 @@ int block_copy_call_status(BlockCopyCallState *call_state, bool *error_is_read)return call_state->ret; } +void block_copy_call_cancel (BlockCopyCallState *call_state) +{ + call_state->cancelled = true; +block_copy_kick (call_state); +} +BdrvDirtyBitmap *block_copy_dirty_bitmap (BlockCopyState *s) {return s->copy_bitmap;
Signature · 1 line
2.29.2
[PULL 27/53] block/block-copy: More explicit call_state
In reply to Max ReitzFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
Refactor common path to use BlockCopyCallState pointer as parameter, to prepare it for use in asynchronous block-copy (at least, we'll need to run block-copy in a coroutine, passing the whole parameters as one pointer).
Message-Id: <[email protected]>
--- block/block-copy.c | 51 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 13 deletions(-)
block/block-copy.c +38 -13
@@ -30,7 +30,15 @@ static coroutine_fn int block_copy_task_entry(AioTask *task);typedef struct BlockCopyCallState { +/* IN parameters */ +BlockCopyState *s; +int64_t offset; +int64_t bytes; + +/* State */ bool failed; + +/* OUT parameters */ bool error_is_read; }BlockCopyCallState ;
@@ -544,15 +552,17 @@ int64_t block_copy_reset_unallocated(BlockCopyState *s,* Returns 1 if dirty clusters found and successfully copied, 0 if no dirty * clusters found and -errno on failure. */ -static int coroutine_fn block_copy_dirty_clusters(BlockCopyState *s, -int64_t offset,int64_t bytes, -bool *error_is_read) +static int coroutine_fn +block_copy_dirty_clusters (BlockCopyCallState *call_state) { +BlockCopyState *s = call_state->s; +int64_t offset = call_state->offset; +int64_t bytes = call_state->bytes; +int ret =0 ;bool found_dirty = false;int64_t end = offset + bytes;AioTaskPool *aio =NULL ; -BlockCopyCallState call_state = {false, false};/* * block_copy() user is responsible for keeping source and target in same
@@ -568,7 +578,7 @@ static int coroutine_fn block_copy_dirty_clusters(BlockCopyState *s,BlockCopyTask *task;int64_t status_bytes; - task =block_copy_task_create (s, &call_state, offset, bytes); + task =block_copy_task_create (s, call_state, offset, bytes);if (!task) {/* No more dirty bits in the bitmap */ trace_block_copy_skip_range (s, offset, bytes);
@@ -633,15 +643,12 @@ out:aio_task_pool_free (aio); } -if (error_is_read && ret <0 ) { - *error_is_read = call_state.error_is_read; - }return ret <0 ? ret : found_dirty; }/* -* block_copy +* block_copy_common * * Copy requested region, accordingly to dirty bitmap. * Collaborate with parallel block_copy requests: if they succeed it will help
@@ -649,16 +656,16 @@ out:* it means that some I/O operation failed in context of _this_ block_copy call, * not some parallel operation. */ -int coroutine_fn block_copy(BlockCopyState *s, int64_t offset, int64_t bytes, -bool *error_is_read) +static int coroutine_fn block_copy_common(BlockCopyCallState *call_state) {int ret; do { - ret = block_copy_dirty_clusters(s, offset, bytes, error_is_read); + ret = block_copy_dirty_clusters(call_state); if (ret == 0) { - ret = block_copy_wait_one(s, offset, bytes); + ret = block_copy_wait_one(call_state->s, call_state->offset, + call_state->bytes); } /*
@@ -675,6 +682,24 @@ int coroutine_fn block_copy(BlockCopyState *s, int64_t offset, int64_t bytes,return ret; } +int coroutine_fn block_copy(BlockCopyState *s, int64_t start, int64_t bytes, +bool *error_is_read) +{ +BlockCopyCallState call_state = { + .s = s, + .offset = start, + .bytes = bytes, + }; + +int ret =block_copy_common (&call_state); + +if (error_is_read && ret <0 ) { + *error_is_read = call_state.error_is_read; + } + +return ret; +} +BdrvDirtyBitmap *block_copy_dirty_bitmap (BlockCopyState *s) {return s->copy_bitmap;
Signature · 1 line
2.29.2
[PULL 37/53] iotests/129: Limit backup's max-chunk/max-workers
In reply to Max ReitzRight now, this does not change anything, because backup ignores max-chunk and max-workers. However, as soon as backup is switched over to block-copy for the background copying process, we will need it to keep 129 passing.
Message-Id: <[email protected]>
--- tests/qemu-iotests/129 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
tests/qemu-iotests/129 +6 -1
@@ -71,9 +71,14 @@ class TestStopWithBlockJob(iotests.QMPTestCase): sync="full", buf_size=65536) def test_drive_backup(self): + # Limit max-chunk and max-workers so that block-copy will not + # launch so many workers working on so much data each that + # stop's bdrv_drain_all() would finish the job self.do_test_stop("drive-backup", device="drive0", target=self.target_img, format=iotests.imgfmt, - sync="full") + sync="full", + x_perf={ 'max-chunk': 65536, + 'max-workers': 8 }) def test_block_commit(self): # Add overlay above the source node so that we actually use a
Signature · 1 line
2.29.2
[PULL 33/53] blockjob: add set_speed to BlockJobDriver
In reply to Max ReitzFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
We are going to use async block-copy call in backup, so we'll need to passthrough setting backup speed to block-copy call.
Message-Id: <[email protected]>
--- include/block/blockjob_int.h | 2 ++ blockjob.c | 6 ++++++ 2 files changed, 8 insertions(+)
include/block/blockjob_int.h +2 -0
@@ -52,6 +52,8 @@ struct BlockJobDriver {* besides job->blk to the new AioContext. */ void (*attached_aio_context)(BlockJob *job,AioContext *new_context); + +void (*set_speed)(BlockJob *job,int64_t speed); };/**
blockjob.c +6 -0
@@ -256,6 +256,7 @@ static bool job_timer_pending(Job *job)void block_job_set_speed (BlockJob *job,int64_t speed,Error **errp) { +const BlockJobDriver *drv =block_job_driver (job);int64_t old_speed = job->speed;if (job_apply_verb (&job->job,JOB_VERB_SET_SPEED , errp)) {
@@ -270,6 +271,11 @@ void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp)ratelimit_set_speed (&job->limit, speed,BLOCK_JOB_SLICE_TIME ); job->speed = speed; + +if (drv->set_speed) { + drv->set_speed (job, speed); + } +if (speed && speed <= old_speed) {return ; }
Signature · 1 line
2.29.2
[PULL 21/53] iotests/129: Actually test a commit job
In reply to Max ReitzBefore this patch, test_block_commit() performs an active commit, which under the hood is a mirror job. If we want to test various different block jobs, we should perhaps run an actual commit job instead.
Doing so requires adding an overlay above the source node before the commit is done (and then specifying the source node as the top node for the commit job).
Message-Id: <[email protected]>
--- tests/qemu-iotests/129 | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-)
tests/qemu-iotests/129 +25 -2
@@ -27,6 +27,7 @@ class TestStopWithBlockJob(iotests.QMPTestCase): test_img = os.path.join(iotests.test_dir, 'test.img') target_img = os.path.join(iotests.test_dir, 'target.img') base_img = os.path.join(iotests.test_dir, 'base.img') + overlay_img = os.path.join(iotests.test_dir, 'overlay.img') def setUp(self): iotests.qemu_img('create', '-f', iotests.imgfmt, self.base_img, "1G")
@@ -37,6 +38,7 @@ class TestStopWithBlockJob(iotests.QMPTestCase): self.vm.add_object('throttle-group,id=tg0,x-bps-total=1024') source_drive = 'driver=throttle,' \ + 'node-name=source,' \ 'throttle-group=tg0,' \ f'file.driver={iotests.imgfmt},' \ f'file.file.filename={self.test_img}'
@@ -46,7 +48,8 @@ class TestStopWithBlockJob(iotests.QMPTestCase): def tearDown(self): self.vm.shutdown() - for img in (self.test_img, self.target_img, self.base_img): + for img in (self.test_img, self.target_img, self.base_img, + self.overlay_img): iotests.try_remove(img) def do_test_stop(self, cmd, **args):
@@ -73,7 +76,27 @@ class TestStopWithBlockJob(iotests.QMPTestCase): sync="full") def test_block_commit(self): - self.do_test_stop("block-commit", device="drive0") + # Add overlay above the source node so that we actually use a + # commit job instead of a mirror job + + iotests.qemu_img('create', '-f', iotests.imgfmt, self.overlay_img, + '1G') + + result = self.vm.qmp('blockdev-add', **{ + 'node-name': 'overlay', + 'driver': iotests.imgfmt, + 'file': { + 'driver': 'file', + 'filename': self.overlay_img + } + }) + self.assert_qmp(result, 'return', {}) + + result = self.vm.qmp('blockdev-snapshot', + node='source', overlay='overlay') + self.assert_qmp(result, 'return', {}) + + self.do_test_stop('block-commit', device='drive0', top_node='source') if __name__ == '__main__': iotests.main(supported_fmts=["qcow2"],
Signature · 1 line
2.29.2
[PULL 30/53] block/block-copy: add list of all call-states
In reply to Max ReitzFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
It simplifies debugging.
Message-Id: <[email protected]>
--- block/block-copy.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
block/block-copy.c +10 -1
@@ -42,6 +42,9 @@ typedef struct BlockCopyCallState {/* Coroutine where async block-copy is running */ Coroutine *co; +/* To reference all call states from BlockCopyState */ +QLIST_ENTRY (BlockCopyCallState) list; +/* State */ int ret;bool finished;
@@ -81,7 +84,8 @@ typedef struct BlockCopyState {bool use_copy_range;int64_t copy_size;uint64_t len; - QLIST_HEAD(, BlockCopyTask) tasks; + QLIST_HEAD(, BlockCopyTask) tasks; /* All tasks from all block-copy calls */ + QLIST_HEAD(, BlockCopyCallState) calls;BdrvRequestFlags write_flags;
@@ -282,6 +286,7 @@ BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target, }QLIST_INIT (&s->tasks); +QLIST_INIT (&s->calls);return s; }
@@ -669,6 +674,8 @@ static int coroutine_fn block_copy_common(BlockCopyCallState *call_state) {int ret; +QLIST_INSERT_HEAD (&call_state->s->calls, call_state, list); + do { ret = block_copy_dirty_clusters(call_state);
@@ -694,6 +701,8 @@ static int coroutine_fn block_copy_common(BlockCopyCallState *call_state) call_state->cb (call_state->cb_opaque); } +QLIST_REMOVE (call_state, list); +return ret; }
Signature · 1 line
2.29.2
[PULL 38/53] iotests: 185: prepare for backup over block-copy
In reply to Max ReitzFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
The further change of moving backup to be a one block-copy call will make copying chunk-size and cluster-size two separate things. So, even with 64k cluster sized qcow2 image, default chunk would be 1M. 185 test however assumes, that with speed limited to 64K, one iteration would result in offset=64K. It will change, as first iteration would result in offset=1M independently of speed.
So, let's explicitly specify, what test wants: set max-chunk to 64K, so that one iteration is 64K. Note, that we don't need to limit max-workers, as block-copy rate limiter will handle the situation and wouldn't start new workers when speed limit is obviously reached.
Message-Id: <[email protected]>
--- tests/qemu-iotests/185 | 3 ++- tests/qemu-iotests/185.out | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
tests/qemu-iotests/185 +2 -1
@@ -183,7 +183,8 @@ _send_qemu_cmd $h \ 'target': '$TEST_IMG.copy', 'format': '$IMGFMT', 'sync': 'full', - 'speed': 65536 } }" \ + 'speed': 65536, + 'x-perf': {'max-chunk': 65536} } }" \ "return" # If we don't sleep here 'quit' command races with disk I/O
tests/qemu-iotests/185.out +2 -1
@@ -88,7 +88,8 @@ Formatting 'TEST_DIR/t.qcow2.copy', fmt=qcow2 cluster_size=65536 extended_l2=off 'target': 'TEST_DIR/t.IMGFMT.copy', 'format': 'IMGFMT', 'sync': 'full', - 'speed': 65536 } } + 'speed': 65536, + 'x-perf': { 'max-chunk': 65536 } } } Formatting 'TEST_DIR/t.qcow2.copy', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=67108864 lazy_refcounts=off refcount_bits=16 {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "created", "id": "disk"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "running", "id": "disk"}}
Signature · 1 line
2.29.2
[PULL 26/53] qapi: backup: add perf.use-copy-range parameter
In reply to Max ReitzFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
Experiments show, that copy_range is not always making things faster. So, to make experimentation simpler, let's add a parameter. Some more perf parameters will be added soon, so here is a new struct.
For now, add new backup qmp parameter with x- prefix for the following reasons:
- We are going to add more performance parameters, some will be related to the whole block-copy process, some only to background copying in backup (ignored for copy-before-write operations).
- On the other hand, we are going to use block-copy interface in other block jobs, which will need performance options as well.. And it should be the same structure or at least somehow related.
So, there are too much unclean things about how the interface and now we need the new options mostly for testing. Let's keep them experimental for a while.
In do_backup_common() new x-perf parameter handled in a way to make further options addition simpler.
We add use-copy-range with default=true, and we'll change the default in further patch, after moving backup to use block-copy.
Message-Id: <[email protected]>
--- qapi/block-core.json | 17 ++++++++++++++++- block/backup-top.h | 1 + include/block/block-copy.h | 2 +- include/block/block_int.h | 3 +++ block/backup-top.c | 4 +++- block/backup.c | 6 +++++- block/block-copy.c | 4 ++-- block/replication.c | 2 ++ blockdev.c | 8 ++++++++ 9 files changed, 41 insertions(+), 6 deletions(-)
qapi/block-core.json +16 -1
@@ -1371,6 +1371,19 @@ { 'struct': 'BlockdevSnapshot', 'data': { 'node': 'str', 'overlay': 'str' } } +## +# @BackupPerf: +# +# Optional parameters for backup. These parameters don't affect +# functionality, but may significantly affect performance. +# +# @use-copy-range: Use copy offloading. Default true. +# +# Since: 6.0 +## +{ 'struct': 'BackupPerf', + 'data': { '*use-copy-range': 'bool' }} + ## # @BackupCommon: #
@@ -1426,6 +1439,8 @@ # above node specified by @drive. If this option is not given, # a node name is autogenerated. (Since: 4.2) # +# @x-perf: Performance options. (Since 6.0) +# # Note: @on-source-error and @on-target-error only affect background # I/O. If an error occurs during a guest write request, the device's # rerror/werror actions will be used.
@@ -1440,7 +1455,7 @@ '*on-source-error': 'BlockdevOnError', '*on-target-error': 'BlockdevOnError', '*auto-finalize': 'bool', '*auto-dismiss': 'bool', - '*filter-node-name': 'str' } } + '*filter-node-name': 'str', '*x-perf': 'BackupPerf' } } ## # @DriveBackup:
block/backup-top.h +1 -0
@@ -33,6 +33,7 @@ BlockDriverState *bdrv_backup_top_append(BlockDriverState *source,BlockDriverState *target, const char *filter_node_name, uint64_t cluster_size, + BackupPerf *perf, BdrvRequestFlags write_flags, BlockCopyState **bcs, Error **errp);
include/block/block-copy.h +1 -1
@@ -22,7 +22,7 @@ typedef void (*ProgressBytesCallbackFunc)(int64_t bytes, void *opaque);typedef struct BlockCopyState BlockCopyState ;BlockCopyState *block_copy_state_new (BdrvChild *source,BdrvChild *target, -int64_t cluster_size, +int64_t cluster_size,bool use_copy_range,BdrvRequestFlags write_flags,Error **errp);
include/block/block_int.h +3 -0
@@ -1266,6 +1266,8 @@ void mirror_start(const char *job_id, BlockDriverState *bs,* @sync_mode: What parts of the disk image should be copied to the destination. * @sync_bitmap: The dirty bitmap if sync_mode is 'bitmap' or 'incremental' * @bitmap_mode: The bitmap synchronization policy to use. +* @perf: Performance options. All actual fields assumed to be present, +* all ".has_*" fields are ignored. * @on_source_error: The action to take upon error reading from the source. * @on_target_error: The action to take upon error writing to the target. * @creation_flags: Flags that control the behavior of the Job lifetime.
@@ -1284,6 +1286,7 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,BitmapSyncMode bitmap_mode, bool compress, const char *filter_node_name, + BackupPerf *perf, BlockdevOnError on_source_error, BlockdevOnError on_target_error, int creation_flags,
block/backup-top.c +3 -1
@@ -186,6 +186,7 @@ BlockDriverState *bdrv_backup_top_append(BlockDriverState *source,BlockDriverState *target, const char *filter_node_name, uint64_t cluster_size, + BackupPerf *perf, BdrvRequestFlags write_flags, BlockCopyState **bcs, Error **errp)
@@ -244,7 +245,8 @@ BlockDriverState *bdrv_backup_top_append(BlockDriverState *source, state->cluster_size = cluster_size; state->bcs =block_copy_state_new (top->backing, state->target, - cluster_size, write_flags, &local_err); + cluster_size, perf->use_copy_range, + write_flags, &local_err);if (local_err) {error_prepend (&local_err,"Cannot create block-copy-state: " ); goto fail;
block/backup.c +5 -1
@@ -46,6 +46,7 @@ typedef struct BackupBlockJob {uint64_t len;uint64_t bytes_read;int64_t cluster_size; +BackupPerf perf;BlockCopyState *bcs; } BackupBlockJob;
@@ -335,6 +336,7 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,BitmapSyncMode bitmap_mode, bool compress, const char *filter_node_name, + BackupPerf *perf, BlockdevOnError on_source_error, BlockdevOnError on_target_error, int creation_flags,
@@ -441,7 +443,8 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs, (compress ?BDRV_REQ_WRITE_COMPRESSED :0 ), backup_top =bdrv_backup_top_append (bs, target, filter_node_name, - cluster_size, write_flags, &bcs, errp); + cluster_size, perf, + write_flags, &bcs, errp);if (!backup_top) { goto error; }
@@ -464,6 +467,7 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs, job->bcs = bcs; job->cluster_size = cluster_size; job->len = len; + job->perf = *perf;block_copy_set_progress_callback (bcs, backup_progress_bytes_callback, job);block_copy_set_progress_meter (bcs, &job->common.job.progress);
block/block-copy.c +2 -2
@@ -218,7 +218,7 @@ static uint32_t block_copy_max_transfer(BdrvChild *source, BdrvChild *target) }BlockCopyState *block_copy_state_new (BdrvChild *source,BdrvChild *target, -int64_t cluster_size, +int64_t cluster_size,bool use_copy_range,BdrvRequestFlags write_flags,Error **errp) {BlockCopyState *s;
@@ -260,7 +260,7 @@ BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target,* We enable copy-range, but keep small copy_size, until first * successful copy_range (look at block_copy_do_copy). */ - s->use_copy_range = true; + s->use_copy_range = use_copy_range; s->copy_size =MAX (s->cluster_size,BLOCK_COPY_MAX_BUFFER ); }
block/replication.c +2 -0
@@ -454,6 +454,7 @@ static void replication_start(ReplicationState *rs, ReplicationMode mode,int64_t active_length, hidden_length, disk_length;AioContext *aio_context;Error *local_err =NULL ; +BackupPerf perf = { .use_copy_range = true }; aio_context =bdrv_get_aio_context (bs);aio_context_acquire (aio_context);
@@ -558,6 +559,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,BLOCKDEV_ON_ERROR_REPORT ,BLOCKDEV_ON_ERROR_REPORT ,JOB_INTERNAL , backup_job_completed, bs,NULL , &local_err);
blockdev.c +8 -0
@@ -2829,6 +2829,7 @@ static BlockJob *do_backup_common(BackupCommon *backup, {BlockJob *job =NULL ;BdrvDirtyBitmap *bmap =NULL ; +BackupPerf perf = { .use_copy_range = true };int job_flags =JOB_DEFAULT ;if (!backup->has_speed) {
@@ -2853,6 +2854,12 @@ static BlockJob *do_backup_common(BackupCommon *backup, backup->compress = false; } +if (backup->x_perf) { +if (backup->x_perf->has_use_copy_range) { + perf.use_copy_range = backup->x_perf->use_copy_range; + } + } +if ((backup->sync ==MIRROR_SYNC_MODE_BITMAP ) || (backup->sync ==MIRROR_SYNC_MODE_INCREMENTAL )) {/* done before desugaring 'incremental' to print the right message */
@@ -2926,6 +2933,7 @@ static BlockJob *do_backup_common(BackupCommon *backup, backup->sync, bmap, backup->bitmap_mode, backup->compress, backup->filter_node_name, + &perf, backup->on_source_error, backup->on_target_error, job_flags, NULL, NULL, txn, errp);
Signature · 1 line
2.29.2
[PULL 39/53] iotests: 219: prepare for backup over block-copy
In reply to Max ReitzFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
The further change of moving backup to be a one block-copy call will make copying chunk-size and cluster-size two separate things. So, even with 64k cluster sized qcow2 image, default chunk would be 1M. Test 219 depends on specified chunk-size. Update it for explicit chunk-size for backup as for mirror.
Message-Id: <[email protected]>
--- tests/qemu-iotests/219 | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
tests/qemu-iotests/219 +7 -6
@@ -204,13 +204,13 @@ with iotests.FilePath('disk.img') as disk_path, \ # but related to this also automatic state transitions like job # completion), but still get pause points often enough to avoid making this # test very slow, it's important to have the right ratio between speed and - # buf_size. + # copy-chunk-size. # - # For backup, buf_size is hard-coded to the source image cluster size (64k), - # so we'll pick the same for mirror. The slice time, i.e. the granularity - # of the rate limiting is 100ms. With a speed of 256k per second, we can - # get four pause points per second. This gives us 250ms per iteration, - # which should be enough to stay deterministic. + # Chose 64k copy-chunk-size both for mirror (by buf_size) and backup (by + # x-max-chunk). The slice time, i.e. the granularity of the rate limiting + # is 100ms. With a speed of 256k per second, we can get four pause points + # per second. This gives us 250ms per iteration, which should be enough to + # stay deterministic. test_job_lifecycle(vm, 'drive-mirror', has_ready=True, job_args={ 'device': 'drive0-node',
@@ -227,6 +227,7 @@ with iotests.FilePath('disk.img') as disk_path, \ 'target': copy_path, 'sync': 'full', 'speed': 262144, + 'x-perf': {'max-chunk': 65536}, 'auto-finalize': auto_finalize, 'auto-dismiss': auto_dismiss, })
Signature · 1 line
2.29.2
[PULL 31/53] block/block-copy: add ratelimit to block-copy
In reply to Max ReitzFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
We are going to directly use one async block-copy operation for backup job, so we need rate limiter.
We want to maintain current backup behavior: only background copying is limited and copy-before-write operations only participate in limit calculation. Therefore we need one rate limiter for block-copy state and boolean flag for block-copy call state for actual limitation.
Note, that we can't just calculate each chunk in limiter after successful copying: it will not save us from starting a lot of async sub-requests which will exceed limit too much. Instead let's use the following scheme on sub-request creation:
1. If at the moment limit is not exceeded, create the request and account it immediately.
2. If at the moment limit is already exceeded, drop create sub-request and handle limit instead (by sleep).
With this approach we'll never exceed the limit more than by one sub-request (which pretty much matches current backup behavior).
Note also, that if there is in-flight block-copy async call, block_copy_kick() should be used after set-speed to apply new setup faster. For that block_copy_kick() published in this patch.
Message-Id: <[email protected]>
--- include/block/block-copy.h | 5 ++++- block/backup-top.c | 2 +- block/backup.c | 2 +- block/block-copy.c | 46 +++++++++++++++++++++++++++++++++++++- 4 files changed, 51 insertions(+), 4 deletions(-)
include/block/block-copy.h +4 -1
@@ -41,7 +41,7 @@ int64_t block_copy_reset_unallocated(BlockCopyState *s, int64_t offset, int64_t *count); int coroutine_fn block_copy(BlockCopyState *s, int64_t offset, int64_t bytes, -bool *error_is_read); +bool ignore_ratelimit,bool *error_is_read);/* * Run block-copy in a coroutine, create corresponding BlockCopyCallState
@@ -76,6 +76,9 @@ bool block_copy_call_succeeded(BlockCopyCallState *call_state);bool block_copy_call_failed (BlockCopyCallState *call_state);int block_copy_call_status (BlockCopyCallState *call_state,bool *error_is_read); +void block_copy_set_speed (BlockCopyState *s,uint64_t speed); +void block_copy_kick (BlockCopyCallState *call_state); +BdrvDirtyBitmap *block_copy_dirty_bitmap (BlockCopyState *s);void block_copy_set_skip_unallocated (BlockCopyState *s,bool skip);
block/backup-top.c +1 -1
@@ -61,7 +61,7 @@ static coroutine_fn int backup_top_cbw(BlockDriverState *bs, uint64_t offset, off =QEMU_ALIGN_DOWN (offset, s->cluster_size); end =QEMU_ALIGN_UP (offset + bytes, s->cluster_size); -return block_copy (s->bcs, off, end - off,NULL ); +return block_copy (s->bcs, off, end - off, true,NULL ); } static int coroutine_fn backup_top_co_pdiscard(BlockDriverState *bs,
block/backup.c +1 -1
@@ -72,7 +72,7 @@ static int coroutine_fn backup_do_cow(BackupBlockJob *job,trace_backup_do_cow_enter (job, start, offset, bytes); - ret =block_copy (job->bcs, start, end - start, error_is_read); + ret =block_copy (job->bcs, start, end - start, true, error_is_read);trace_backup_do_cow_return (job, offset, bytes, ret);
block/block-copy.c +45 -1
96 lines not on this page · raw message
Signature · 1 line
2.29.2
[PULL 40/53] iotests: 257: prepare for backup over block-copy
In reply to Max ReitzFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
Iotest 257 dumps a lot of in-progress information of backup job, such as offset and bitmap dirtiness. Further commit will move backup to be one block-copy call, which will introduce async parallel requests instead of plain cluster-by-cluster copying. To keep things deterministic, allow only one worker (only one copy request at a time) for this test.
Message-Id: <[email protected]>
--- tests/qemu-iotests/257 | 1 + tests/qemu-iotests/257.out | 306 ++++++++++++++++++------------------- 2 files changed, 154 insertions(+), 153 deletions(-)
tests/qemu-iotests/257 +1 -0
@@ -192,6 +192,7 @@ def blockdev_backup(vm, device, target, sync, **kwargs): target=target, sync=sync, filter_node_name='backup-top', + x_perf={'max-workers': 1}, **kwargs) return result
tests/qemu-iotests/257.out +153 -153
1,043 lines not on this page · raw message
Signature · 1 line
2.29.2
[PULL 29/53] block/block-copy: add max_chunk and max_workers parameters
In reply to Max ReitzFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
They will be used for backup.
Message-Id: <[email protected]>
--- include/block/block-copy.h | 6 ++++++ block/block-copy.c | 11 +++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-)
include/block/block-copy.h +6 -0
@@ -49,9 +49,15 @@ int coroutine_fn block_copy(BlockCopyState *s, int64_t offset, int64_t bytes,* * Caller is responsible to call block_copy_call_free() to free * BlockCopyCallState object. +* +* @max_workers means maximum of parallel coroutines to execute sub-requests, +* must be > 0. +* +* @max_chunk means maximum length for one IO operation. Zero means unlimited. */ BlockCopyCallState *block_copy_async (BlockCopyState *s,int64_t offset,int64_t bytes, +int max_workers,int64_t max_chunk,BlockCopyAsyncCallbackFunc cb,void *cb_opaque);
block/block-copy.c +9 -2
@@ -34,6 +34,8 @@ typedef struct BlockCopyCallState {BlockCopyState *s;int64_t offset;int64_t bytes; +int max_workers; +int64_t max_chunk;BlockCopyAsyncCallbackFunc cb;void *cb_opaque;
@@ -148,10 +150,11 @@ static BlockCopyTask *block_copy_task_create(BlockCopyState *s, int64_t offset, int64_t bytes) {BlockCopyTask *task; +int64_t max_chunk =MIN_NON_ZERO (s->copy_size, call_state->max_chunk);if (!bdrv_dirty_bitmap_next_dirty_area (s->copy_bitmap, offset, offset + bytes, - s->copy_size, &offset, &bytes)) + max_chunk, &offset, &bytes)) {return NULL ; }
@@ -623,7 +626,7 @@ block_copy_dirty_clusters(BlockCopyCallState *call_state) bytes = end - offset;if (!aio && bytes) { - aio =aio_task_pool_new (BLOCK_COPY_MAX_WORKERS ); + aio =aio_task_pool_new (call_state->max_workers); } ret =block_copy_task_run (aio, task);
@@ -701,6 +704,7 @@ int coroutine_fn block_copy(BlockCopyState *s, int64_t start, int64_t bytes, .s = s, .offset = start, .bytes = bytes, + .max_workers = BLOCK_COPY_MAX_WORKERS, };int ret =block_copy_common (&call_state);
@@ -719,6 +723,7 @@ static void coroutine_fn block_copy_async_co_entry(void *opaque)BlockCopyCallState *block_copy_async (BlockCopyState *s,int64_t offset,int64_t bytes, +int max_workers,int64_t max_chunk,BlockCopyAsyncCallbackFunc cb,void *cb_opaque) {
@@ -728,6 +733,8 @@ BlockCopyCallState *block_copy_async(BlockCopyState *s, .s = s, .offset = offset, .bytes = bytes, + .max_workers = max_workers, + .max_chunk = max_chunk, .cb = cb, .cb_opaque = cb_opaque,
Signature · 1 line
2.29.2
[PULL 44/53] qapi: backup: disable copy_range by default
In reply to Max ReitzFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
Further commit will add a benchmark (scripts/simplebench/bench-backup.py), which will show that backup works better with async parallel requests (previous commit) and disabled copy_range. So, let's disable copy_range by default.
Note: the option was added several commits ago with default to true, to follow old behavior (the feature was enabled unconditionally), and only now we are going to change the default behavior.
Message-Id: <[email protected]>
--- qapi/block-core.json | 2 +- blockdev.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
qapi/block-core.json +1 -1
@@ -1377,7 +1377,7 @@ # Optional parameters for backup. These parameters don't affect # functionality, but may significantly affect performance. # -# @use-copy-range: Use copy offloading. Default true. +# @use-copy-range: Use copy offloading. Default false. # # @max-workers: Maximum number of parallel requests for the sustained background # copying process. Doesn't influence copy-before-write operations.
blockdev.c +1 -1
@@ -2829,7 +2829,7 @@ static BlockJob *do_backup_common(BackupCommon *backup, {BlockJob *job =NULL ;BdrvDirtyBitmap *bmap =NULL ; -BackupPerf perf = { .use_copy_range = true, .max_workers =64 }; +BackupPerf perf = { .max_workers =64 };int job_flags =JOB_DEFAULT ;if (!backup->has_speed) {
Signature · 1 line
2.29.2
[PULL 34/53] job: call job_enter from job_pause
In reply to Max ReitzFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
If main job coroutine called job_yield (while some background process is in progress), we should give it a chance to call job_pause_point(). It will be used in backup, when moved on async block-copy.
Note, that job_user_pause is not enough: we want to handle child_job_drained_begin() as well, which call job_pause().
Still, if job is already in job_do_yield() in job_pause_point() we should not enter it.
iotest 109 output is modified: on stop we do bdrv_drain_all() which now triggers job pause immediately (and pause after ready is standby).
Message-Id: <[email protected]>
--- job.c | 3 +++ tests/qemu-iotests/109.out | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+)
job.c +3 -0
@@ -553,6 +553,9 @@ static bool job_timer_not_pending(Job *job)void job_pause (Job *job) { job->pause_count++; +if (!job->paused) { +job_enter (job); + } }void job_resume (Job *job)
tests/qemu-iotests/109.out +24 -0
@@ -42,6 +42,8 @@ read 512/512 bytes at offset 0 {"execute":"quit"} {"return": {}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false, "reason": "host-qmp-quit"}} +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "standby", "id": "src"}} +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "ready", "id": "src"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "waiting", "id": "src"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "pending", "id": "src"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 1024, "offset": 1024, "speed": 0, "type": "mirror"}}
@@ -91,6 +93,8 @@ read 512/512 bytes at offset 0 {"execute":"quit"} {"return": {}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false, "reason": "host-qmp-quit"}} +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "standby", "id": "src"}} +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "ready", "id": "src"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "waiting", "id": "src"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "pending", "id": "src"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 197120, "offset": 197120, "speed": 0, "type": "mirror"}}
@@ -140,6 +144,8 @@ read 512/512 bytes at offset 0 {"execute":"quit"} {"return": {}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false, "reason": "host-qmp-quit"}} +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "standby", "id": "src"}} +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "ready", "id": "src"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "waiting", "id": "src"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "pending", "id": "src"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 327680, "offset": 327680, "speed": 0, "type": "mirror"}}
@@ -189,6 +195,8 @@ read 512/512 bytes at offset 0 {"execute":"quit"} {"return": {}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false, "reason": "host-qmp-quit"}} +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "standby", "id": "src"}} +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "ready", "id": "src"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "waiting", "id": "src"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "pending", "id": "src"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 1024, "offset": 1024, "speed": 0, "type": "mirror"}}
@@ -238,6 +246,8 @@ read 512/512 bytes at offset 0 {"execute":"quit"} {"return": {}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false, "reason": "host-qmp-quit"}} +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "standby", "id": "src"}} +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "ready", "id": "src"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "waiting", "id": "src"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "pending", "id": "src"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 65536, "offset": 65536, "speed": 0, "type": "mirror"}}
@@ -287,6 +297,8 @@ read 512/512 bytes at offset 0 {"execute":"quit"} {"return": {}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false, "reason": "host-qmp-quit"}} +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "standby", "id": "src"}} +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "ready", "id": "src"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "waiting", "id": "src"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "pending", "id": "src"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 2560, "offset": 2560, "speed": 0, "type": "mirror"}}
@@ -335,6 +347,8 @@ read 512/512 bytes at offset 0 {"execute":"quit"} {"return": {}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false, "reason": "host-qmp-quit"}} +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "standby", "id": "src"}} +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "ready", "id": "src"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "waiting", "id": "src"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "pending", "id": "src"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 2560, "offset": 2560, "speed": 0, "type": "mirror"}}
@@ -383,6 +397,8 @@ read 512/512 bytes at offset 0 {"execute":"quit"} {"return": {}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false, "reason": "host-qmp-quit"}} +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "standby", "id": "src"}} +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "ready", "id": "src"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "waiting", "id": "src"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "pending", "id": "src"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 31457280, "offset": 31457280, "speed": 0, "type": "mirror"}}
@@ -431,6 +447,8 @@ read 512/512 bytes at offset 0 {"execute":"quit"} {"return": {}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false, "reason": "host-qmp-quit"}} +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "standby", "id": "src"}} +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "ready", "id": "src"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "waiting", "id": "src"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "pending", "id": "src"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 327680, "offset": 327680, "speed": 0, "type": "mirror"}}
@@ -479,6 +497,8 @@ read 512/512 bytes at offset 0 {"execute":"quit"} {"return": {}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false, "reason": "host-qmp-quit"}} +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "standby", "id": "src"}} +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "ready", "id": "src"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "waiting", "id": "src"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "pending", "id": "src"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 2048, "offset": 2048, "speed": 0, "type": "mirror"}}
@@ -507,6 +527,8 @@ WARNING: Image format was not specified for 'TEST_DIR/t.raw' and probing guessed {"execute":"quit"} {"return": {}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false, "reason": "host-qmp-quit"}} +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "standby", "id": "src"}} +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "ready", "id": "src"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "waiting", "id": "src"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "pending", "id": "src"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 512, "offset": 512, "speed": 0, "type": "mirror"}}
@@ -528,6 +550,8 @@ Images are identical. {"execute":"quit"} {"return": {}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false, "reason": "host-qmp-quit"}} +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "standby", "id": "src"}} +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "ready", "id": "src"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "waiting", "id": "src"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "pending", "id": "src"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "src", "len": 512, "offset": 512, "speed": 0, "type": "mirror"}}
Signature · 1 line
2.29.2
[PULL 43/53] backup: move to block-copy
In reply to Max ReitzFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
This brings async request handling and block-status driven chunk sizes to backup out of the box, which improves backup performance.
Message-Id: <[email protected]>
--- block/backup.c | 187 +++++++++++++++++++++++++++++++------------------ 1 file changed, 120 insertions(+), 67 deletions(-)
block/backup.c +120 -67
@@ -22,7 +22,6 @@#include "block/block-copy.h" #include "qapi/error.h" #include "qapi/qmp/qerror.h" -#include "qemu/ratelimit.h" #include "qemu/cutils.h" #include "sysemu/block-backend.h" #include "qemu/bitmap.h"
@@ -44,41 +43,17 @@ typedef struct BackupBlockJob {BlockdevOnError on_source_error;BlockdevOnError on_target_error;uint64_t len; -uint64_t bytes_read;int64_t cluster_size;BackupPerf perf;BlockCopyState *bcs; + +bool wait; +BlockCopyCallState *bg_bcs_call; } BackupBlockJob;static const BlockJobDriver backup_job_driver; -static void backup_progress_bytes_callback (int64_t bytes,void *opaque) -{ -BackupBlockJob *s = opaque; - - s->bytes_read += bytes; -} - -static int coroutine_fn backup_do_cow(BackupBlockJob *job, -int64_t offset,uint64_t bytes, -bool *error_is_read) -{ -int ret =0 ; -int64_t start, end;/* bytes */ - - start =QEMU_ALIGN_DOWN (offset, job->cluster_size); - end =QEMU_ALIGN_UP (bytes + offset, job->cluster_size); - -trace_backup_do_cow_enter (job, start, offset, bytes); - - ret =block_copy (job->bcs, start, end - start, true, error_is_read); - -trace_backup_do_cow_return (job, offset, bytes, ret); - -return ret; -} -static void backup_cleanup_sync_bitmap (BackupBlockJob *job,int ret) {BdrvDirtyBitmap *bm;
@@ -158,53 +133,96 @@ static BlockErrorAction backup_error_action(BackupBlockJob *job, } } -static bool coroutine_fn yield_and_check(BackupBlockJob *job) +static void coroutine_fn backup_block_copy_callback(void *opaque) { -uint64_t delay_ns; - -if (job_is_cancelled (&job->common.job)) { -return true; - } - -/* -* We need to yield even for delay_ns = 0 so that bdrv_drain_all() can -* return. Without a yield, the VM would not reboot. -*/ - delay_ns =block_job_ratelimit_get_delay (&job->common, job->bytes_read); - job->bytes_read =0 ; -job_sleep_ns (&job->common.job, delay_ns); +BackupBlockJob *s = opaque; -if (job_is_cancelled (&job->common.job)) { -return true; +if (s->wait) { + s->wait = false; +aio_co_wake (s->common.job.co); + }else { +job_enter (&s->common.job); } - -return false; } static int coroutine_fn backup_loop(BackupBlockJob *job) { -bool error_is_read; -int64_t offset; -BdrvDirtyBitmapIter *bdbi; +BlockCopyCallState *s =NULL ;int ret =0 ; +bool error_is_read; +BlockErrorAction act; + +while (true) {/* retry loop */ + job->bg_bcs_call = s =block_copy_async (job->bcs,0 , +QEMU_ALIGN_UP (job->len, job->cluster_size), + job->perf.max_workers, job->perf.max_chunk, + backup_block_copy_callback, job); + +while (!block_copy_call_finished (s) && + !job_is_cancelled (&job->common.job)) + { +job_yield (&job->common.job); + } - bdbi =bdrv_dirty_iter_new (block_copy_dirty_bitmap (job->bcs)); -while ((offset =bdrv_dirty_iter_next (bdbi)) !=-1 ) { -do { -if (yield_and_check (job)) { - goto out; - } - ret =backup_do_cow (job, offset, job->cluster_size, &error_is_read); -if (ret <0 &&backup_error_action (job, error_is_read, -ret) == -BLOCK_ERROR_ACTION_REPORT ) - { - goto out; - } - }while (ret <0 ); +if (!block_copy_call_finished (s)) { +assert (job_is_cancelled (&job->common.job)); +/* +* Note that we can't use job_yield() here, as it doesn't work for +* cancelled job. +*/ +block_copy_call_cancel (s); + job->wait = true; +qemu_coroutine_yield (); +assert (block_copy_call_finished (s)); + ret =0 ; + goto out; + } + +if (job_is_cancelled (&job->common.job) || +block_copy_call_succeeded (s)) + { + ret =0 ; + goto out; + } + +if (block_copy_call_cancelled (s)) { +/* +* Job is not cancelled but only block-copy call. This is possible +* after job pause. Now the pause is finished, start new block-copy +* iteration. +*/ +block_copy_call_free (s); +continue ; + } + +/* The only remaining case is failed block-copy call. */ +assert (block_copy_call_failed (s)); + + ret =block_copy_call_status (s, &error_is_read); + act =backup_error_action (job, error_is_read, -ret); +switch (act) { +case BLOCK_ERROR_ACTION_REPORT : + goto out; +case BLOCK_ERROR_ACTION_STOP : +/* +* Go to pause prior to starting new block-copy call on the next +* iteration. +*/ +job_pause_point (&job->common.job); +break ; +case BLOCK_ERROR_ACTION_IGNORE : +/* Proceed to new block-copy call to retry. */ +break ; +default : +abort (); + } + +block_copy_call_free (s); } - out: -bdrv_dirty_iter_free (bdbi); +out: +block_copy_call_free (s); + job->bg_bcs_call =NULL ;return ret; }
@@ -245,7 +263,13 @@ static int coroutine_fn backup_run(Job *job, Error **errp)int64_t count;for (offset =0 ; offset < s->len; ) { -if (yield_and_check (s)) { +if (job_is_cancelled (job)) { +return -ECANCELED ; + } + +job_pause_point (job); + +if (job_is_cancelled (job)) {return -ECANCELED ; }
@@ -278,6 +302,33 @@ static int coroutine_fn backup_run(Job *job, Error **errp)return 0 ; } +static void coroutine_fn backup_pause(Job *job) +{ +BackupBlockJob *s =container_of (job, BackupBlockJob, common.job); + +if (s->bg_bcs_call && !block_copy_call_finished (s->bg_bcs_call)) { +block_copy_call_cancel (s->bg_bcs_call); + s->wait = true; +qemu_coroutine_yield (); + } +} + +static void coroutine_fn backup_set_speed(BlockJob *job, int64_t speed) +{ +BackupBlockJob *s =container_of (job, BackupBlockJob, common); + +/* +* block_job_set_speed() is called first from block_job_create(), when we +* don't yet have s->bcs. +*/ +if (s->bcs) { +block_copy_set_speed (s->bcs, speed); +if (s->bg_bcs_call) { +block_copy_kick (s->bg_bcs_call); + } + } +} +static const BlockJobDriver backup_job_driver = { .job_driver = { .instance_size =sizeof (BackupBlockJob),
@@ -288,7 +339,9 @@ static const BlockJobDriver backup_job_driver = { .commit = backup_commit, .abort = backup_abort, .clean = backup_clean, - } + .pause = backup_pause, + }, + .set_speed = backup_set_speed, }; static int64_t backup_calculate_cluster_size(BlockDriverState *target,
@@ -485,8 +538,8 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs, job->len = len; job->perf = *perf; -block_copy_set_progress_callback (bcs, backup_progress_bytes_callback, job);block_copy_set_progress_meter (bcs, &job->common.job.progress); +block_copy_set_speed (bcs, speed);/* Required permissions are already taken by backup-top target */ block_job_add_bdrv(&job->common, "target", target, 0, BLK_PERM_ALL,
Signature · 1 line
2.29.2
[PULL 35/53] qapi: backup: add max-chunk and max-workers to x-perf struct
In reply to Max ReitzFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
Add new parameters to configure future backup features. The patch doesn't introduce aio backup requests (so we actually have only one worker) neither requests larger than one cluster. Still, formally we satisfy these maximums anyway, so add the parameters now, to facilitate further patch which will really change backup job behavior.
Message-Id: <[email protected]>
--- qapi/block-core.json | 13 ++++++++++++- block/backup.c | 28 +++++++++++++++++++++++----- block/replication.c | 2 +- blockdev.c | 8 +++++++- 4 files changed, 43 insertions(+), 8 deletions(-)
qapi/block-core.json +12 -1
@@ -1379,10 +1379,21 @@ # # @use-copy-range: Use copy offloading. Default true. # +# @max-workers: Maximum number of parallel requests for the sustained background +# copying process. Doesn't influence copy-before-write operations. +# Default 64. +# +# @max-chunk: Maximum request length for the sustained background copying +# process. Doesn't influence copy-before-write operations. +# 0 means unlimited. If max-chunk is non-zero then it should not be +# less than job cluster size which is calculated as maximum of +# target image cluster size and 64k. Default 0. +# # Since: 6.0 ## { 'struct': 'BackupPerf', - 'data': { '*use-copy-range': 'bool' }} + 'data': { '*use-copy-range': 'bool', + '*max-workers': 'int', '*max-chunk': 'int64' } } ## # @BackupCommon:
block/backup.c +23 -5
@@ -388,6 +388,29 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,return NULL ; } + cluster_size =backup_calculate_cluster_size (target, errp); +if (cluster_size <0 ) { + goto error; + } + +if (perf->max_workers <1 ) { +error_setg (errp,"max-workers must be greater than zero" ); +return NULL ; + } + +if (perf->max_chunk <0 ) { +error_setg (errp,"max-chunk must be zero (which means no limit) or " +"positive" ); +return NULL ; + } + +if (perf->max_chunk && perf->max_chunk < cluster_size) { +error_setg (errp,"Required max-chunk (%" PRIi64") is less than backup " +"cluster size (%" PRIi64")" , perf->max_chunk, cluster_size); +return NULL ; + } + +if (sync_bitmap) {/* If we need to write to this bitmap, check that we can: */ if (bitmap_mode != BITMAP_SYNC_MODE_NEVER &&
@@ -420,11 +443,6 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs, goto error; } - cluster_size =backup_calculate_cluster_size (target, errp); -if (cluster_size <0 ) { - goto error; - } -/* * If source is in backing chain of target assume that target is going to be * used for "image fleecing", i.e. it should represent a kind of snapshot of
block/replication.c +1 -1
@@ -454,7 +454,7 @@ static void replication_start(ReplicationState *rs, ReplicationMode mode,int64_t active_length, hidden_length, disk_length;AioContext *aio_context;Error *local_err =NULL ; -BackupPerf perf = { .use_copy_range = true }; +BackupPerf perf = { .use_copy_range = true, .max_workers =1 }; aio_context =bdrv_get_aio_context (bs);aio_context_acquire (aio_context);
blockdev.c +7 -1
@@ -2829,7 +2829,7 @@ static BlockJob *do_backup_common(BackupCommon *backup, {BlockJob *job =NULL ;BdrvDirtyBitmap *bmap =NULL ; -BackupPerf perf = { .use_copy_range = true }; +BackupPerf perf = { .use_copy_range = true, .max_workers =64 };int job_flags =JOB_DEFAULT ;if (!backup->has_speed) {
@@ -2858,6 +2858,12 @@ static BlockJob *do_backup_common(BackupCommon *backup,if (backup->x_perf->has_use_copy_range) { perf.use_copy_range = backup->x_perf->use_copy_range; } +if (backup->x_perf->has_max_workers) { + perf.max_workers = backup->x_perf->max_workers; + } +if (backup->x_perf->has_max_chunk) { + perf.max_chunk = backup->x_perf->max_chunk; + } } if ((backup->sync == MIRROR_SYNC_MODE_BITMAP) ||
Signature · 1 line
2.29.2
[PULL 45/53] block/block-copy: drop unused block_copy_set_progress_callback()
In reply to Max ReitzFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
Drop unused code.
Message-Id: <[email protected]>
--- include/block/block-copy.h | 6 ------ block/block-copy.c | 15 --------------- 2 files changed, 21 deletions(-)
include/block/block-copy.h +0 -6
@@ -18,7 +18,6 @@#include "block/block.h" #include "qemu/co-shared-resource.h" -typedef void (*ProgressBytesCallbackFunc )(int64_t bytes,void *opaque);typedef void (*BlockCopyAsyncCallbackFunc )(void *opaque);typedef struct BlockCopyState BlockCopyState ;typedef struct BlockCopyCallState BlockCopyCallState ;
@@ -28,11 +27,6 @@ BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target,BdrvRequestFlags write_flags, Error **errp); -void block_copy_set_progress_callback ( -BlockCopyState *s, -ProgressBytesCallbackFunc progress_bytes_callback, -void *progress_opaque); -void block_copy_set_progress_meter (BlockCopyState *s,ProgressMeter *pm);void block_copy_state_free (BlockCopyState *s);
block/block-copy.c +0 -15
@@ -110,9 +110,6 @@ typedef struct BlockCopyState {bool skip_unallocated;ProgressMeter *progress; -/* progress_bytes_callback: called when some copying progress is done. */ -ProgressBytesCallbackFunc progress_bytes_callback; -void *progress_opaque;SharedResource *mem;
@@ -298,15 +295,6 @@ BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target,return s; } -void block_copy_set_progress_callback ( -BlockCopyState *s, -ProgressBytesCallbackFunc progress_bytes_callback, -void *progress_opaque) -{ - s->progress_bytes_callback = progress_bytes_callback; - s->progress_opaque = progress_opaque; -} -void block_copy_set_progress_meter (BlockCopyState *s,ProgressMeter *pm) { s->progress = pm;
@@ -454,9 +442,6 @@ static coroutine_fn int block_copy_task_entry(AioTask *task) t->call_state->error_is_read = error_is_read; }else {progress_work_done (t->s->progress, t->bytes); -if (t->s->progress_bytes_callback) { - t->s->progress_bytes_callback (t->bytes, t->s->progress_opaque); - } }co_put_to_shres (t->s->mem, t->bytes);block_copy_task_end (t, ret);
Signature · 1 line
2.29.2
[PULL 41/53] block/block-copy: make progress_bytes_callback optional
In reply to Max ReitzFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
We are going to stop use of this callback in the following commit. Still the callback handling code will be dropped in a separate commit. So, for now let's make it optional.
Message-Id: <[email protected]>
--- block/block-copy.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
block/block-copy.c +3 -1
@@ -454,7 +454,9 @@ static coroutine_fn int block_copy_task_entry(AioTask *task) t->call_state->error_is_read = error_is_read; }else {progress_work_done (t->s->progress, t->bytes); - t->s->progress_bytes_callback (t->bytes, t->s->progress_opaque); +if (t->s->progress_bytes_callback) { + t->s->progress_bytes_callback (t->bytes, t->s->progress_opaque); + } }co_put_to_shres (t->s->mem, t->bytes);block_copy_task_end (t, ret);
Signature · 1 line
2.29.2
[PULL 47/53] simplebench/bench_block_job: use correct shebang line with python3
In reply to Max ReitzFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
Message-Id: <[email protected]>
--- scripts/simplebench/bench_block_job.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/simplebench/bench_block_job.py +1 -1
@@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Benchmark block jobs #
Signature · 1 line
2.29.2
[PULL 36/53] iotests: 56: prepare for backup over block-copy
In reply to Max ReitzFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
After introducing parallel async copy requests instead of plain cluster-by-cluster copying loop, we'll have to wait for paused status, as we need to wait for several parallel request. So, let's gently wait instead of just asserting that job already paused.
Message-Id: <[email protected]>
--- tests/qemu-iotests/056 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
tests/qemu-iotests/056 +7 -2
@@ -308,8 +308,13 @@ class BackupTest(iotests.QMPTestCase): event = self.vm.event_wait(name="BLOCK_JOB_ERROR", match={'data': {'device': 'drive0'}}) self.assertNotEqual(event, None) - # OK, job should be wedged - res = self.vm.qmp('query-block-jobs') + # OK, job should pause, but it can't do it immediately, as it can't + # cancel other parallel requests (which didn't fail) + with iotests.Timeout(60, "Timeout waiting for backup actually paused"): + while True: + res = self.vm.qmp('query-block-jobs') + if res['return'][0]['status'] == 'paused': + break self.assert_qmp(res, 'return[0]/status', 'paused') res = self.vm.qmp('block-job-dismiss', id='drive0') self.assert_qmp(res, 'error/desc',
Signature · 1 line
2.29.2
[PULL 50/53] block: report errno when flock fcntl fails
In reply to Max ReitzFrom: David Edmondson <[email protected]>
When a call to fcntl(2) for the purpose of adding file locks fails with an error other than EAGAIN or EACCES, report the error returned by fcntl.
EAGAIN or EACCES are elided as they are considered to be common failures, indicating that a conflicting lock is held by another process.
No errors are elided when removing file locks.
Message-Id: <[email protected]>
--- block/file-posix.c | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-)
block/file-posix.c +28 -10
@@ -216,6 +216,20 @@ typedef struct RawPosixAIOData {static int cdrom_reopen (BlockDriverState *bs);#endif +/* +* Elide EAGAIN and EACCES details when failing to lock, as this +* indicates that the specified file region is already locked by +* another process, which is considered a common scenario. +*/ +#define raw_lock_error_setg_errno (errp, err, fmt, ...) \ + do { \ + if ((err) == EAGAIN || (err) == EACCES) { \ + error_setg((errp), (fmt), ## __VA_ARGS__); \ + } else { \ + error_setg_errno((errp), (err), (fmt), ## __VA_ARGS__); \ + } \ + } while (0) +#if defined(__NetBSD__)static int raw_normalize_devicepath (const char **filename,Error **errp) {
@@ -836,7 +850,8 @@ static int raw_apply_lock_bytes(BDRVRawState *s, int fd,if ((perm_lock_bits & bit) && !(locked_perm & bit)) { ret =qemu_lock_fd (fd, off,1 , false);if (ret) { -error_setg (errp,"Failed to lock byte %d" , off); +raw_lock_error_setg_errno (errp, -ret,"Failed to lock byte %d" , + off);return ret; }else if (s) { s->locked_perm |= bit;
@@ -844,7 +859,7 @@ static int raw_apply_lock_bytes(BDRVRawState *s, int fd, }else if (unlock && (locked_perm & bit) && !(perm_lock_bits & bit)) { ret =qemu_unlock_fd (fd, off,1 );if (ret) { -error_setg (errp,"Failed to unlock byte %d" , off); +error_setg_errno (errp, -ret,"Failed to unlock byte %d" , off);return ret; }else if (s) { s->locked_perm &= ~bit;
@@ -857,7 +872,8 @@ static int raw_apply_lock_bytes(BDRVRawState *s, int fd,if ((shared_perm_lock_bits & bit) && !(locked_shared_perm & bit)) { ret =qemu_lock_fd (fd, off,1 , false);if (ret) { -error_setg (errp,"Failed to lock byte %d" , off); +raw_lock_error_setg_errno (errp, -ret,"Failed to lock byte %d" , + off);return ret; }else if (s) { s->locked_shared_perm |= bit;
@@ -866,7 +882,7 @@ static int raw_apply_lock_bytes(BDRVRawState *s, int fd, !(shared_perm_lock_bits & bit)) { ret =qemu_unlock_fd (fd, off,1 );if (ret) { -error_setg (errp,"Failed to unlock byte %d" , off); +error_setg_errno (errp, -ret,"Failed to unlock byte %d" , off);return ret; }else if (s) { s->locked_shared_perm &= ~bit;
@@ -890,9 +906,10 @@ static int raw_check_lock_bytes(int fd, uint64_t perm, uint64_t shared_perm, ret =qemu_lock_fd_test (fd, off,1 , true);if (ret) {char *perm_name =bdrv_perm_names (p); -error_setg (errp, -"Failed to get \"%s\" lock" , - perm_name); + +raw_lock_error_setg_errno (errp, -ret, +"Failed to get \"%s\" lock" , + perm_name);g_free (perm_name);return ret; }
@@ -905,9 +922,10 @@ static int raw_check_lock_bytes(int fd, uint64_t perm, uint64_t shared_perm, ret =qemu_lock_fd_test (fd, off,1 , true);if (ret) {char *perm_name =bdrv_perm_names (p); -error_setg (errp, -"Failed to get shared \"%s\" lock" , - perm_name); + +raw_lock_error_setg_errno (errp, -ret, +"Failed to get shared \"%s\" lock" , + perm_name);g_free (perm_name);return ret; }
Signature · 1 line
2.29.2
[PULL 48/53] simplebench: bench_block_job: add cmd_options argument
In reply to Max ReitzFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
Add argument to allow additional block-job options.
Message-Id: <[email protected]>
--- scripts/simplebench/bench-example.py | 2 +- scripts/simplebench/bench_block_job.py | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-)
scripts/simplebench/bench-example.py +1 -1
@@ -25,7 +25,7 @@ from bench_block_job import bench_block_copy, drv_file, drv_nbd def bench_func(env, case): """ Handle one "cell" of benchmarking table. """ - return bench_block_copy(env['qemu_binary'], env['cmd'], + return bench_block_copy(env['qemu_binary'], env['cmd'], {} case['source'], case['target'])
scripts/simplebench/bench_block_job.py +7 -4
@@ -78,16 +78,19 @@ def bench_block_job(cmd, cmd_args, qemu_args): # Bench backup or mirror -def bench_block_copy(qemu_binary, cmd, source, target): +def bench_block_copy(qemu_binary, cmd, cmd_options, source, target): """Helper to run bench_block_job() for mirror or backup""" assert cmd in ('blockdev-backup', 'blockdev-mirror') source['node-name'] = 'source' target['node-name'] = 'target' - return bench_block_job(cmd, - {'job-id': 'job0', 'device': 'source', - 'target': 'target', 'sync': 'full'}, + cmd_options['job-id'] = 'job0' + cmd_options['device'] = 'source' + cmd_options['target'] = 'target' + cmd_options['sync'] = 'full' + + return bench_block_job(cmd, cmd_options, [qemu_binary, '-blockdev', json.dumps(source), '-blockdev', json.dumps(target)])
Signature · 1 line
2.29.2
[PULL 51/53] iotests: Add test for the regression fixed in c8bf9a9169
In reply to Max ReitzFrom: Alberto Garcia <[email protected]>
Message-Id: <[email protected]>
--- tests/qemu-iotests/313 | 104 +++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/313.out | 29 +++++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 134 insertions(+) create mode 100755 tests/qemu-iotests/313 create mode 100644 tests/qemu-iotests/313.out
tests/qemu-iotests/313 new file +104 -0
@@ -0,0 +1,104 @@ +#!/usr/bin/env bash +# group: rw auto quick +# +# Test for the regression fixed in commit c8bf9a9169 +# +# Copyright (C) 2020 Igalia, S.L. +# Author: Alberto Garcia <[email protected]> +# Based on a test case by Maxim Levitsky <[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/>. +# + +# creator [email protected] + +seq=`basename $0` +echo "QA output created by $seq" + +status=1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter + +_supported_fmt qcow2 +_supported_proto file +_supported_os Linux +_unsupported_imgopts cluster_size refcount_bits extended_l2 compat=0.10 data_file + +# The cluster size must be at least the granularity of the mirror job (4KB) +# Note that larger cluster sizes will produce very large images (several GBs) +cluster_size=4096 +refcount_bits=64 # Make it equal to the L2 entry size for convenience +options="cluster_size=${cluster_size},refcount_bits=${refcount_bits}" + +# Number of refcount entries per refcount blocks +ref_entries=$(( ${cluster_size} * 8 / ${refcount_bits} )) + +# Number of data clusters needed to fill a refcount block +# Equals ${ref_entries} minus two (one L2 table and one refcount block) +data_clusters_per_refblock=$(( ${ref_entries} - 2 )) + +# Number of entries in the refcount cache +ref_blocks=4 + +# Write enough data clusters to fill the refcount cache and allocate +# one more refcount block. +# Subtract 3 clusters from the total: qcow2 header, refcount table, L1 table +total_data_clusters=$(( ${data_clusters_per_refblock} * ${ref_blocks} + 1 - 3 )) + +# Total size to write in bytes +total_size=$(( ${total_data_clusters} * ${cluster_size} )) + +echo +echo '### Create the image' +echo +TEST_IMG_FILE=$TEST_IMG.base _make_test_img -o $options $total_size | _filter_img_create_size + +echo +echo '### Write data to allocate more refcount blocks than the cache can hold' +echo +$QEMU_IO -c "write -P 1 0 $total_size" $TEST_IMG.base | _filter_qemu_io + +echo +echo '### Create an overlay' +echo +_make_test_img -F $IMGFMT -b $TEST_IMG.base -o $options | _filter_img_create_size + +echo +echo '### Fill the overlay with zeroes' +echo +$QEMU_IO -c "write -z 0 $total_size" $TEST_IMG | _filter_qemu_io + +echo +echo '### Commit changes to the base image' +echo +$QEMU_IMG commit $TEST_IMG + +echo +echo '### Check the base image' +echo +$QEMU_IMG check $TEST_IMG.base + +# success, all done +echo "*** done" +rm -f $seq.full +status=0
tests/qemu-iotests/313.out new file +29 -0
@@ -0,0 +1,29 @@ +QA output created by 313 + +### Create the image + +Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=SIZE + +### Write data to allocate more refcount blocks than the cache can hold + +wrote 8347648/8347648 bytes at offset 0 +7.961 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +### Create an overlay + +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=SIZE backing_file=TEST_DIR/t.IMGFMT.base backing_fmt=IMGFMT + +### Fill the overlay with zeroes + +wrote 8347648/8347648 bytes at offset 0 +7.961 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +### Commit changes to the base image + +Image committed. + +### Check the base image + +No errors were found on the image. +Image end offset: 8396800 +*** done
tests/qemu-iotests/group +1 -0
@@ -320,3 +320,4 @@ 309 rw auto quick 310 rw quick 312 rw quick +313 rw auto quick
Signature · 1 line
2.29.2
[PULL 42/53] block/backup: drop extra gotos from backup_run()
In reply to Max ReitzFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
Message-Id: <[email protected]>
--- block/backup.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
block/backup.c +5 -7
@@ -236,7 +236,7 @@ static void backup_init_bcs_bitmap(BackupBlockJob *job) static int coroutine_fn backup_run(Job *job, Error **errp) {BackupBlockJob *s =container_of (job, BackupBlockJob, common.job); -int ret =0 ; +int ret;backup_init_bcs_bitmap (s);
@@ -246,13 +246,12 @@ static int coroutine_fn backup_run(Job *job, Error **errp)for (offset =0 ; offset < s->len; ) {if (yield_and_check (s)) { - ret = -ECANCELED ; - goto out; +return -ECANCELED ; } ret =block_copy_reset_unallocated (s->bcs, offset, &count);if (ret <0 ) { - goto out; +return ret; } offset += count;
@@ -273,11 +272,10 @@ static int coroutine_fn backup_run(Job *job, Error **errp)job_yield (job); } }else { - ret =backup_loop (s); +return backup_loop (s); } - out: -return ret; +return 0 ; }static const BlockJobDriver backup_job_driver = {
Signature · 1 line
2.29.2
[PULL 52/53] iotests/118: Drop 'change' test
In reply to Max ReitzCommit 0afec75734331 removed the 'change' QMP command, so we can no longer test it in 118.
('qmp: remove deprecated "change" command')
Message-Id: <[email protected]>
--- tests/qemu-iotests/118 | 20 +------------------- tests/qemu-iotests/118.out | 4 ++-- 2 files changed, 3 insertions(+), 21 deletions(-)
tests/qemu-iotests/118 +1 -19
@@ -1,8 +1,7 @@ #!/usr/bin/env python3 # group: rw # -# Test case for the QMP 'change' command and all other associated -# commands +# Test case for media change monitor commands # # Copyright (C) 2015 Red Hat, Inc. #
@@ -74,23 +73,6 @@ class ChangeBaseClass(iotests.QMPTestCase): class GeneralChangeTestsBaseClass(ChangeBaseClass): - def test_change(self): - # 'change' requires a drive name, so skip the test for blockdev - if not self.use_drive: - return - - result = self.vm.qmp('change', device='drive0', target=new_img, - arg=iotests.imgfmt) - self.assert_qmp(result, 'return', {}) - - self.wait_for_open() - self.wait_for_close() - - result = self.vm.qmp('query-block') - if self.has_real_tray: - self.assert_qmp(result, 'return[0]/tray_open', False) - self.assert_qmp(result, 'return[0]/inserted/image/filename', new_img) - def test_blockdev_change_medium(self): result = self.vm.qmp('blockdev-change-medium', id=self.device_name, filename=new_img,
tests/qemu-iotests/118.out +2 -2
@@ -1,5 +1,5 @@ -....................................................................................................................................................................... +........................................................................................................................................................... ---------------------------------------------------------------------- -Ran 167 tests +Ran 155 tests OK
Signature · 1 line
2.29.2
[PULL 49/53] simplebench: add bench-backup.py
In reply to Max ReitzFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
Add script to benchmark new backup architecture.
Message-Id: <[email protected]>
--- scripts/simplebench/bench-backup.py | 167 ++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100755 scripts/simplebench/bench-backup.py
scripts/simplebench/bench-backup.py new file +167 -0
@@ -0,0 +1,167 @@ +#!/usr/bin/env python3 +# +# Bench backup block-job +# +# Copyright (c) 2020 Virtuozzo International GmbH. +# +# 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/>. +# + +import argparse +import json + +import simplebench +from results_to_text import results_to_text +from bench_block_job import bench_block_copy, drv_file, drv_nbd + + +def bench_func(env, case): + """ Handle one "cell" of benchmarking table. """ + cmd_options = env['cmd-options'] if 'cmd-options' in env else {} + return bench_block_copy(env['qemu-binary'], env['cmd'], + cmd_options, + case['source'], case['target']) + + +def bench(args): + test_cases = [] + + sources = {} + targets = {} + for d in args.dir: + label, path = d.split(':') # paths with colon not supported + sources[label] = drv_file(path + '/test-source') + targets[label] = drv_file(path + '/test-target') + + if args.nbd: + nbd = args.nbd.split(':') + host = nbd[0] + port = '10809' if len(nbd) == 1 else nbd[1] + drv = drv_nbd(host, port) + sources['nbd'] = drv + targets['nbd'] = drv + + for t in args.test: + src, dst = t.split(':') + + test_cases.append({ + 'id': t, + 'source': sources[src], + 'target': targets[dst] + }) + + binaries = [] # list of (<label>, <path>, [<options>]) + for i, q in enumerate(args.env): + name_path = q.split(':') + if len(name_path) == 1: + label = f'q{i}' + path_opts = name_path[0].split(',') + else: + assert len(name_path) == 2 # paths with colon not supported + label = name_path[0] + path_opts = name_path[1].split(',') + + binaries.append((label, path_opts[0], path_opts[1:])) + + test_envs = [] + + bin_paths = {} + for i, q in enumerate(args.env): + opts = q.split(',') + label_path = opts[0] + opts = opts[1:] + + if ':' in label_path: + # path with colon inside is not supported + label, path = label_path.split(':') + bin_paths[label] = path + elif label_path in bin_paths: + label = label_path + path = bin_paths[label] + else: + path = label_path + label = f'q{i}' + bin_paths[label] = path + + x_perf = {} + is_mirror = False + for opt in opts: + if opt == 'mirror': + is_mirror = True + elif opt == 'copy-range=on': + x_perf['use-copy-range'] = True + elif opt == 'copy-range=off': + x_perf['use-copy-range'] = False + elif opt.startswith('max-workers='): + x_perf['max-workers'] = int(opt.split('=')[1]) + + if is_mirror: + assert not x_perf + test_envs.append({ + 'id': f'mirror({label})', + 'cmd': 'blockdev-mirror', + 'qemu-binary': path + }) + else: + test_envs.append({ + 'id': f'backup({label})\n' + '\n'.join(opts), + 'cmd': 'blockdev-backup', + 'cmd-options': {'x-perf': x_perf} if x_perf else {}, + 'qemu-binary': path + }) + + result = simplebench.bench(bench_func, test_envs, test_cases, count=3) + with open('results.json', 'w') as f: + json.dump(result, f, indent=4) + print(results_to_text(result)) + + +class ExtendAction(argparse.Action): + def __call__(self, parser, namespace, values, option_string=None): + items = getattr(namespace, self.dest) or [] + items.extend(values) + setattr(namespace, self.dest, items) + + +if __name__ == '__main__': + p = argparse.ArgumentParser('Backup benchmark', epilog=''' +ENV format + + (LABEL:PATH|LABEL|PATH)[,max-workers=N][,use-copy-range=(on|off)][,mirror] + + LABEL short name for the binary + PATH path to the binary + max-workers set x-perf.max-workers of backup job + use-copy-range set x-perf.use-copy-range of backup job + mirror use mirror job instead of backup''', + formatter_class=argparse.RawTextHelpFormatter) + p.add_argument('--env', nargs='+', help='''\ +Qemu binaries with labels and options, see below +"ENV format" section''', + action=ExtendAction) + p.add_argument('--dir', nargs='+', help='''\ +Directories, each containing "test-source" and/or +"test-target" files, raw images to used in +benchmarking. File path with label, like +label:/path/to/directory''', + action=ExtendAction) + p.add_argument('--nbd', help='''\ +host:port for remote NBD image, (or just host, for +default port 10809). Use it in tests, label is "nbd" +(but you cannot create test nbd:nbd).''') + p.add_argument('--test', nargs='+', help='''\ +Tests, in form source-dir-label:target-dir-label''', + action=ExtendAction) + + bench(p.parse_args())
Signature · 1 line
2.29.2
[PULL 53/53] iotests/178: Pass value to invalid option
In reply to Max Reitzccd3b3b8112 has deprecated short-hand boolean options (i.e., options with values). All options without values are interpreted as boolean options, so this includes the invalid option "snapshot.foo" used in iotest 178.
So after ccd3b3b8112, 178 fails with:
+qemu-img: warning: short-form boolean option 'snapshot.foo' deprecated +Please use snapshot.foo=on instead
Suppress that deprecation warning by passing some value to it (it does not matter which, because the option is invalid anyway).
("qemu-option: warn for short-form boolean options")
Message-Id: <[email protected]>
--- tests/qemu-iotests/178 | 2 +- tests/qemu-iotests/178.out.qcow2 | 2 +- tests/qemu-iotests/178.out.raw | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
tests/qemu-iotests/178 +1 -1
@@ -57,7 +57,7 @@ $QEMU_IMG measure --image-opts # missing filename $QEMU_IMG measure -f qcow2 # missing filename $QEMU_IMG measure -l snap1 # missing filename $QEMU_IMG measure -o , # invalid option list -$QEMU_IMG measure -l snapshot.foo # invalid snapshot option +$QEMU_IMG measure -l snapshot.foo=bar # invalid snapshot option $QEMU_IMG measure --output foo # invalid output format $QEMU_IMG measure --size -1 # invalid image size $QEMU_IMG measure -O foo "$TEST_IMG" # unknown image file format
tests/qemu-iotests/178.out.qcow2 +1 -1
@@ -11,7 +11,7 @@ qemu-img: --image-opts, -f, and -l require a filename argument. qemu-img: --image-opts, -f, and -l require a filename argument. qemu-img: Invalid option list: , qemu-img: Invalid parameter 'snapshot.foo' -qemu-img: Failed in parsing snapshot param 'snapshot.foo' +qemu-img: Failed in parsing snapshot param 'snapshot.foo=bar' qemu-img: --output must be used with human or json as argument. qemu-img: Invalid image size specified. Must be between 0 and 9223372036854775807. qemu-img: Unknown file format 'foo'
tests/qemu-iotests/178.out.raw +1 -1
@@ -11,7 +11,7 @@ qemu-img: --image-opts, -f, and -l require a filename argument. qemu-img: --image-opts, -f, and -l require a filename argument. qemu-img: Invalid option list: , qemu-img: Invalid parameter 'snapshot.foo' -qemu-img: Failed in parsing snapshot param 'snapshot.foo' +qemu-img: Failed in parsing snapshot param 'snapshot.foo=bar' qemu-img: --output must be used with human or json as argument. qemu-img: Invalid image size specified. Must be between 0 and 9223372036854775807. qemu-img: Unknown file format 'foo'
Signature · 1 line
2.29.2
[PULL 46/53] block/block-copy: drop unused argument of block_copy()
In reply to Max ReitzFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
Message-Id: <[email protected]>
--- include/block/block-copy.h | 2 +- block/backup-top.c | 2 +- block/block-copy.c | 10 ++-------- 3 files changed, 4 insertions(+), 10 deletions(-)
include/block/block-copy.h +1 -1
@@ -35,7 +35,7 @@ int64_t block_copy_reset_unallocated(BlockCopyState *s, int64_t offset, int64_t *count); int coroutine_fn block_copy(BlockCopyState *s, int64_t offset, int64_t bytes, -bool ignore_ratelimit,bool *error_is_read); +bool ignore_ratelimit);/* * Run block-copy in a coroutine, create corresponding BlockCopyCallState
block/backup-top.c +1 -1
@@ -61,7 +61,7 @@ static coroutine_fn int backup_top_cbw(BlockDriverState *bs, uint64_t offset, off =QEMU_ALIGN_DOWN (offset, s->cluster_size); end =QEMU_ALIGN_UP (offset + bytes, s->cluster_size); -return block_copy (s->bcs, off, end - off, true,NULL ); +return block_copy (s->bcs, off, end - off, true); } static int coroutine_fn backup_top_co_pdiscard(BlockDriverState *bs,
block/block-copy.c +2 -8
@@ -723,7 +723,7 @@ static int coroutine_fn block_copy_common(BlockCopyCallState *call_state) } int coroutine_fn block_copy(BlockCopyState *s, int64_t start, int64_t bytes, -bool ignore_ratelimit,bool *error_is_read) +bool ignore_ratelimit) {BlockCopyCallState call_state = { .s = s,
@@ -733,13 +733,7 @@ int coroutine_fn block_copy(BlockCopyState *s, int64_t start, int64_t bytes, .max_workers = BLOCK_COPY_MAX_WORKERS, }; -int ret =block_copy_common (&call_state); - -if (error_is_read && ret <0 ) { - *error_is_read = call_state.error_is_read; - } - -return ret; +return block_copy_common (&call_state); } static void coroutine_fn block_copy_async_co_entry(void *opaque)
Signature · 1 line
2.29.2
Peter Maydell
AppliedQuoted 13 lines · Max Reitz
The following changes since commit
31ee895047bdcf7387e3570cbd2a473c6f744b08:Merge remote-tracking branch 'remotes/jasowang/tags/net-pull-request' into staging (2021-01-25 15:56:13 +0000)
are available in the Git repository at:
https://github.com/XanClic/qemu.git tags/pull-block-2021-01-26
for you to fetch changes up to
bb24cdc5efee580e81f71c5ff0fd980f2cc179d0:iotests/178: Pass value to invalid option (2021-01-26 14:36:37 +0100)
Quoted 9 lines
----------------------------------------------------------------
Block patches:
- Make backup block jobs use asynchronous requests with the block-copy module
- Use COR filter node for stream block jobs
- Make coroutine-sigaltstack’sqemu_coroutine_new()function thread-safe
- Report error string when file locking fails with an unexpected errno
- iotest fixes, additions, and some refactoring
Applied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/6.0
for any user-visible changes.
-- PMM