Bug 1975688
| Summary: | qemu-nbd block status reports allocated zero area in qcow2 image as a hole | ||
|---|---|---|---|
| Product: | Red Hat Enterprise Linux 9 | Reporter: | zixchen |
| Component: | qemu-kvm | Assignee: | Eric Blake <eblake> |
| qemu-kvm sub component: | NBD | QA Contact: | Tingting Mao <timao> |
| Status: | CLOSED CURRENTRELEASE | Docs Contact: | |
| Severity: | high | ||
| Priority: | high | CC: | coli, eblake, jinzhao, juzhang, kkiwi, nsoffer, virt-maint, xuwei |
| Version: | 9.0 | Keywords: | Triaged |
| Target Milestone: | beta | Flags: | pm-rhel:
mirror+
|
| Target Release: | --- | ||
| Hardware: | x86_64 | ||
| OS: | Linux | ||
| Whiteboard: | |||
| Fixed In Version: | Doc Type: | If docs needed, set a value | |
| Doc Text: | Story Points: | --- | |
| Clone Of: | 1968693 | Environment: | |
| Last Closed: | 2021-10-15 06:39:03 UTC | Type: | Bug |
| Regression: | --- | Mount Type: | --- |
| Documentation: | --- | CRM: | |
| Verified Versions: | Category: | --- | |
| oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |
| Cloudforms Team: | --- | Target Upstream Version: | |
| Embargoed: | |||
| Bug Depends On: | 1968693 | ||
| Bug Blocks: | |||
|
Description
zixchen
2021-06-24 08:16:08 UTC
Further upstream discussion decided that: - adding a 'qemu:joint-allocation' metacontext NBD extension was not necessary. https://lists.gnu.org/archive/html/qemu-devel/2021-06/msg02787.html - RHV is planning to consume the already-existing qemu-nbd 'qemu:allocation-depth' metacontext correctly. - 'qemu-img map --output=json' was enhanced to show better output: a275b452c65 qemu-img: Reword 'qemu-img map --output=json' docs 8417e1378ca qemu-img: Make unallocated part of backing chain obvious in map Upstream qemu 6.1 contains both those patches, therefore RHEL 9 picks them up by rebase. Hi Eric,
After tried again in latest qemu packages, still hit the issue. Could you please help to check?
Thanks.
Tested with:
qemu-kvm-6.1.0-4.el9
kernel-5.14.0-0.rc7.54.el9.x86_64
Steps:
1. Create an image with a backing file:
# qemu-img create base.raw $((4*64*1024))
# qemu-img create -f qcow2 -b base.raw -F raw top.qcow2
2. Write data to the first 3 cluster in the base image:
# qemu-io -f raw -c "write -P 65 0 64k" base.raw
# qemu-io -f raw -c "write -P 66 64k 64k" base.raw
# qemu-io -f raw -c "write -P 67 128k 64k" base.raw
3. Write data to the second cluster of the top image, hiding the second cluster in the backing file:
# qemu-io -f qcow2 -c "write -P 69 64k 64k" top.qcow2
4. Write zeroes to the third cluster of the top imge, hiding the third cluster in the backing file:
# qemu-io -f qcow2 -c "write -z 128k 64k" top.qcow2
5. Query the image via qemu-nbd
# qemu-nbd -r -t -f qcow2 top.qcow2 &
# qemu-img map --output json nbd://localhost
[{ "start": 0, "length": 131072, "depth": 0, "present": true, "zero": false, "data": true, "offset": 0},
{ "start": 131072, "length": 131072, "depth": 0, "present": true, "zero": true, "data": false, "offset": 131072}]
# nbdinfo --map nbd://localhost
0 131072 0 data
131072 131072 3 hole,zero
Note: from what I learnt from the bug, the expected result should be like:
# nbdinfo --map nbd://localhost
0 131072 0 allocated
131072 65536 2 zero
196608 65536 3 hole,zero
# qemu-img map --output=json nbd://localhost
[
{ "start": 0, "length": 131072, "zero": false, "hole": false},
{ "start": 131072, "length": 65536, "zero": true, "hole": false}
{ "start": 196608, "length": 65536, "zero": true, "hole": true}
]
(In reply to Tingting Mao from comment #2) > Hi Eric, > > After tried again in latest qemu packages, still hit the issue. Could you > please help to check? > > Thanks. > > > Tested with: > qemu-kvm-6.1.0-4.el9 > kernel-5.14.0-0.rc7.54.el9.x86_64 > > > Steps: > 1. Create an image with a backing file: > # qemu-img create base.raw $((4*64*1024)) > # qemu-img create -f qcow2 -b base.raw -F raw top.qcow2 > > 2. Write data to the first 3 cluster in the base image: > # qemu-io -f raw -c "write -P 65 0 64k" base.raw > # qemu-io -f raw -c "write -P 66 64k 64k" base.raw > # qemu-io -f raw -c "write -P 67 128k 64k" base.raw > > 3. Write data to the second cluster of the top image, hiding the second > cluster in the backing file: > # qemu-io -f qcow2 -c "write -P 69 64k 64k" top.qcow2 > > 4. Write zeroes to the third cluster of the top imge, hiding the third > cluster in the backing file: > # qemu-io -f qcow2 -c "write -z 128k 64k" top.qcow2 Good so far. > > 5. Query the image via qemu-nbd > # qemu-nbd -r -t -f qcow2 top.qcow2 & This step fails to export the allocation depth information. In order to faithfully recreate the backing chain, you want to also use -A, as in: qemu-nbd -r -t -A -f qcow2 top.qcow2 & > # qemu-img map --output json nbd://localhost > [{ "start": 0, "length": 131072, "depth": 0, "present": true, "zero": false, > "data": true, "offset": 0}, > { "start": 131072, "length": 131072, "depth": 0, "present": true, "zero": > true, "data": false, "offset": 131072}] > > # nbdinfo --map nbd://localhost > 0 131072 0 data > 131072 131072 3 hole,zero This output is correct, but not the only possible answer. Remember, '--map' is shorthand for '--map=base:allocation', which only shows the basic NBD block status. When viewed over NBD, qemu cannot directly see any backing image. From the point of view of the NBD protocol, the first two clusters have data, all remaining clusters read as zero, and behave as if currently unallocated. You could also inspect the qemu allocation depth, to learn which portions of the image at the server come from which depth. With the -A added above, that would be: $ nbdinfo --map=qemu:allocation-depth nbd://localhost 0 65536 2 backing depth 2 65536 131072 1 local 196608 65536 2 backing depth 2 which correctly shows clusters 0 and 3 from the backing file, and 1 and 2 from the top.qcow2 image. > > > > Note: from what I learnt from the bug, the expected result should be like: > # nbdinfo --map nbd://localhost > 0 131072 0 allocated > 131072 65536 2 zero > 196608 65536 3 hole,zero This would also be correct, but less precise. The NBD protocol does not require the server to advertise whether a cluster is a hole (which would be how you get this information). In your particular case, it depends on whether qemu's code for inspecting top.qcow2 reports that cluster as merely reading as zero, or as also being currently unallocated. In general, the reporting of 'zero' is more important that the reporting of 'hole', and it is merely a quality-of-implementation, rather than a bug, if 'hole' is omitted where it could have been reported. But knowing where the holes are is insufficient for reconstructing a backing chain, particularly since this was one of the actual bug fixes in upstream qemu (older qemu reported an unallocated zero cluster as 'zero' only; newer qemu more precisely reports it as 'hole,zero'). And to double-check that top.qcow2 has an unallocated zero cluster (rather than an allocated cluster with actual zero contents), you can perform: $ qemu-img map --output=json -f qcow2 top.qcow2 [{ "start": 0, "length": 65536, "depth": 1, "present": true, "zero": false, "data": true, "offset": 0}, { "start": 65536, "length": 65536, "depth": 0, "present": true, "zero": false, "data": true, "offset": 327680}, { "start": 131072, "length": 65536, "depth": 0, "present": true, "zero": true, "data": false}, { "start": 196608, "length": 65536, "depth": 1, "present": true, "zero": true, "data": false, "offset": 196608}] Note how cluster 2 does not have an "offset" output, showing that the earlier 'qemu-io -c "write -z ...' command did the write zero without actually allocating the cluster in the qcow2 file. If you use "write -P 0" instead, that would force the cluster to be allocated, but then qemu loses the ability to quickly determine that the cluster reads as zero, so you get this different output (but also correct): $ qemu-io -f qcow2 -c 'w -P 0 128k 64k' top.qcow2 wrote 65536/65536 bytes at offset 131072 64 KiB, 1 ops; 00.02 sec (4.148 MiB/sec and 66.3733 ops/sec) $ qemu-img map --output=json -f qcow2 top.qcow2 [{ "start": 0, "length": 65536, "depth": 1, "present": true, "zero": false, "data": true, "offset": 0}, { "start": 65536, "length": 131072, "depth": 0, "present": true, "zero": false, "data": true, "offset": 327680}, { "start": 196608, "length": 65536, "depth": 1, "present": true, "zero": true, "data": false, "offset": 196608}] $ qemu-nbd -r -t -f qcow2 -A top.qcow2 $ nbdinfo --map nbd://localhost 0 196608 0 data 196608 65536 3 hole,zero > > # qemu-img map --output=json nbd://localhost > [ > { "start": 0, "length": 131072, "zero": false, "hole": false}, > { "start": 131072, "length": 65536, "zero": true, "hole": false} > { "start": 196608, "length": 65536, "zero": true, "hole": true} > ] The upstream change made in qemu 6.1 in response to this bug was the addition of the "present":true/false boolean when directly querying qcow2 files with 'qemu-img map'; but when querying over NBD, you will never see "present":false (because from qemu's perspective, there is no backing file on qemu's end). Reconstructing the backing chain over NBD requires the use of the qemu:allocation-depth metadata context (using -A on the qemu-nbd side, and using nbdinfo --map=qemu:allocation-depth or similar on the client side). But that behavior was already possible in upstream qemu 6.0, so there remains nothing to change downstream as a result of this bug. I added ITR=9.0.0 - since the fix went into 6.1, we could conceivably use bug 1997408 as the depends on bug and qemu-kvm-6.1.0-1.el9 as the fixed in version... We'd just need QE to set ITM to get the release+, then "if" verified with the above information just moved to VERIFIED (unless we need Mirek to add to errata in some way - that's a step I'm never quite clear if we need to do). It's clear now. Thanks a lot for Eric's info.
Exposed the image as below:
# qemu-nbd -r -t -A -f qcow2 top.qcow2 &
Dump the image info:
# nbdinfo --map=qemu:allocation-depth nbd://localhost
0 65536 2 backing depth 2
65536 131072 1 local
196608 65536 2 backing depth 2
# qemu-img map --output=json nbd://localhost
[{ "start": 0, "length": 131072, "depth": 0, "present": true, "zero": false, "data": true, "offset": 0},
{ "start": 131072, "length": 131072, "depth": 0, "present": true, "zero": true, "data": false, "offset": 131072}]
# qemu-img map --output=json -f qcow2 top.qcow2
[{ "start": 0, "length": 65536, "depth": 1, "present": true, "zero": false, "data": true, "offset": 0},
{ "start": 65536, "length": 65536, "depth": 0, "present": true, "zero": false, "data": true, "offset": 327680},
{ "start": 131072, "length": 65536, "depth": 0, "present": true, "zero": true, "data": false},
{ "start": 196608, "length": 65536, "depth": 1, "present": true, "zero": true, "data": false, "offset": 196608}]
|