Closed arvidjaar closed 4 years ago
Thanks for the report.
The way this space calculator works is a little bit naughty. By constructing some fake replacements for the official Chunk, Stripe etc classes, we fool the usage report module and have it believe it's looking at an actual filesystem. The input in those fake objects is rather simple, and not completely correct. (A 1 byte chunk etc...) This is fragile, because FakeChunk has num_stripes 1 and then RAID5 subtracts the amount of parity, then it's 0 and BOOM. Funny enough, raid6 makes it end up as -1.
I just looked back at my bash history, grepping for all the options I ever used while writing this, and I see a lot of raid6, raid1 and other things, but no raid5. Great.
I guess starting to add proper tests will full code coverage and testing a lot of inputs on scripts is not a luxury at this point. I might start doing that during this year, but I'll first continue on the turorial.
Anyway, this can be quick fixed by just putting any number >=3 in that place, but it doesn't feel right, because this type of bug will appear in the future again.
The other way to fix it, is to have the usage report system accept some extra options, like forcibly setting target profiles (this is why the fake chunk exists, to have it detect target profile).
I think I have an acceptable fix here now, that adds providing data_metadata_ratio (whoa, another bug, that -r didn't have any effect at all?) and target profiles for the simulation. I'll clean up and push it tomorrow. It removed all FakeStuff except for the FakeFileSystem which needs to have FakeDevItem of the right sizes.
Fun fact is that this also makes it possible to point the usage code to a real running filesystem and then tell it to predict what would happen when converting it to another profile (like, if it would be possible at all).
I pushed something to develop branch. Please try it. :)
15 1T 2T 3T
Error: When using mixed groups, metadata and data profile need to be identical.
bor@bor-Latitude-E5450:~/src/python-btrfs$ ./bin/btrfs-space-calculator -m raid5 -d raid5 -M -r 15 1T 2T 3T
Traceback (most recent call last):
File "./bin/btrfs-space-calculator", line 167, in <module>
main()
File "./bin/btrfs-space-calculator", line 137, in main
target_profile_mixed=metadata_profile,
File "/home/bor/src/python-btrfs/bin/btrfs/fs_usage.py", line 559, in __init__
self._simulate_chunk_allocations(device_sizes)
File "/home/bor/src/python-btrfs/bin/btrfs/fs_usage.py", line 735, in _simulate_chunk_allocations
chunk_size = self._alloc_chunk(_sizes, flags)
File "/home/bor/src/python-btrfs/bin/btrfs/fs_usage.py", line 674, in _alloc_chunk
raise ValueError("Only DATA and METADATA supported here")
ValueError: Only DATA and METADATA supported here
bor@bor-Latitude-E5450:~/src/python-btrfs$ git describe
v11-6-g0e7a393
bor@bor-Latitude-E5450:~/src/python-btrfs$
Yes, this clearly needs proper tests that try all combinations of input.
FYI, because this is just too ugly to be true, I included it in an unblock request for Debian Buster: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=925306
Fingers crossed! :)
By the way: the fix for Buster on top of v11 is 2 lines, not the >120 lines future proof change that's in develop branch.
It does not matter whether I use
raid5
for data or metadata. Other profiles seem to work after quick testing.