Skip to contentSkip to conversation

block: allow partial info-block query

PATCH Superseded John Snow 2 participants 13 messages Dec 12, 2015 – Dec 14, 2015 Block layer

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

John Snow

author
#0 lore raw

v2 cover block: allow partial info-block query

Max: Did you have in mind something like this?

v2:
- Fix qemu-img from now choking when it gets a partial response.

________________________________________________________________________________

For convenience, this branch is available at:
https://github.com/jnsnow/qemu.git branch block-allow-partial-query
https://github.com/jnsnow/qemu/tree/block-allow-partial-query

This version is tagged block-allow-partial-query-v2:
https://github.com/jnsnow/qemu/releases/tag/block-allow-partial-query-v2

John Snow (4):
block/qapi: do not redundantly print "actual path" block/qapi: always report full_backing_filename
qemu-img: abort when full_backing_filename not present block/qapi: allow best-effort query

 block/qapi.c               | 18 +++++++++++-------
 qemu-img.c                 |  5 ++++-
 tests/qemu-iotests/043.out |  2 ++
 tests/qemu-iotests/110.out |  5 ++++-
 4 files changed, 21 insertions(+), 9 deletions(-)
Signature · 1 line
2.4.3
author
#1 lore raw

PATCH v2 1/4 block/qapi: do not redundantly print "actual path"

If it happens to match the backing path, that was the actual path.

---
 block/qapi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
block/qapi.c +3 -1
index 267f147..01569da 100644
@@ -676,7 +676,9 @@ void bdrv_image_info_dump(fprintf_function func_fprintf, void *f,
 
     if (info->has_backing_filename) {
         func_fprintf(f, "backing file: %s", info->backing_filename);
-        if (info->has_full_backing_filename) {
+        if (info->has_full_backing_filename &&
+            (strcmp(info->backing_filename,
+                    info->full_backing_filename) != 0)) {
             func_fprintf(f, " (actual path: %s)", info->full_backing_filename);
         }
         func_fprintf(f, "\n");
Signature · 1 line
2.4.3
Reviewed-by on v2 1/4
#2 lore raw

Re: [Qemu-devel] [PATCH v2 1/4] block/qapi: do not redundantly print "actual path"

Quoted 6 lines · John Snow

If it happens to match the backing path, that was the actual path.

---
 block/qapi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
author
#3 lore raw

PATCH v2 2/4 block/qapi: always report full_backing_filename

In reply to John Snow

Always report full_backing_filename, even if it's the same as backing_filename. In the next patch, full_backing_filename may be omitted if it cannot be generated instead of allowing e.g. drive_query to abort if it runs into this scenario.

The presence or absence of the "full" field becomes useful information.

---
 block/qapi.c               | 7 ++++---
 tests/qemu-iotests/043.out | 2 ++
 2 files changed, 6 insertions(+), 3 deletions(-)
block/qapi.c +4 -3
index 01569da..0e6b333 100644
@@ -251,9 +251,10 @@ void bdrv_query_image_info(BlockDriverState *bs,
             return;
         }
 
-        if (strcmp(backing_filename, backing_filename2) != 0) {
-            info->full_backing_filename =
-                        g_strdup(backing_filename2);
+        /* Always report the full_backing_filename if present, even if it's the
+         * same as backing_filename. That they are same is useful info. */
+        if (backing_filename2) {
+            info->full_backing_filename = g_strdup(backing_filename2);
             info->has_full_backing_filename = true;
         }
 
tests/qemu-iotests/043.out +2 -0
index 33f8cc3..b37d2a3 100644
@@ -44,6 +44,7 @@ cluster_size: 65536
         "filename": "TEST_DIR/t.IMGFMT",
         "cluster-size": 65536,
         "format": "IMGFMT",
+        "full-backing-filename": "TEST_DIR/t.IMGFMT.2.base",
         "backing-filename": "TEST_DIR/t.IMGFMT.2.base",
         "dirty-flag": false
     },
@@ -52,6 +53,7 @@ cluster_size: 65536
         "filename": "TEST_DIR/t.IMGFMT.2.base",
         "cluster-size": 65536,
         "format": "IMGFMT",
+        "full-backing-filename": "TEST_DIR/t.IMGFMT.1.base",
         "backing-filename": "TEST_DIR/t.IMGFMT.1.base",
         "dirty-flag": false
     },
Signature · 1 line
2.4.3
#4 lore raw

Re: [Qemu-devel] [PATCH v2 2/4] block/qapi: always report full_backing_filename

Quoted 18 lines · John Snow

Always report full_backing_filename, even if it's the same as backing_filename. In the next patch, full_backing_filename may be omitted if it cannot be generated instead of allowing e.g. drive_query to abort if it runs into this scenario.

The presence or absence of the "full" field becomes useful information.

---
 block/qapi.c               | 7 ++++---
 tests/qemu-iotests/043.out | 2 ++
 2 files changed, 6 insertions(+), 3 deletions(-)
block/qapi.c +0 -0
index 01569da..0e6b333 100644

block/qapi.c void bdrv_query_image_info(BlockDriverState *bs, · line 256

Quoted 9 lines
block/qapi.c +3 -3
@@ -251,9 +251,10 @@ void bdrv_query_image_info(BlockDriverState *bs,
             return;
         }
 
-        if (strcmp(backing_filename, backing_filename2) != 0) {
-            info->full_backing_filename =
-                        g_strdup(backing_filename2);
+        /* Always report the full_backing_filename if present, even if it's the
+         * same as backing_filename. That they are same is useful info. */
+        if (backing_filename2) {

Is there a reason for this non-NULL check? Because it always is non-NULL right now.

Max

Quoted 25 lines
block/qapi.c +1 -0
+            info->full_backing_filename = g_strdup(backing_filename2);
             info->has_full_backing_filename = true;
         }
 
tests/qemu-iotests/043.out +2 -0
index 33f8cc3..b37d2a3 100644
@@ -44,6 +44,7 @@ cluster_size: 65536
         "filename": "TEST_DIR/t.IMGFMT",
         "cluster-size": 65536,
         "format": "IMGFMT",
+        "full-backing-filename": "TEST_DIR/t.IMGFMT.2.base",
         "backing-filename": "TEST_DIR/t.IMGFMT.2.base",
         "dirty-flag": false
     },
@@ -52,6 +53,7 @@ cluster_size: 65536
         "filename": "TEST_DIR/t.IMGFMT.2.base",
         "cluster-size": 65536,
         "format": "IMGFMT",
+        "full-backing-filename": "TEST_DIR/t.IMGFMT.1.base",
         "backing-filename": "TEST_DIR/t.IMGFMT.1.base",
         "dirty-flag": false
     },
author
#5 lore raw

Re: [Qemu-devel] [PATCH v2 2/4] block/qapi: always report full_backing_filename

Quoted 32 lines · Max Reitz
Quoted 18 lines · John Snow

Always report full_backing_filename, even if it's the same as backing_filename. In the next patch, full_backing_filename may be omitted if it cannot be generated instead of allowing e.g. drive_query to abort if it runs into this scenario.

The presence or absence of the "full" field becomes useful information.

---
 block/qapi.c               | 7 ++++---
 tests/qemu-iotests/043.out | 2 ++
 2 files changed, 6 insertions(+), 3 deletions(-)
block/qapi.c +0 -0
index 01569da..0e6b333 100644

block/qapi.c void bdrv_query_image_info(BlockDriverState *bs, · line 256

Quoted 9 lines
block/qapi.c +3 -3
@@ -251,9 +251,10 @@ void bdrv_query_image_info(BlockDriverState *bs,
             return;
         }
 
-        if (strcmp(backing_filename, backing_filename2) != 0) {
-            info->full_backing_filename =
-                        g_strdup(backing_filename2);
+        /* Always report the full_backing_filename if present, even if it's the
+         * same as backing_filename. That they are same is useful info. */
+        if (backing_filename2) {

Is there a reason for this non-NULL check? Because it always is non-NULL right now.

Quoted 2 lines

Max

No, I was just being convenient with re-ordering patches. It can be NULL by the end of the set. I'll clean it if there's other work to do.

Quoted 27 lines
Quoted 25 lines
block/qapi.c +1 -0
+            info->full_backing_filename = g_strdup(backing_filename2);
             info->has_full_backing_filename = true;
         }
 
tests/qemu-iotests/043.out +2 -0
index 33f8cc3..b37d2a3 100644
@@ -44,6 +44,7 @@ cluster_size: 65536
         "filename": "TEST_DIR/t.IMGFMT",
         "cluster-size": 65536,
         "format": "IMGFMT",
+        "full-backing-filename": "TEST_DIR/t.IMGFMT.2.base",
         "backing-filename": "TEST_DIR/t.IMGFMT.2.base",
         "dirty-flag": false
     },
@@ -52,6 +53,7 @@ cluster_size: 65536
         "filename": "TEST_DIR/t.IMGFMT.2.base",
         "cluster-size": 65536,
         "format": "IMGFMT",
+        "full-backing-filename": "TEST_DIR/t.IMGFMT.1.base",
         "backing-filename": "TEST_DIR/t.IMGFMT.1.base",
         "dirty-flag": false
     },
Signature · 1 line
—js
Reviewed-by
#6 lore raw

Re: [Qemu-devel] [PATCH v2 2/4] block/qapi: always report full_backing_filename

Quoted 35 lines · John Snow
Quoted 32 lines · Max Reitz
Quoted 18 lines · John Snow

Always report full_backing_filename, even if it's the same as backing_filename. In the next patch, full_backing_filename may be omitted if it cannot be generated instead of allowing e.g. drive_query to abort if it runs into this scenario.

The presence or absence of the "full" field becomes useful information.

---
 block/qapi.c               | 7 ++++---
 tests/qemu-iotests/043.out | 2 ++
 2 files changed, 6 insertions(+), 3 deletions(-)
block/qapi.c +0 -0
index 01569da..0e6b333 100644

block/qapi.c void bdrv_query_image_info(BlockDriverState *bs, · line 256

Quoted 9 lines
block/qapi.c +3 -3
@@ -251,9 +251,10 @@ void bdrv_query_image_info(BlockDriverState *bs,
             return;
         }
 
-        if (strcmp(backing_filename, backing_filename2) != 0) {
-            info->full_backing_filename =
-                        g_strdup(backing_filename2);
+        /* Always report the full_backing_filename if present, even if it's the
+         * same as backing_filename. That they are same is useful info. */
+        if (backing_filename2) {

Is there a reason for this non-NULL check? Because it always is non-NULL right now.

Quoted 5 lines
Quoted 2 lines

Max

No, I was just being convenient with re-ordering patches. It can be NULL by the end of the set. I'll clean it if there's other work to do.

Oh, OK, that's fine then.

Quoted 29 lines
Quoted 28 lines
Quoted 26 lines
block/qapi.c +1 -0
+            info->full_backing_filename = g_strdup(backing_filename2);
             info->has_full_backing_filename = true;
         }
 
tests/qemu-iotests/043.out +2 -0
index 33f8cc3..b37d2a3 100644
@@ -44,6 +44,7 @@ cluster_size: 65536
         "filename": "TEST_DIR/t.IMGFMT",
         "cluster-size": 65536,
         "format": "IMGFMT",
+        "full-backing-filename": "TEST_DIR/t.IMGFMT.2.base",
         "backing-filename": "TEST_DIR/t.IMGFMT.2.base",
         "dirty-flag": false
     },
@@ -52,6 +53,7 @@ cluster_size: 65536
         "filename": "TEST_DIR/t.IMGFMT.2.base",
         "cluster-size": 65536,
         "format": "IMGFMT",
+        "full-backing-filename": "TEST_DIR/t.IMGFMT.1.base",
         "backing-filename": "TEST_DIR/t.IMGFMT.1.base",
         "dirty-flag": false
     },
author
#7 lore raw

PATCH v2 3/4 qemu-img: abort when full_backing_filename not present

In reply to John Snow

...But only if we have the backing_filename. It means something Scary happened and we can't really be quite exactly sure if we can trust the backing_filename.

---
 qemu-img.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
qemu-img.c +4 -1
index 033011c..272bb0b 100644
@@ -2040,7 +2040,10 @@ static ImageInfoList *collect_image_info_list(const char *filename,
             if (info->has_full_backing_filename) {
                 filename = info->full_backing_filename;
             } else if (info->has_backing_filename) {
-                filename = info->backing_filename;
+                error_report("Could not determine absolute backing filename,"
+                             " but backing filename '%s' present",
+                             info->backing_filename);
+                goto err;
             }
             if (info->has_backing_filename_format) {
                 fmt = info->backing_filename_format;
Signature · 1 line
2.4.3
Reviewed-by on v2 3/4
#8 lore raw

Re: [Qemu-devel] [PATCH v2 3/4] qemu-img: abort when full_backing_filename not present

Quoted 8 lines · John Snow

...But only if we have the backing_filename. It means something Scary happened and we can't really be quite exactly sure if we can trust the backing_filename.

---
 qemu-img.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
author
#9 lore raw

PATCH v2 4/4 block/qapi: allow best-effort query

In reply to John Snow

For more complex BDS trees that can be created under normal circumstances, we lose the ability to issue query commands because of our inability to re-construct the absolute filename.

Instead, omit this field when it is a problem and present as much information as we can.

This will change the expected output in iotest 110, where we will now see a json filename and the lack of an absolute filename instead of an error.

---
 block/qapi.c               | 7 ++++---
 tests/qemu-iotests/110.out | 5 ++++-
 2 files changed, 8 insertions(+), 4 deletions(-)
block/qapi.c +4 -3
index 0e6b333..f581c48 100644
@@ -245,10 +245,11 @@ void bdrv_query_image_info(BlockDriverState *bs,
         info->has_backing_filename = true;
         bdrv_get_full_backing_filename(bs, backing_filename2, PATH_MAX, &err);
         if (err) {
-            error_propagate(errp, err);
-            qapi_free_ImageInfo(info);
+            /* Can't reconstruct the full backing filename, so we must omit
+             * this field and apply a Best Effort to this query. */
             g_free(backing_filename2);
-            return;
+            backing_filename2 = NULL;
+            error_free(err);
         }
 
         /* Always report the full_backing_filename if present, even if it's the
tests/qemu-iotests/110.out +4 -1
index 0270980..425485f 100644
@@ -11,7 +11,10 @@ backing file: t.IMGFMT.base (actual path: TEST_DIR/t.IMGFMT.base)
 
 === Non-reconstructable filename ===
 
-qemu-img: Cannot use relative backing file names for 'json:{"driver": "IMGFMT", "file": {"set-state.0.event": "read_aio", "image": {"driver": "file", "filename": "TEST_DIR/t.IMGFMT"}, "driver": "blkdebug", "set-state.0.new_state": 42}}'
+image: json:{"driver": "IMGFMT", "file": {"set-state.0.event": "read_aio", "image": {"driver": "file", "filename": "TEST_DIR/t.IMGFMT"}, "driver": "blkdebug", "set-state.0.new_state": 42}}
+file format: IMGFMT
+virtual size: 64M (67108864 bytes)
+backing file: t.IMGFMT.base
 
 === Backing name is always relative to the backed image ===
 
Signature · 1 line
2.4.3
Reviewed-by on v2 4/4
#10 lore raw

Re: [Qemu-devel] [PATCH v2 4/4] block/qapi: allow best-effort query

Quoted 7 lines · John Snow

For more complex BDS trees that can be created under normal circumstances, we lose the ability to issue query commands because of our inability to re-construct the absolute filename.

Instead, omit this field when it is a problem and present as much information as we can.

Quoted 8 lines

This will change the expected output in iotest 110, where we will now see a json filename and the lack of an absolute filename instead of an error.

---
 block/qapi.c               | 7 ++++---
 tests/qemu-iotests/110.out | 5 ++++-
 2 files changed, 8 insertions(+), 4 deletions(-)
#11 lore raw
In reply to John Snow
Quoted 1 line · John Snow

Max: Did you have in mind something like this?

What I had in mind was fixing the whole thing (the test case in 110 should actually work just fine, because you can easily determine the base directory to be used). ;-)

I've been working on that myself anyway, so yes, regarding not aborting block-status if some full backing filename cannot be reconstructed, this looks good (by preventing qemu-img from resorting to the relative filename when querying the backing chain).

There is a single thing I don't find quite perfect:

$ mkdir -p foo
$ ./qemu-img create -f qcow2 foo/base.qcow2 64M
$ ./qemu-img create -f qcow2 -b base.qcow2 foo/top.qcow2
$ ./qemu-img info foo/top.qcow2
[...]
backing file: base.qcow2 (actual path: foo/base.qcow2)
[...]
$ ./qemu-img info \
    "json:{'lazy-refcounts':true,'file.filename':'foo/top.qcow2'}"
[...]
backing file: base.qcow2
[...]
$ cd foo
$ ../qemu-img info top.qcow2
[...]
backing file: base.qcow2
[...]

Before this series, there was only one case where the actual path information was missing: If it equals the raw relative filename. Now, there are two cases: As can be seen in the last invokation, it still will not be emitted if actual and raw filename are equal. But as you can see in the second invokation, it will be hidden also if it simply cannot be determined.

Therefore, if the actual path information is missing, the user cannot determine[1] whether this is due to the actual path (relative to the CWD) is equal to the (raw) relative path to the overlay; or whether this is due to some error in determining the absolute filename.

[1] You can by testing whether --backing-chain emits an error. But that is a bit crude.

I think we should put a note there if an error occurred while determining the absolute backing filename.

(Doing that is pretty simple:

if (!info->has_full_backing_filename) {
    func_fprintf(f, " (cannot determine actual path)");
} else if (strcmp(...)) {
    func_fprintf(f, " (actual path: %s)", ...);
}

)

I think that should be an additional patch between 2 and 4.

Max

Quoted 25 lines

v2:
- Fix qemu-img from now choking when it gets a partial response.

________________________________________________________________________________

For convenience, this branch is available at:
https://github.com/jnsnow/qemu.git branch block-allow-partial-query
https://github.com/jnsnow/qemu/tree/block-allow-partial-query

This version is tagged block-allow-partial-query-v2:
https://github.com/jnsnow/qemu/releases/tag/block-allow-partial-query-v2

John Snow (4):
block/qapi: do not redundantly print "actual path" block/qapi: always report full_backing_filename
qemu-img: abort when full_backing_filename not present block/qapi: allow best-effort query

 block/qapi.c               | 18 +++++++++++-------
 qemu-img.c                 |  5 ++++-
 tests/qemu-iotests/043.out |  2 ++
 tests/qemu-iotests/110.out |  5 ++++-
 4 files changed, 21 insertions(+), 9 deletions(-)
author
#12 lore raw
Quoted 7 lines · Max Reitz
Quoted 1 line · John Snow

Max: Did you have in mind something like this?

What I had in mind was fixing the whole thing (the test case in 110 should actually work just fine, because you can easily determine the base directory to be used). ;-)

Well, yes... though I figured there was some value in this bit alone -- assuming that the fixing of the filename strategy would take longer. You understand this problem best AFAICT.

Quoted 5 lines

I've been working on that myself anyway, so yes, regarding not aborting block-status if some full backing filename cannot be reconstructed, this looks good (by preventing qemu-img from resorting to the relative filename when querying the backing chain).

I look forward to a less confusing filename situation. :|

Quoted 22 lines

There is a single thing I don't find quite perfect:

$ mkdir -p foo
$ ./qemu-img create -f qcow2 foo/base.qcow2 64M
$ ./qemu-img create -f qcow2 -b base.qcow2 foo/top.qcow2
$ ./qemu-img info foo/top.qcow2
[...]
backing file: base.qcow2 (actual path: foo/base.qcow2)
[...]
$ ./qemu-img info \
    "json:{'lazy-refcounts':true,'file.filename':'foo/top.qcow2'}"
[...]
backing file: base.qcow2
[...]
$ cd foo
$ ../qemu-img info top.qcow2
[...]
backing file: base.qcow2
[...]
Quoted 7 lines

Before this series, there was only one case where the actual path information was missing: If it equals the raw relative filename. Now, there are two cases: As can be seen in the last invokation, it still will not be emitted if actual and raw filename are equal. But as you can see in the second invokation, it will be hidden also if it simply cannot be determined.

Tch, yes.

Quoted 17 lines

Therefore, if the actual path information is missing, the user cannot determine[1] whether this is due to the actual path (relative to the CWD) is equal to the (raw) relative path to the overlay; or whether this is due to some error in determining the absolute filename.

[1] You can by testing whether --backing-chain emits an error. But that is a bit crude.

I think we should put a note there if an error occurred while determining the absolute backing filename.

(Doing that is pretty simple:

if (!info->has_full_backing_filename) {
    func_fprintf(f, " (cannot determine actual path)");
} else if (strcmp(...)) {
    func_fprintf(f, " (actual path: %s)", ...);
}
Quoted 6 lines

)

I think that should be an additional patch between 2 and 4.

Max

Yes, thanks.

Quoted 27 lines
Quoted 25 lines

v2:
- Fix qemu-img from now choking when it gets a partial response.

________________________________________________________________________________

For convenience, this branch is available at:
https://github.com/jnsnow/qemu.git branch block-allow-partial-query
https://github.com/jnsnow/qemu/tree/block-allow-partial-query

This version is tagged block-allow-partial-query-v2:
https://github.com/jnsnow/qemu/releases/tag/block-allow-partial-query-v2

John Snow (4):
block/qapi: do not redundantly print "actual path" block/qapi: always report full_backing_filename
qemu-img: abort when full_backing_filename not present block/qapi: allow best-effort query

 block/qapi.c               | 18 +++++++++++-------
 qemu-img.c                 |  5 ++++-
 tests/qemu-iotests/043.out |  2 ++
 tests/qemu-iotests/110.out |  5 ++++-
 4 files changed, 21 insertions(+), 9 deletions(-)