[PATCH v4 27/34] block: Use child_of_bds in remaining places

Max Reitz posted 34 patches 5 years, 9 months ago
[PATCH v4 27/34] block: Use child_of_bds in remaining places
Posted by Max Reitz 5 years, 9 months ago
Replace child_file by child_of_bds in all remaining places (excluding
tests).

Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 block.c              |  3 ++-
 block/backup-top.c   |  4 ++--
 block/blklogwrites.c |  4 ++--
 block/raw-format.c   | 15 +++++++++++++--
 4 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/block.c b/block.c
index d138a3c261..fb94adcca4 100644
--- a/block.c
+++ b/block.c
@@ -3406,7 +3406,8 @@ static BlockDriverState *bdrv_open_inherit(const char *filename,
         BlockDriverState *file_bs;
 
         file_bs = bdrv_open_child_bs(filename, options, "file", bs,
-                                     &child_file, 0, true, &local_err);
+                                     &child_of_bds, BDRV_CHILD_IMAGE,
+                                     true, &local_err);
         if (local_err) {
             goto fail;
         }
diff --git a/block/backup-top.c b/block/backup-top.c
index f059617095..8af2c5fe9b 100644
--- a/block/backup-top.c
+++ b/block/backup-top.c
@@ -215,8 +215,8 @@ BlockDriverState *bdrv_backup_top_append(BlockDriverState *source,
              source->supported_zero_flags);
 
     bdrv_ref(target);
-    state->target = bdrv_attach_child(top, target, "target", &child_file, 0,
-                                      errp);
+    state->target = bdrv_attach_child(top, target, "target", &child_of_bds,
+                                      BDRV_CHILD_DATA, errp);
     if (!state->target) {
         bdrv_unref(target);
         bdrv_unref(top);
diff --git a/block/blklogwrites.c b/block/blklogwrites.c
index 78b0c49460..3a57b273fc 100644
--- a/block/blklogwrites.c
+++ b/block/blklogwrites.c
@@ -167,8 +167,8 @@ static int blk_log_writes_open(BlockDriverState *bs, QDict *options, int flags,
     }
 
     /* Open the log file */
-    s->log_file = bdrv_open_child(NULL, options, "log", bs, &child_file, 0,
-                                  false, &local_err);
+    s->log_file = bdrv_open_child(NULL, options, "log", bs, &child_of_bds,
+                                  BDRV_CHILD_METADATA, false, &local_err);
     if (local_err) {
         ret = -EINVAL;
         error_propagate(errp, local_err);
diff --git a/block/raw-format.c b/block/raw-format.c
index 824fe70686..bfb4d7ddb7 100644
--- a/block/raw-format.c
+++ b/block/raw-format.c
@@ -441,6 +441,7 @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags,
     BDRVRawState *s = bs->opaque;
     bool has_size;
     uint64_t offset, size;
+    BdrvChildRole file_role;
     int ret;
 
     ret = raw_read_options(options, &offset, &has_size, &size, errp);
@@ -448,8 +449,18 @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags,
         return ret;
     }
 
-    bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0,
-                               false, errp);
+    /*
+     * Without offset and a size limit, this driver behaves very much
+     * like a filter.  With any such limit, it does not.
+     */
+    if (offset || has_size) {
+        file_role = BDRV_CHILD_DATA | BDRV_CHILD_PRIMARY;
+    } else {
+        file_role = BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY;
+    }
+
+    bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds,
+                               file_role, false, errp);
     if (!bs->file) {
         return -EINVAL;
     }
-- 
2.26.2


Re: [PATCH v4 27/34] block: Use child_of_bds in remaining places
Posted by Eric Blake 5 years, 9 months ago
On 5/13/20 6:05 AM, Max Reitz wrote:
> Replace child_file by child_of_bds in all remaining places (excluding
> tests).
> 
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
>   block.c              |  3 ++-
>   block/backup-top.c   |  4 ++--
>   block/blklogwrites.c |  4 ++--
>   block/raw-format.c   | 15 +++++++++++++--
>   4 files changed, 19 insertions(+), 7 deletions(-)
> 

> @@ -448,8 +449,18 @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags,
>           return ret;
>       }
>   
> -    bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0,
> -                               false, errp);
> +    /*
> +     * Without offset and a size limit, this driver behaves very much
> +     * like a filter.  With any such limit, it does not.
> +     */
> +    if (offset || has_size) {
> +        file_role = BDRV_CHILD_DATA | BDRV_CHILD_PRIMARY;
> +    } else {
> +        file_role = BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY;
> +    }

I wonder if we'll hit subtle bugs where one but not the other use of raw 
breaks because of the difference in roles.  I know we have _some_ iotest 
coverage of raw with offsets, but wonder if we might need more (or a way 
to add it on top of existing images, similar to how we can easily toggle 
qcow2 options like refcount size for interesting non-default test runs).

> +
> +    bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds,
> +                               file_role, false, errp);
>       if (!bs->file) {
>           return -EINVAL;
>       }
> 

At any rate, if we have corner-case bugs, I don't think this is making 
them worse.
Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org