Btrfs: fix inaccurate available space on raid0 profile
When we use raid0 as the data profile, df command may show us a very inaccurate value of the available space, which may be much less than the real one. It may make the users puzzled. Fix it by changing the calculation of the available space, and making it be more similar to a fake chunk allocation. Signed-off-by: Miao Xie <miaox@cn.fujitsu.com> Signed-off-by: Chris Mason <chris.mason@oracle.com>
This commit is contained in:
Родитель
3642320e07
Коммит
39fb26c398
|
@ -1079,7 +1079,7 @@ static int btrfs_calc_avail_data_space(struct btrfs_root *root, u64 *free_bytes)
|
||||||
u64 avail_space;
|
u64 avail_space;
|
||||||
u64 used_space;
|
u64 used_space;
|
||||||
u64 min_stripe_size;
|
u64 min_stripe_size;
|
||||||
int min_stripes = 1;
|
int min_stripes = 1, num_stripes = 1;
|
||||||
int i = 0, nr_devices;
|
int i = 0, nr_devices;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
@ -1093,12 +1093,16 @@ static int btrfs_calc_avail_data_space(struct btrfs_root *root, u64 *free_bytes)
|
||||||
|
|
||||||
/* calc min stripe number for data space alloction */
|
/* calc min stripe number for data space alloction */
|
||||||
type = btrfs_get_alloc_profile(root, 1);
|
type = btrfs_get_alloc_profile(root, 1);
|
||||||
if (type & BTRFS_BLOCK_GROUP_RAID0)
|
if (type & BTRFS_BLOCK_GROUP_RAID0) {
|
||||||
min_stripes = 2;
|
min_stripes = 2;
|
||||||
else if (type & BTRFS_BLOCK_GROUP_RAID1)
|
num_stripes = nr_devices;
|
||||||
|
} else if (type & BTRFS_BLOCK_GROUP_RAID1) {
|
||||||
min_stripes = 2;
|
min_stripes = 2;
|
||||||
else if (type & BTRFS_BLOCK_GROUP_RAID10)
|
num_stripes = 2;
|
||||||
|
} else if (type & BTRFS_BLOCK_GROUP_RAID10) {
|
||||||
min_stripes = 4;
|
min_stripes = 4;
|
||||||
|
num_stripes = 4;
|
||||||
|
}
|
||||||
|
|
||||||
if (type & BTRFS_BLOCK_GROUP_DUP)
|
if (type & BTRFS_BLOCK_GROUP_DUP)
|
||||||
min_stripe_size = 2 * BTRFS_STRIPE_LEN;
|
min_stripe_size = 2 * BTRFS_STRIPE_LEN;
|
||||||
|
@ -1167,13 +1171,16 @@ static int btrfs_calc_avail_data_space(struct btrfs_root *root, u64 *free_bytes)
|
||||||
i = nr_devices - 1;
|
i = nr_devices - 1;
|
||||||
avail_space = 0;
|
avail_space = 0;
|
||||||
while (nr_devices >= min_stripes) {
|
while (nr_devices >= min_stripes) {
|
||||||
|
if (num_stripes > nr_devices)
|
||||||
|
num_stripes = nr_devices;
|
||||||
|
|
||||||
if (devices_info[i].max_avail >= min_stripe_size) {
|
if (devices_info[i].max_avail >= min_stripe_size) {
|
||||||
int j;
|
int j;
|
||||||
u64 alloc_size;
|
u64 alloc_size;
|
||||||
|
|
||||||
avail_space += devices_info[i].max_avail * min_stripes;
|
avail_space += devices_info[i].max_avail * num_stripes;
|
||||||
alloc_size = devices_info[i].max_avail;
|
alloc_size = devices_info[i].max_avail;
|
||||||
for (j = i + 1 - min_stripes; j <= i; j++)
|
for (j = i + 1 - num_stripes; j <= i; j++)
|
||||||
devices_info[j].max_avail -= alloc_size;
|
devices_info[j].max_avail -= alloc_size;
|
||||||
}
|
}
|
||||||
i--;
|
i--;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче