2014-02-13 19:19:01 +00:00
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public
|
|
|
|
* License v2 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 021110-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <errno.h>
|
2014-02-13 19:19:50 +00:00
|
|
|
#include <stdarg.h>
|
2014-12-17 17:11:58 +00:00
|
|
|
#include <getopt.h>
|
2014-02-13 19:19:01 +00:00
|
|
|
|
|
|
|
#include "utils.h"
|
|
|
|
#include "kerncompat.h"
|
|
|
|
#include "ctree.h"
|
2014-02-13 19:19:50 +00:00
|
|
|
#include "string-table.h"
|
2015-04-17 16:29:38 +00:00
|
|
|
#include "cmds-fi-usage.h"
|
2014-02-13 19:19:01 +00:00
|
|
|
#include "commands.h"
|
|
|
|
|
|
|
|
#include "version.h"
|
2017-01-25 15:35:00 +00:00
|
|
|
#include "help.h"
|
2014-02-13 19:19:01 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Add the chunk info to the chunk_info list
|
|
|
|
*/
|
|
|
|
static int add_info_to_list(struct chunk_info **info_ptr,
|
|
|
|
int *info_count,
|
|
|
|
struct btrfs_chunk *chunk)
|
|
|
|
{
|
|
|
|
|
|
|
|
u64 type = btrfs_stack_chunk_type(chunk);
|
|
|
|
u64 size = btrfs_stack_chunk_length(chunk);
|
|
|
|
int num_stripes = btrfs_stack_chunk_num_stripes(chunk);
|
|
|
|
int j;
|
|
|
|
|
|
|
|
for (j = 0 ; j < num_stripes ; j++) {
|
|
|
|
int i;
|
2016-01-04 01:01:30 +00:00
|
|
|
struct chunk_info *p = NULL;
|
2014-02-13 19:19:01 +00:00
|
|
|
struct btrfs_stripe *stripe;
|
|
|
|
u64 devid;
|
|
|
|
|
|
|
|
stripe = btrfs_stripe_nr(chunk, j);
|
|
|
|
devid = btrfs_stack_stripe_devid(stripe);
|
|
|
|
|
|
|
|
for (i = 0 ; i < *info_count ; i++)
|
|
|
|
if ((*info_ptr)[i].type == type &&
|
|
|
|
(*info_ptr)[i].devid == devid &&
|
|
|
|
(*info_ptr)[i].num_stripes == num_stripes ) {
|
|
|
|
p = (*info_ptr) + i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!p) {
|
2016-01-12 13:34:41 +00:00
|
|
|
int tmp = sizeof(struct btrfs_chunk) * (*info_count + 1);
|
|
|
|
struct chunk_info *res = realloc(*info_ptr, tmp);
|
2014-02-13 19:19:01 +00:00
|
|
|
|
|
|
|
if (!res) {
|
2014-04-19 11:12:03 +00:00
|
|
|
free(*info_ptr);
|
2016-01-11 10:01:47 +00:00
|
|
|
error("not enough memory");
|
2014-04-28 16:55:05 +00:00
|
|
|
return -ENOMEM;
|
2014-02-13 19:19:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*info_ptr = res;
|
|
|
|
p = res + *info_count;
|
|
|
|
(*info_count)++;
|
|
|
|
|
|
|
|
p->devid = devid;
|
|
|
|
p->type = type;
|
|
|
|
p->size = 0;
|
|
|
|
p->num_stripes = num_stripes;
|
|
|
|
}
|
|
|
|
|
|
|
|
p->size += size;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Helper to sort the chunk type
|
|
|
|
*/
|
|
|
|
static int cmp_chunk_block_group(u64 f1, u64 f2)
|
|
|
|
{
|
|
|
|
|
|
|
|
u64 mask;
|
|
|
|
|
|
|
|
if ((f1 & BTRFS_BLOCK_GROUP_TYPE_MASK) ==
|
|
|
|
(f2 & BTRFS_BLOCK_GROUP_TYPE_MASK))
|
|
|
|
mask = BTRFS_BLOCK_GROUP_PROFILE_MASK;
|
|
|
|
else if (f2 & BTRFS_BLOCK_GROUP_SYSTEM)
|
|
|
|
return -1;
|
|
|
|
else if (f1 & BTRFS_BLOCK_GROUP_SYSTEM)
|
|
|
|
return +1;
|
|
|
|
else
|
|
|
|
mask = BTRFS_BLOCK_GROUP_TYPE_MASK;
|
|
|
|
|
|
|
|
if ((f1 & mask) > (f2 & mask))
|
|
|
|
return +1;
|
|
|
|
else if ((f1 & mask) < (f2 & mask))
|
|
|
|
return -1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Helper to sort the chunk
|
|
|
|
*/
|
|
|
|
static int cmp_chunk_info(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
return cmp_chunk_block_group(
|
|
|
|
((struct chunk_info *)a)->type,
|
|
|
|
((struct chunk_info *)b)->type);
|
|
|
|
}
|
|
|
|
|
2014-04-25 17:39:11 +00:00
|
|
|
static int load_chunk_info(int fd, struct chunk_info **info_ptr, int *info_count)
|
2014-02-13 19:19:01 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct btrfs_ioctl_search_args args;
|
|
|
|
struct btrfs_ioctl_search_key *sk = &args.key;
|
|
|
|
struct btrfs_ioctl_search_header *sh;
|
|
|
|
unsigned long off = 0;
|
|
|
|
int i, e;
|
|
|
|
|
|
|
|
memset(&args, 0, sizeof(args));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* there may be more than one ROOT_ITEM key if there are
|
|
|
|
* snapshots pending deletion, we have to loop through
|
|
|
|
* them.
|
|
|
|
*/
|
|
|
|
sk->tree_id = BTRFS_CHUNK_TREE_OBJECTID;
|
|
|
|
|
|
|
|
sk->min_objectid = 0;
|
|
|
|
sk->max_objectid = (u64)-1;
|
|
|
|
sk->max_type = 0;
|
|
|
|
sk->min_type = (u8)-1;
|
|
|
|
sk->min_offset = 0;
|
|
|
|
sk->max_offset = (u64)-1;
|
|
|
|
sk->min_transid = 0;
|
|
|
|
sk->max_transid = (u64)-1;
|
|
|
|
sk->nr_items = 4096;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
|
|
|
|
e = errno;
|
2014-07-24 03:21:54 +00:00
|
|
|
if (e == EPERM)
|
|
|
|
return -e;
|
2014-04-24 13:21:16 +00:00
|
|
|
|
2014-02-13 19:19:01 +00:00
|
|
|
if (ret < 0) {
|
2016-01-11 10:01:47 +00:00
|
|
|
error("cannot look up chunk tree info: %s",
|
2014-02-13 19:19:01 +00:00
|
|
|
strerror(e));
|
2014-07-24 03:21:54 +00:00
|
|
|
return 1;
|
2014-02-13 19:19:01 +00:00
|
|
|
}
|
|
|
|
/* the ioctl returns the number of item it found in nr_items */
|
|
|
|
|
|
|
|
if (sk->nr_items == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
off = 0;
|
|
|
|
for (i = 0; i < sk->nr_items; i++) {
|
|
|
|
struct btrfs_chunk *item;
|
|
|
|
sh = (struct btrfs_ioctl_search_header *)(args.buf +
|
|
|
|
off);
|
|
|
|
|
|
|
|
off += sizeof(*sh);
|
|
|
|
item = (struct btrfs_chunk *)(args.buf + off);
|
|
|
|
|
2014-04-28 16:55:05 +00:00
|
|
|
ret = add_info_to_list(info_ptr, info_count, item);
|
|
|
|
if (ret) {
|
2016-01-04 01:01:30 +00:00
|
|
|
*info_ptr = NULL;
|
2014-07-24 03:21:54 +00:00
|
|
|
return 1;
|
2014-02-13 19:19:01 +00:00
|
|
|
}
|
|
|
|
|
2016-05-03 14:20:52 +00:00
|
|
|
off += btrfs_search_header_len(sh);
|
2014-02-13 19:19:01 +00:00
|
|
|
|
2016-05-03 14:20:52 +00:00
|
|
|
sk->min_objectid = btrfs_search_header_objectid(sh);
|
|
|
|
sk->min_type = btrfs_search_header_type(sh);
|
|
|
|
sk->min_offset = btrfs_search_header_offset(sh)+1;
|
2014-02-13 19:19:01 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
if (!sk->min_offset) /* overflow */
|
|
|
|
sk->min_type++;
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!sk->min_type)
|
|
|
|
sk->min_objectid++;
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!sk->min_objectid)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
qsort(*info_ptr, *info_count, sizeof(struct chunk_info),
|
|
|
|
cmp_chunk_info);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Helper to sort the struct btrfs_ioctl_space_info
|
|
|
|
*/
|
|
|
|
static int cmp_btrfs_ioctl_space_info(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
return cmp_chunk_block_group(
|
|
|
|
((struct btrfs_ioctl_space_info *)a)->flags,
|
|
|
|
((struct btrfs_ioctl_space_info *)b)->flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function load all the information about the space usage
|
|
|
|
*/
|
|
|
|
static struct btrfs_ioctl_space_args *load_space_info(int fd, char *path)
|
|
|
|
{
|
2016-01-04 01:01:30 +00:00
|
|
|
struct btrfs_ioctl_space_args *sargs = NULL, *sargs_orig = NULL;
|
2016-01-12 10:20:18 +00:00
|
|
|
int ret, count;
|
2014-02-13 19:19:01 +00:00
|
|
|
|
2014-04-24 16:37:50 +00:00
|
|
|
sargs_orig = sargs = calloc(1, sizeof(struct btrfs_ioctl_space_args));
|
2014-02-13 19:19:01 +00:00
|
|
|
if (!sargs) {
|
2016-01-11 10:01:47 +00:00
|
|
|
error("not enough memory");
|
2014-02-13 19:19:01 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
sargs->space_slots = 0;
|
|
|
|
sargs->total_spaces = 0;
|
|
|
|
|
|
|
|
ret = ioctl(fd, BTRFS_IOC_SPACE_INFO, sargs);
|
2016-01-12 12:35:50 +00:00
|
|
|
if (ret < 0) {
|
2016-01-12 10:20:18 +00:00
|
|
|
error("cannot get space info on '%s': %s", path,
|
|
|
|
strerror(errno));
|
2014-02-13 19:19:01 +00:00
|
|
|
free(sargs);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (!sargs->total_spaces) {
|
|
|
|
free(sargs);
|
|
|
|
printf("No chunks found\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
count = sargs->total_spaces;
|
|
|
|
|
|
|
|
sargs = realloc(sargs, sizeof(struct btrfs_ioctl_space_args) +
|
|
|
|
(count * sizeof(struct btrfs_ioctl_space_info)));
|
|
|
|
if (!sargs) {
|
|
|
|
free(sargs_orig);
|
2016-01-11 10:01:47 +00:00
|
|
|
error("not enough memory");
|
2014-02-13 19:19:01 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
sargs->space_slots = count;
|
|
|
|
sargs->total_spaces = 0;
|
|
|
|
|
|
|
|
ret = ioctl(fd, BTRFS_IOC_SPACE_INFO, sargs);
|
2016-01-12 12:35:50 +00:00
|
|
|
if (ret < 0) {
|
2016-01-11 10:01:47 +00:00
|
|
|
error("cannot get space info with %u slots: %s",
|
2016-01-12 10:20:18 +00:00
|
|
|
count, strerror(errno));
|
2014-02-13 19:19:01 +00:00
|
|
|
free(sargs);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
qsort(&(sargs->spaces), count, sizeof(struct btrfs_ioctl_space_info),
|
|
|
|
cmp_btrfs_ioctl_space_info);
|
|
|
|
|
|
|
|
return sargs;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2016-05-11 23:50:36 +00:00
|
|
|
* This function computes the space occupied by a *single* RAID5/RAID6 chunk.
|
2014-02-13 19:19:01 +00:00
|
|
|
* The computation is performed on the basis of the number of stripes
|
2014-04-23 17:00:22 +00:00
|
|
|
* which compose the chunk, which could be different from the number of devices
|
2014-02-13 19:19:01 +00:00
|
|
|
* if a disk is added later.
|
|
|
|
*/
|
2017-02-09 16:42:02 +00:00
|
|
|
static void get_raid56_used(struct chunk_info *chunks, int chunkcount,
|
2014-04-25 17:39:11 +00:00
|
|
|
u64 *raid5_used, u64 *raid6_used)
|
2014-02-13 19:19:01 +00:00
|
|
|
{
|
2014-07-24 03:21:52 +00:00
|
|
|
struct chunk_info *info_ptr = chunks;
|
2014-04-25 17:39:11 +00:00
|
|
|
*raid5_used = 0;
|
|
|
|
*raid6_used = 0;
|
|
|
|
|
|
|
|
while (chunkcount-- > 0) {
|
2014-07-24 03:21:52 +00:00
|
|
|
if (info_ptr->type & BTRFS_BLOCK_GROUP_RAID5)
|
|
|
|
(*raid5_used) += info_ptr->size / (info_ptr->num_stripes - 1);
|
|
|
|
if (info_ptr->type & BTRFS_BLOCK_GROUP_RAID6)
|
|
|
|
(*raid6_used) += info_ptr->size / (info_ptr->num_stripes - 2);
|
|
|
|
info_ptr++;
|
2014-02-13 19:19:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-24 03:03:05 +00:00
|
|
|
#define MIN_UNALOCATED_THRESH SZ_16M
|
2014-04-25 17:39:11 +00:00
|
|
|
static int print_filesystem_usage_overall(int fd, struct chunk_info *chunkinfo,
|
|
|
|
int chunkcount, struct device_info *devinfo, int devcount,
|
2014-12-18 13:52:36 +00:00
|
|
|
char *path, unsigned unit_mode)
|
2014-02-13 19:19:01 +00:00
|
|
|
{
|
2016-01-04 01:01:30 +00:00
|
|
|
struct btrfs_ioctl_space_args *sargs = NULL;
|
2014-02-13 19:19:01 +00:00
|
|
|
int i;
|
|
|
|
int ret = 0;
|
btrfs-progs: rework calculations of fi usage
This patch reworks the basic calculations of 'fi usage'. It does not address
all problems but should make the code more prepared to do so.
The original code tries to estimate the free space that could lead to negative
numbers for some raid profiles:
Data, RAID1: total=147.00GiB, used=141.92GiB
System, RAID1: total=32.00MiB, used=36.00KiB
Metadata, RAID1: total=2.00GiB, used=1.17GiB
GlobalReserve, single: total=404.00MiB, used=0.00B
Overall:
Device size: 279.46GiB
Device allocated: 298.06GiB
Device unallocated: 16.00EiB
Used: 286.18GiB
Free (estimated): 8.00EiB (min: 8.00EiB)
Data ratio: 2.00
Metadata ratio: 2.00
Global reserve: 404.00MiB (used: 0.00B)
Eg. "Device size" - "Device allocated" = negative number or a very large
positive, hence the EiB values.
There are logical and raw numbers multiplied by ratios mixed together,
so the new code makes it explicit which kind is being used. The data and
metadata ratios are calculated separately.
Output after this patch will look like:
Overall:
Device size: 558.92GiB
Device allocated: 298.06GiB
Device unallocated: 260.86GiB
Used: 286.18GiB
Free (estimated): 135.51GiB (min: 135.51GiB)
Data ratio: 2.00
Metadata ratio: 2.00
Global reserve: 404.00MiB (used: 0.00B)
Data,RAID1: Size:147.00GiB, Used:141.92GiB
/dev/sdc 147.00GiB
/dev/sdd 147.00GiB
Metadata,RAID1: Size:2.00GiB, Used:1.17GiB
/dev/sdc 2.00GiB
/dev/sdd 2.00GiB
System,RAID1: Size:32.00MiB, Used:36.00KiB
/dev/sdc 32.00MiB
/dev/sdd 32.00MiB
Unallocated:
/dev/sdc 130.43GiB
/dev/sdd 130.43GiB
Changes:
* Device size is now the raw size, same for the following three
* Free is the logical size
* Max/min were reduced to just min
Filesystem Size Used Avail Use% Mounted on
/dev/sdc 280G 144G 141G 51% /mnt/sdc
The difference between Avail and Free is there because userspace tool does a
different guesswork than kernel.
Issues not addressed by this patch:
* RAID56 profiles are not handled
* mixed profiles are not handled
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-06-26 13:42:24 +00:00
|
|
|
int width = 10; /* default 10 for human units */
|
|
|
|
/*
|
|
|
|
* r_* prefix is for raw data
|
|
|
|
* l_* is for logical
|
|
|
|
*/
|
|
|
|
u64 r_total_size = 0; /* filesystem size, sum of device sizes */
|
|
|
|
u64 r_total_chunks = 0; /* sum of chunks sizes on disk(s) */
|
|
|
|
u64 r_total_used = 0;
|
|
|
|
u64 r_total_unused = 0;
|
2015-03-17 13:41:01 +00:00
|
|
|
u64 r_total_missing = 0; /* sum of missing devices size */
|
btrfs-progs: rework calculations of fi usage
This patch reworks the basic calculations of 'fi usage'. It does not address
all problems but should make the code more prepared to do so.
The original code tries to estimate the free space that could lead to negative
numbers for some raid profiles:
Data, RAID1: total=147.00GiB, used=141.92GiB
System, RAID1: total=32.00MiB, used=36.00KiB
Metadata, RAID1: total=2.00GiB, used=1.17GiB
GlobalReserve, single: total=404.00MiB, used=0.00B
Overall:
Device size: 279.46GiB
Device allocated: 298.06GiB
Device unallocated: 16.00EiB
Used: 286.18GiB
Free (estimated): 8.00EiB (min: 8.00EiB)
Data ratio: 2.00
Metadata ratio: 2.00
Global reserve: 404.00MiB (used: 0.00B)
Eg. "Device size" - "Device allocated" = negative number or a very large
positive, hence the EiB values.
There are logical and raw numbers multiplied by ratios mixed together,
so the new code makes it explicit which kind is being used. The data and
metadata ratios are calculated separately.
Output after this patch will look like:
Overall:
Device size: 558.92GiB
Device allocated: 298.06GiB
Device unallocated: 260.86GiB
Used: 286.18GiB
Free (estimated): 135.51GiB (min: 135.51GiB)
Data ratio: 2.00
Metadata ratio: 2.00
Global reserve: 404.00MiB (used: 0.00B)
Data,RAID1: Size:147.00GiB, Used:141.92GiB
/dev/sdc 147.00GiB
/dev/sdd 147.00GiB
Metadata,RAID1: Size:2.00GiB, Used:1.17GiB
/dev/sdc 2.00GiB
/dev/sdd 2.00GiB
System,RAID1: Size:32.00MiB, Used:36.00KiB
/dev/sdc 32.00MiB
/dev/sdd 32.00MiB
Unallocated:
/dev/sdc 130.43GiB
/dev/sdd 130.43GiB
Changes:
* Device size is now the raw size, same for the following three
* Free is the logical size
* Max/min were reduced to just min
Filesystem Size Used Avail Use% Mounted on
/dev/sdc 280G 144G 141G 51% /mnt/sdc
The difference between Avail and Free is there because userspace tool does a
different guesswork than kernel.
Issues not addressed by this patch:
* RAID56 profiles are not handled
* mixed profiles are not handled
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-06-26 13:42:24 +00:00
|
|
|
u64 r_data_used = 0;
|
|
|
|
u64 r_data_chunks = 0;
|
|
|
|
u64 l_data_chunks = 0;
|
|
|
|
u64 r_metadata_used = 0;
|
|
|
|
u64 r_metadata_chunks = 0;
|
|
|
|
u64 l_metadata_chunks = 0;
|
|
|
|
u64 r_system_used = 0;
|
|
|
|
u64 r_system_chunks = 0;
|
|
|
|
double data_ratio;
|
|
|
|
double metadata_ratio;
|
|
|
|
/* logical */
|
|
|
|
u64 raid5_used = 0;
|
|
|
|
u64 raid6_used = 0;
|
|
|
|
u64 l_global_reserve = 0;
|
|
|
|
u64 l_global_reserve_used = 0;
|
|
|
|
u64 free_estimated = 0;
|
|
|
|
u64 free_min = 0;
|
|
|
|
int max_data_ratio = 1;
|
2016-01-13 11:59:42 +00:00
|
|
|
int mixed = 0;
|
2014-02-13 19:19:01 +00:00
|
|
|
|
2014-04-28 16:55:05 +00:00
|
|
|
sargs = load_space_info(fd, path);
|
|
|
|
if (!sargs) {
|
|
|
|
ret = 1;
|
2014-02-13 19:19:01 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
btrfs-progs: rework calculations of fi usage
This patch reworks the basic calculations of 'fi usage'. It does not address
all problems but should make the code more prepared to do so.
The original code tries to estimate the free space that could lead to negative
numbers for some raid profiles:
Data, RAID1: total=147.00GiB, used=141.92GiB
System, RAID1: total=32.00MiB, used=36.00KiB
Metadata, RAID1: total=2.00GiB, used=1.17GiB
GlobalReserve, single: total=404.00MiB, used=0.00B
Overall:
Device size: 279.46GiB
Device allocated: 298.06GiB
Device unallocated: 16.00EiB
Used: 286.18GiB
Free (estimated): 8.00EiB (min: 8.00EiB)
Data ratio: 2.00
Metadata ratio: 2.00
Global reserve: 404.00MiB (used: 0.00B)
Eg. "Device size" - "Device allocated" = negative number or a very large
positive, hence the EiB values.
There are logical and raw numbers multiplied by ratios mixed together,
so the new code makes it explicit which kind is being used. The data and
metadata ratios are calculated separately.
Output after this patch will look like:
Overall:
Device size: 558.92GiB
Device allocated: 298.06GiB
Device unallocated: 260.86GiB
Used: 286.18GiB
Free (estimated): 135.51GiB (min: 135.51GiB)
Data ratio: 2.00
Metadata ratio: 2.00
Global reserve: 404.00MiB (used: 0.00B)
Data,RAID1: Size:147.00GiB, Used:141.92GiB
/dev/sdc 147.00GiB
/dev/sdd 147.00GiB
Metadata,RAID1: Size:2.00GiB, Used:1.17GiB
/dev/sdc 2.00GiB
/dev/sdd 2.00GiB
System,RAID1: Size:32.00MiB, Used:36.00KiB
/dev/sdc 32.00MiB
/dev/sdd 32.00MiB
Unallocated:
/dev/sdc 130.43GiB
/dev/sdd 130.43GiB
Changes:
* Device size is now the raw size, same for the following three
* Free is the logical size
* Max/min were reduced to just min
Filesystem Size Used Avail Use% Mounted on
/dev/sdc 280G 144G 141G 51% /mnt/sdc
The difference between Avail and Free is there because userspace tool does a
different guesswork than kernel.
Issues not addressed by this patch:
* RAID56 profiles are not handled
* mixed profiles are not handled
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-06-26 13:42:24 +00:00
|
|
|
r_total_size = 0;
|
2015-03-17 13:41:01 +00:00
|
|
|
for (i = 0; i < devcount; i++) {
|
|
|
|
r_total_size += devinfo[i].size;
|
|
|
|
if (!devinfo[i].device_size)
|
|
|
|
r_total_missing += devinfo[i].size;
|
|
|
|
}
|
btrfs-progs: rework calculations of fi usage
This patch reworks the basic calculations of 'fi usage'. It does not address
all problems but should make the code more prepared to do so.
The original code tries to estimate the free space that could lead to negative
numbers for some raid profiles:
Data, RAID1: total=147.00GiB, used=141.92GiB
System, RAID1: total=32.00MiB, used=36.00KiB
Metadata, RAID1: total=2.00GiB, used=1.17GiB
GlobalReserve, single: total=404.00MiB, used=0.00B
Overall:
Device size: 279.46GiB
Device allocated: 298.06GiB
Device unallocated: 16.00EiB
Used: 286.18GiB
Free (estimated): 8.00EiB (min: 8.00EiB)
Data ratio: 2.00
Metadata ratio: 2.00
Global reserve: 404.00MiB (used: 0.00B)
Eg. "Device size" - "Device allocated" = negative number or a very large
positive, hence the EiB values.
There are logical and raw numbers multiplied by ratios mixed together,
so the new code makes it explicit which kind is being used. The data and
metadata ratios are calculated separately.
Output after this patch will look like:
Overall:
Device size: 558.92GiB
Device allocated: 298.06GiB
Device unallocated: 260.86GiB
Used: 286.18GiB
Free (estimated): 135.51GiB (min: 135.51GiB)
Data ratio: 2.00
Metadata ratio: 2.00
Global reserve: 404.00MiB (used: 0.00B)
Data,RAID1: Size:147.00GiB, Used:141.92GiB
/dev/sdc 147.00GiB
/dev/sdd 147.00GiB
Metadata,RAID1: Size:2.00GiB, Used:1.17GiB
/dev/sdc 2.00GiB
/dev/sdd 2.00GiB
System,RAID1: Size:32.00MiB, Used:36.00KiB
/dev/sdc 32.00MiB
/dev/sdd 32.00MiB
Unallocated:
/dev/sdc 130.43GiB
/dev/sdd 130.43GiB
Changes:
* Device size is now the raw size, same for the following three
* Free is the logical size
* Max/min were reduced to just min
Filesystem Size Used Avail Use% Mounted on
/dev/sdc 280G 144G 141G 51% /mnt/sdc
The difference between Avail and Free is there because userspace tool does a
different guesswork than kernel.
Issues not addressed by this patch:
* RAID56 profiles are not handled
* mixed profiles are not handled
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-06-26 13:42:24 +00:00
|
|
|
|
|
|
|
if (r_total_size == 0) {
|
2016-01-11 10:01:47 +00:00
|
|
|
error("cannot get space info on '%s': %s",
|
btrfs-progs: rework calculations of fi usage
This patch reworks the basic calculations of 'fi usage'. It does not address
all problems but should make the code more prepared to do so.
The original code tries to estimate the free space that could lead to negative
numbers for some raid profiles:
Data, RAID1: total=147.00GiB, used=141.92GiB
System, RAID1: total=32.00MiB, used=36.00KiB
Metadata, RAID1: total=2.00GiB, used=1.17GiB
GlobalReserve, single: total=404.00MiB, used=0.00B
Overall:
Device size: 279.46GiB
Device allocated: 298.06GiB
Device unallocated: 16.00EiB
Used: 286.18GiB
Free (estimated): 8.00EiB (min: 8.00EiB)
Data ratio: 2.00
Metadata ratio: 2.00
Global reserve: 404.00MiB (used: 0.00B)
Eg. "Device size" - "Device allocated" = negative number or a very large
positive, hence the EiB values.
There are logical and raw numbers multiplied by ratios mixed together,
so the new code makes it explicit which kind is being used. The data and
metadata ratios are calculated separately.
Output after this patch will look like:
Overall:
Device size: 558.92GiB
Device allocated: 298.06GiB
Device unallocated: 260.86GiB
Used: 286.18GiB
Free (estimated): 135.51GiB (min: 135.51GiB)
Data ratio: 2.00
Metadata ratio: 2.00
Global reserve: 404.00MiB (used: 0.00B)
Data,RAID1: Size:147.00GiB, Used:141.92GiB
/dev/sdc 147.00GiB
/dev/sdd 147.00GiB
Metadata,RAID1: Size:2.00GiB, Used:1.17GiB
/dev/sdc 2.00GiB
/dev/sdd 2.00GiB
System,RAID1: Size:32.00MiB, Used:36.00KiB
/dev/sdc 32.00MiB
/dev/sdd 32.00MiB
Unallocated:
/dev/sdc 130.43GiB
/dev/sdd 130.43GiB
Changes:
* Device size is now the raw size, same for the following three
* Free is the logical size
* Max/min were reduced to just min
Filesystem Size Used Avail Use% Mounted on
/dev/sdc 280G 144G 141G 51% /mnt/sdc
The difference between Avail and Free is there because userspace tool does a
different guesswork than kernel.
Issues not addressed by this patch:
* RAID56 profiles are not handled
* mixed profiles are not handled
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-06-26 13:42:24 +00:00
|
|
|
path, strerror(errno));
|
2014-02-13 19:19:01 +00:00
|
|
|
|
2014-04-28 16:55:05 +00:00
|
|
|
ret = 1;
|
2014-02-13 19:19:01 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
2017-02-09 16:42:02 +00:00
|
|
|
get_raid56_used(chunkinfo, chunkcount, &raid5_used, &raid6_used);
|
2014-02-13 19:19:01 +00:00
|
|
|
|
|
|
|
for (i = 0; i < sargs->total_spaces; i++) {
|
btrfs-progs: rework calculations of fi usage
This patch reworks the basic calculations of 'fi usage'. It does not address
all problems but should make the code more prepared to do so.
The original code tries to estimate the free space that could lead to negative
numbers for some raid profiles:
Data, RAID1: total=147.00GiB, used=141.92GiB
System, RAID1: total=32.00MiB, used=36.00KiB
Metadata, RAID1: total=2.00GiB, used=1.17GiB
GlobalReserve, single: total=404.00MiB, used=0.00B
Overall:
Device size: 279.46GiB
Device allocated: 298.06GiB
Device unallocated: 16.00EiB
Used: 286.18GiB
Free (estimated): 8.00EiB (min: 8.00EiB)
Data ratio: 2.00
Metadata ratio: 2.00
Global reserve: 404.00MiB (used: 0.00B)
Eg. "Device size" - "Device allocated" = negative number or a very large
positive, hence the EiB values.
There are logical and raw numbers multiplied by ratios mixed together,
so the new code makes it explicit which kind is being used. The data and
metadata ratios are calculated separately.
Output after this patch will look like:
Overall:
Device size: 558.92GiB
Device allocated: 298.06GiB
Device unallocated: 260.86GiB
Used: 286.18GiB
Free (estimated): 135.51GiB (min: 135.51GiB)
Data ratio: 2.00
Metadata ratio: 2.00
Global reserve: 404.00MiB (used: 0.00B)
Data,RAID1: Size:147.00GiB, Used:141.92GiB
/dev/sdc 147.00GiB
/dev/sdd 147.00GiB
Metadata,RAID1: Size:2.00GiB, Used:1.17GiB
/dev/sdc 2.00GiB
/dev/sdd 2.00GiB
System,RAID1: Size:32.00MiB, Used:36.00KiB
/dev/sdc 32.00MiB
/dev/sdd 32.00MiB
Unallocated:
/dev/sdc 130.43GiB
/dev/sdd 130.43GiB
Changes:
* Device size is now the raw size, same for the following three
* Free is the logical size
* Max/min were reduced to just min
Filesystem Size Used Avail Use% Mounted on
/dev/sdc 280G 144G 141G 51% /mnt/sdc
The difference between Avail and Free is there because userspace tool does a
different guesswork than kernel.
Issues not addressed by this patch:
* RAID56 profiles are not handled
* mixed profiles are not handled
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-06-26 13:42:24 +00:00
|
|
|
int ratio;
|
2014-02-13 19:19:01 +00:00
|
|
|
u64 flags = sargs->spaces[i].flags;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The raid5/raid6 ratio depends by the stripes number
|
|
|
|
* used by every chunk. It is computed separately
|
|
|
|
*/
|
|
|
|
if (flags & BTRFS_BLOCK_GROUP_RAID0)
|
|
|
|
ratio = 1;
|
|
|
|
else if (flags & BTRFS_BLOCK_GROUP_RAID1)
|
|
|
|
ratio = 2;
|
|
|
|
else if (flags & BTRFS_BLOCK_GROUP_RAID5)
|
|
|
|
ratio = 0;
|
|
|
|
else if (flags & BTRFS_BLOCK_GROUP_RAID6)
|
|
|
|
ratio = 0;
|
|
|
|
else if (flags & BTRFS_BLOCK_GROUP_DUP)
|
|
|
|
ratio = 2;
|
|
|
|
else if (flags & BTRFS_BLOCK_GROUP_RAID10)
|
|
|
|
ratio = 2;
|
|
|
|
else
|
|
|
|
ratio = 1;
|
|
|
|
|
btrfs-progs: rework calculations of fi usage
This patch reworks the basic calculations of 'fi usage'. It does not address
all problems but should make the code more prepared to do so.
The original code tries to estimate the free space that could lead to negative
numbers for some raid profiles:
Data, RAID1: total=147.00GiB, used=141.92GiB
System, RAID1: total=32.00MiB, used=36.00KiB
Metadata, RAID1: total=2.00GiB, used=1.17GiB
GlobalReserve, single: total=404.00MiB, used=0.00B
Overall:
Device size: 279.46GiB
Device allocated: 298.06GiB
Device unallocated: 16.00EiB
Used: 286.18GiB
Free (estimated): 8.00EiB (min: 8.00EiB)
Data ratio: 2.00
Metadata ratio: 2.00
Global reserve: 404.00MiB (used: 0.00B)
Eg. "Device size" - "Device allocated" = negative number or a very large
positive, hence the EiB values.
There are logical and raw numbers multiplied by ratios mixed together,
so the new code makes it explicit which kind is being used. The data and
metadata ratios are calculated separately.
Output after this patch will look like:
Overall:
Device size: 558.92GiB
Device allocated: 298.06GiB
Device unallocated: 260.86GiB
Used: 286.18GiB
Free (estimated): 135.51GiB (min: 135.51GiB)
Data ratio: 2.00
Metadata ratio: 2.00
Global reserve: 404.00MiB (used: 0.00B)
Data,RAID1: Size:147.00GiB, Used:141.92GiB
/dev/sdc 147.00GiB
/dev/sdd 147.00GiB
Metadata,RAID1: Size:2.00GiB, Used:1.17GiB
/dev/sdc 2.00GiB
/dev/sdd 2.00GiB
System,RAID1: Size:32.00MiB, Used:36.00KiB
/dev/sdc 32.00MiB
/dev/sdd 32.00MiB
Unallocated:
/dev/sdc 130.43GiB
/dev/sdd 130.43GiB
Changes:
* Device size is now the raw size, same for the following three
* Free is the logical size
* Max/min were reduced to just min
Filesystem Size Used Avail Use% Mounted on
/dev/sdc 280G 144G 141G 51% /mnt/sdc
The difference between Avail and Free is there because userspace tool does a
different guesswork than kernel.
Issues not addressed by this patch:
* RAID56 profiles are not handled
* mixed profiles are not handled
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-06-26 13:42:24 +00:00
|
|
|
if (!ratio)
|
2016-01-11 10:01:47 +00:00
|
|
|
warning("RAID56 detected, not implemented");
|
btrfs-progs: rework calculations of fi usage
This patch reworks the basic calculations of 'fi usage'. It does not address
all problems but should make the code more prepared to do so.
The original code tries to estimate the free space that could lead to negative
numbers for some raid profiles:
Data, RAID1: total=147.00GiB, used=141.92GiB
System, RAID1: total=32.00MiB, used=36.00KiB
Metadata, RAID1: total=2.00GiB, used=1.17GiB
GlobalReserve, single: total=404.00MiB, used=0.00B
Overall:
Device size: 279.46GiB
Device allocated: 298.06GiB
Device unallocated: 16.00EiB
Used: 286.18GiB
Free (estimated): 8.00EiB (min: 8.00EiB)
Data ratio: 2.00
Metadata ratio: 2.00
Global reserve: 404.00MiB (used: 0.00B)
Eg. "Device size" - "Device allocated" = negative number or a very large
positive, hence the EiB values.
There are logical and raw numbers multiplied by ratios mixed together,
so the new code makes it explicit which kind is being used. The data and
metadata ratios are calculated separately.
Output after this patch will look like:
Overall:
Device size: 558.92GiB
Device allocated: 298.06GiB
Device unallocated: 260.86GiB
Used: 286.18GiB
Free (estimated): 135.51GiB (min: 135.51GiB)
Data ratio: 2.00
Metadata ratio: 2.00
Global reserve: 404.00MiB (used: 0.00B)
Data,RAID1: Size:147.00GiB, Used:141.92GiB
/dev/sdc 147.00GiB
/dev/sdd 147.00GiB
Metadata,RAID1: Size:2.00GiB, Used:1.17GiB
/dev/sdc 2.00GiB
/dev/sdd 2.00GiB
System,RAID1: Size:32.00MiB, Used:36.00KiB
/dev/sdc 32.00MiB
/dev/sdd 32.00MiB
Unallocated:
/dev/sdc 130.43GiB
/dev/sdd 130.43GiB
Changes:
* Device size is now the raw size, same for the following three
* Free is the logical size
* Max/min were reduced to just min
Filesystem Size Used Avail Use% Mounted on
/dev/sdc 280G 144G 141G 51% /mnt/sdc
The difference between Avail and Free is there because userspace tool does a
different guesswork than kernel.
Issues not addressed by this patch:
* RAID56 profiles are not handled
* mixed profiles are not handled
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-06-26 13:42:24 +00:00
|
|
|
|
|
|
|
if (ratio > max_data_ratio)
|
|
|
|
max_data_ratio = ratio;
|
|
|
|
|
2014-04-29 15:32:22 +00:00
|
|
|
if (flags & BTRFS_SPACE_INFO_GLOBAL_RSV) {
|
btrfs-progs: rework calculations of fi usage
This patch reworks the basic calculations of 'fi usage'. It does not address
all problems but should make the code more prepared to do so.
The original code tries to estimate the free space that could lead to negative
numbers for some raid profiles:
Data, RAID1: total=147.00GiB, used=141.92GiB
System, RAID1: total=32.00MiB, used=36.00KiB
Metadata, RAID1: total=2.00GiB, used=1.17GiB
GlobalReserve, single: total=404.00MiB, used=0.00B
Overall:
Device size: 279.46GiB
Device allocated: 298.06GiB
Device unallocated: 16.00EiB
Used: 286.18GiB
Free (estimated): 8.00EiB (min: 8.00EiB)
Data ratio: 2.00
Metadata ratio: 2.00
Global reserve: 404.00MiB (used: 0.00B)
Eg. "Device size" - "Device allocated" = negative number or a very large
positive, hence the EiB values.
There are logical and raw numbers multiplied by ratios mixed together,
so the new code makes it explicit which kind is being used. The data and
metadata ratios are calculated separately.
Output after this patch will look like:
Overall:
Device size: 558.92GiB
Device allocated: 298.06GiB
Device unallocated: 260.86GiB
Used: 286.18GiB
Free (estimated): 135.51GiB (min: 135.51GiB)
Data ratio: 2.00
Metadata ratio: 2.00
Global reserve: 404.00MiB (used: 0.00B)
Data,RAID1: Size:147.00GiB, Used:141.92GiB
/dev/sdc 147.00GiB
/dev/sdd 147.00GiB
Metadata,RAID1: Size:2.00GiB, Used:1.17GiB
/dev/sdc 2.00GiB
/dev/sdd 2.00GiB
System,RAID1: Size:32.00MiB, Used:36.00KiB
/dev/sdc 32.00MiB
/dev/sdd 32.00MiB
Unallocated:
/dev/sdc 130.43GiB
/dev/sdd 130.43GiB
Changes:
* Device size is now the raw size, same for the following three
* Free is the logical size
* Max/min were reduced to just min
Filesystem Size Used Avail Use% Mounted on
/dev/sdc 280G 144G 141G 51% /mnt/sdc
The difference between Avail and Free is there because userspace tool does a
different guesswork than kernel.
Issues not addressed by this patch:
* RAID56 profiles are not handled
* mixed profiles are not handled
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-06-26 13:42:24 +00:00
|
|
|
l_global_reserve = sargs->spaces[i].total_bytes;
|
|
|
|
l_global_reserve_used = sargs->spaces[i].used_bytes;
|
|
|
|
}
|
|
|
|
if ((flags & (BTRFS_BLOCK_GROUP_DATA | BTRFS_BLOCK_GROUP_METADATA))
|
2016-01-13 11:59:42 +00:00
|
|
|
== (BTRFS_BLOCK_GROUP_DATA | BTRFS_BLOCK_GROUP_METADATA)) {
|
|
|
|
mixed = 1;
|
2014-04-29 15:32:22 +00:00
|
|
|
}
|
btrfs-progs: rework calculations of fi usage
This patch reworks the basic calculations of 'fi usage'. It does not address
all problems but should make the code more prepared to do so.
The original code tries to estimate the free space that could lead to negative
numbers for some raid profiles:
Data, RAID1: total=147.00GiB, used=141.92GiB
System, RAID1: total=32.00MiB, used=36.00KiB
Metadata, RAID1: total=2.00GiB, used=1.17GiB
GlobalReserve, single: total=404.00MiB, used=0.00B
Overall:
Device size: 279.46GiB
Device allocated: 298.06GiB
Device unallocated: 16.00EiB
Used: 286.18GiB
Free (estimated): 8.00EiB (min: 8.00EiB)
Data ratio: 2.00
Metadata ratio: 2.00
Global reserve: 404.00MiB (used: 0.00B)
Eg. "Device size" - "Device allocated" = negative number or a very large
positive, hence the EiB values.
There are logical and raw numbers multiplied by ratios mixed together,
so the new code makes it explicit which kind is being used. The data and
metadata ratios are calculated separately.
Output after this patch will look like:
Overall:
Device size: 558.92GiB
Device allocated: 298.06GiB
Device unallocated: 260.86GiB
Used: 286.18GiB
Free (estimated): 135.51GiB (min: 135.51GiB)
Data ratio: 2.00
Metadata ratio: 2.00
Global reserve: 404.00MiB (used: 0.00B)
Data,RAID1: Size:147.00GiB, Used:141.92GiB
/dev/sdc 147.00GiB
/dev/sdd 147.00GiB
Metadata,RAID1: Size:2.00GiB, Used:1.17GiB
/dev/sdc 2.00GiB
/dev/sdd 2.00GiB
System,RAID1: Size:32.00MiB, Used:36.00KiB
/dev/sdc 32.00MiB
/dev/sdd 32.00MiB
Unallocated:
/dev/sdc 130.43GiB
/dev/sdd 130.43GiB
Changes:
* Device size is now the raw size, same for the following three
* Free is the logical size
* Max/min were reduced to just min
Filesystem Size Used Avail Use% Mounted on
/dev/sdc 280G 144G 141G 51% /mnt/sdc
The difference between Avail and Free is there because userspace tool does a
different guesswork than kernel.
Issues not addressed by this patch:
* RAID56 profiles are not handled
* mixed profiles are not handled
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-06-26 13:42:24 +00:00
|
|
|
if (flags & BTRFS_BLOCK_GROUP_DATA) {
|
|
|
|
r_data_used += sargs->spaces[i].used_bytes * ratio;
|
|
|
|
r_data_chunks += sargs->spaces[i].total_bytes * ratio;
|
|
|
|
l_data_chunks += sargs->spaces[i].total_bytes;
|
|
|
|
}
|
|
|
|
if (flags & BTRFS_BLOCK_GROUP_METADATA) {
|
|
|
|
r_metadata_used += sargs->spaces[i].used_bytes * ratio;
|
|
|
|
r_metadata_chunks += sargs->spaces[i].total_bytes * ratio;
|
|
|
|
l_metadata_chunks += sargs->spaces[i].total_bytes;
|
|
|
|
}
|
|
|
|
if (flags & BTRFS_BLOCK_GROUP_SYSTEM) {
|
|
|
|
r_system_used += sargs->spaces[i].used_bytes * ratio;
|
|
|
|
r_system_chunks += sargs->spaces[i].total_bytes * ratio;
|
|
|
|
}
|
|
|
|
}
|
2014-02-13 19:19:01 +00:00
|
|
|
|
2016-01-13 11:59:42 +00:00
|
|
|
r_total_chunks = r_data_chunks + r_system_chunks;
|
|
|
|
r_total_used = r_data_used + r_system_used;
|
|
|
|
if (!mixed) {
|
|
|
|
r_total_chunks += r_metadata_chunks;
|
|
|
|
r_total_used += r_metadata_used;
|
|
|
|
}
|
btrfs-progs: rework calculations of fi usage
This patch reworks the basic calculations of 'fi usage'. It does not address
all problems but should make the code more prepared to do so.
The original code tries to estimate the free space that could lead to negative
numbers for some raid profiles:
Data, RAID1: total=147.00GiB, used=141.92GiB
System, RAID1: total=32.00MiB, used=36.00KiB
Metadata, RAID1: total=2.00GiB, used=1.17GiB
GlobalReserve, single: total=404.00MiB, used=0.00B
Overall:
Device size: 279.46GiB
Device allocated: 298.06GiB
Device unallocated: 16.00EiB
Used: 286.18GiB
Free (estimated): 8.00EiB (min: 8.00EiB)
Data ratio: 2.00
Metadata ratio: 2.00
Global reserve: 404.00MiB (used: 0.00B)
Eg. "Device size" - "Device allocated" = negative number or a very large
positive, hence the EiB values.
There are logical and raw numbers multiplied by ratios mixed together,
so the new code makes it explicit which kind is being used. The data and
metadata ratios are calculated separately.
Output after this patch will look like:
Overall:
Device size: 558.92GiB
Device allocated: 298.06GiB
Device unallocated: 260.86GiB
Used: 286.18GiB
Free (estimated): 135.51GiB (min: 135.51GiB)
Data ratio: 2.00
Metadata ratio: 2.00
Global reserve: 404.00MiB (used: 0.00B)
Data,RAID1: Size:147.00GiB, Used:141.92GiB
/dev/sdc 147.00GiB
/dev/sdd 147.00GiB
Metadata,RAID1: Size:2.00GiB, Used:1.17GiB
/dev/sdc 2.00GiB
/dev/sdd 2.00GiB
System,RAID1: Size:32.00MiB, Used:36.00KiB
/dev/sdc 32.00MiB
/dev/sdd 32.00MiB
Unallocated:
/dev/sdc 130.43GiB
/dev/sdd 130.43GiB
Changes:
* Device size is now the raw size, same for the following three
* Free is the logical size
* Max/min were reduced to just min
Filesystem Size Used Avail Use% Mounted on
/dev/sdc 280G 144G 141G 51% /mnt/sdc
The difference between Avail and Free is there because userspace tool does a
different guesswork than kernel.
Issues not addressed by this patch:
* RAID56 profiles are not handled
* mixed profiles are not handled
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-06-26 13:42:24 +00:00
|
|
|
r_total_unused = r_total_size - r_total_chunks;
|
2014-02-13 19:19:01 +00:00
|
|
|
|
btrfs-progs: rework calculations of fi usage
This patch reworks the basic calculations of 'fi usage'. It does not address
all problems but should make the code more prepared to do so.
The original code tries to estimate the free space that could lead to negative
numbers for some raid profiles:
Data, RAID1: total=147.00GiB, used=141.92GiB
System, RAID1: total=32.00MiB, used=36.00KiB
Metadata, RAID1: total=2.00GiB, used=1.17GiB
GlobalReserve, single: total=404.00MiB, used=0.00B
Overall:
Device size: 279.46GiB
Device allocated: 298.06GiB
Device unallocated: 16.00EiB
Used: 286.18GiB
Free (estimated): 8.00EiB (min: 8.00EiB)
Data ratio: 2.00
Metadata ratio: 2.00
Global reserve: 404.00MiB (used: 0.00B)
Eg. "Device size" - "Device allocated" = negative number or a very large
positive, hence the EiB values.
There are logical and raw numbers multiplied by ratios mixed together,
so the new code makes it explicit which kind is being used. The data and
metadata ratios are calculated separately.
Output after this patch will look like:
Overall:
Device size: 558.92GiB
Device allocated: 298.06GiB
Device unallocated: 260.86GiB
Used: 286.18GiB
Free (estimated): 135.51GiB (min: 135.51GiB)
Data ratio: 2.00
Metadata ratio: 2.00
Global reserve: 404.00MiB (used: 0.00B)
Data,RAID1: Size:147.00GiB, Used:141.92GiB
/dev/sdc 147.00GiB
/dev/sdd 147.00GiB
Metadata,RAID1: Size:2.00GiB, Used:1.17GiB
/dev/sdc 2.00GiB
/dev/sdd 2.00GiB
System,RAID1: Size:32.00MiB, Used:36.00KiB
/dev/sdc 32.00MiB
/dev/sdd 32.00MiB
Unallocated:
/dev/sdc 130.43GiB
/dev/sdd 130.43GiB
Changes:
* Device size is now the raw size, same for the following three
* Free is the logical size
* Max/min were reduced to just min
Filesystem Size Used Avail Use% Mounted on
/dev/sdc 280G 144G 141G 51% /mnt/sdc
The difference between Avail and Free is there because userspace tool does a
different guesswork than kernel.
Issues not addressed by this patch:
* RAID56 profiles are not handled
* mixed profiles are not handled
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-06-26 13:42:24 +00:00
|
|
|
/* Raw / Logical = raid factor, >= 1 */
|
|
|
|
data_ratio = (double)r_data_chunks / l_data_chunks;
|
2016-01-13 11:59:42 +00:00
|
|
|
if (mixed)
|
|
|
|
metadata_ratio = data_ratio;
|
|
|
|
else
|
|
|
|
metadata_ratio = (double)r_metadata_chunks / l_metadata_chunks;
|
2014-02-13 19:19:01 +00:00
|
|
|
|
btrfs-progs: rework calculations of fi usage
This patch reworks the basic calculations of 'fi usage'. It does not address
all problems but should make the code more prepared to do so.
The original code tries to estimate the free space that could lead to negative
numbers for some raid profiles:
Data, RAID1: total=147.00GiB, used=141.92GiB
System, RAID1: total=32.00MiB, used=36.00KiB
Metadata, RAID1: total=2.00GiB, used=1.17GiB
GlobalReserve, single: total=404.00MiB, used=0.00B
Overall:
Device size: 279.46GiB
Device allocated: 298.06GiB
Device unallocated: 16.00EiB
Used: 286.18GiB
Free (estimated): 8.00EiB (min: 8.00EiB)
Data ratio: 2.00
Metadata ratio: 2.00
Global reserve: 404.00MiB (used: 0.00B)
Eg. "Device size" - "Device allocated" = negative number or a very large
positive, hence the EiB values.
There are logical and raw numbers multiplied by ratios mixed together,
so the new code makes it explicit which kind is being used. The data and
metadata ratios are calculated separately.
Output after this patch will look like:
Overall:
Device size: 558.92GiB
Device allocated: 298.06GiB
Device unallocated: 260.86GiB
Used: 286.18GiB
Free (estimated): 135.51GiB (min: 135.51GiB)
Data ratio: 2.00
Metadata ratio: 2.00
Global reserve: 404.00MiB (used: 0.00B)
Data,RAID1: Size:147.00GiB, Used:141.92GiB
/dev/sdc 147.00GiB
/dev/sdd 147.00GiB
Metadata,RAID1: Size:2.00GiB, Used:1.17GiB
/dev/sdc 2.00GiB
/dev/sdd 2.00GiB
System,RAID1: Size:32.00MiB, Used:36.00KiB
/dev/sdc 32.00MiB
/dev/sdd 32.00MiB
Unallocated:
/dev/sdc 130.43GiB
/dev/sdd 130.43GiB
Changes:
* Device size is now the raw size, same for the following three
* Free is the logical size
* Max/min were reduced to just min
Filesystem Size Used Avail Use% Mounted on
/dev/sdc 280G 144G 141G 51% /mnt/sdc
The difference between Avail and Free is there because userspace tool does a
different guesswork than kernel.
Issues not addressed by this patch:
* RAID56 profiles are not handled
* mixed profiles are not handled
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-06-26 13:42:24 +00:00
|
|
|
#if 0
|
2014-02-13 19:19:01 +00:00
|
|
|
/* add the raid5/6 allocated space */
|
|
|
|
total_chunks += raid5_used + raid6_used;
|
btrfs-progs: rework calculations of fi usage
This patch reworks the basic calculations of 'fi usage'. It does not address
all problems but should make the code more prepared to do so.
The original code tries to estimate the free space that could lead to negative
numbers for some raid profiles:
Data, RAID1: total=147.00GiB, used=141.92GiB
System, RAID1: total=32.00MiB, used=36.00KiB
Metadata, RAID1: total=2.00GiB, used=1.17GiB
GlobalReserve, single: total=404.00MiB, used=0.00B
Overall:
Device size: 279.46GiB
Device allocated: 298.06GiB
Device unallocated: 16.00EiB
Used: 286.18GiB
Free (estimated): 8.00EiB (min: 8.00EiB)
Data ratio: 2.00
Metadata ratio: 2.00
Global reserve: 404.00MiB (used: 0.00B)
Eg. "Device size" - "Device allocated" = negative number or a very large
positive, hence the EiB values.
There are logical and raw numbers multiplied by ratios mixed together,
so the new code makes it explicit which kind is being used. The data and
metadata ratios are calculated separately.
Output after this patch will look like:
Overall:
Device size: 558.92GiB
Device allocated: 298.06GiB
Device unallocated: 260.86GiB
Used: 286.18GiB
Free (estimated): 135.51GiB (min: 135.51GiB)
Data ratio: 2.00
Metadata ratio: 2.00
Global reserve: 404.00MiB (used: 0.00B)
Data,RAID1: Size:147.00GiB, Used:141.92GiB
/dev/sdc 147.00GiB
/dev/sdd 147.00GiB
Metadata,RAID1: Size:2.00GiB, Used:1.17GiB
/dev/sdc 2.00GiB
/dev/sdd 2.00GiB
System,RAID1: Size:32.00MiB, Used:36.00KiB
/dev/sdc 32.00MiB
/dev/sdd 32.00MiB
Unallocated:
/dev/sdc 130.43GiB
/dev/sdd 130.43GiB
Changes:
* Device size is now the raw size, same for the following three
* Free is the logical size
* Max/min were reduced to just min
Filesystem Size Used Avail Use% Mounted on
/dev/sdc 280G 144G 141G 51% /mnt/sdc
The difference between Avail and Free is there because userspace tool does a
different guesswork than kernel.
Issues not addressed by this patch:
* RAID56 profiles are not handled
* mixed profiles are not handled
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-06-26 13:42:24 +00:00
|
|
|
#endif
|
2014-02-13 19:19:01 +00:00
|
|
|
|
btrfs-progs: rework calculations of fi usage
This patch reworks the basic calculations of 'fi usage'. It does not address
all problems but should make the code more prepared to do so.
The original code tries to estimate the free space that could lead to negative
numbers for some raid profiles:
Data, RAID1: total=147.00GiB, used=141.92GiB
System, RAID1: total=32.00MiB, used=36.00KiB
Metadata, RAID1: total=2.00GiB, used=1.17GiB
GlobalReserve, single: total=404.00MiB, used=0.00B
Overall:
Device size: 279.46GiB
Device allocated: 298.06GiB
Device unallocated: 16.00EiB
Used: 286.18GiB
Free (estimated): 8.00EiB (min: 8.00EiB)
Data ratio: 2.00
Metadata ratio: 2.00
Global reserve: 404.00MiB (used: 0.00B)
Eg. "Device size" - "Device allocated" = negative number or a very large
positive, hence the EiB values.
There are logical and raw numbers multiplied by ratios mixed together,
so the new code makes it explicit which kind is being used. The data and
metadata ratios are calculated separately.
Output after this patch will look like:
Overall:
Device size: 558.92GiB
Device allocated: 298.06GiB
Device unallocated: 260.86GiB
Used: 286.18GiB
Free (estimated): 135.51GiB (min: 135.51GiB)
Data ratio: 2.00
Metadata ratio: 2.00
Global reserve: 404.00MiB (used: 0.00B)
Data,RAID1: Size:147.00GiB, Used:141.92GiB
/dev/sdc 147.00GiB
/dev/sdd 147.00GiB
Metadata,RAID1: Size:2.00GiB, Used:1.17GiB
/dev/sdc 2.00GiB
/dev/sdd 2.00GiB
System,RAID1: Size:32.00MiB, Used:36.00KiB
/dev/sdc 32.00MiB
/dev/sdd 32.00MiB
Unallocated:
/dev/sdc 130.43GiB
/dev/sdd 130.43GiB
Changes:
* Device size is now the raw size, same for the following three
* Free is the logical size
* Max/min were reduced to just min
Filesystem Size Used Avail Use% Mounted on
/dev/sdc 280G 144G 141G 51% /mnt/sdc
The difference between Avail and Free is there because userspace tool does a
different guesswork than kernel.
Issues not addressed by this patch:
* RAID56 profiles are not handled
* mixed profiles are not handled
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-06-26 13:42:24 +00:00
|
|
|
/*
|
|
|
|
* We're able to fill at least DATA for the unused space
|
|
|
|
*
|
|
|
|
* With mixed raid levels, this gives a rough estimate but more
|
|
|
|
* accurate than just counting the logical free space
|
|
|
|
* (l_data_chunks - l_data_used)
|
|
|
|
*
|
|
|
|
* In non-mixed case there's no difference.
|
|
|
|
*/
|
|
|
|
free_estimated = (r_data_chunks - r_data_used) / data_ratio;
|
2016-01-13 11:59:42 +00:00
|
|
|
/*
|
|
|
|
* For mixed-bg the metadata are left out in calculations thus global
|
|
|
|
* reserve would be lost. Part of it could be permanently allocated,
|
|
|
|
* we have to subtract the used bytes so we don't go under zero free.
|
|
|
|
*/
|
|
|
|
if (mixed)
|
|
|
|
free_estimated -= l_global_reserve - l_global_reserve_used;
|
btrfs-progs: rework calculations of fi usage
This patch reworks the basic calculations of 'fi usage'. It does not address
all problems but should make the code more prepared to do so.
The original code tries to estimate the free space that could lead to negative
numbers for some raid profiles:
Data, RAID1: total=147.00GiB, used=141.92GiB
System, RAID1: total=32.00MiB, used=36.00KiB
Metadata, RAID1: total=2.00GiB, used=1.17GiB
GlobalReserve, single: total=404.00MiB, used=0.00B
Overall:
Device size: 279.46GiB
Device allocated: 298.06GiB
Device unallocated: 16.00EiB
Used: 286.18GiB
Free (estimated): 8.00EiB (min: 8.00EiB)
Data ratio: 2.00
Metadata ratio: 2.00
Global reserve: 404.00MiB (used: 0.00B)
Eg. "Device size" - "Device allocated" = negative number or a very large
positive, hence the EiB values.
There are logical and raw numbers multiplied by ratios mixed together,
so the new code makes it explicit which kind is being used. The data and
metadata ratios are calculated separately.
Output after this patch will look like:
Overall:
Device size: 558.92GiB
Device allocated: 298.06GiB
Device unallocated: 260.86GiB
Used: 286.18GiB
Free (estimated): 135.51GiB (min: 135.51GiB)
Data ratio: 2.00
Metadata ratio: 2.00
Global reserve: 404.00MiB (used: 0.00B)
Data,RAID1: Size:147.00GiB, Used:141.92GiB
/dev/sdc 147.00GiB
/dev/sdd 147.00GiB
Metadata,RAID1: Size:2.00GiB, Used:1.17GiB
/dev/sdc 2.00GiB
/dev/sdd 2.00GiB
System,RAID1: Size:32.00MiB, Used:36.00KiB
/dev/sdc 32.00MiB
/dev/sdd 32.00MiB
Unallocated:
/dev/sdc 130.43GiB
/dev/sdd 130.43GiB
Changes:
* Device size is now the raw size, same for the following three
* Free is the logical size
* Max/min were reduced to just min
Filesystem Size Used Avail Use% Mounted on
/dev/sdc 280G 144G 141G 51% /mnt/sdc
The difference between Avail and Free is there because userspace tool does a
different guesswork than kernel.
Issues not addressed by this patch:
* RAID56 profiles are not handled
* mixed profiles are not handled
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-06-26 13:42:24 +00:00
|
|
|
free_min = free_estimated;
|
|
|
|
|
|
|
|
/* Chop unallocatable space */
|
|
|
|
/* FIXME: must be applied per device */
|
|
|
|
if (r_total_unused >= MIN_UNALOCATED_THRESH) {
|
|
|
|
free_estimated += r_total_unused / data_ratio;
|
|
|
|
/* Match the calculation of 'df', use the highest raid ratio */
|
|
|
|
free_min += r_total_unused / max_data_ratio;
|
|
|
|
}
|
2014-02-13 19:19:01 +00:00
|
|
|
|
2014-12-18 13:52:36 +00:00
|
|
|
if (unit_mode != UNITS_HUMAN)
|
2014-02-13 19:19:01 +00:00
|
|
|
width = 18;
|
|
|
|
|
2014-04-25 15:24:40 +00:00
|
|
|
printf("Overall:\n");
|
|
|
|
|
|
|
|
printf(" Device size:\t\t%*s\n", width,
|
2014-12-18 13:52:36 +00:00
|
|
|
pretty_size_mode(r_total_size, unit_mode));
|
2014-04-25 15:24:40 +00:00
|
|
|
printf(" Device allocated:\t\t%*s\n", width,
|
2014-12-18 13:52:36 +00:00
|
|
|
pretty_size_mode(r_total_chunks, unit_mode));
|
2014-04-25 15:24:40 +00:00
|
|
|
printf(" Device unallocated:\t\t%*s\n", width,
|
2017-01-03 17:26:43 +00:00
|
|
|
pretty_size_mode(r_total_unused, unit_mode | UNITS_NEGATIVE));
|
2015-03-17 13:41:01 +00:00
|
|
|
printf(" Device missing:\t\t%*s\n", width,
|
|
|
|
pretty_size_mode(r_total_missing, unit_mode));
|
2014-04-25 15:24:40 +00:00
|
|
|
printf(" Used:\t\t\t%*s\n", width,
|
2014-12-18 13:52:36 +00:00
|
|
|
pretty_size_mode(r_total_used, unit_mode));
|
btrfs-progs: rework calculations of fi usage
This patch reworks the basic calculations of 'fi usage'. It does not address
all problems but should make the code more prepared to do so.
The original code tries to estimate the free space that could lead to negative
numbers for some raid profiles:
Data, RAID1: total=147.00GiB, used=141.92GiB
System, RAID1: total=32.00MiB, used=36.00KiB
Metadata, RAID1: total=2.00GiB, used=1.17GiB
GlobalReserve, single: total=404.00MiB, used=0.00B
Overall:
Device size: 279.46GiB
Device allocated: 298.06GiB
Device unallocated: 16.00EiB
Used: 286.18GiB
Free (estimated): 8.00EiB (min: 8.00EiB)
Data ratio: 2.00
Metadata ratio: 2.00
Global reserve: 404.00MiB (used: 0.00B)
Eg. "Device size" - "Device allocated" = negative number or a very large
positive, hence the EiB values.
There are logical and raw numbers multiplied by ratios mixed together,
so the new code makes it explicit which kind is being used. The data and
metadata ratios are calculated separately.
Output after this patch will look like:
Overall:
Device size: 558.92GiB
Device allocated: 298.06GiB
Device unallocated: 260.86GiB
Used: 286.18GiB
Free (estimated): 135.51GiB (min: 135.51GiB)
Data ratio: 2.00
Metadata ratio: 2.00
Global reserve: 404.00MiB (used: 0.00B)
Data,RAID1: Size:147.00GiB, Used:141.92GiB
/dev/sdc 147.00GiB
/dev/sdd 147.00GiB
Metadata,RAID1: Size:2.00GiB, Used:1.17GiB
/dev/sdc 2.00GiB
/dev/sdd 2.00GiB
System,RAID1: Size:32.00MiB, Used:36.00KiB
/dev/sdc 32.00MiB
/dev/sdd 32.00MiB
Unallocated:
/dev/sdc 130.43GiB
/dev/sdd 130.43GiB
Changes:
* Device size is now the raw size, same for the following three
* Free is the logical size
* Max/min were reduced to just min
Filesystem Size Used Avail Use% Mounted on
/dev/sdc 280G 144G 141G 51% /mnt/sdc
The difference between Avail and Free is there because userspace tool does a
different guesswork than kernel.
Issues not addressed by this patch:
* RAID56 profiles are not handled
* mixed profiles are not handled
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-06-26 13:42:24 +00:00
|
|
|
printf(" Free (estimated):\t\t%*s\t(",
|
2014-02-13 19:19:01 +00:00
|
|
|
width,
|
2014-12-18 13:52:36 +00:00
|
|
|
pretty_size_mode(free_estimated, unit_mode));
|
|
|
|
printf("min: %s)\n", pretty_size_mode(free_min, unit_mode));
|
btrfs-progs: rework calculations of fi usage
This patch reworks the basic calculations of 'fi usage'. It does not address
all problems but should make the code more prepared to do so.
The original code tries to estimate the free space that could lead to negative
numbers for some raid profiles:
Data, RAID1: total=147.00GiB, used=141.92GiB
System, RAID1: total=32.00MiB, used=36.00KiB
Metadata, RAID1: total=2.00GiB, used=1.17GiB
GlobalReserve, single: total=404.00MiB, used=0.00B
Overall:
Device size: 279.46GiB
Device allocated: 298.06GiB
Device unallocated: 16.00EiB
Used: 286.18GiB
Free (estimated): 8.00EiB (min: 8.00EiB)
Data ratio: 2.00
Metadata ratio: 2.00
Global reserve: 404.00MiB (used: 0.00B)
Eg. "Device size" - "Device allocated" = negative number or a very large
positive, hence the EiB values.
There are logical and raw numbers multiplied by ratios mixed together,
so the new code makes it explicit which kind is being used. The data and
metadata ratios are calculated separately.
Output after this patch will look like:
Overall:
Device size: 558.92GiB
Device allocated: 298.06GiB
Device unallocated: 260.86GiB
Used: 286.18GiB
Free (estimated): 135.51GiB (min: 135.51GiB)
Data ratio: 2.00
Metadata ratio: 2.00
Global reserve: 404.00MiB (used: 0.00B)
Data,RAID1: Size:147.00GiB, Used:141.92GiB
/dev/sdc 147.00GiB
/dev/sdd 147.00GiB
Metadata,RAID1: Size:2.00GiB, Used:1.17GiB
/dev/sdc 2.00GiB
/dev/sdd 2.00GiB
System,RAID1: Size:32.00MiB, Used:36.00KiB
/dev/sdc 32.00MiB
/dev/sdd 32.00MiB
Unallocated:
/dev/sdc 130.43GiB
/dev/sdd 130.43GiB
Changes:
* Device size is now the raw size, same for the following three
* Free is the logical size
* Max/min were reduced to just min
Filesystem Size Used Avail Use% Mounted on
/dev/sdc 280G 144G 141G 51% /mnt/sdc
The difference between Avail and Free is there because userspace tool does a
different guesswork than kernel.
Issues not addressed by this patch:
* RAID56 profiles are not handled
* mixed profiles are not handled
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-06-26 13:42:24 +00:00
|
|
|
printf(" Data ratio:\t\t\t%*.2f\n",
|
|
|
|
width, data_ratio);
|
|
|
|
printf(" Metadata ratio:\t\t%*.2f\n",
|
|
|
|
width, metadata_ratio);
|
2014-04-29 15:32:22 +00:00
|
|
|
printf(" Global reserve:\t\t%*s\t(used: %s)\n", width,
|
2014-12-18 13:52:36 +00:00
|
|
|
pretty_size_mode(l_global_reserve, unit_mode),
|
|
|
|
pretty_size_mode(l_global_reserve_used, unit_mode));
|
2014-02-13 19:19:01 +00:00
|
|
|
|
|
|
|
exit:
|
|
|
|
|
|
|
|
if (sargs)
|
|
|
|
free(sargs);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-02-13 19:19:50 +00:00
|
|
|
/*
|
2014-04-23 17:00:22 +00:00
|
|
|
* Helper to sort the device_info structure
|
2014-02-13 19:19:50 +00:00
|
|
|
*/
|
2014-04-23 17:00:22 +00:00
|
|
|
static int cmp_device_info(const void *a, const void *b)
|
2014-02-13 19:19:50 +00:00
|
|
|
{
|
2014-04-23 17:00:22 +00:00
|
|
|
return strcmp(((struct device_info *)a)->path,
|
|
|
|
((struct device_info *)b)->path);
|
2014-02-13 19:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-04-23 17:00:22 +00:00
|
|
|
* This function loads the device_info structure and put them in an array
|
2014-02-13 19:19:50 +00:00
|
|
|
*/
|
2014-04-25 17:39:11 +00:00
|
|
|
static int load_device_info(int fd, struct device_info **device_info_ptr,
|
2014-04-23 17:00:22 +00:00
|
|
|
int *device_info_count)
|
2014-02-13 19:19:50 +00:00
|
|
|
{
|
2015-10-02 15:44:21 +00:00
|
|
|
int ret, i, ndevs;
|
2014-02-13 19:19:50 +00:00
|
|
|
struct btrfs_ioctl_fs_info_args fi_args;
|
|
|
|
struct btrfs_ioctl_dev_info_args dev_info;
|
2014-04-23 17:00:22 +00:00
|
|
|
struct device_info *info;
|
2014-02-13 19:19:50 +00:00
|
|
|
|
2014-04-23 17:00:22 +00:00
|
|
|
*device_info_count = 0;
|
2016-01-04 01:01:30 +00:00
|
|
|
*device_info_ptr = NULL;
|
2014-02-13 19:19:50 +00:00
|
|
|
|
|
|
|
ret = ioctl(fd, BTRFS_IOC_FS_INFO, &fi_args);
|
|
|
|
if (ret < 0) {
|
2015-10-02 15:44:21 +00:00
|
|
|
if (errno == EPERM)
|
|
|
|
return -errno;
|
2016-01-11 10:01:47 +00:00
|
|
|
error("cannot get filesystem info: %s",
|
2015-10-02 15:44:21 +00:00
|
|
|
strerror(errno));
|
2014-07-24 03:21:54 +00:00
|
|
|
return 1;
|
2014-02-13 19:19:50 +00:00
|
|
|
}
|
|
|
|
|
2014-04-24 16:37:50 +00:00
|
|
|
info = calloc(fi_args.num_devices, sizeof(struct device_info));
|
2014-02-13 19:19:50 +00:00
|
|
|
if (!info) {
|
2016-01-11 10:01:47 +00:00
|
|
|
error("not enough memory");
|
2014-07-24 03:21:54 +00:00
|
|
|
return 1;
|
2014-02-13 19:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0, ndevs = 0 ; i <= fi_args.max_id ; i++) {
|
2016-08-26 10:53:31 +00:00
|
|
|
if (ndevs >= fi_args.num_devices) {
|
|
|
|
error("unexpected number of devices: %d >= %llu", ndevs,
|
|
|
|
(unsigned long long)fi_args.num_devices);
|
|
|
|
goto out;
|
|
|
|
}
|
2014-04-24 16:37:50 +00:00
|
|
|
memset(&dev_info, 0, sizeof(dev_info));
|
2014-02-13 19:19:50 +00:00
|
|
|
ret = get_device_info(fd, i, &dev_info);
|
|
|
|
|
|
|
|
if (ret == -ENODEV)
|
|
|
|
continue;
|
|
|
|
if (ret) {
|
2016-01-11 10:01:47 +00:00
|
|
|
error("cannot get info about device devid=%d", i);
|
2016-08-26 10:53:31 +00:00
|
|
|
goto out;
|
2014-02-13 19:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
info[ndevs].devid = dev_info.devid;
|
2015-03-17 13:41:01 +00:00
|
|
|
if (!dev_info.path[0]) {
|
|
|
|
strcpy(info[ndevs].path, "missing");
|
|
|
|
} else {
|
|
|
|
strcpy(info[ndevs].path, (char *)dev_info.path);
|
|
|
|
info[ndevs].device_size =
|
|
|
|
get_partition_size((char *)dev_info.path);
|
|
|
|
}
|
2014-04-24 16:32:27 +00:00
|
|
|
info[ndevs].size = dev_info.total_bytes;
|
2014-02-13 19:19:50 +00:00
|
|
|
++ndevs;
|
|
|
|
}
|
|
|
|
|
2016-08-26 10:53:31 +00:00
|
|
|
if (ndevs != fi_args.num_devices) {
|
|
|
|
error("unexpected number of devices: %d != %llu", ndevs,
|
|
|
|
(unsigned long long)fi_args.num_devices);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2014-02-13 19:19:50 +00:00
|
|
|
qsort(info, fi_args.num_devices,
|
2014-04-23 17:00:22 +00:00
|
|
|
sizeof(struct device_info), cmp_device_info);
|
2014-02-13 19:19:50 +00:00
|
|
|
|
2014-04-23 17:00:22 +00:00
|
|
|
*device_info_count = fi_args.num_devices;
|
|
|
|
*device_info_ptr = info;
|
2014-02-13 19:19:50 +00:00
|
|
|
|
|
|
|
return 0;
|
2016-08-26 10:53:31 +00:00
|
|
|
|
|
|
|
out:
|
|
|
|
free(info);
|
|
|
|
return ret;
|
2014-02-13 19:19:50 +00:00
|
|
|
}
|
|
|
|
|
2014-04-25 17:39:11 +00:00
|
|
|
int load_chunk_and_device_info(int fd, struct chunk_info **chunkinfo,
|
|
|
|
int *chunkcount, struct device_info **devinfo, int *devcount)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = load_chunk_info(fd, chunkinfo, chunkcount);
|
|
|
|
if (ret == -EPERM) {
|
2016-01-11 10:01:47 +00:00
|
|
|
warning(
|
|
|
|
"cannot read detailed chunk info, RAID5/6 numbers will be incorrect, run as root");
|
2014-04-25 17:39:11 +00:00
|
|
|
} else if (ret) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = load_device_info(fd, devinfo, devcount);
|
|
|
|
if (ret == -EPERM) {
|
2016-01-11 10:01:47 +00:00
|
|
|
warning(
|
|
|
|
"cannot get filesystem info from ioctl(FS_INFO), run as root");
|
2014-04-25 17:39:11 +00:00
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-02-13 19:19:50 +00:00
|
|
|
/*
|
|
|
|
* This function computes the size of a chunk in a disk
|
|
|
|
*/
|
|
|
|
static u64 calc_chunk_size(struct chunk_info *ci)
|
|
|
|
{
|
|
|
|
if (ci->type & BTRFS_BLOCK_GROUP_RAID0)
|
|
|
|
return ci->size / ci->num_stripes;
|
|
|
|
else if (ci->type & BTRFS_BLOCK_GROUP_RAID1)
|
|
|
|
return ci->size ;
|
|
|
|
else if (ci->type & BTRFS_BLOCK_GROUP_DUP)
|
|
|
|
return ci->size ;
|
|
|
|
else if (ci->type & BTRFS_BLOCK_GROUP_RAID5)
|
|
|
|
return ci->size / (ci->num_stripes -1);
|
|
|
|
else if (ci->type & BTRFS_BLOCK_GROUP_RAID6)
|
|
|
|
return ci->size / (ci->num_stripes -2);
|
|
|
|
else if (ci->type & BTRFS_BLOCK_GROUP_RAID10)
|
|
|
|
return ci->size / ci->num_stripes;
|
|
|
|
return ci->size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-04-23 16:47:52 +00:00
|
|
|
* This function print the results of the command "btrfs fi usage"
|
2014-02-13 19:19:50 +00:00
|
|
|
* in tabular format
|
|
|
|
*/
|
2014-12-18 13:52:36 +00:00
|
|
|
static void _cmd_filesystem_usage_tabular(unsigned unit_mode,
|
2014-02-13 19:19:50 +00:00
|
|
|
struct btrfs_ioctl_space_args *sargs,
|
|
|
|
struct chunk_info *chunks_info_ptr,
|
|
|
|
int chunks_info_count,
|
2014-04-23 17:00:22 +00:00
|
|
|
struct device_info *device_info_ptr,
|
|
|
|
int device_info_count)
|
2014-02-13 19:19:50 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
u64 total_unused = 0;
|
2016-01-04 01:01:30 +00:00
|
|
|
struct string_table *matrix = NULL;
|
2014-02-13 19:19:50 +00:00
|
|
|
int ncols, nrows;
|
2015-11-02 17:24:28 +00:00
|
|
|
int col;
|
|
|
|
int unallocated_col;
|
2015-11-02 23:08:32 +00:00
|
|
|
int spaceinfos_col;
|
2015-11-02 17:54:48 +00:00
|
|
|
const int vhdr_skip = 3; /* amount of vertical header space */
|
2014-02-13 19:19:50 +00:00
|
|
|
|
2015-11-02 23:19:41 +00:00
|
|
|
/* id, path, unallocated */
|
|
|
|
ncols = 3;
|
|
|
|
spaceinfos_col = 2;
|
2015-11-02 17:44:45 +00:00
|
|
|
/* Properly count the real space infos */
|
|
|
|
for (i = 0; i < sargs->total_spaces; i++) {
|
|
|
|
if (sargs->spaces[i].flags & BTRFS_SPACE_INFO_GLOBAL_RSV)
|
|
|
|
continue;
|
|
|
|
ncols++;
|
|
|
|
}
|
|
|
|
|
2015-11-02 17:24:28 +00:00
|
|
|
/* 2 for header, empty line, devices, ===, total, used */
|
2015-11-02 17:54:48 +00:00
|
|
|
nrows = vhdr_skip + device_info_count + 1 + 2;
|
2014-02-13 19:19:50 +00:00
|
|
|
|
|
|
|
matrix = table_create(ncols, nrows);
|
|
|
|
if (!matrix) {
|
2016-01-11 10:01:47 +00:00
|
|
|
error("not enough memory");
|
2014-02-13 19:19:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-11-02 17:24:28 +00:00
|
|
|
/*
|
|
|
|
* We have to skip the global block reserve everywhere as it's an
|
|
|
|
* artificial blockgroup
|
|
|
|
*/
|
|
|
|
|
2014-02-13 19:19:50 +00:00
|
|
|
/* header */
|
2015-11-02 23:08:32 +00:00
|
|
|
for (i = 0, col = spaceinfos_col; i < sargs->total_spaces; i++) {
|
2014-02-13 19:19:50 +00:00
|
|
|
u64 flags = sargs->spaces[i].flags;
|
2014-04-29 15:32:22 +00:00
|
|
|
|
|
|
|
if (flags & BTRFS_SPACE_INFO_GLOBAL_RSV)
|
|
|
|
continue;
|
|
|
|
|
2015-11-02 17:32:04 +00:00
|
|
|
table_printf(matrix, col, 0, "<%s",
|
|
|
|
btrfs_group_type_str(flags));
|
|
|
|
table_printf(matrix, col, 1, "<%s",
|
|
|
|
btrfs_group_profile_str(flags));
|
|
|
|
col++;
|
2014-02-13 19:19:50 +00:00
|
|
|
}
|
2015-11-02 17:24:28 +00:00
|
|
|
unallocated_col = col;
|
2014-02-13 19:19:50 +00:00
|
|
|
|
2015-11-02 23:19:41 +00:00
|
|
|
table_printf(matrix, 0, 1, "<Id");
|
|
|
|
table_printf(matrix, 1, 1, "<Path");
|
2015-11-02 17:24:28 +00:00
|
|
|
table_printf(matrix, unallocated_col, 1, "<Unallocated");
|
2014-02-13 19:19:50 +00:00
|
|
|
|
|
|
|
/* body */
|
2014-04-23 17:00:22 +00:00
|
|
|
for (i = 0; i < device_info_count; i++) {
|
2015-11-02 17:24:28 +00:00
|
|
|
int k;
|
2014-02-13 19:19:50 +00:00
|
|
|
char *p;
|
|
|
|
|
|
|
|
u64 total_allocated = 0, unused;
|
|
|
|
|
2014-04-23 17:00:22 +00:00
|
|
|
p = strrchr(device_info_ptr[i].path, '/');
|
2014-02-13 19:19:50 +00:00
|
|
|
if (!p)
|
2014-04-23 17:00:22 +00:00
|
|
|
p = device_info_ptr[i].path;
|
2014-02-13 19:19:50 +00:00
|
|
|
else
|
|
|
|
p++;
|
|
|
|
|
2015-11-02 23:19:41 +00:00
|
|
|
table_printf(matrix, 0, vhdr_skip + i, ">%llu",
|
|
|
|
device_info_ptr[i].devid);
|
|
|
|
table_printf(matrix, 1, vhdr_skip + i, "<%s",
|
2015-11-02 17:54:48 +00:00
|
|
|
device_info_ptr[i].path);
|
2014-02-13 19:19:50 +00:00
|
|
|
|
2015-11-02 23:08:32 +00:00
|
|
|
for (col = spaceinfos_col, k = 0; k < sargs->total_spaces; k++) {
|
2014-02-13 19:19:50 +00:00
|
|
|
u64 flags = sargs->spaces[k].flags;
|
2014-04-23 17:00:22 +00:00
|
|
|
u64 devid = device_info_ptr[i].devid;
|
2014-02-13 19:19:50 +00:00
|
|
|
int j;
|
|
|
|
u64 size = 0;
|
|
|
|
|
2015-11-02 17:24:28 +00:00
|
|
|
if (flags & BTRFS_SPACE_INFO_GLOBAL_RSV)
|
|
|
|
continue;
|
|
|
|
|
2014-02-13 19:19:50 +00:00
|
|
|
for (j = 0 ; j < chunks_info_count ; j++) {
|
|
|
|
if (chunks_info_ptr[j].type != flags )
|
|
|
|
continue;
|
|
|
|
if (chunks_info_ptr[j].devid != devid)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
size += calc_chunk_size(chunks_info_ptr+j);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size)
|
2015-11-02 17:54:48 +00:00
|
|
|
table_printf(matrix, col, vhdr_skip+ i,
|
2014-12-18 13:52:36 +00:00
|
|
|
">%s", pretty_size_mode(size, unit_mode));
|
2014-02-13 19:19:50 +00:00
|
|
|
else
|
2015-11-02 17:54:48 +00:00
|
|
|
table_printf(matrix, col, vhdr_skip + i, ">-");
|
2014-02-13 19:19:50 +00:00
|
|
|
|
|
|
|
total_allocated += size;
|
|
|
|
col++;
|
|
|
|
}
|
|
|
|
|
2014-04-23 17:00:22 +00:00
|
|
|
unused = get_partition_size(device_info_ptr[i].path)
|
|
|
|
- total_allocated;
|
2014-02-13 19:19:50 +00:00
|
|
|
|
2017-01-03 17:26:43 +00:00
|
|
|
table_printf(matrix, unallocated_col, vhdr_skip + i, ">%s",
|
|
|
|
pretty_size_mode(unused, unit_mode | UNITS_NEGATIVE));
|
2014-02-13 19:19:50 +00:00
|
|
|
total_unused += unused;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-11-03 00:09:50 +00:00
|
|
|
for (i = 0; i < spaceinfos_col; i++) {
|
|
|
|
table_printf(matrix, i, vhdr_skip - 1, "*-");
|
|
|
|
table_printf(matrix, i, vhdr_skip + device_info_count, "*-");
|
|
|
|
}
|
|
|
|
|
2015-11-02 23:08:32 +00:00
|
|
|
for (i = 0, col = spaceinfos_col; i < sargs->total_spaces; i++) {
|
2015-11-02 17:24:28 +00:00
|
|
|
if (sargs->spaces[i].flags & BTRFS_SPACE_INFO_GLOBAL_RSV)
|
|
|
|
continue;
|
|
|
|
|
2015-11-03 00:09:50 +00:00
|
|
|
table_printf(matrix, col, vhdr_skip - 1, "*-");
|
|
|
|
table_printf(matrix, col, vhdr_skip + device_info_count, "*-");
|
|
|
|
col++;
|
2015-11-02 17:24:28 +00:00
|
|
|
}
|
|
|
|
/* One for Unallocated */
|
2015-11-03 00:09:50 +00:00
|
|
|
table_printf(matrix, col, vhdr_skip - 1, "*-");
|
|
|
|
table_printf(matrix, col, vhdr_skip + device_info_count, "*-");
|
2014-02-13 19:19:50 +00:00
|
|
|
|
|
|
|
/* footer */
|
2015-11-02 23:19:41 +00:00
|
|
|
table_printf(matrix, 1, vhdr_skip + device_info_count + 1, "<Total");
|
2015-11-02 23:08:32 +00:00
|
|
|
for (i = 0, col = spaceinfos_col; i < sargs->total_spaces; i++) {
|
2015-11-02 17:24:28 +00:00
|
|
|
if (sargs->spaces[i].flags & BTRFS_SPACE_INFO_GLOBAL_RSV)
|
|
|
|
continue;
|
|
|
|
|
2015-11-02 17:54:48 +00:00
|
|
|
table_printf(matrix, col++, vhdr_skip + device_info_count + 1,
|
|
|
|
">%s",
|
2014-12-18 13:52:36 +00:00
|
|
|
pretty_size_mode(sargs->spaces[i].total_bytes, unit_mode));
|
2015-11-02 17:24:28 +00:00
|
|
|
}
|
2014-02-13 19:19:50 +00:00
|
|
|
|
2015-11-02 17:54:48 +00:00
|
|
|
table_printf(matrix, unallocated_col, vhdr_skip + device_info_count + 1,
|
2017-01-03 17:26:43 +00:00
|
|
|
">%s",
|
|
|
|
pretty_size_mode(total_unused, unit_mode | UNITS_NEGATIVE));
|
2014-02-13 19:19:50 +00:00
|
|
|
|
2015-11-02 23:19:41 +00:00
|
|
|
table_printf(matrix, 1, vhdr_skip + device_info_count + 2, "<Used");
|
2015-11-02 23:08:32 +00:00
|
|
|
for (i = 0, col = spaceinfos_col; i < sargs->total_spaces; i++) {
|
2015-11-02 17:24:28 +00:00
|
|
|
if (sargs->spaces[i].flags & BTRFS_SPACE_INFO_GLOBAL_RSV)
|
|
|
|
continue;
|
|
|
|
|
2015-11-02 17:54:48 +00:00
|
|
|
table_printf(matrix, col++, vhdr_skip + device_info_count + 2,
|
|
|
|
">%s",
|
2014-12-18 13:52:36 +00:00
|
|
|
pretty_size_mode(sargs->spaces[i].used_bytes, unit_mode));
|
2015-11-02 17:24:28 +00:00
|
|
|
}
|
2014-02-13 19:19:50 +00:00
|
|
|
|
|
|
|
table_dump(matrix);
|
|
|
|
table_free(matrix);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function prints the unused space per every disk
|
|
|
|
*/
|
|
|
|
static void print_unused(struct chunk_info *info_ptr,
|
|
|
|
int info_count,
|
2014-04-23 17:00:22 +00:00
|
|
|
struct device_info *device_info_ptr,
|
|
|
|
int device_info_count,
|
2014-12-18 13:52:36 +00:00
|
|
|
unsigned unit_mode)
|
2014-02-13 19:19:50 +00:00
|
|
|
{
|
|
|
|
int i;
|
2014-04-23 17:00:22 +00:00
|
|
|
for (i = 0; i < device_info_count; i++) {
|
2014-02-13 19:19:50 +00:00
|
|
|
int j;
|
|
|
|
u64 total = 0;
|
|
|
|
|
2014-04-23 17:00:22 +00:00
|
|
|
for (j = 0; j < info_count; j++)
|
|
|
|
if (info_ptr[j].devid == device_info_ptr[i].devid)
|
2014-02-13 19:19:50 +00:00
|
|
|
total += calc_chunk_size(info_ptr+j);
|
|
|
|
|
|
|
|
printf(" %s\t%10s\n",
|
2014-04-23 17:00:22 +00:00
|
|
|
device_info_ptr[i].path,
|
2014-12-18 13:52:36 +00:00
|
|
|
pretty_size_mode(device_info_ptr[i].size - total,
|
|
|
|
unit_mode));
|
2014-02-13 19:19:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function prints the allocated chunk per every disk
|
|
|
|
*/
|
2014-04-23 17:00:22 +00:00
|
|
|
static void print_chunk_device(u64 chunk_type,
|
2014-02-13 19:19:50 +00:00
|
|
|
struct chunk_info *chunks_info_ptr,
|
|
|
|
int chunks_info_count,
|
2014-04-23 17:00:22 +00:00
|
|
|
struct device_info *device_info_ptr,
|
|
|
|
int device_info_count,
|
2014-12-18 13:52:36 +00:00
|
|
|
unsigned unit_mode)
|
2014-02-13 19:19:50 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2014-04-23 17:00:22 +00:00
|
|
|
for (i = 0; i < device_info_count; i++) {
|
2014-02-13 19:19:50 +00:00
|
|
|
int j;
|
|
|
|
u64 total = 0;
|
|
|
|
|
2014-04-23 17:00:22 +00:00
|
|
|
for (j = 0; j < chunks_info_count; j++) {
|
2014-02-13 19:19:50 +00:00
|
|
|
|
|
|
|
if (chunks_info_ptr[j].type != chunk_type)
|
|
|
|
continue;
|
2014-04-23 17:00:22 +00:00
|
|
|
if (chunks_info_ptr[j].devid != device_info_ptr[i].devid)
|
2014-02-13 19:19:50 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
total += calc_chunk_size(&(chunks_info_ptr[j]));
|
|
|
|
//total += chunks_info_ptr[j].size;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (total > 0)
|
|
|
|
printf(" %s\t%10s\n",
|
2014-04-23 17:00:22 +00:00
|
|
|
device_info_ptr[i].path,
|
2014-12-18 13:52:36 +00:00
|
|
|
pretty_size_mode(total, unit_mode));
|
2014-02-13 19:19:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-04-23 16:47:52 +00:00
|
|
|
* This function print the results of the command "btrfs fi usage"
|
2014-02-13 19:19:50 +00:00
|
|
|
* in linear format
|
|
|
|
*/
|
2014-12-18 13:52:36 +00:00
|
|
|
static void _cmd_filesystem_usage_linear(unsigned unit_mode,
|
2014-02-13 19:19:50 +00:00
|
|
|
struct btrfs_ioctl_space_args *sargs,
|
|
|
|
struct chunk_info *info_ptr,
|
|
|
|
int info_count,
|
2014-04-23 17:00:22 +00:00
|
|
|
struct device_info *device_info_ptr,
|
|
|
|
int device_info_count)
|
2014-02-13 19:19:50 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < sargs->total_spaces; i++) {
|
|
|
|
const char *description;
|
|
|
|
const char *r_mode;
|
|
|
|
u64 flags = sargs->spaces[i].flags;
|
2014-04-29 15:32:22 +00:00
|
|
|
|
|
|
|
if (flags & BTRFS_SPACE_INFO_GLOBAL_RSV)
|
|
|
|
continue;
|
|
|
|
|
2014-02-13 19:19:50 +00:00
|
|
|
description = btrfs_group_type_str(flags);
|
|
|
|
r_mode = btrfs_group_profile_str(flags);
|
|
|
|
|
|
|
|
printf("%s,%s: Size:%s, ",
|
|
|
|
description,
|
|
|
|
r_mode,
|
2014-04-28 16:13:16 +00:00
|
|
|
pretty_size_mode(sargs->spaces[i].total_bytes,
|
2014-12-18 13:52:36 +00:00
|
|
|
unit_mode));
|
2014-02-13 19:19:50 +00:00
|
|
|
printf("Used:%s\n",
|
2014-12-18 13:52:36 +00:00
|
|
|
pretty_size_mode(sargs->spaces[i].used_bytes, unit_mode));
|
2014-04-23 17:00:22 +00:00
|
|
|
print_chunk_device(flags, info_ptr, info_count,
|
2014-12-18 13:52:36 +00:00
|
|
|
device_info_ptr, device_info_count, unit_mode);
|
2014-02-13 19:19:50 +00:00
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Unallocated:\n");
|
2014-04-23 17:00:22 +00:00
|
|
|
print_unused(info_ptr, info_count, device_info_ptr, device_info_count,
|
2017-01-03 17:26:43 +00:00
|
|
|
unit_mode | UNITS_NEGATIVE);
|
2014-02-13 19:19:50 +00:00
|
|
|
}
|
|
|
|
|
2014-04-25 17:39:11 +00:00
|
|
|
static int print_filesystem_usage_by_chunk(int fd,
|
|
|
|
struct chunk_info *chunkinfo, int chunkcount,
|
|
|
|
struct device_info *devinfo, int devcount,
|
2014-12-18 13:52:36 +00:00
|
|
|
char *path, unsigned unit_mode, int tabular)
|
2014-02-13 19:19:50 +00:00
|
|
|
{
|
2014-04-25 17:39:11 +00:00
|
|
|
struct btrfs_ioctl_space_args *sargs;
|
2014-02-13 19:19:50 +00:00
|
|
|
int ret = 0;
|
|
|
|
|
2014-04-25 17:39:11 +00:00
|
|
|
if (!chunkinfo)
|
|
|
|
return 0;
|
2014-02-13 19:19:50 +00:00
|
|
|
|
2014-04-25 17:39:11 +00:00
|
|
|
sargs = load_space_info(fd, path);
|
|
|
|
if (!sargs) {
|
|
|
|
ret = 1;
|
2014-04-28 16:55:05 +00:00
|
|
|
goto out;
|
2014-02-13 19:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (tabular)
|
2014-12-18 13:52:36 +00:00
|
|
|
_cmd_filesystem_usage_tabular(unit_mode, sargs, chunkinfo,
|
2014-04-25 17:39:11 +00:00
|
|
|
chunkcount, devinfo, devcount);
|
2014-02-13 19:19:50 +00:00
|
|
|
else
|
2014-12-18 13:52:36 +00:00
|
|
|
_cmd_filesystem_usage_linear(unit_mode, sargs, chunkinfo,
|
2014-04-25 17:39:11 +00:00
|
|
|
chunkcount, devinfo, devcount);
|
2014-02-13 19:19:50 +00:00
|
|
|
|
2014-04-25 17:39:11 +00:00
|
|
|
free(sargs);
|
2014-04-28 16:55:05 +00:00
|
|
|
out:
|
2014-02-13 19:19:50 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-04-23 16:47:52 +00:00
|
|
|
const char * const cmd_filesystem_usage_usage[] = {
|
2014-12-17 17:11:58 +00:00
|
|
|
"btrfs filesystem usage [options] <path> [<path>..]",
|
|
|
|
"Show detailed information about internal filesystem usage .",
|
2015-11-06 15:39:49 +00:00
|
|
|
HELPINFO_UNITS_SHORT_LONG,
|
2014-12-17 17:11:58 +00:00
|
|
|
"-T show data in tabular format",
|
2014-02-13 19:19:50 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2014-04-23 16:47:52 +00:00
|
|
|
int cmd_filesystem_usage(int argc, char **argv)
|
2014-02-13 19:19:50 +00:00
|
|
|
{
|
2014-04-28 16:55:05 +00:00
|
|
|
int ret = 0;
|
2015-09-01 07:12:06 +00:00
|
|
|
unsigned unit_mode;
|
|
|
|
int i;
|
|
|
|
int more_than_one = 0;
|
|
|
|
int tabular = 0;
|
|
|
|
|
|
|
|
unit_mode = get_unit_mode_from_arg(&argc, argv, 1);
|
2014-02-13 19:19:50 +00:00
|
|
|
|
|
|
|
while (1) {
|
2015-04-08 15:33:55 +00:00
|
|
|
int c;
|
2014-04-25 17:39:11 +00:00
|
|
|
|
2015-09-01 07:12:06 +00:00
|
|
|
c = getopt(argc, argv, "T");
|
2014-02-13 19:19:50 +00:00
|
|
|
if (c < 0)
|
|
|
|
break;
|
2015-09-01 07:12:06 +00:00
|
|
|
|
2014-02-13 19:19:50 +00:00
|
|
|
switch (c) {
|
2014-12-17 17:05:48 +00:00
|
|
|
case 'T':
|
2014-02-13 19:19:50 +00:00
|
|
|
tabular = 1;
|
|
|
|
break;
|
|
|
|
default:
|
2014-04-23 16:47:52 +00:00
|
|
|
usage(cmd_filesystem_usage_usage);
|
2014-02-13 19:19:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-06 03:36:46 +00:00
|
|
|
if (check_argc_min(argc - optind, 1))
|
2014-04-23 16:47:52 +00:00
|
|
|
usage(cmd_filesystem_usage_usage);
|
2014-02-13 19:19:50 +00:00
|
|
|
|
2014-04-25 17:39:11 +00:00
|
|
|
for (i = optind; i < argc; i++) {
|
|
|
|
int fd;
|
|
|
|
DIR *dirstream = NULL;
|
|
|
|
struct chunk_info *chunkinfo = NULL;
|
|
|
|
struct device_info *devinfo = NULL;
|
|
|
|
int chunkcount = 0;
|
|
|
|
int devcount = 0;
|
2014-02-13 19:19:50 +00:00
|
|
|
|
2015-10-12 13:22:55 +00:00
|
|
|
fd = btrfs_open_dir(argv[i], &dirstream, 1);
|
2014-02-13 19:19:50 +00:00
|
|
|
if (fd < 0) {
|
2014-04-28 16:55:05 +00:00
|
|
|
ret = 1;
|
|
|
|
goto out;
|
2014-02-13 19:19:50 +00:00
|
|
|
}
|
2014-04-25 15:24:40 +00:00
|
|
|
if (more_than_one)
|
|
|
|
printf("\n");
|
|
|
|
|
2014-04-25 17:39:11 +00:00
|
|
|
ret = load_chunk_and_device_info(fd, &chunkinfo, &chunkcount,
|
|
|
|
&devinfo, &devcount);
|
|
|
|
if (ret)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = print_filesystem_usage_overall(fd, chunkinfo, chunkcount,
|
2014-12-17 17:11:58 +00:00
|
|
|
devinfo, devcount, argv[i], unit_mode);
|
2014-04-25 17:39:11 +00:00
|
|
|
if (ret)
|
|
|
|
goto cleanup;
|
2014-04-25 15:24:40 +00:00
|
|
|
printf("\n");
|
2014-04-25 17:39:11 +00:00
|
|
|
ret = print_filesystem_usage_by_chunk(fd, chunkinfo, chunkcount,
|
2014-12-17 17:11:58 +00:00
|
|
|
devinfo, devcount, argv[i], unit_mode, tabular);
|
2014-04-25 17:39:11 +00:00
|
|
|
cleanup:
|
2014-02-13 19:19:50 +00:00
|
|
|
close_file_or_dir(fd, dirstream);
|
2014-04-25 17:39:11 +00:00
|
|
|
free(chunkinfo);
|
|
|
|
free(devinfo);
|
2014-02-13 19:19:50 +00:00
|
|
|
|
2014-04-25 17:39:11 +00:00
|
|
|
if (ret)
|
2014-04-28 16:55:05 +00:00
|
|
|
goto out;
|
2014-02-13 19:19:50 +00:00
|
|
|
more_than_one = 1;
|
|
|
|
}
|
|
|
|
|
2014-04-28 16:55:05 +00:00
|
|
|
out:
|
|
|
|
return !!ret;
|
2014-02-13 19:19:50 +00:00
|
|
|
}
|
2014-02-13 19:20:12 +00:00
|
|
|
|
2017-02-09 16:42:02 +00:00
|
|
|
void print_device_chunks(struct device_info *devinfo,
|
2014-04-23 17:00:22 +00:00
|
|
|
struct chunk_info *chunks_info_ptr,
|
2014-12-18 13:52:36 +00:00
|
|
|
int chunks_info_count, unsigned unit_mode)
|
2014-02-13 19:20:12 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
u64 allocated = 0;
|
|
|
|
|
|
|
|
for (i = 0 ; i < chunks_info_count ; i++) {
|
|
|
|
const char *description;
|
|
|
|
const char *r_mode;
|
|
|
|
u64 flags;
|
|
|
|
u64 size;
|
|
|
|
|
2014-04-24 16:57:12 +00:00
|
|
|
if (chunks_info_ptr[i].devid != devinfo->devid)
|
2014-02-13 19:20:12 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
flags = chunks_info_ptr[i].type;
|
|
|
|
|
|
|
|
description = btrfs_group_type_str(flags);
|
|
|
|
r_mode = btrfs_group_profile_str(flags);
|
|
|
|
size = calc_chunk_size(chunks_info_ptr+i);
|
|
|
|
printf(" %s,%s:%*s%10s\n",
|
|
|
|
description,
|
|
|
|
r_mode,
|
|
|
|
(int)(20 - strlen(description) - strlen(r_mode)), "",
|
2014-12-18 13:52:36 +00:00
|
|
|
pretty_size_mode(size, unit_mode));
|
2014-02-13 19:20:12 +00:00
|
|
|
|
|
|
|
allocated += size;
|
|
|
|
|
|
|
|
}
|
|
|
|
printf(" Unallocated: %*s%10s\n",
|
|
|
|
(int)(20 - strlen("Unallocated")), "",
|
2017-01-03 17:26:43 +00:00
|
|
|
pretty_size_mode(devinfo->size - allocated,
|
|
|
|
unit_mode | UNITS_NEGATIVE));
|
2014-04-24 16:32:27 +00:00
|
|
|
}
|
2014-02-13 19:20:12 +00:00
|
|
|
|
2017-02-09 16:42:02 +00:00
|
|
|
void print_device_sizes(struct device_info *devinfo, unsigned unit_mode)
|
2014-04-24 16:32:27 +00:00
|
|
|
{
|
|
|
|
printf(" Device size: %*s%10s\n",
|
|
|
|
(int)(20 - strlen("Device size")), "",
|
2014-12-18 13:52:36 +00:00
|
|
|
pretty_size_mode(devinfo->device_size, unit_mode));
|
2016-05-17 14:21:00 +00:00
|
|
|
printf(" Device slack: %*s%10s\n",
|
|
|
|
(int)(20 - strlen("Device slack")), "",
|
|
|
|
pretty_size_mode(devinfo->device_size - devinfo->size,
|
|
|
|
unit_mode));
|
2014-02-13 19:20:12 +00:00
|
|
|
}
|