Apply COR-filter to the block-stream permanently
v14 cover Apply COR-filter to the block-stream permanently
Hi all!
I decided to post v14 myself, to show how to keep the test with parallel stream jobs.
So, main addition in v14 is "bottom" argument for stream job. Next week I'll send a follow-up with deprecation for old "base" API.
Also, I already finished my work on updating permissions, so that we don't need ".active"-like things to add/drop filters, still, as v14 is a lot bigger than v2, and I believe this this v14 is closer to be merged, so I'd better resend my
"[PATCH v2 00/36] block: update graph permissions update", basing on
this v14 (and reworking filter drop/remove).
05: fix bdrv_is_allocated_above() usage
09: merge change from further commit which uses unfiltered_bs for bdrv_find_backing_image 10: new
11: new
12: new, splitted from last commit to simplify it a bit
13: - pass bottom option to filter always (who know, may be base will appear during the job)
- keep test test_stream_parallel in 30 iotest
- rework changes in 245 iotest
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: create BlockdevOptionsCor structure for COR driver
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: skip filters when writing backing file name to QCOW2 header
block: apply COR-filter to block-stream jobs
Vladimir Sementsov-Ogievskiy (3):
qapi: block-stream: add "bottom" argument
iotests: 30: prepare to COR filter insertion by stream job block/stream: add s->target_bs
qapi/block-core.json | 35 ++++++- block/copy-on-read.h | 32 +++++++ include/block/block.h | 10 +- include/block/block_int.h | 12 ++- block.c | 25 +++++ block/copy-on-read.c | 143 ++++++++++++++++++++++++--- block/io.c | 12 ++- block/monitor/block-hmp-cmds.c | 7 +- block/stream.c | 170 +++++++++++++++++++++++---------- blockdev.c | 71 ++++++++++---- tests/qemu-iotests/030 | 12 ++- tests/qemu-iotests/141.out | 2 +- tests/qemu-iotests/245 | 20 ++-- tests/qemu-iotests/310 | 114 ++++++++++++++++++++++ tests/qemu-iotests/310.out | 15 +++ tests/qemu-iotests/group | 1 + 16 files changed, 574 insertions(+), 107 deletions(-) create mode 100644 block/copy-on-read.h create mode 100755 tests/qemu-iotests/310 create mode 100644 tests/qemu-iotests/310.out
Signature · 1 line
2.21.3
PATCH v14 1/13 copy-on-read: support preadv/pwritev_part functions
From: Andrey Shinkevich <[email protected]>
Add support for the recently introduced functionsbdrv_co_preadv_part()
andbdrv_co_pwritev_part()
to the COR-filter driver.
--- 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.21.3
PATCH v14 2/13 block: add API function to insert a node
In reply to Vladimir Sementsov-OgievskiyFrom: Andrey Shinkevich <[email protected]>
Provide API for insertion a node to backing chain.
--- include/block/block.h | 2 ++ block.c | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+)
include/block/block.h +2 -0
@@ -350,6 +350,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
@@ -4698,6 +4698,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.21.3
Re: [PATCH v14 02/13] block: add API function to insert a node
Quoted 11 lines · Vladimir Sementsov-Ogievskiy
From: Andrey Shinkevich <[email protected]>
Provide API for insertion a node to backing chain.
Suggested-by Max Reitz <[email protected]>Signed-off-by Andrey Shinkevich <[email protected]>Reviewed-by Vladimir Sementsov-Ogievskiy <[email protected]>--- include/block/block.h | 2 ++ block.c | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+)
[...]
Quoted 5 lines
block.c +0
-0
block.c static void bdrv_delete(BlockDriverState *bs) · line 4707
Quoted 10 lines
block.c +7
-0@@ -4698,6 +4698,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);
s/ = / = /
With that done:
PATCH v14 3/13 copy-on-read: add filter drop function
In reply to Vladimir Sementsov-OgievskiyFrom: 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.
--- 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.21.3
Re: [PATCH v14 03/13] copy-on-read: add filter drop function
Quoted 12 lines · Vladimir Sementsov-Ogievskiy
From: 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 functionbdrv_insert_node()can be used.
The new functionbdrv_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 functionbdrv_remove_node()on the block generic layer.
Quoted 7 lines
Signed-off-by Andrey Shinkevich <[email protected]>Reviewed-by Vladimir Sementsov-Ogievskiy <[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
PATCH v14 4/13 qapi: add filter-node-name to block-stream
In reply to Vladimir Sementsov-OgievskiyFrom: 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.
--- 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: 5.2) +# # @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
@@ -1134,6 +1134,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 commit 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
@@ -1146,7 +1149,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
@@ -2499,6 +2499,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)
@@ -2581,7 +2582,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.21.3
Re: [PATCH v14 04/13] qapi: add filter-node-name to block-stream
Quoted 20 lines · Vladimir Sementsov-Ogievskiy
From: 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.
Signed-off-by Andrey Shinkevich <[email protected]>Reviewed-by Vladimir Sementsov-Ogievskiy <[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 +0
-0
qapi/block-core.json line 2549
Quoted 7 lines
qapi/block-core.json +4
-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: 5.2)
*6.0
Quoted 4 lines
qapi/block-core.json +1
-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.
[...]
include/block/block_int.h int is_windows_drive(const char *filename); · line 1139
Quoted 11 lines
include/block/block_int.h +3
-0@@ -1134,6 +1134,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 commit job inserts into the graph above @bs. NULL means +* that a node name should be autogenerated.
Personally, I find such descriptions to be more easily readable (or rather more easily visually separable from other parameters) if they’re indented. I understand that two other parameters’ descriptions aren’t indented either (but one is), so in the end it’s your choice. (But I thought a little nudging couldn’t hurt.)
So either way (with *6.0):
PATCH v14 5/13 qapi: create BlockdevOptionsCor structure for COR driver
In reply to Vladimir Sementsov-OgievskiyFrom: Andrey Shinkevich <[email protected]>
Create the BlockdevOptionsCor structure for COR driver specific options splitting it off form the BlockdevOptionsGenericFormat. The only option 'bottom' node in the structure denotes an image file that limits the COR operations in the backing chain.
We are going to use the COR-filter for a block-stream job and will pass a bottom node name to the COR driver. The bottom node is the first non-filter overlay of the base. It was introduced because the base node itself may change due to possible concurrent jobs.
--- qapi/block-core.json | 21 +++++++++++++++- block/copy-on-read.c | 57 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 75 insertions(+), 3 deletions(-)
qapi/block-core.json +20 -1
@@ -3942,6 +3942,25 @@ '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). +# For the block-stream job, it will be the first non-filter overlay of +# the base node. We do not involve the base node into the COR +# operations because the base may change due to a concurrent +# block-commit job on the same backing chain. +# +# Since: 5.2 +## +{ 'struct': 'BlockdevOptionsCor', + 'base': 'BlockdevOptionsGenericFormat', + 'data': { '*bottom': 'str' } } + ## # @BlockdevOptions: #
@@ -3994,7 +4013,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 +55 -2
88 lines not on this page · raw message
Signature · 1 line
2.21.3
Re: [PATCH v14 05/13] qapi: create BlockdevOptionsCor structure for COR driver
I don’t like this patch’s subject very much, because I find the implementation of the @bottom option to be more noteworthy than the addition of the QAPI structure.
Quoted 27 lines · Vladimir Sementsov-Ogievskiy
From: Andrey Shinkevich <[email protected]>
Create the BlockdevOptionsCor structure for COR driver specific options splitting it off form the BlockdevOptionsGenericFormat. The only option 'bottom' node in the structure denotes an image file that limits the COR operations in the backing chain.
We are going to use the COR-filter for a block-stream job and will pass a bottom node name to the COR driver. The bottom node is the first non-filter overlay of the base. It was introduced because the base node itself may change due to possible concurrent jobs.Suggested-by Max Reitz <[email protected]>Suggested-by Vladimir Sementsov-Ogievskiy <[email protected]>Signed-off-by Andrey Shinkevich <[email protected]>[vsementsov: fix bdrv_is_allocated_above() usage]Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- qapi/block-core.json | 21 +++++++++++++++- block/copy-on-read.c | 57 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 75 insertions(+), 3 deletions(-)qapi/block-core.json +0
-0@@ -3942,6 +3942,25 @@ 'data': { 'throttle-group': 'str',
qapi/block-core.json line 3952
Quoted 10 lines
qapi/block-core.json +8
-0'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).
This seems to me like something’s missing. Perhaps technically there isn’t, but “limits the COR operations” begs the question (to me) “Limits them in what way?” (to which the answer is: No data below @bottom is copied).
Could you make it more verbose? Perhaps something like “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”?
qapi/block-core.json line 3956
Quoted 4 lines
qapi/block-core.json +4
-0+# For the block-stream job, it will be the first non-filter overlay of +# the base node. We do not involve the base node into the COR +# operations because the base may change due to a concurrent +# block-commit job on the same backing chain.
I think the default behavior should be mentioned here somewhere, i.e. that no limit is applied, so that data from all backing layers may be copied.
qapi/block-core.json line 3958
Quoted 2 lines
qapi/block-core.json +2
-0+# +# Since: 5.2
*6.0
Quoted 8 lines
qapi/block-core.json +5
-0+## +{ 'struct': 'BlockdevOptionsCor', + 'base': 'BlockdevOptionsGenericFormat', + 'data': { '*bottom': 'str' } } + ## # @BlockdevOptions: #
[...]
Quoted 4 lines
block/copy-on-read.c +0
-0
[...]
block/copy-on-read.c static int cor_open(BlockDriverState *bs, QDict *options, int flags, · line 65
Quoted 11 lines
block/copy-on-read.c +7
-0@@ -51,7 +56,17 @@ static int cor_open(BlockDriverState *bs, QDict *options, int flags, ((BDRV_REQ_FUA |BDRV_REQ_MAY_UNMAP |BDRV_REQ_NO_FALLBACK ) & bs->file->bs->supported_zero_flags); +if (bottom_node) { + bottom_bs =bdrv_lookup_bs (NULL , bottom_node, errp); +if (!bottom_bs) { +error_setg (errp,"Bottom node '%s' not found" , bottom_node); +qdict_del (options,"bottom" ); +return -EINVAL ; + }
Should we verify that bottom_bs is not a filter, as required by the schema?
Max
Re: [PATCH v14 05/13] qapi: create BlockdevOptionsCor structure for COR driver
Quoted 44 lines · Max Reitz
I don’t like this patch’s subject very much, because I find the implementation of the @bottom option to be more noteworthy than the addition of the QAPI structure.
Quoted 29 lines · Vladimir Sementsov-Ogievskiy
From: Andrey Shinkevich <[email protected]>
Create the BlockdevOptionsCor structure for COR driver specific options splitting it off form the BlockdevOptionsGenericFormat. The only option 'bottom' node in the structure denotes an image file that limits the COR operations in the backing chain.
We are going to use the COR-filter for a block-stream job and will pass a bottom node name to the COR driver. The bottom node is the first non-filter overlay of the base. It was introduced because the base node itself may change due to possible concurrent jobs.Suggested-by Max Reitz <[email protected]>Suggested-by Vladimir Sementsov-Ogievskiy <[email protected]>Signed-off-by Andrey Shinkevich <[email protected]>[vsementsov: fix bdrv_is_allocated_above() usage]Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>---
qapi/block-core.json| 21 +++++++++++++++-block/copy-on-read.c| 57 ++++++++++++++++++++++++++++++++++++++++++--2 files changed, 75 insertions(+), 3 deletions(-)qapi/block-core.json +0
-0@@ -3942,6 +3942,25 @@ 'data': { 'throttle-group': 'str','file' : 'BlockdevRef'
} }qapi/block-core.json line 3952
Quoted 8 lines
qapi/block-core.json +8
-0+ +## +# @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).This seems to me like something’s missing. Perhaps technically there isn’t, but “limits the COR operations” begs the question (to me) “Limits them in what way?” (to which the answer is: No data below @bottom is copied).
Quoted 1 line
Could you make it more verbose? Perhaps something like “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”?
Sounds good for me.
Quoted 6 lines
qapi/block-core.json line 3956
Quoted 5 lines
qapi/block-core.json +4
-0+# For the block-stream job, it will be the first non-filter overlay of +# the base node. We do not involve the base node into the COR +# operations because the base may change due to a concurrent +# block-commit job on the same backing chain.
I now see that paragraph conflicts with further introduce of "bottom" for stream job itself. I think it may be safely dropped. It's a wrong place to describe how block-stream works.
Quoted 1 line
I think the default behavior should be mentioned here somewhere, i.e. that no limit is applied, so that data from all backing layers may be copied.
agree
Quoted 24 lines
qapi/block-core.json
Quoted 3 lines
qapi/block-core.json +2
-0+# +# Since: 5.2*6.0
Quoted 8 lines
qapi/block-core.json +5
-0+## +{ 'struct': 'BlockdevOptionsCor', + 'base': 'BlockdevOptionsGenericFormat', + 'data': { '*bottom': 'str' } } +##
# @BlockdevOptions:
#[...]
Quoted 4 lines
block/copy-on-read.c +0
-0[...]
Quoted 13 lines
Quoted 10 lines
block/copy-on-read.c +0
-0@@ -51,7 +56,17 @@ static int cor_open(BlockDriverState *bs, QDict *options, int flags,((
BDRV_REQ_FUA|BDRV_REQ_MAY_UNMAP|BDRV_REQ_NO_FALLBACK) &bs->file->bs->supported_zero_flags);
+ if (bottom_node) {
+bottom_bs=bdrv_lookup_bs(NULL, bottom_node, errp); + if (!bottom_bs) {
+error_setg(errp, "Bottom node '%s' not found", bottom_node); +qdict_del(options, "bottom");
+ return-EINVAL;
+ }Should we verify that
bottom_bsis not a filter, as required by the schema?
yes, thanks for the catch!
Hmm.. Interesting, we don't freeze the backing chain in cor filter open. And I think we shouldn't. But then, bottom node may disappear. We should handle it without a crash.
I suggest:
1. document, that if bottom node disappear from the backing chain of the filter, it continues to work like without any specified "bottom" node
2. do bdrv_ref/bdrv_unref of bottom_bs, to not work with dead pointer
3. check in cor_co_preadv_part() is bottom_bs is still in backing chain or not
Haha, bottom node may return into backing chain at some moment and we can continue to handle it:)
Signature · 2 lines
Best regards, Vladimir
Re: [PATCH v14 05/13] qapi: create BlockdevOptionsCor structure for COR driver
Quoted 110 lines · Vladimir Sementsov-Ogievskiy
Quoted 46 lines · Max Reitz
I don’t like this patch’s subject very much, because I find the implementation of the @bottom option to be more noteworthy than the addition of the QAPI structure.
Quoted 36 lines · Vladimir Sementsov-Ogievskiy
From: Andrey Shinkevich <[email protected]>
Create the BlockdevOptionsCor structure for COR driver specific options splitting it off form the BlockdevOptionsGenericFormat. The only option 'bottom' node in the structure denotes an image file that limits the COR operations in the backing chain.
We are going to use the COR-filter for a block-stream job and will pass a bottom node name to the COR driver. The bottom node is the first non-filter overlay of the base. It was introduced because the base node itself may change due to possible concurrent jobs.Suggested-by Max Reitz <[email protected]>Suggested-by Vladimir Sementsov-Ogievskiy <[email protected]>Signed-off-by Andrey Shinkevich <[email protected]>[vsementsov: fix bdrv_is_allocated_above() usage]Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>---
qapi/block-core.json| 21 +++++++++++++++-block/copy-on-read.c| 57 ++++++++++++++++++++++++++++++++++++++++++--2 files changed, 75 insertions(+), 3 deletions(-)qapi/block-core.json +0
-0@@ -3942,6 +3942,25 @@ 'data': { 'throttle-group': 'str','file' : 'BlockdevRef'
} }qapi/block-core.json +7
-0+ +## +# @BlockdevOptionsCor: +# +# Driver specific block device options for the copy-on-read driver. +# +# @bottom: the name of a non-filter node (allocation-bearing layer)Quoted 2 lines
that limits
+# the COR operations in the backing chain (inclusive).This seems to me like something’s missing. Perhaps technically there isn’t, but “limits the COR operations” begs the question (to me) “Limits them in what way?” (to which the answer is: No data below @bottom is copied).
Quoted 1 line
Could you make it more verbose? Perhaps something like “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”?
Sounds good for me.
Quoted 7 lines
qapi/block-core.json line 3956
Quoted 6 lines
+# For the block-stream job, it will be the first non-filter overlay of
qapi/block-core.json +3
-0+# the base node. We do not involve the base node into the COR +# operations because the base may change due to a concurrent +# block-commit job on the same backing chain.I now see that paragraph conflicts with further introduce of "bottom" for stream job itself. I think it may be safely dropped. It's a wrong place to describe how block-stream works.
Quoted 1 line
I think the default behavior should be mentioned here somewhere, i.e. that no limit is applied, so that data from all backing layers may be copied.
agree
Quoted 24 lines
qapi/block-core.json
Quoted 3 lines
qapi/block-core.json +2
-0+# +# Since: 5.2*6.0
Quoted 8 lines
qapi/block-core.json +5
-0+## +{ 'struct': 'BlockdevOptionsCor', + 'base': 'BlockdevOptionsGenericFormat', + 'data': { '*bottom': 'str' } } +##
# @BlockdevOptions:
#[...]
Quoted 4 lines
block/copy-on-read.c +0
-0[...]
Quoted 15 lines
Quoted 4 lines
block/copy-on-read.c +0
-0@@ -51,7 +56,17 @@ static int cor_open(BlockDriverState *bs, QDict *options, int flags,((
BDRV_REQ_FUA|BDRV_REQ_MAY_UNMAP|BDRV_REQ_NO_FALLBACK) &bs->file->bs->supported_zero_flags);Quoted 8 lines
+ if (
bottom_node) {
+bottom_bs=bdrv_lookup_bs(NULL, bottom_node, errp); + if (!bottom_bs) {
+error_setg(errp, "Bottom node '%s' not found", bottom_node);
+qdict_del(options, "bottom");
+ return-EINVAL;
+ }Should we verify that
bottom_bsis not a filter, as required by the schema?yes, thanks for the catch!
Hmm.. Interesting, we don't freeze the backing chain in cor filter open. And I think we shouldn't. But then, bottom node may disappear. We should handle it without a crash.
Quoted 7 lines
I suggest:
1. document, that if bottom node disappear from the backing chain of the filter, it continues to work like without any specified "bottom" node
2. do bdrv_ref/bdrv_unref of
bottom_bs, to not work with dead pointer3. check in
cor_co_preadv_part()isbottom_bsis still in backing chain or not
Hm, right.
Alternatively, we could also freeze the chain until the bottom node and then allow changing the @bottom node through reopen. Then it would have to be manually unset before the bottom node is allowed to disappear from the chain.
Would freezing the chain pose a problem?
Max
Re: [PATCH v14 05/13] qapi: create BlockdevOptionsCor structure for COR driver
Quoted 112 lines · Max Reitz
Quoted 111 lines · Vladimir Sementsov-Ogievskiy
Quoted 44 lines · Max Reitz
I don’t like this patch’s subject very much, because I find the implementation of the @bottom option to be more noteworthy than the addition of the QAPI structure.
Quoted 29 lines · Vladimir Sementsov-Ogievskiy
From: Andrey Shinkevich <[email protected]>
Create the BlockdevOptionsCor structure for COR driver specific options splitting it off form the BlockdevOptionsGenericFormat. The only option 'bottom' node in the structure denotes an image file that limits the COR operations in the backing chain.
We are going to use the COR-filter for a block-stream job and will pass a bottom node name to the COR driver. The bottom node is the first non-filter overlay of the base. It was introduced because the base node itself may change due to possible concurrent jobs.Suggested-by Max Reitz <[email protected]>Suggested-by Vladimir Sementsov-Ogievskiy <[email protected]>Signed-off-by Andrey Shinkevich <[email protected]>[vsementsov: fix bdrv_is_allocated_above() usage]Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>---
qapi/block-core.json| 21 +++++++++++++++-block/copy-on-read.c| 57 ++++++++++++++++++++++++++++++++++++++++++--2 files changed, 75 insertions(+), 3 deletions(-)qapi/block-core.json +0
-0@@ -3942,6 +3942,25 @@ 'data': { 'throttle-group': 'str','file' : 'BlockdevRef'
} }qapi/block-core.json line 3952
Quoted 8 lines
qapi/block-core.json +8
-0+ +## +# @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).This seems to me like something’s missing. Perhaps technically there isn’t, but “limits the COR operations” begs the question (to me) “Limits them in what way?” (to which the answer is: No data below @bottom is copied).
Quoted 1 line
Could you make it more verbose? Perhaps something like “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”?
Sounds good for me.
Quoted 6 lines
qapi/block-core.json line 3956
Quoted 5 lines
qapi/block-core.json +4
-0+# For the block-stream job, it will be the first non-filter overlay of +# the base node. We do not involve the base node into the COR +# operations because the base may change due to a concurrent +# block-commit job on the same backing chain.I now see that paragraph conflicts with further introduce of "bottom" for stream job itself. I think it may be safely dropped. It's a wrong place to describe how block-stream works.
Quoted 1 line
I think the default behavior should be mentioned here somewhere, i.e. that no limit is applied, so that data from all backing layers may be copied.
agree
Quoted 24 lines
qapi/block-core.json
Quoted 3 lines
qapi/block-core.json +2
-0+# +# Since: 5.2*6.0
Quoted 8 lines
qapi/block-core.json +5
-0+## +{ 'struct': 'BlockdevOptionsCor', + 'base': 'BlockdevOptionsGenericFormat', + 'data': { '*bottom': 'str' } } +##
# @BlockdevOptions:
#[...]
Quoted 4 lines
block/copy-on-read.c +0
-0[...]
Quoted 13 lines
Quoted 10 lines
block/copy-on-read.c +0
-0@@ -51,7 +56,17 @@ static int cor_open(BlockDriverState *bs, QDict *options, int flags,((
BDRV_REQ_FUA|BDRV_REQ_MAY_UNMAP|BDRV_REQ_NO_FALLBACK) &bs->file->bs->supported_zero_flags);
+ if (bottom_node) {
+bottom_bs=bdrv_lookup_bs(NULL, bottom_node, errp); + if (!bottom_bs) {
+error_setg(errp, "Bottom node '%s' not found", bottom_node); +qdict_del(options, "bottom");
+ return-EINVAL;
+ }Should we verify that
bottom_bsis not a filter, as required by the schema?yes, thanks for the catch!
Hmm.. Interesting, we don't freeze the backing chain in cor filter open. And I think we shouldn't. But then, bottom node may disappear. We should handle it without a crash.
I suggest:
1. document, that if bottom node disappear from the backing chain of the filter, it continues to work like without any specified "bottom" node
2. do bdrv_ref/bdrv_unref of
bottom_bs, to not work with dead pointer
Quoted 8 lines
Quoted 1 line
3. check in
cor_co_preadv_part()isbottom_bsis still in backing chain or notHm, right.
Alternatively, we could also freeze the chain until the bottom node and then allow changing the @bottom node through reopen. Then it would have to be manually unset before the bottom node is allowed to disappear from the chain.
Would freezing the chain pose a problem?
Hmm. Then we'll just need not freeze it in block-stream, so freezing is done by filter.
It's just more restrictive.. But I can't imagine reasonable cases where user specify bottom node and than remove it. Forcing user to reopen the filter to change the bottom node may be more clean then "just don't care". OK, I think we can freeze the chain in the filter.
Signature · 2 lines
Best regards, Vladimir
PATCH v14 6/13 iotests: add #310 to test bottom node in COR driver
In reply to Vladimir Sementsov-OgievskiyFrom: 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.
--- tests/qemu-iotests/310 | 114 +++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/310.out | 15 +++++ tests/qemu-iotests/group | 1 + 3 files changed, 130 insertions(+) create mode 100755 tests/qemu-iotests/310 create mode 100644 tests/qemu-iotests/310.out
tests/qemu-iotests/310 new file +114 -0
@@ -0,0 +1,114 @@ +#!/usr/bin/env python3 +# +# 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', 'qcow', 'qed', 'vmdk'], + 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('') + + assert qemu_io_silent(base_img_path, '-c', 'discard 0 4M') == 0 + assert qemu_io_silent(mid_img_path, '-c', 'discard 0M 5M') == 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
@@ -316,3 +316,4 @@ 305 rw quick 307 rw quick export 309 rw auto quick +310 rw quick
Signature · 1 line
2.21.3
Re: [PATCH v14 06/13] iotests: add #310 to test bottom node in COR driver
Quoted 118 lines · Vladimir Sementsov-Ogievskiy
From: 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.
Signed-off-by Andrey Shinkevich <[email protected]>Reviewed-by Vladimir Sementsov-Ogievskiy <[email protected]>--- tests/qemu-iotests/310 | 114 +++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/310.out | 15 +++++ tests/qemu-iotests/group | 1 + 3 files changed, 130 insertions(+)create mode 100755 tests/qemu-iotests/310
create mode 100644 tests/qemu-iotests/310.outtests/qemu-iotests/310 new file +97
-0@@ -0,0 +1,114 @@ +#!/usr/bin/env python3 +# +# 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', 'qcow', 'qed', 'vmdk'], + 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',
tests/qemu-iotests/310 line 107
Quoted 10 lines
tests/qemu-iotests/310 new file +10
-0+ command_line='qemu-io node0 "read 0 5M"')) + + vm.shutdown() + + log('') + log('--- Checking COR result ---') + log('') + + assert qemu_io_silent(base_img_path, '-c', 'discard 0 4M') == 0 + assert qemu_io_silent(mid_img_path, '-c', 'discard 0M 5M') == 0
The data discard leaves behind is undefined, so this may not result in zeroes. (In fact, the test does fail for me with vmdk, qed, and qcow.)
'write -z' would work better, although perhaps you intentionally chose
discard to just drop the data from the backing images.
In that case, you could also recreate the middle image, so it’s empty then – the only problem with that is that it’ll break VMDK because it stores this reference to its backing image, and if the backing image is changed, you’ll get EINVAL when falling back to it...
(The same goes for overwriting any data in the backing image, though, be it with discard, write -z, or write -P 0. So I suppose VMDK just won’t work with this test.)
Max
Quoted 7 lines
tests/qemu-iotests/310 new file +7
-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')
Re: [PATCH v14 06/13] iotests: add #310 to test bottom node in COR driver
Quoted 132 lines · Max Reitz
Quoted 118 lines · Vladimir Sementsov-Ogievskiy
From: 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.
Signed-off-by Andrey Shinkevich <[email protected]>Reviewed-by Vladimir Sementsov-Ogievskiy <[email protected]>---
tests/qemu-iotests/310 | 114 +++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/310.out | 15 +++++ tests/qemu-iotests/group | 1 +3 files changed, 130 insertions(+)create mode 100755 tests/qemu-iotests/310
create mode 100644 tests/qemu-iotests/310.outtests/qemu-iotests/310 new file +97
-0@@ -0,0 +1,114 @@ +#!/usr/bin/env python3 +# +# 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', 'qcow', 'qed', 'vmdk'], + 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',tests/qemu-iotests/310 line 107
Quoted 10 lines
tests/qemu-iotests/310 new file +10
-0+ command_line='qemu-io node0 "read 0 5M"')) + + vm.shutdown() + + log('') + log('--- Checking COR result ---') + log('') + + assert qemu_io_silent(base_img_path, '-c', 'discard 0 4M') == 0 + assert qemu_io_silent(mid_img_path, '-c', 'discard 0M 5M') == 0The data discard leaves behind is undefined, so this may not result in zeroes. (In fact, the test does fail for me with vmdk, qed, and qcow.) 'write -z' would work better, although perhaps you intentionally chose discard to just drop the data from the backing images.
Quoted 4 lines
In that case, you could also recreate the middle image, so it’s empty then – the only problem with that is that it’ll break VMDK because it stores this reference to its backing image, and if the backing image is changed, you’ll get EINVAL when falling back to it...
(The same goes for overwriting any data in the backing image, though, be it with discard, write -z, or write -P 0. So I suppose VMDK just won’t work with this test.)
I think the goal is just to be sure the following reads read from the top and check exactly that COR works.
So we can just use 'write -z'.. Or, we can changed the backing file of top_img to nothing instead. Can qemu-img do it?
Quoted 9 lines
Quoted 8 lines
tests/qemu-iotests/310 new file +7
-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')
Signature · 2 lines
Best regards, Vladimir
Re: [PATCH v14 06/13] iotests: add #310 to test bottom node in COR driver
Quoted 136 lines · Vladimir Sementsov-Ogievskiy
Quoted 135 lines · Max Reitz
Quoted 121 lines · Vladimir Sementsov-Ogievskiy
From: 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.
Signed-off-by Andrey Shinkevich <[email protected]>Reviewed-by Vladimir Sementsov-Ogievskiy <[email protected]>---
tests/qemu-iotests/310 | 114 +++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/310.out | 15 +++++ tests/qemu-iotests/group | 1 +3 files changed, 130 insertions(+)create mode 100755 tests/qemu-iotests/310
create mode 100644 tests/qemu-iotests/310.outtests/qemu-iotests/310 new file +26
-0@@ -0,0 +1,114 @@ +#!/usr/bin/env python3 +# +# 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', 'qcow', 'qed','vmdk'],
+ supported_platforms=['linux'])tests/qemu-iotests/310 new file +18
-0+ +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
+ assertqemu_io_silent(base_img_path, '-c', 'write -P 1 0M 1M')== 0 + assertqemu_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 + assertqemu_io_silent(mid_img_path, '-c', 'write -P 3 2M 1M')== 0 + assertqemu_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 + assertqemu_io_silent(top_img_path, '-c', 'write -P 2 1M 1M')== 0tests/qemu-iotests/310 new file +43
-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',tests/qemu-iotests/310 line 107
Quoted 10 lines
tests/qemu-iotests/310 new file +10
-0+ command_line='qemu-io node0 "read 0 5M"')) + + vm.shutdown() + + log('') + log('--- Checking COR result ---') + log('') + + assert qemu_io_silent(base_img_path, '-c', 'discard 0 4M') == 0 + assert qemu_io_silent(mid_img_path, '-c', 'discard 0M 5M') == 0The data discard leaves behind is undefined, so this may not result in zeroes. (In fact, the test does fail for me with vmdk, qed, and qcow.) 'write -z' would work better, although perhaps you intentionally chose discard to just drop the data from the backing images.
Quoted 8 lines
Quoted 4 lines
In that case, you could also recreate the middle image, so it’s empty then – the only problem with that is that it’ll break VMDK because it stores this reference to its backing image, and if the backing image is changed, you’ll get EINVAL when falling back to it...
(The same goes for overwriting any data in the backing image, though, be it with discard, write -z, or write -P 0. So I suppose VMDK just won’t work with this test.)
I think the goal is just to be sure the following reads read from the top and check exactly that COR works.
So we can just use 'write -z'.. Or, we can changed the backing file of
top_imgto nothing instead. Can qemu-img do it?
Yes, with rebase -u -b ''. (I think I tested that, and that too didn’t work for all formats, though...?)
Max
PATCH v14 7/13 block: include supported_read_flags into BDS structure
In reply to Vladimir Sementsov-OgievskiyFrom: 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.
--- include/block/block_int.h | 4 ++++ block/io.c | 12 ++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-)
include/block/block_int.h +4 -0
@@ -873,6 +873,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 +10 -2
@@ -1405,6 +1405,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;
@@ -1426,9 +1429,13 @@ static int coroutine_fn bdrv_aligned_preadv(BdrvChild *child, goto out; } +if (flags & ~bs->supported_read_flags) { +abort (); + } + 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; }
@@ -1441,7 +1448,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.21.3
Re: [PATCH v14 07/13] block: include supported_read_flags into BDS structure
Quoted 14 lines · Vladimir Sementsov-Ogievskiy
From: Andrey Shinkevich <[email protected]>
Add the new member
supported_read_flagsto 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.Suggested-by Vladimir Sementsov-Ogievskiy <[email protected]>Signed-off-by Andrey Shinkevich <[email protected]>Reviewed-by Vladimir Sementsov-Ogievskiy <[email protected]>--- include/block/block_int.h | 4 ++++ block/io.c | 12 ++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-)
[...]
Quoted 4 lines
block/io.c +0
-0
[...]
block/io.c static int coroutine_fn bdrv_aligned_preadv(BdrvChild *child, · line 1434
Quoted 7 lines
block/io.c +3
-0@@ -1426,9 +1429,13 @@ static int coroutine_fn bdrv_aligned_preadv(BdrvChild *child, goto out; } +if (flags & ~bs->supported_read_flags) { +abort (); + }
I’d prefer an assert(!(flags & ~bs->supported_read_flags)), so in case we do abort, there’s going to be an error message that immediately tells what the problem is.
Apart from that:
Quoted 7 lines
block/io.c +2
-1+ 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; }
Re: [PATCH v14 07/13] block: include supported_read_flags into BDS structure
Quoted 25 lines · Max Reitz
Quoted 14 lines · Vladimir Sementsov-Ogievskiy
From: Andrey Shinkevich <[email protected]>
Add the new member
supported_read_flagsto 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.Suggested-by Vladimir Sementsov-Ogievskiy <[email protected]>Signed-off-by Andrey Shinkevich <[email protected]>Reviewed-by Vladimir Sementsov-Ogievskiy <[email protected]>---
include/block/block_int.h| 4 ++++
block/io.c | 12 ++++++++++--2 files changed, 14 insertions(+), 2 deletions(-)[...]
Quoted 4 lines
block/io.c +0
-0[...]
Quoted 8 lines
block/io.c static int coroutine_fn bdrv_aligned_preadv(BdrvChild *child, · line 1433
Quoted 6 lines
block/io.c +3
-0@@ -1426,9 +1429,13 @@ static int coroutine_fn bdrv_aligned_preadv(BdrvChild *child, goto out; } + if (flags & ~bs->supported_read_flags) { + abort(); + }I’d prefer an
assert(!(flags & ~bs->supported_read_flags)), so in case we do abort, there’s going to be an error message that immediately tells what the problem is.
agree. and one-line check is shorter than three-line
Quoted 13 lines
Apart from that:
Reviewed-by Max Reitz <[email protected]>Quoted 7 lines
block/io.c +2
-1+ 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; }
Signature · 2 lines
Best regards, Vladimir
PATCH v14 8/13 copy-on-read: skip non-guest reads if no copy needed
In reply to Vladimir Sementsov-OgievskiyFrom: 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.
--- include/block/block.h | 8 +++++--- block/copy-on-read.c | 14 ++++++++++---- 2 files changed, 15 insertions(+), 7 deletions(-)
include/block/block.h +5 -3
@@ -81,9 +81,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,/* Mask of valid flags */
block/copy-on-read.c +10 -4
@@ -49,6 +49,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);
@@ -150,10 +152,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.21.3
Re: [PATCH v14 08/13] copy-on-read: skip non-guest reads if no copy needed
Quoted 14 lines · Vladimir Sementsov-Ogievskiy
From: Andrey Shinkevich <[email protected]>
If the flag
BDRV_REQ_PREFETCHwas 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_PREFETCHflag to thesupported_read_flagsof the COR-filter.block: Modify the comment for the flag
BDRV_REQ_PREFETCHas we are going to use it alone and pass it to the COR-filter driver for further processing.
Quoted 6 lines
Signed-off-by Andrey Shinkevich <[email protected]>Reviewed-by Vladimir Sementsov-Ogievskiy <[email protected]>--- include/block/block.h | 8 +++++--- block/copy-on-read.c | 14 ++++++++++---- 2 files changed, 15 insertions(+), 7 deletions(-)
PATCH v14 9/13 stream: skip filters when writing backing file name to QCOW2 header
In reply to Vladimir Sementsov-OgievskiyFrom: Andrey Shinkevich <[email protected]>
Avoid writing a filter JSON file name and a filter format name to QCOW2 image when the backing file is being changed after the block stream job. It can occur due to a concurrent commit job on the same backing chain.
A user is still able to assign the 'backing-file' parameter for a block-stream job keeping in mind the possible issue mentioned above. If the user does not specify the 'backing-file' parameter, QEMU will assign it automatically.
--- block/stream.c | 21 +++++++++++++++++++-- blockdev.c | 8 +------- 2 files changed, 20 insertions(+), 9 deletions(-)
block/stream.c +19 -2
@@ -17,6 +17,7 @@#include "block/blockjob_int.h" #include "qapi/error.h" #include "qapi/qmp/qerror.h" +#include "qemu/error-report.h" #include "qemu/ratelimit.h" #include "sysemu/block-backend.h"
@@ -65,6 +66,8 @@ 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 *base_unfiltered; +BlockDriverState *backing_bs;Error *local_err =NULL ;int ret =0 ;
@@ -75,8 +78,22 @@ static int stream_prepare(Job *job)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 (base_id) { + backing_bs =bdrv_find_backing_image (unfiltered_bs, base_id); +if (backing_bs && backing_bs->drv) { + base_fmt = backing_bs->drv->format_name; + }else { +error_report ("Format not found for backing file %s" , + s->backing_file_str); + } + }else { + base_unfiltered =bdrv_skip_filters (base); +if (base_unfiltered) { + base_id = base_unfiltered->filename; +if (base_unfiltered->drv) { + base_fmt = base_unfiltered->drv->format_name; + } + } } }bdrv_set_backing_hd (unfiltered_bs, base, &local_err);
blockdev.c +1 -7
@@ -2508,7 +2508,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) {
@@ -2536,7 +2535,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) {
@@ -2551,7 +2549,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 */
@@ -2571,9 +2568,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 ; }
@@ -2581,7 +2575,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.21.3
Re: [PATCH v14 09/13] stream: skip filters when writing backing file name to QCOW2 header
Quoted 23 lines · Vladimir Sementsov-Ogievskiy
From: Andrey Shinkevich <[email protected]>
Avoid writing a filter JSON file name and a filter format name to QCOW2 image when the backing file is being changed after the block stream job. It can occur due to a concurrent commit job on the same backing chain.
A user is still able to assign the 'backing-file' parameter for a block-stream job keeping in mind the possible issue mentioned above. If the user does not specify the 'backing-file' parameter, QEMU will assign it automatically.Signed-off-by Andrey Shinkevich <[email protected]>[vsementsov: use unfiltered_bs for bdrv_find_backing_image()]Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- block/stream.c | 21 +++++++++++++++++++-- blockdev.c | 8 +------- 2 files changed, 20 insertions(+), 9 deletions(-)block/stream.c +0
-0
[...]
block/stream.c static int stream_prepare(Job *job) · line 87
Quoted 13 lines
block/stream.c +7
-2@@ -75,8 +78,22 @@ static int stream_prepare(Job *job)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 (base_id) { + backing_bs =bdrv_find_backing_image (unfiltered_bs, base_id); +if (backing_bs && backing_bs->drv) { + base_fmt = backing_bs->drv->format_name; + }else { +error_report ("Format not found for backing file %s" , + s->backing_file_str);
I think it’s actually going to be rather likely that we’re not going to find the backing file here. If the user were to use a filename that just appears as-such in the backing chain, they wouldn’t need to specify a backing-file parameter at all, because the one figured out automatically would be just fine.
But then again, what are we supposed to do then. We can continue as before, which is to just use the base node’s format. But if the user wants to perhaps use a backing file that isn’t even open in qemu (a copy of the the base on some different storage), we have no idea what format it’s in.
So printing an error here, but continuing on with setting a backing_fmt is probably the most reasonable thing to do indeed.
block/stream.c static int stream_prepare(Job *job) · line 91
Quoted 4 lines
block/stream.c +4
-0+ } + }else { + base_unfiltered =bdrv_skip_filters (base); +if (base_unfiltered) {
@base_unfiltered cannot be NULL here (because @base is sure not to be NULL). Of course, double-checking isn’t wrong, it just looks a bit weird, because it seems to imply that we might end up with a case where base != NULL, but base_id == NULL. Anyway:
Quoted 8 lines
block/stream.c +5
-0+ base_id = base_unfiltered->filename; +if (base_unfiltered->drv) { + base_fmt = base_unfiltered->drv->format_name; + } + } } }bdrv_set_backing_hd (unfiltered_bs, base, &local_err);
PATCH v14 10/13 qapi: block-stream: add "bottom" argument
In reply to Vladimir Sementsov-OgievskiyThe 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.
--- qapi/block-core.json | 8 +++-- include/block/block_int.h | 1 + block/monitor/block-hmp-cmds.c | 3 +- block/stream.c | 50 +++++++++++++++++++--------- blockdev.c | 61 ++++++++++++++++++++++++++++------ 5 files changed, 94 insertions(+), 29 deletions(-)
qapi/block-core.json +6 -2
@@ -2522,6 +2522,10 @@ # @base-node: the node name of the backing file. # It cannot be set if @base is also set. (Since 2.8) # +# @bottom: the last node in the chain that should be streamed into +# top. It cannot be set any of @base, @base-node or @backing-file +# is 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
@@ -1152,6 +1152,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 +51 -10
100 lines not on this page · raw message
Signature · 1 line
2.21.3
Re: [PATCH v14 10/13] qapi: block-stream: add "bottom" argument
Quoted 34 lines · Vladimir Sementsov-Ogievskiy
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_baseandbase_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.
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- qapi/block-core.json | 8 +++-- include/block/block_int.h | 1 + block/monitor/block-hmp-cmds.c | 3 +- block/stream.c | 50 +++++++++++++++++++--------- blockdev.c | 61 ++++++++++++++++++++++++++++------ 5 files changed, 94 insertions(+), 29 deletions(-)qapi/block-core.json +0
-0
qapi/block-core.json line 2526
Quoted 5 lines
qapi/block-core.json +2
-0@@ -2522,6 +2522,10 @@ # @base-node: the node name of the backing file. # It cannot be set if @base is also set. (Since 2.8) # +# @bottom: the last node in the chain that should be streamed into +# top. It cannot be set any of @base, @base-node or @backing-file
s/set any/set if any/
But what’s the problem with backing-file? The fact that specifying backing-file means that stream will look for that filename in the backing chain when the job is done (so if you use @bottom, we generally don’t want to rely on the presence of any nodes below it)?
(If so, I would have thought that we actually want the user to specify backing-file so we don’t have to look down below @bottom to look for a filename. Perhaps a @backing-fmt parameter would help.)
[...]
Quoted 4 lines
blockdev.c +0
-0
[...]
Quoted 8 lines
blockdev.c +2
-2@@ -2551,8 +2567,33 @@ void qmp_block_stream(bool has_job_id, const char *job_id, const char *device,bdrv_refresh_filename (base_bs); } -/* Check for op blockers in the whole chain between bs and base */ - for (iter = bs; iter && iter != base_bs; +if (has_bottom) { + bottom_bs =bdrv_lookup_bs (NULL , bottom, errp);
blockdev.c void qmp_block_stream(bool has_job_id, const char *job_id, const char *device, · line 2581
Quoted 10 lines
blockdev.c +10
-0+if (!bottom_bs) { + goto out; + } +if (!bottom_bs->drv) { +error_setg (errp,"Node '%s' is not open" , bottom); + goto out; + } +if (bottom_bs->drv->is_filter) { +error_setg (errp,"Node '%s' is filter, use non-filter node" +"as 'bottom'" , bottom);
Missing a space between “node” and “as”. (Also, probably two articles, i.e. “Node '%s' is a filter, use a non-filter node...”.)
The rest looks good to me, but I’m withholding my R-b because I haven’t understood why using @bottom precludes giving @backing-file.
Max
Re: [PATCH v14 10/13] qapi: block-stream: add "bottom" argument
Quoted 43 lines · Max Reitz
Quoted 34 lines · Vladimir Sementsov-Ogievskiy
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_baseandbase_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.
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>---
qapi/block-core.json | 8 +++-- include/block/block_int.h | 1 +block/monitor/block-hmp-cmds.c| 3 +-
block/stream.c | 50 +++++++++++++++++++--------- blockdev.c | 61 ++++++++++++++++++++++++++++------5 files changed, 94 insertions(+), 29 deletions(-)qapi/block-core.json +0
-0qapi/block-core.json line 2526
Quoted 5 lines
qapi/block-core.json +2
-0@@ -2522,6 +2522,10 @@ # @base-node: the node name of the backing file. # It cannot be set if @base is also set. (Since 2.8) # +# @bottom: the last node in the chain that should be streamed into +# top. It cannot be set any of @base, @base-node or @backing-files/set any/set if any/
Quoted 1 line
But what’s the problem with backing-file? The fact that specifying backing-file means that stream will look for that filename in the backing chain when the job is done (so if you use @bottom, we generally don’t want to rely on the presence of any nodes below it)?
I just wanted to deprecate 'backing-file' together with base and base-node as a next step. If user wants to set backing file unrelated to current backing-chain, is it correct at all? It's a direct violation of what's going on, and I doubt that other parts of Qemu working with backing-file are prepared for such situation. User can do it by hand later.. Anyway, we'll have three releases deprecation period for people to come and cry that this is a really needed option, so we can support it later on demand.
Quoted 2 lines
(If so, I would have thought that we actually want the user to specify backing-file so we don’t have to look down below @bottom to look for a filename. Perhaps a @backing-fmt parameter would help.)
If we decide that 'backing-file' is really needed, than yes we should require backing-fmt to be specified together with backing-file when using new "bottom" interface.
Quoted 34 lines
[...]
Quoted 4 lines
blockdev.c +0
-0[...]
Quoted 7 lines
blockdev.c +2
-2@@ -2551,8 +2567,33 @@ void qmp_block_stream(bool has_job_id, const char *job_id, const char *device, bdrv_refresh_filename(base_bs); } - /* Check for op blockers in the whole chain between bs and base */ - for (iter = bs; iter && iter != base_bs; + if (has_bottom) { + bottom_bs = bdrv_lookup_bs(NULL, bottom, errp);blockdev.c void qmp_block_stream(bool has_job_id, const char *job_id, const char *device, · line 2580
Quoted 10 lines
blockdev.c +10
-0+ if (!bottom_bs) { + goto out; + } + if (!bottom_bs->drv) { + error_setg(errp, "Node '%s' is not open", bottom); + goto out; + } + if (bottom_bs->drv->is_filter) { + error_setg(errp, "Node '%s' is filter, use non-filter node" + "as 'bottom'", bottom);Missing a space between “node” and “as”. (Also, probably two articles, i.e. “Node '%s' is a filter, use a non-filter node...”.)
The rest looks good to me, but I’m withholding my R-b because I haven’t understood why using @bottom precludes giving @backing-file.
Max
Signature · 2 lines
Best regards, Vladimir
Re: [PATCH v14 10/13] qapi: block-stream: add "bottom" argument
Quoted 45 lines · Vladimir Sementsov-Ogievskiy
Quoted 44 lines · Max Reitz
Quoted 39 lines · Vladimir Sementsov-Ogievskiy
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_baseandbase_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.
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>---
qapi/block-core.json | 8 +++-- include/block/block_int.h | 1 +block/monitor/block-hmp-cmds.c| 3 +-
block/stream.c | 50 +++++++++++++++++++--------- blockdev.c | 61 ++++++++++++++++++++++++++++------5 files changed, 94 insertions(+), 29 deletions(-)qapi/block-core.json +2
-0@@ -2522,6 +2522,10 @@ # @base-node: the node name of the backing file. # It cannot be set if @base is also set. (Since 2.8) # +# @bottom: the last node in the chain that should be streamed into +# top. It cannot be set any of @base, @base-node orQuoted 1 line
@backing-file
s/set any/set if any/
Quoted 8 lines
Quoted 1 line
But what’s the problem with backing-file? The fact that specifying backing-file means that stream will look for that filename in the backing chain when the job is done (so if you use @bottom, we generally don’t want to rely on the presence of any nodes below it)?
I just wanted to deprecate 'backing-file' together with base and base-node as a next step. If user wants to set backing file unrelated to current backing-chain, is it correct at all? It's a direct violation of what's going on, and I doubt that other parts of Qemu working with backing-file are prepared for such situation. User can do it by hand later.. Anyway, we'll have three releases deprecation period for people to come and cry that this is a really needed option, so we can support it later on demand.
Quoted 2 lines
(If so, I would have thought that we actually want the user to specify backing-file so we don’t have to look down below @bottom to look for a filename. Perhaps a @backing-fmt parameter would help.)
If we decide that 'backing-file' is really needed, than yes we should require backing-fmt to be specified together with backing-file when using new "bottom" interface.
Before I can agree on removing backing-file (or deprecating it), I need to know what it’s actually used for. I actually don’t, though. The only reason I could imagine was because the user wanted to write some string into there that is different from base.filename.
(The original commit 13d8cc515df does mention cases like FD passing, where qemu has no idea what an appropriate filename would be (it can only see /dev/fd/*). From that, it does appear to me that it’ll be needed even with @bottom.)
Max
Re: [PATCH v14 10/13] qapi: block-stream: add "bottom" argument
Quoted 50 lines · Max Reitz
Quoted 49 lines · Vladimir Sementsov-Ogievskiy
Quoted 43 lines · Max Reitz
Quoted 34 lines · Vladimir Sementsov-Ogievskiy
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_baseandbase_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.
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>---
qapi/block-core.json | 8 +++-- include/block/block_int.h | 1 +block/monitor/block-hmp-cmds.c| 3 +-
block/stream.c | 50 +++++++++++++++++++--------- blockdev.c | 61 ++++++++++++++++++++++++++++------5 files changed, 94 insertions(+), 29 deletions(-)qapi/block-core.json +0
-0qapi/block-core.json line 2526
Quoted 5 lines
qapi/block-core.json +2
-0@@ -2522,6 +2522,10 @@ # @base-node: the node name of the backing file. # It cannot be set if @base is also set. (Since 2.8) # +# @bottom: the last node in the chain that should be streamed into +# top. It cannot be set any of @base, @base-node or @backing-files/set any/set if any/
Quoted 1 line
But what’s the problem with backing-file? The fact that specifying backing-file means that stream will look for that filename in the backing chain when the job is done (so if you use @bottom, we generally don’t want to rely on the presence of any nodes below it)?
I just wanted to deprecate 'backing-file' together with base and base-node as a next step. If user wants to set backing file unrelated to current backing-chain, is it correct at all? It's a direct violation of what's going on, and I doubt that other parts of Qemu working with backing-file are prepared for such situation. User can do it by hand later.. Anyway, we'll have three releases deprecation period for people to come and cry that this is a really needed option, so we can support it later on demand.
Quoted 1 line
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
(If so, I would have thought that we actually want the user to specify backing-file so we don’t have to look down below @bottom to look for a filename. Perhaps a @backing-fmt parameter would help.)
If we decide that 'backing-file' is really needed, than yes we should require backing-fmt to be specified together with backing-file when using new "bottom" interface.
Before I can agree on removing backing-file (or deprecating it), I need to know what it’s actually used for. I actually don’t, though. The only reason I could imagine was because the user wanted to write some string into there that is different from base.filename.
(The original commit
13d8cc515dfdoes mention cases like FD passing, where qemu has no idea what an appropriate filename would be (it can only see /dev/fd/*). From that, it does appear to me that it’ll be needed even with @bottom.)
I should have checked it myself.. That's one more reason for my "RFC: don't store backing filename in qcow2 image"..
OK, do you think we can require backing-fmt to be specified if backing-file and bottom are specified? Or allow omitting it and deprecate this thing? We actually already have deprecation message in bdrv_change_backing_file(), and how we are trying to workaround it in block-stream will not work with file descriptors anyway (hmm, and old code works, so, actually 09 is a regression?)
Signature · 2 lines
Best regards, Vladimir
Re: [PATCH v14 10/13] qapi: block-stream: add "bottom" argument
Quoted 56 lines · Vladimir Sementsov-Ogievskiy
Quoted 55 lines · Max Reitz
Quoted 54 lines · Vladimir Sementsov-Ogievskiy
Quoted 45 lines · Max Reitz
Quoted 40 lines · Vladimir Sementsov-Ogievskiy
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_baseandbase_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.
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>---
qapi/block-core.json | 8 +++-- include/block/block_int.h | 1 +block/monitor/block-hmp-cmds.c| 3 +-
block/stream.c | 50 +++++++++++++++++++--------- blockdev.c | 61
++++++++++++++++++++++++++++------5 files changed, 94 insertions(+), 29 deletions(-)qapi/block-core.json +2
-0@@ -2522,6 +2522,10 @@ # @base-node: the node name of the backing file. # It cannot be set if @base is also set. (Since 2.8) # +# @bottom: the last node in the chain that should be streamed into +# top. It cannot be set any of @base, @base-node orQuoted 1 line
@backing-file
s/set any/set if any/
Quoted 1 line
But what’s the problem with backing-file? The fact that specifying backing-file means that stream will look for that filename in the backing chain when the job is done (so if you use @bottom, we generally don’t want to rely on the presence of any nodes below it)?
I just wanted to deprecate 'backing-file' together with base and base-node as a next step. If user wants to set backing file unrelated to current backing-chain, is it correct at all? It's a direct violation of what's going on, and I doubt that other parts of Qemu working with backing-file are prepared for such situation. User can do it by hand later.. Anyway, we'll have three releases deprecation period for people to come and cry that this is a really needed option, so we can support it later on demand.
Quoted 2 lines
(If so, I would have thought that we actually want the user to specify backing-file so we don’t have to look down below @bottom to look for a filename. Perhaps a @backing-fmt parameter would help.)
If we decide that 'backing-file' is really needed, than yes we should require backing-fmt to be specified together with backing-file when using new "bottom" interface.
Quoted 8 lines
Quoted 4 lines
Before I can agree on removing backing-file (or deprecating it), I need to know what it’s actually used for. I actually don’t, though. The only reason I could imagine was because the user wanted to write some string into there that is different from base.filename.
(The original commit
13d8cc515dfdoes mention cases like FD passing, where qemu has no idea what an appropriate filename would be (it can only see /dev/fd/*). From that, it does appear to me that it’ll be needed even with @bottom.)I should have checked it myself.. That's one more reason for my "RFC: don't store backing filename in qcow2 image"..
OK, do you think we can require backing-fmt to be specified if backing-file and bottom are specified?
Sure.
Quoted 1 line
Or allow omitting it and deprecate this thing? We actually already have deprecation message in
bdrv_change_backing_file(), and how we are trying to workaround it in block-stream will not work with file descriptors anyway (hmm, and old code works, so, actually 09 is a regression?)
I think requiring backing-fmt for bottom + backing-file would be the most simple and clean way, hopefully saving us some headaches.
Max
PATCH v14 11/13 iotests: 30: prepare to COR filter insertion by stream job
In reply to Vladimir Sementsov-Ogievskiytest_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.
--- tests/qemu-iotests/030 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tests/qemu-iotests/030 +3 -1
@@ -245,7 +245,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.21.3
Re: [PATCH v14 11/13] iotests: 30: prepare to COR filter insertion by stream job
Quoted 5 lines · Vladimir Sementsov-Ogievskiy
test_stream_parallelrun 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 asabove_basenode.
Quoted 7 lines
Correct thing to do is move to new interface: "bottom" argument instead of base. This guarantees that jobs don't intersect by their actions.
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- tests/qemu-iotests/030 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
PATCH v14 12/13 block/stream: add s->target_bs
In reply to Vladimir Sementsov-OgievskiyAdd 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.
--- block/stream.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-)
block/stream.c +10 -13
@@ -34,6 +34,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;
@@ -54,24 +55,21 @@ 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 *base_unfiltered;BlockDriverState *backing_bs;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)) {
@@ -111,13 +109,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);
@@ -127,8 +124,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 ;
@@ -141,7 +137,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; }
@@ -153,7 +149,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) {
@@ -215,7 +211,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. */
@@ -330,6 +326,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.21.3
Re: [PATCH v14 12/13] block/stream: add s->target_bs
Quoted 9 lines · Vladimir Sementsov-Ogievskiy
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.
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- block/stream.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-)
PATCH v14 13/13 block: apply COR-filter to block-stream jobs
In reply to Vladimir Sementsov-OgievskiyFrom: 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.
--- block/stream.c | 78 ++++++++++++++++++++++++++------------ tests/qemu-iotests/030 | 8 ++-- tests/qemu-iotests/141.out | 2 +- tests/qemu-iotests/245 | 20 ++++++---- 4 files changed, 72 insertions(+), 36 deletions(-)
block/stream.c +54 -24
@@ -18,8 +18,10 @@#include "qapi/error.h" #include "qapi/qmp/qerror.h" #include "qemu/error-report.h" +#include "qapi/qmp/qdict.h" #include "qemu/ratelimit.h" #include "sysemu/block-backend.h" +#include "block/copy-on-read.h" enum {/*
@@ -34,6 +36,7 @@ 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;
@@ -46,8 +49,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 ); +return blk_co_preadv (blk, offset, bytes,NULL ,BDRV_REQ_PREFETCH ); }static void stream_abort (Job *job)
@@ -55,7 +57,7 @@ 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); +bdrv_unfreeze_backing_chain (s->cor_filter_bs, s->above_base); } }
@@ -69,7 +71,7 @@ static int stream_prepare(Job *job)Error *local_err =NULL ;int ret =0 ; -bdrv_unfreeze_backing_chain (s->target_bs, s->above_base); +bdrv_unfreeze_backing_chain (s->cor_filter_bs, s->above_base); s->chain_frozen = false;if (bdrv_cow_child (unfiltered_bs)) {
@@ -117,6 +119,8 @@ static void stream_clean(Job *job)bdrv_reopen_set_read_only (s->target_bs, true,NULL ); } +bdrv_cor_filter_drop (s->cor_filter_bs); +g_free (s->backing_file_str); }
@@ -125,7 +129,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 ;
@@ -143,15 +146,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;
@@ -210,10 +204,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; }
@@ -244,7 +234,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));
@@ -295,17 +287,49 @@ void stream_start(const char *job_id, BlockDriverState *bs, } } -/* 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 ==NULL ) { + goto fail; + } + +if (!filter_node_name) { + cor_filter_bs->implicit = true; + } + +if (bdrv_freeze_backing_chain (cor_filter_bs, bs, errp) <0 ) { +bdrv_cor_filter_drop (cor_filter_bs); + cor_filter_bs =NULL ; + goto fail; + } + + 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
@@ -326,6 +350,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->cor_filter_bs = cor_filter_bs; s->target_bs = bs; s->bs_read_only = bs_read_only; s->chain_frozen = true;
@@ -339,5 +364,10 @@ fail:if (bs_read_only) {bdrv_reopen_set_read_only (bs, true,NULL ); } -bdrv_unfreeze_backing_chain (bs, above_base); +if (cor_filter_bs) { +bdrv_unfreeze_backing_chain (cor_filter_bs, above_base); +bdrv_cor_filter_drop (cor_filter_bs); + }else { +bdrv_unfreeze_backing_chain (bs, above_base); + } }
tests/qemu-iotests/030 +5 -3
@@ -278,12 +278,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',
@@ -296,7 +298,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
@@ -99,7 +99,7 @@ wrote 1048576/1048576 bytes at offset 0 {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "created", "id": "job0"}} {"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": {}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "aborting", "id": "job0"}}
tests/qemu-iotests/245 +12 -8
@@ -892,20 +892,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.21.3
Re: [PATCH v14 13/13] block: apply COR-filter to block-stream jobs
Quoted 28 lines · Vladimir Sementsov-Ogievskiy
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]>--- block/stream.c | 78 ++++++++++++++++++++++++++------------ tests/qemu-iotests/030 | 8 ++-- tests/qemu-iotests/141.out | 2 +- tests/qemu-iotests/245 | 20 ++++++---- 4 files changed, 72 insertions(+), 36 deletions(-)block/stream.c +0
-0
[...]
Quoted 1 line
block/stream.c +0
-0@@ -295,17 +287,49 @@ void stream_start(const char *job_id, BlockDriverState *bs,
[...]
block/stream.c void stream_start(const char *job_id, BlockDriverState *bs, · line 295
Quoted 6 lines
block/stream.c +6
-0+ 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);
Hm. Should we set this option even if no base was specified?
On one hand, omitting this option would cor_co_preadv_part() a bit quicker.
On the other, what happens when you add a backing file below the bottom node during streaming (yes, a largely theoretical case)... Now, all data from it is ignored. That seemed a bit strange to me at first, but on second thought, it makes more sense. Doing anything else would produce a garbage result basically, because stream_run() doesn’t take such a change into account.
So... After all I think I agree with setting @bottom unconditionally.
And that’s the only comment I had. :)
Re: [PATCH v14 13/13] block: apply COR-filter to block-stream jobs
Quoted 43 lines · Max Reitz
Quoted 28 lines · Vladimir Sementsov-Ogievskiy
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]>---
block/stream.c | 78 ++++++++++++++++++++++++++------------ tests/qemu-iotests/030 | 8 ++-- tests/qemu-iotests/141.out | 2 +-
tests/qemu-iotests/245 | 20 ++++++----4 files changed, 72 insertions(+), 36 deletions(-)block/stream.c +0
-0[...]
Quoted 1 line
block/stream.c +0
-0@@ -295,17 +287,49 @@ void stream_start(const char *job_id, BlockDriverState *bs,[...]
Quoted 6 lines
+ opts =
qdict_new();
+
+qdict_put_str(opts, "driver", "copy-on-read");
+qdict_put_str(opts, "file", bdrv_get_node_name(bs)); + /* Pass thebase_overlaynode name as 'bottom' to COR driver */ +qdict_put_str(opts, "bottom", base_overlay->node_name);
Quoted 5 lines
Hm. Should we set this option even if no base was specified?
On one hand, omitting this option would
cor_co_preadv_part()a bit quicker.On the other, what happens when you add a backing file below the bottom node during streaming (yes, a largely theoretical case)...
Yes, that's what I was thinking about.
And more: we are moving to using "bottom" and deprecate "base". So bottom is the main concept, and it can't be NULL. If user don't specify it, than default bottom - is the current bottom node in the chain.
I think, we are not going to introduce a different behavior for stream "without bottom", when user can add more nodes to the chain during the job, and all of them will be removed after the job. It will require rethinking of freezing and keeping references on intermediate nodes at least..
Quoted 2 lines
Now, all data from it is ignored. That seemed a bit strange to me at first, but on second thought, it makes more sense. Doing anything else would produce a garbage result basically, because
stream_run()doesn’t take such a change into account.
yes
Quoted 6 lines
So... After all I think I agree with setting @bottom unconditionally.
And that’s the only comment I had. :)
Reviewed-by Max Reitz <[email protected]>
Thanks! v15 will come next week)
Signature · 2 lines
Best regards, Vladimir