Skip to content

Commit

Permalink
Add helper to calc dev extent length for chunk
Browse files Browse the repository at this point in the history
chunk.length is the amount of real user data we can store in this chunk.

When we want to know how much raw disk space is occupied by a btrfs
chunk, we need to know how many device extents are used for it, and how
big they are (they are all the same size).

The amount can be found by looking at the amount of "stripe" objects
which are stored inside the "chunk" metadata object. The size of them is
not stored in there, but can be calculated using some simple rules, so
that we don't have to go and look up dev extent objects from another
tree.
  • Loading branch information
knorrie committed Jul 23, 2018
1 parent 38a9230 commit 6376962
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions btrfs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,21 @@ def block_group_profile_str(flags):
return block_group_flags_str(flags & BLOCK_GROUP_PROFILE_MASK)


_chunk_to_dev_extent_length_fnmap = {
BLOCK_GROUP_SINGLE: lambda chunk: chunk.length,
BLOCK_GROUP_RAID0: lambda chunk: chunk.length // len(chunk.stripes),
BLOCK_GROUP_RAID1: lambda chunk: chunk.length,
BLOCK_GROUP_DUP: lambda chunk: chunk.length,
BLOCK_GROUP_RAID10: lambda chunk: chunk.length // (len(chunk.stripes) // 2),
BLOCK_GROUP_RAID5: lambda chunk: chunk.length // len(chunk.stripes - 1),
BLOCK_GROUP_RAID6: lambda chunk: chunk.length // len(chunk.stripes - 2),
}


def chunk_to_dev_extent_length(chunk):
return _chunk_to_dev_extent_length_fnmap[chunk.type & BLOCK_GROUP_PROFILE_MASK](chunk)


_block_group_profile_ratio_map = {
BLOCK_GROUP_SINGLE: 1,
BLOCK_GROUP_RAID0: 1,
Expand Down

0 comments on commit 6376962

Please sign in to comment.