[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PULL 14/53] block: apply COR-filter to block-stream jobs
From: |
Philippe Mathieu-Daudé |
Subject: |
Re: [PULL 14/53] block: apply COR-filter to block-stream jobs |
Date: |
Thu, 28 Jan 2021 19:38:25 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 |
Hi Andrey,
On 1/26/21 3:19 PM, Max Reitz wrote:
> From: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
>
> 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 <andrey.shinkevich@virtuozzo.com>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> Message-Id: <20201216061703.70908-14-vsementsov@virtuozzo.com>
> Reviewed-by: Max Reitz <mreitz@redhat.com>
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
> block/stream.c | 105 ++++++++++++++++++++++---------------
> tests/qemu-iotests/030 | 8 +--
> tests/qemu-iotests/141.out | 2 +-
> tests/qemu-iotests/245 | 20 ++++---
> 4 files changed, 80 insertions(+), 55 deletions(-)
>
> diff --git a/block/stream.c b/block/stream.c
...
> @@ -228,7 +211,9 @@ void stream_start(const char *job_id, BlockDriverState
> *bs,
> bool bs_read_only;
> int basic_flags = BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED;
> BlockDriverState *base_overlay;
> + BlockDriverState *cor_filter_bs = NULL;
> BlockDriverState *above_base;
> + QDict *opts;
>
> assert(!(base && bottom));
> assert(!(backing_file_str && bottom));
> @@ -266,30 +251,62 @@ void stream_start(const char *job_id, BlockDriverState
> *bs,
> }
> }
>
> - if (bdrv_freeze_backing_chain(bs, above_base, errp) < 0) {
> - return;
> - }
> -
> /* Make sure that the image is opened in read-write mode */
> bs_read_only = bdrv_is_read_only(bs);
> if (bs_read_only) {
> - if (bdrv_reopen_set_read_only(bs, false, errp) != 0) {
> - bs_read_only = false;
> - goto fail;
> + int ret;
> + /* Hold the chain during reopen */
> + if (bdrv_freeze_backing_chain(bs, above_base, errp) < 0) {
> + return;
> + }
> +
> + ret = bdrv_reopen_set_read_only(bs, false, errp);
> +
> + /* failure, or cor-filter will hold the chain */
> + bdrv_unfreeze_backing_chain(bs, above_base);
> +
> + if (ret < 0) {
> + return;
> }
> }
>
> - /* Prevent concurrent jobs trying to modify the graph structure here, we
> - * already have our own plans. Also don't allow resize as the image size
> is
> - * queried only at the job start and then cached. */
> - s = block_job_create(job_id, &stream_job_driver, NULL, bs,
> - basic_flags | BLK_PERM_GRAPH_MOD,
> + opts = qdict_new();
Coverity reported (CID 1445793) that this resource could be leaked...
> +
> + qdict_put_str(opts, "driver", "copy-on-read");
> + qdict_put_str(opts, "file", bdrv_get_node_name(bs));
> + /* Pass the base_overlay node name as 'bottom' to COR driver */
> + qdict_put_str(opts, "bottom", base_overlay->node_name);
> + if (filter_node_name) {
> + qdict_put_str(opts, "node-name", filter_node_name);
> + }
> +
> + cor_filter_bs = bdrv_insert_node(bs, opts, BDRV_O_RDWR, errp);
> + if (!cor_filter_bs) {
... probably here.
Should we call g_free(opts) here?
> + goto fail;
> + }
> +
> + if (!filter_node_name) {
> + cor_filter_bs->implicit = true;
> + }
> +
> + s = block_job_create(job_id, &stream_job_driver, NULL, cor_filter_bs,
> + BLK_PERM_CONSISTENT_READ,
> basic_flags | BLK_PERM_WRITE,
> speed, creation_flags, NULL, NULL, errp);
> if (!s) {
> goto fail;
> }
>
> + /*
> + * Prevent concurrent jobs trying to modify the graph structure here, we
> + * already have our own plans. Also don't allow resize as the image size
> is
> + * queried only at the job start and then cached.
> + */
> + if (block_job_add_bdrv(&s->common, "active node", bs, 0,
> + basic_flags | BLK_PERM_WRITE, &error_abort)) {
> + goto fail;
> + }
> +
> /* Block all intermediate nodes between bs and base, because they will
> * disappear from the chain after this operation. The streaming job reads
> * every block only once, assuming that it doesn't change, so forbid
> writes
> @@ -310,9 +327,9 @@ void stream_start(const char *job_id, BlockDriverState
> *bs,
> s->base_overlay = base_overlay;
> s->above_base = above_base;
> s->backing_file_str = g_strdup(backing_file_str);
> + s->cor_filter_bs = cor_filter_bs;
> s->target_bs = bs;
> s->bs_read_only = bs_read_only;
> - s->chain_frozen = true;
>
> s->on_error = on_error;
> trace_stream_start(bs, base, s);
> @@ -320,8 +337,10 @@ void stream_start(const char *job_id, BlockDriverState
> *bs,
> return;
>
> fail:
> + if (cor_filter_bs) {
> + bdrv_cor_filter_drop(cor_filter_bs);
> + }
> if (bs_read_only) {
> bdrv_reopen_set_read_only(bs, true, NULL);
> }
> - bdrv_unfreeze_backing_chain(bs, above_base);
> }
...
- [PULL 03/53] block: add API function to insert a node, (continued)
- [PULL 03/53] block: add API function to insert a node, Max Reitz, 2021/01/26
- [PULL 04/53] copy-on-read: add filter drop function, Max Reitz, 2021/01/26
- [PULL 05/53] qapi: add filter-node-name to block-stream, Max Reitz, 2021/01/26
- [PULL 07/53] iotests: add #310 to test bottom node in COR driver, Max Reitz, 2021/01/26
- [PULL 06/53] qapi: copy-on-read filter: add 'bottom' option, Max Reitz, 2021/01/26
- [PULL 08/53] block: include supported_read_flags into BDS structure, Max Reitz, 2021/01/26
- [PULL 11/53] qapi: block-stream: add "bottom" argument, Max Reitz, 2021/01/26
- [PULL 16/53] iotests/297: Rewrite in Python and extend reach, Max Reitz, 2021/01/26
- [PULL 17/53] iotests: Move try_remove to iotests.py, Max Reitz, 2021/01/26
- [PULL 14/53] block: apply COR-filter to block-stream jobs, Max Reitz, 2021/01/26
- Re: [PULL 14/53] block: apply COR-filter to block-stream jobs,
Philippe Mathieu-Daudé <=
[PULL 10/53] stream: rework backing-file changing, Max Reitz, 2021/01/26
[PULL 13/53] block/stream: add s->target_bs, Max Reitz, 2021/01/26
[PULL 12/53] iotests: 30: prepare to COR filter insertion by stream job, Max Reitz, 2021/01/26
[PULL 09/53] copy-on-read: skip non-guest reads if no copy needed, Max Reitz, 2021/01/26
[PULL 20/53] iotests/129: Use throttle node, Max Reitz, 2021/01/26
[PULL 22/53] iotests/129: Limit mirror job's buffer size, Max Reitz, 2021/01/26
[PULL 15/53] iotests.py: Assume a couple of variables as given, Max Reitz, 2021/01/26