Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 128729
b: refs/heads/master
c: 9b3f68b
h: refs/heads/master
i:
  128727: 7088a15
v: v3
  • Loading branch information
Chris Mason committed Sep 25, 2008
1 parent 3f08eeb commit c5ac26e
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 8 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 7b13b7b119c932a5eca486db4113f4c1fe3b97a8
refs/heads/master: 9b3f68b90674419add8be1c0aa740dcdf04f44cc
68 changes: 61 additions & 7 deletions trunk/fs/btrfs/volumes.c
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,27 @@ int btrfs_add_system_chunk(struct btrfs_trans_handle *trans,
return 0;
}

static u64 div_factor(u64 num, int factor)
{
if (factor == 10)
return num;
num *= factor;
do_div(num, 10);
return num;
}

static u64 chunk_bytes_by_type(u64 type, u64 calc_size, int num_stripes,
int sub_stripes)
{
if (type & (BTRFS_BLOCK_GROUP_RAID1 | BTRFS_BLOCK_GROUP_DUP))
return calc_size;
else if (type & BTRFS_BLOCK_GROUP_RAID10)
return calc_size * (num_stripes / sub_stripes);
else
return calc_size * num_stripes;
}


int btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
struct btrfs_root *extent_root, u64 *start,
u64 *num_bytes, u64 type)
Expand All @@ -643,11 +664,14 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
struct extent_map_tree *em_tree;
struct map_lookup *map;
struct extent_map *em;
int min_chunk_size = 8 * 1024 * 1024;
u64 physical;
u64 calc_size = 1024 * 1024 * 1024;
u64 min_free = calc_size;
u64 max_chunk_size = calc_size;
u64 min_free;
u64 avail;
u64 max_avail = 0;
u64 percent_max;
int num_stripes = 1;
int sub_stripes = 0;
int looped = 0;
Expand All @@ -666,6 +690,8 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
if (type & (BTRFS_BLOCK_GROUP_RAID1)) {
num_stripes = min_t(u64, 2,
btrfs_super_num_devices(&info->super_copy));
if (num_stripes < 2)
return -ENOSPC;
}
if (type & (BTRFS_BLOCK_GROUP_RAID10)) {
num_stripes = btrfs_super_num_devices(&info->super_copy);
Expand All @@ -674,13 +700,45 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
num_stripes &= ~(u32)1;
sub_stripes = 2;
}

if (type & BTRFS_BLOCK_GROUP_DATA) {
max_chunk_size = 10 * calc_size;
min_chunk_size = 256 * 1024 * 1024;
} else if (type & BTRFS_BLOCK_GROUP_METADATA) {
max_chunk_size = 4 * calc_size;
min_chunk_size = 64 * 1024 * 1024;
} else {
min_chunk_size = 32 * 1024 * 1024;
}

/* we don't want a chunk larger than 10% of the FS */
percent_max = div_factor(btrfs_super_total_bytes(&info->super_copy), 1);
max_chunk_size = min(percent_max, max_chunk_size);

if (calc_size * num_stripes > max_chunk_size) {
calc_size = max_chunk_size;
do_div(calc_size, num_stripes);
do_div(calc_size, stripe_len);
calc_size *= stripe_len;
}
/* we don't want tiny stripes */
*num_bytes = chunk_bytes_by_type(type, calc_size,
num_stripes, sub_stripes);
calc_size = max_t(u64, chunk_bytes_by_type(type, min_chunk_size,
num_stripes, sub_stripes), calc_size);

again:
do_div(calc_size, stripe_len);
calc_size *= stripe_len;

INIT_LIST_HEAD(&private_devs);
cur = dev_list->next;
index = 0;

if (type & BTRFS_BLOCK_GROUP_DUP)
min_free = calc_size * 2;
else
min_free = calc_size;

/* build a private list of devices we will allocate from */
while(index < num_stripes) {
Expand Down Expand Up @@ -727,13 +785,9 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
}

stripes = &chunk->stripe;
*num_bytes = chunk_bytes_by_type(type, calc_size,
num_stripes, sub_stripes);

if (type & (BTRFS_BLOCK_GROUP_RAID1 | BTRFS_BLOCK_GROUP_DUP))
*num_bytes = calc_size;
else if (type & BTRFS_BLOCK_GROUP_RAID10)
*num_bytes = calc_size * (num_stripes / sub_stripes);
else
*num_bytes = calc_size * num_stripes;

index = 0;
printk("new chunk type %Lu start %Lu size %Lu\n", type, key.offset, *num_bytes);
Expand Down

0 comments on commit c5ac26e

Please sign in to comment.