diff options
author | Ilya Dryomov <idryomov@gmail.com> | 2012-01-16 15:04:47 -0500 |
---|---|---|
committer | Ilya Dryomov <idryomov@gmail.com> | 2012-01-16 15:04:47 -0500 |
commit | 5ce5b3c0916ba3a2e34cf648b94044adc5ef9e76 (patch) | |
tree | 0cfbc8eeea18b9491275c59b8a7eed1471a2abd3 /fs/btrfs/volumes.c | |
parent | ed25e9b26f898d8d63ae4a836489f1923534143b (diff) |
Btrfs: usage filter
Select chunks that are less than X percent full.
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Diffstat (limited to 'fs/btrfs/volumes.c')
-rw-r--r-- | fs/btrfs/volumes.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 447bd422d867..b858242374db 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c | |||
@@ -2120,6 +2120,36 @@ static int chunk_profiles_filter(u64 chunk_profile, | |||
2120 | return 1; | 2120 | return 1; |
2121 | } | 2121 | } |
2122 | 2122 | ||
2123 | static u64 div_factor_fine(u64 num, int factor) | ||
2124 | { | ||
2125 | if (factor <= 0) | ||
2126 | return 0; | ||
2127 | if (factor >= 100) | ||
2128 | return num; | ||
2129 | |||
2130 | num *= factor; | ||
2131 | do_div(num, 100); | ||
2132 | return num; | ||
2133 | } | ||
2134 | |||
2135 | static int chunk_usage_filter(struct btrfs_fs_info *fs_info, u64 chunk_offset, | ||
2136 | struct btrfs_balance_args *bargs) | ||
2137 | { | ||
2138 | struct btrfs_block_group_cache *cache; | ||
2139 | u64 chunk_used, user_thresh; | ||
2140 | int ret = 1; | ||
2141 | |||
2142 | cache = btrfs_lookup_block_group(fs_info, chunk_offset); | ||
2143 | chunk_used = btrfs_block_group_used(&cache->item); | ||
2144 | |||
2145 | user_thresh = div_factor_fine(cache->key.offset, bargs->usage); | ||
2146 | if (chunk_used < user_thresh) | ||
2147 | ret = 0; | ||
2148 | |||
2149 | btrfs_put_block_group(cache); | ||
2150 | return ret; | ||
2151 | } | ||
2152 | |||
2123 | static int should_balance_chunk(struct btrfs_root *root, | 2153 | static int should_balance_chunk(struct btrfs_root *root, |
2124 | struct extent_buffer *leaf, | 2154 | struct extent_buffer *leaf, |
2125 | struct btrfs_chunk *chunk, u64 chunk_offset) | 2155 | struct btrfs_chunk *chunk, u64 chunk_offset) |
@@ -2147,6 +2177,12 @@ static int should_balance_chunk(struct btrfs_root *root, | |||
2147 | return 0; | 2177 | return 0; |
2148 | } | 2178 | } |
2149 | 2179 | ||
2180 | /* usage filter */ | ||
2181 | if ((bargs->flags & BTRFS_BALANCE_ARGS_USAGE) && | ||
2182 | chunk_usage_filter(bctl->fs_info, chunk_offset, bargs)) { | ||
2183 | return 0; | ||
2184 | } | ||
2185 | |||
2150 | return 1; | 2186 | return 1; |
2151 | } | 2187 | } |
2152 | 2188 | ||