I've been working on a slightly cursed (?) side project to try and tie together Stratis and topolvm, and I've hit a bit of a strange issue. I need some way to figure out "how much space is available in the pool" that *is not reserved by a filesystem size limit*, i.e. I want to find `total pool size - size limits of all filesystems - space used by metadata.`
But how much space is used by the metadata? Originally, my algorithm was roughly:
reserved_filesystem_space = sum(for each filesystem -> filesystem.size_limit - filesystem.used)
pool_space_remaining = pool_space_total - pool_space_used - reserved_filesystem_space
The idea here is that the pool already tells me how much space is actually in use, so I just need to add on the difference between that and the size limits. (Or to view it differently, the space used by metadata is the total used space - the space used by the filesystems.) This worked...until I tested with snapshots, at which point I realized that the pool space property being physical space means that it doesn't count copy-on-write data, which I do actually want to count for this use case!
After some thinking, I realized that on stratis 3.7, I could get *the available pool size excluding metadata* from the metadata itself, summing thin_data_dev. Then, I can calculate my space remaining by summing all the size limits and subtracting it from the total summed thin_data_dev.
My question is...is this roughly correct? It seems to make intuitive sense to just subtract the limits from the size of the thin data device, but I'm not confident that the thin data device is what I'm actually looking for.