From: Kevin Wolf <kwolf@redhat.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, famz@redhat.com,
stefanha@redhat.com, jcody@redhat.com, mreitz@redhat.com,
den@openvz.org, eblake@redhat.com
Subject: Re: [Qemu-devel] [PATCH v4 04/11] block: improve should_update_child
Date: Tue, 6 Nov 2018 19:09:32 +0100 [thread overview]
Message-ID: <20181106180932.GJ4758@linux.fritz.box> (raw)
In-Reply-To: <20181015160633.63130-5-vsementsov@virtuozzo.com>
Am 15.10.2018 um 18:06 hat Vladimir Sementsov-Ogievskiy geschrieben:
> As it already said in the comment, we don't want to create loops in
> parent->child relations. So, when we try to append @to to @c, we should
> check that @c is not in @to children subtree, and we should check it
> recursively, not only the first level. The patch provides BFS-based
> search, to check the relations.
>
> This is needed for further fleecing-hook filter usage: we need to
> append it to source, when the hook is already a parent of target, and
> source may be in a backing chain of target (fleecing-scheme). So, on
> appending, the hook should not became a child (direct or through
> children subtree) of the target.
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
> block.c | 32 +++++++++++++++++++++++++++-----
> 1 file changed, 27 insertions(+), 5 deletions(-)
>
> diff --git a/block.c b/block.c
> index c298ca6a19..7f605b0bf0 100644
> --- a/block.c
> +++ b/block.c
> @@ -3432,7 +3432,7 @@ void bdrv_close_all(void)
>
> static bool should_update_child(BdrvChild *c, BlockDriverState *to)
> {
> - BdrvChild *to_c;
> + GList *queue = NULL, *pos;
>
> if (c->role->stay_at_node) {
> return false;
> @@ -3468,13 +3468,35 @@ static bool should_update_child(BdrvChild *c, BlockDriverState *to)
> * if A is a child of B, that means we cannot replace A by B there
> * because that would create a loop. Silently detaching A from B
> * is also not really an option. So overall just leaving A in
> - * place there is the most sensible choice. */
> - QLIST_FOREACH(to_c, &to->children, next) {
> - if (to_c == c) {
> - return false;
> + * place there is the most sensible choice.
> + *
> + * upd: If the child @c belongs to the @to's children, or children of it's
> + * children and so on - this would create a loop to. To prevent it let's do
> + * a BFS search on @to children subtree.
> + */
I don't like the "upd:" thing. Let me try to rephrase the addition:
We would also create a loop in any cases where @c is only indirectly
referenced by @to. Prevent this by returning false if @c is found
(by breadth-first search) anywhere in the whole subtree of @to.
Also, even though the coding style says 80 characters per line, the
existing comment seems to use only 70 characters. Let's try to stay
consistent here, otherwise it looks a bit odd.
> + pos = queue = g_list_append(queue, to);
> + while (pos) {
> + BlockDriverState *v = pos->data;
> + BdrvChild *c2;
> +
> + QLIST_FOREACH(c2, &v->children, next) {
> + if (c2 == c) {
> + g_list_free(queue);
> + return false;
> + }
> +
> + if (g_list_find(queue, c2->bs)) {
> + continue;
> + }
> +
> + queue = g_list_append(queue, c2->bs);
> }
> +
> + pos = pos->next;
> }
>
> + g_list_free(queue);
> return true;
> }
The functional change looks good to me.
Kevin
next prev parent reply other threads:[~2018-11-06 18:11 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-15 16:06 [Qemu-devel] [PATCH v4 00/11] backup-top filter driver for backup Vladimir Sementsov-Ogievskiy
2018-10-15 16:06 ` [Qemu-devel] [PATCH v4 01/11] block/backup: simplify backup_incremental_init_copy_bitmap Vladimir Sementsov-Ogievskiy
2018-10-15 16:06 ` [Qemu-devel] [PATCH v4 02/11] block/backup: move to copy_bitmap with granularity Vladimir Sementsov-Ogievskiy
2018-10-15 16:06 ` [Qemu-devel] [PATCH v4 03/11] block: allow serialized reads to intersect Vladimir Sementsov-Ogievskiy
2018-11-06 17:57 ` Kevin Wolf
2018-11-07 10:08 ` Vladimir Sementsov-Ogievskiy
2018-10-15 16:06 ` [Qemu-devel] [PATCH v4 04/11] block: improve should_update_child Vladimir Sementsov-Ogievskiy
2018-11-06 18:09 ` Kevin Wolf [this message]
2018-10-15 16:06 ` [Qemu-devel] [PATCH v4 05/11] iotests: handle -f argument correctly for qemu_io_silent Vladimir Sementsov-Ogievskiy
2018-10-15 16:06 ` [Qemu-devel] [PATCH v4 06/11] iotests: allow resume_drive by node name Vladimir Sementsov-Ogievskiy
2018-10-15 16:06 ` [Qemu-devel] [PATCH v4 07/11] iotests: prepare 055 to graph changes during backup job Vladimir Sementsov-Ogievskiy
2018-10-15 16:06 ` [Qemu-devel] [PATCH v4 08/11] block: introduce backup-top filter driver Vladimir Sementsov-Ogievskiy
2018-10-15 16:06 ` [Qemu-devel] [PATCH v4 09/11] block: add lock/unlock range functions Vladimir Sementsov-Ogievskiy
2018-10-15 16:06 ` [Qemu-devel] [PATCH v4 10/11] block/backup: tiny refactor backup_job_create Vladimir Sementsov-Ogievskiy
2018-10-15 16:06 ` [Qemu-devel] [PATCH v4 11/11] block/backup: use backup-top instead of write notifiers Vladimir Sementsov-Ogievskiy
2018-11-06 17:35 ` Kevin Wolf
2018-11-02 16:41 ` [Qemu-devel] ping Re: [PATCH v4 00/11] backup-top filter driver for backup Vladimir Sementsov-Ogievskiy
2018-11-06 17:21 ` Kevin Wolf
2018-11-06 22:35 ` [Qemu-devel] [Qemu-block] " John Snow
2018-11-07 10:16 ` Vladimir Sementsov-Ogievskiy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181106180932.GJ4758@linux.fritz.box \
--to=kwolf@redhat.com \
--cc=den@openvz.org \
--cc=eblake@redhat.com \
--cc=famz@redhat.com \
--cc=jcody@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=vsementsov@virtuozzo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).