Note: This is technically the first part of my active mirror followup. But just very technically. I noticed that that followup started to consist of two parts, namely (A) fix filtery things in the block layer, and (B) fix active mirror. So I decided to split it. This is part A. Part B is “mirror: Mainly coroutine refinements”.
When we introduced filters, we did it a bit casually. Sure, we talked a lot about them before, but that was mostly discussion about where implicit filters should be added to the graph (note that we currently only have two implicit filters, those being mirror and commit). But in the end, we really just designated some drivers filters (Quorum, blkdebug, etc.) and added some specifically (throttle, COR), without really looking through the block layer to see where issues might occur. It turns out vast areas of the block layer just don’t know about filters and cannot really handle them. Many cases will work in practice, in others, well, too bad, you cannot use some feature because some part deep inside the block layer looks at your filters and thinks they are format nodes. This series sets out to correct a bit of that. I lost my head many times and I’m sure this series is incomplete in many ways, but it really doesn’t do any good if it sits on my disk any longer, it needs to go out now. The most important patches of this series are patches 3 and 4. These introduce functions to encapsulate bs->backing and bs->file accesses. Because sometimes, bs->backing means COW, sometimes it means filtered node. And sometimes, bs->file means metadata storage, and sometimes it means filtered node. With this functions, it’s always clear what the caller wants, and it will always get what it wants. Besides that, patch 3 introduces functions to skip filters which may be used by parts of the block layer that just don’t care about them. Secondly, the restraints put on mirror’s @replaces parameter are revisited and fixed. Thirdly, BDS.backing_file is changed to be constant. I don’t quite know why we modify it whenever we change a BDS’s backing file, but that’s definitely not quite right. This fixes things like being able to perform a commit on a file (using relative filenames) in a directory that’s not qemu’s CWD. Finally, a number of tests are added. There are probably many things that are worthy of discussion, of which only some come to my head, e.g.: - In which cases do we want to skip filters, in which cases do we want to skip implicit filters? My approach was to basically never skip explicitly added filters, except when it’s about finding a file in some tree (e.g. in a backing chain). Maybe there are cases where you think we should skip even explicitly added filters. - I made interesting decisions like “When you mirror from a node, we should indeed mirror from that node, but when replacing it, we should skip leave all implicit filters on top intact.” You may disagree with that. (My reasoning here is that users aren’t supposed to know about implicit filters, and therefore, they should not intend to remove them. Also, mirror accepts only root nodes as the source, so you cannot really specify the node below the implicit filters. But you can use @replaces to drop the implicit filters, if you know they are there.) - New in v3: bdrv_query_bds_stats() is changed: “parent” now means storage, “backing” means COW. This is what makes sense, although it breaks compatibility; but only for filters that use bs->backing for the filtered child (i.e. mirror top and commit top). The alternatives would be: - Leave everything as it is. But this means that whenever you add another filter (throttle or COR), the backing chain is still broken because they use bs->file for their filtered child. So this is not really an option. - Present all filtered children under “backing”. We would need to present them under “parent” as well, though, if they are referenced as bs->file, otherwise this too would break compatibility and would not be any better. This seems rather broken because we may present the same node twice (once as “parent”, once as “backing”). Well, or we decide to break compatibility here, too, but to me it seems wrong to present filtered nodes under “backing” but not under “parent”. So I went for the solution that makes the most sense to me. v3: - General (especially all of those with conflicts not explicitly mentioned here): - Fixed comments to match the now-required /*$...$*/ syntax - Rebasing - Patch 3: - Continue to refer to ->backing in bdrv_open_backing_file() instead of shoehorning in a single bdrv_filtered_cow_child() - Similar for bdrv_backing_overridden(): This is about bs->backing, COW or not - Use bdrv_skip_implicit_filters() in bdrv_drop_intermediate() instead of the old inlined loop which doesn’t work for filters that ue bs->file - No need to force filter drivers to use the wrapper functions. They know perfectly well whether they use bs->backing or bs->file and they can continue to do so. - Use something like an inlined version of bdrv_storage_bs() in bdrv_refresh_limits() before we have the next patch to use the real version - Pretend filter chains are the same as backing chains in bdrv_block_device_info() as to not break backing chains in query results - I hope nobody uses filters during qemu-img convert, but if they do, there now is a hunk that makes it use bdrv_backing_chain_next() to skip them - qemu-img map should skip all filters, not just implicit ones - Some minor things - Patch 4: Rebase fixes (and a spell fix in the commit message) - Patch 5: Added; was suggested by Eric - Patch 7: Fixed for qed git-backport-diff against v2: Key: [----] : patches are identical [####] : number of functional differences between upstream/downstream patch [down] : patch is downstream-only The flags [FC] indicate (F)unctional and (C)ontextual differences, respectively 001/12:[----] [-C] 'block: Mark commit and mirror as filter drivers' 002/12:[----] [--] 'blockdev: Check @replaces in blockdev_mirror_common' 003/12:[0193] [FC] 'block: Filtered children access functions' 004/12:[0020] [FC] 'block: Storage child access function' 005/12:[down] 'block: Inline bdrv_co_block_status_from_*()' 006/12:[0030] [FC] 'block: Fix check_to_replace_node()' 007/12:[0014] [FC] 'iotests: Add tests for mirror @replaces loops' 008/12:[0035] [FC] 'block: Leave BDS.backing_file constant' 009/12:[0008] [FC] 'iotests: Add filter commit test cases' 010/12:[0008] [FC] 'iotests: Add filter mirror test cases' 011/12:[----] [--] 'iotests: Add test for commit in sub directory' 012/12:[0008] [FC] 'iotests: Test committing to overridden backing' Max Reitz (12): block: Mark commit and mirror as filter drivers blockdev: Check @replaces in blockdev_mirror_common block: Filtered children access functions block: Storage child access function block: Inline bdrv_co_block_status_from_*() block: Fix check_to_replace_node() iotests: Add tests for mirror @replaces loops block: Leave BDS.backing_file constant iotests: Add filter commit test cases iotests: Add filter mirror test cases iotests: Add test for commit in sub directory iotests: Test committing to overridden backing qapi/block-core.json | 4 + include/block/block.h | 2 + include/block/block_int.h | 80 +++++--- block.c | 354 ++++++++++++++++++++++++++++----- block/backup.c | 8 +- block/blkdebug.c | 7 +- block/blklogwrites.c | 1 - block/block-backend.c | 16 +- block/commit.c | 36 ++-- block/copy-on-read.c | 2 - block/io.c | 102 +++++----- block/mirror.c | 24 ++- block/qapi.c | 42 ++-- block/snapshot.c | 40 ++-- block/stream.c | 13 +- block/throttle.c | 1 - blockdev.c | 173 ++++++++++++---- migration/block-dirty-bitmap.c | 4 +- nbd/server.c | 6 +- qemu-img.c | 41 ++-- tests/qemu-iotests/020 | 36 ++++ tests/qemu-iotests/020.out | 10 + tests/qemu-iotests/040 | 191 ++++++++++++++++++ tests/qemu-iotests/040.out | 4 +- tests/qemu-iotests/041 | 270 ++++++++++++++++++++++++- tests/qemu-iotests/041.out | 4 +- tests/qemu-iotests/184.out | 7 +- tests/qemu-iotests/191.out | 1 - tests/qemu-iotests/204.out | 1 + tests/qemu-iotests/228 | 6 +- tests/qemu-iotests/228.out | 6 +- 31 files changed, 1203 insertions(+), 289 deletions(-) -- 2.20.1