qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, fam@euphon.net, vsementsov@virtuozzo.com,
	armbru@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com,
	andrey.shinkevich@virtuozzo.com, den@openvz.org,
	mreitz@redhat.com, jsnow@redhat.com
Subject: [PATCH v4 08/15] block: Use CAFs when working with backing chains
Date: Tue, 12 May 2020 19:50:38 +0300	[thread overview]
Message-ID: <1589302245-893269-9-git-send-email-andrey.shinkevich@virtuozzo.com> (raw)
In-Reply-To: <1589302245-893269-1-git-send-email-andrey.shinkevich@virtuozzo.com>

From: Max Reitz <mreitz@redhat.com>

Use child access functions when iterating through backing chains so
filters do not break the chain.

Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 block.c | 40 ++++++++++++++++++++++++++++------------
 1 file changed, 28 insertions(+), 12 deletions(-)

diff --git a/block.c b/block.c
index 459412e..69e9152 100644
--- a/block.c
+++ b/block.c
@@ -4593,7 +4593,8 @@ int bdrv_change_backing_file(BlockDriverState *bs,
 }
 
 /*
- * Finds the image layer in the chain that has 'bs' as its backing file.
+ * Finds the image layer in the chain that has 'bs' (or a filter on
+ * top of it) as its backing file.
  *
  * active is the current topmost image.
  *
@@ -4605,11 +4606,18 @@ int bdrv_change_backing_file(BlockDriverState *bs,
 BlockDriverState *bdrv_find_overlay(BlockDriverState *active,
                                     BlockDriverState *bs)
 {
-    while (active && bs != backing_bs(active)) {
-        active = backing_bs(active);
+    bs = bdrv_skip_rw_filters(bs);
+    active = bdrv_skip_rw_filters(active);
+
+    while (active) {
+        BlockDriverState *next = bdrv_backing_chain_next(active);
+        if (bs == next) {
+            return active;
+        }
+        active = next;
     }
 
-    return active;
+    return NULL;
 }
 
 /* Given a BDS, searches for the base layer. */
@@ -4761,9 +4769,7 @@ int bdrv_drop_intermediate(BlockDriverState *top, BlockDriverState *base,
      * other intermediate nodes have been dropped.
      * If 'top' is an implicit node (e.g. "commit_top") we should skip
      * it because no one inherits from it. We use explicit_top for that. */
-    while (explicit_top && explicit_top->implicit) {
-        explicit_top = backing_bs(explicit_top);
-    }
+    explicit_top = bdrv_skip_implicit_filters(explicit_top);
     update_inherits_from = bdrv_inherits_from_recursive(base, explicit_top);
 
     /* success - we can delete the intermediate states, and link top->base */
@@ -5205,7 +5211,7 @@ BlockDriverState *bdrv_lookup_bs(const char *device,
 bool bdrv_chain_contains(BlockDriverState *top, BlockDriverState *base)
 {
     while (top && top != base) {
-        top = backing_bs(top);
+        top = bdrv_filtered_bs(top);
     }
 
     return top != NULL;
@@ -5466,7 +5472,17 @@ BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs,
 
     is_protocol = path_has_protocol(backing_file);
 
-    for (curr_bs = bs; curr_bs->backing; curr_bs = curr_bs->backing->bs) {
+    /*
+     * Being largely a legacy function, skip any filters here
+     * (because filters do not have normal filenames, so they cannot
+     * match anyway; and allowing json:{} filenames is a bit out of
+     * scope).
+     */
+    for (curr_bs = bdrv_skip_rw_filters(bs);
+         bdrv_filtered_cow_child(curr_bs) != NULL;
+         curr_bs = bdrv_backing_chain_next(curr_bs))
+    {
+        BlockDriverState *bs_below = bdrv_backing_chain_next(curr_bs);
 
         /* If either of the filename paths is actually a protocol, then
          * compare unmodified paths; otherwise make paths relative */
@@ -5474,7 +5490,7 @@ BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs,
             char *backing_file_full_ret;
 
             if (strcmp(backing_file, curr_bs->backing_file) == 0) {
-                retval = curr_bs->backing->bs;
+                retval = bs_below;
                 break;
             }
             /* Also check against the full backing filename for the image */
@@ -5484,7 +5500,7 @@ BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs,
                 bool equal = strcmp(backing_file, backing_file_full_ret) == 0;
                 g_free(backing_file_full_ret);
                 if (equal) {
-                    retval = curr_bs->backing->bs;
+                    retval = bs_below;
                     break;
                 }
             }
@@ -5510,7 +5526,7 @@ BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs,
             g_free(filename_tmp);
 
             if (strcmp(backing_file_full, filename_full) == 0) {
-                retval = curr_bs->backing->bs;
+                retval = bs_below;
                 break;
             }
         }
-- 
1.8.3.1



  parent reply	other threads:[~2020-05-12 17:04 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-12 16:50 [PATCH v4 00/15] Apply COR-filter to the block-stream permanently Andrey Shinkevich
2020-05-12 16:50 ` [PATCH v4 01/15] block: Mark commit and mirror as filter drivers Andrey Shinkevich
2020-05-12 16:50 ` [PATCH v4 02/15] copy-on-read: Support compressed writes Andrey Shinkevich
2020-05-12 16:50 ` [PATCH v4 03/15] block: Add child access functions Andrey Shinkevich
2020-05-12 16:50 ` [PATCH v4 04/15] block: Add chain helper functions Andrey Shinkevich
2020-05-12 16:50 ` [PATCH v4 05/15] block: Include filters when freezing backing chain Andrey Shinkevich
2020-05-12 16:50 ` [PATCH v4 06/15] block: Use CAFs in block status functions Andrey Shinkevich
2020-05-12 16:50 ` [PATCH v4 07/15] commit: Deal with filters when blocking intermediate nodes Andrey Shinkevich
2020-05-12 16:50 ` Andrey Shinkevich [this message]
2020-05-12 16:50 ` [PATCH v4 09/15] block: prepare block-stream for using COR-filter Andrey Shinkevich
2020-05-12 16:50 ` [PATCH v4 10/15] copy-on-read: Support change filename functions Andrey Shinkevich
2020-05-12 16:50 ` [PATCH v4 11/15] copy-on-read: Support preadv/pwritev_part functions Andrey Shinkevich
2020-05-12 16:50 ` [PATCH v4 12/15] copy-on-read: add filter append/drop functions Andrey Shinkevich
2020-05-12 16:50 ` [PATCH v4 13/15] qapi: add filter-node-name to block-stream Andrey Shinkevich
2020-05-12 16:50 ` [PATCH v4 14/15] iotests: prepare 245 for using filter in block-stream Andrey Shinkevich
2020-05-12 16:50 ` [PATCH v4 15/15] block: apply COR-filter to block-stream jobs Andrey Shinkevich
2020-05-12 17:56 ` [PATCH v4 00/15] Apply COR-filter to the block-stream permanently Vladimir Sementsov-Ogievskiy
2020-05-13 14:06   ` Vladimir Sementsov-Ogievskiy
2020-05-13  0:09 ` no-reply
2020-05-13  0:13 ` no-reply
2020-05-13  0:15 ` no-reply

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=1589302245-893269-9-git-send-email-andrey.shinkevich@virtuozzo.com \
    --to=andrey.shinkevich@virtuozzo.com \
    --cc=armbru@redhat.com \
    --cc=den@openvz.org \
    --cc=fam@euphon.net \
    --cc=jsnow@redhat.com \
    --cc=kwolf@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).