query dirty areas according to bitmap via QMP or qemu-nbd
Hi,
sorry if I'm missing the obvious, but is there a way to get the dirty areas according to a dirty bitmap via QMP? I mean as something like offset + size + dirty-flag triples. In my case, the bitmap is also exported via NBD, so same question for qemu-nbd being the client.
I can get the info with "nbdinfo --map", but would like to avoid requiring a tool outside QEMU.
If it is not currently possible, would upstream be interested too in the feature, either for QMP or qemu-nbd?
Best Regards,
Fiona
Quoted 6 lines · Fiona Ebner
Hi,
sorry if I'm missing the obvious, but is there a way to get the dirty areas according to a dirty bitmap via QMP? I mean as something like offset + size + dirty-flag triples. In my case, the bitmap is also exported via NBD, so same question for qemu-nbd being the client.
Over QMP, no - that can produce a potentially large response and possible long time in computing the data, so we have never felt the need to introduce a new QMP command for that purpose. So over NBD is the preferred solution.
Quoted 3 lines
I can get the info with "nbdinfo --map", but would like to avoid requiring a tool outside QEMU.
By default, QEMU as an NBD client only reads the "base:allocation" NBD metacontext, and is not wired to read more than one NBD metacontext at once (weaker than nbdinfo's capabilities). But I have intentionally left in a hack (accessible through QMP as well as from the command line) for connecting a qemu NBD client to an alternative NBD metacontext that feeds the block status, at which point 2 bits of information from the alternative context are observable through the result of block status calls. Note that using such an NBD connection for anything OTHER than block status calls is inadvisable (qemu might incorrectly optimize reads based on its misinterpretation of those block status bits); but as long as you limit the client to block status calls, it's a great way to read out a "qemu:dirty-bitmap:..." metacontext using only a qemu NBD client connection.
git grep -l x-dirty-bitmap tests/qemu-iotests
shows several of the iotests using the backdoor in just that manner. In particular, tests/qemu-img-bitmaps gives the magic decoder ring:
| # x-dirty-bitmap is a hack for reading bitmaps; it abuses block status to | # report "data":false for portions of the bitmap which are set | IMG="driver=nbd,server.type=unix,server.path=$nbd_unix_socket" | nbd_server_start_unix_socket -r -f qcow2 \ | -B b0 -B b1 -B b2 -B b3 "$TEST_IMG" | $QEMU_IMG map --output=json --image-opts \ | "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b0" | _filter_qemu_img_map
meaning the map output includes "data":false for the dirty portions and "data":true for the unchanged portions recorded in bitmap b0 as read from the JSON map output.
Quoted 3 lines
If it is not currently possible, would upstream be interested too in the feature, either for QMP or qemu-nbd?
Improving qemu-img to get at the information without quite the hacky post-processing deciphering would indeed be a useful patch, but it has never risen to the level of enough of an itch for me to write it myself (especially since 'nbdinfo --map's output works just as well).
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
Am 26.07.24 um 17:38 schrieb Eric Blake:
Quoted 44 lines · Fiona Ebner
Quoted 6 lines
Hi,
sorry if I'm missing the obvious, but is there a way to get the dirty areas according to a dirty bitmap via QMP? I mean as something like offset + size + dirty-flag triples. In my case, the bitmap is also exported via NBD, so same question for qemu-nbd being the client.
Over QMP, no - that can produce a potentially large response and possible long time in computing the data, so we have never felt the need to introduce a new QMP command for that purpose. So over NBD is the preferred solution.
Quoted 3 lines
I can get the info with "nbdinfo --map", but would like to avoid requiring a tool outside QEMU.
By default, QEMU as an NBD client only reads the "base:allocation" NBD metacontext, and is not wired to read more than one NBD metacontext at once (weaker than nbdinfo's capabilities). But I have intentionally left in a hack (accessible through QMP as well as from the command line) for connecting a qemu NBD client to an alternative NBD metacontext that feeds the block status, at which point 2 bits of information from the alternative context are observable through the result of block status calls. Note that using such an NBD connection for anything OTHER than block status calls is inadvisable (qemu might incorrectly optimize reads based on its misinterpretation of those block status bits); but as long as you limit the client to block status calls, it's a great way to read out a "qemu:dirty-bitmap:..." metacontext using only a qemu NBD client connection.
git grep -l x-dirty-bitmap tests/qemu-iotests
shows several of the iotests using the backdoor in just that manner. In particular, tests/qemu-img-bitmaps gives the magic decoder ring:
| # x-dirty-bitmap is a hack for reading bitmaps; it abuses block status to | # report "data":false for portions of the bitmap which are set | IMG="driver=nbd,server.type=unix,server.path=$nbd_unix_socket" | nbd_server_start_unix_socket -r -f qcow2 \ | -B b0 -B b1 -B b2 -B b3 "$TEST_IMG" | $QEMU_IMG map --output=json --image-opts \ | "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b0" | _filter_qemu_img_map
Quoted 4 lines
meaning the map output includes "data":false for the dirty portions and "data":true for the unchanged portions recorded in bitmap b0 as read from the JSON map output.
Oh, I didn't think about checking the NBD block driver for such an option :) And thank you for all the explanations!
Quoted 9 lines
Quoted 3 lines
If it is not currently possible, would upstream be interested too in the feature, either for QMP or qemu-nbd?
Improving qemu-img to get at the information without quite the hacky post-processing deciphering would indeed be a useful patch, but it has never risen to the level of enough of an itch for me to write it myself (especially since 'nbdinfo --map's output works just as well).
I might just go with the above for now, but who knows if I'll get around to this some day. Three approaches that come to mind are:
1. qemu-img bitmap --dump
Other bitmap actions won't be supported in combination with NBD.
2. qemu-img map --bitmap NAME
Should it use a dedicated output format compared to the usual "map" output (both human and json) with just "start/offset + length + dirty bit" triples?
3. qemu-nbd --map CONTEXT
With only supporting one context at a time? Would be limited to NBD of course which the other two won't be.
All would require connecting to the NBD export with the correct meta context, which currently means using x_dirty_bitmap internally. So would that even be okay as part of a non-experimental command, or would it require to teach the NBD client code to deal with multiple meta contexts first?
Best Regards,
Fiona
Quoted 10 lines · Fiona Ebner
Quoted 10 lines
In particular, tests/qemu-img-bitmaps gives the magic decoder ring:
| # x-dirty-bitmap is a hack for reading bitmaps; it abuses block status to | # report "data":false for portions of the bitmap which are set | IMG="driver=nbd,server.type=unix,server.path=$nbd_unix_socket" | nbd_server_start_unix_socket -r -f qcow2 \ | -B b0 -B b1 -B b2 -B b3 "$TEST_IMG" | $QEMU_IMG map --output=json --image-opts \ | "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b0" | _filter_qemu_img_map
Quoted 7 lines
Quoted 4 lines
meaning the map output includes "data":false for the dirty portions and "data":true for the unchanged portions recorded in bitmap b0 as read from the JSON map output.
Oh, I didn't think about checking the NBD block driver for such an option :) And thank you for all the explanations!
Glad it helped. The 'x-' in the name is a giveaway that the command is not intended for public use, but for development, it makes iotests easier to write, so I see no reason to drop it.
Quoted 11 lines
Quoted 10 lines
Quoted 4 lines
If it is not currently possible, would upstream be interested too in the feature, either for QMP or qemu-nbd?
Improving qemu-img to get at the information without quite the hacky post-processing deciphering would indeed be a useful patch, but it has never risen to the level of enough of an itch for me to write it myself (especially since 'nbdinfo --map's output works just as well).
Quoted 6 lines
I might just go with the above for now, but who knows if I'll get around to this some day. Three approaches that come to mind are:
1. qemu-img bitmap --dump
Other bitmap actions won't be supported in combination with NBD.
This seems like an independently useful option (for any image with embedded bitmaps, get at the contents of that bitmap). I'm not sure how much code you could reuse from the 'qemu-img map', or if it is better to just write the iteration loops from scratch. More interesting is the observation that since NBD metacontexts are NOT visible as a local bitmap (but rather as block status information), it may still not do what you want for NBD connections.
Quoted 6 lines
2. qemu-img map --bitmap NAME
Should it use a dedicated output format compared to the usual "map" output (both human and json) with just "start/offset + length + dirty bit" triples?
Again, this would work well with local qcow2 images, but I'm not sure if it would translate nicely into NBD client images without more code in block/nbd.c to expose a metacontext as a bitmap rather than its current use of feeding block status.
Quoted 5 lines
3. qemu-nbd --map CONTEXT
With only supporting one context at a time? Would be limited to NBD of course which the other two won't be.
The other two would be hard to implement for NBD, while this one is hard to implement for qcow2. It might be less hacky than x-dirty-bitmap, but also starts duplicating efforts with what nbdinfo can already do.
Quoted 7 lines
All would require connecting to the NBD export with the correct meta context, which currently means using
x_dirty_bitmapinternally. So would that even be okay as part of a non-experimental command, or would it require to teach the NBD client code to deal with multiple meta contexts first?
If you want qemu-img to treat both qcow2 bitmaps and NBD metacontexts transparently from the same command line, we'll definitely need some work on how to make block/nbd.c expose an NBD metacontext as a bitmap (separately from how the existing x-dirty-bitmap just repurposes what is plugged into the block_status callbacks). But handling only one metacontext at a time, rather than having to do multiple in parallel, is probably okay. When you start reading more than one context at once, you have to worry about things like the two contexts returning different lengths of information ("base:allocation" might tell you about a 64k hole while qemu:dirty-bitmap:XXX tells you about a 1M dirty region - but consolidating that into contiguous extents of combined output information is tricky, especially if you don't want to re-query status you already know about one context but not the other).
Quoted 4 lines
Best Regards,
Fiona
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org