* [PATCH 2/6] btrfs-progs: fi usage, add switches to set output units
2014-12-18 14:27 [PATCH 0/6] Btrfs-progs, add units to 'usage' subcommands David Sterba
2014-12-18 14:27 ` [PATCH 1/6] btrfs-progs: fi usage, change option for tabular output to T David Sterba
@ 2014-12-18 14:27 ` David Sterba
2014-12-18 14:27 ` [PATCH 3/6] btrfs-progs: fi usage, update manpage David Sterba
` (3 subsequent siblings)
5 siblings, 0 replies; 11+ messages in thread
From: David Sterba @ 2014-12-18 14:27 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
Same set of options as 'fi df': binary and decimal bases, human readable
options etc.
Signed-off-by: David Sterba <dsterba@suse.cz>
---
cmds-fi-disk_usage.c | 64 +++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 53 insertions(+), 11 deletions(-)
diff --git a/cmds-fi-disk_usage.c b/cmds-fi-disk_usage.c
index 77ab8b4c1604..b3b70cc23fd1 100644
--- a/cmds-fi-disk_usage.c
+++ b/cmds-fi-disk_usage.c
@@ -21,6 +21,7 @@
#include <sys/ioctl.h>
#include <errno.h>
#include <stdarg.h>
+#include <getopt.h>
#include "utils.h"
#include "kerncompat.h"
@@ -844,31 +845,72 @@ out:
}
const char * const cmd_filesystem_usage_usage[] = {
- "btrfs filesystem usage [-b][-t] <path> [<path>..]",
- "Show in which disk the chunks are allocated.",
- "",
- "-b\tSet byte as unit",
- "-T\tShow data in tabular format",
+ "btrfs filesystem usage [options] <path> [<path>..]",
+ "Show detailed information about internal filesystem usage .",
+ "-b|--raw raw numbers in bytes",
+ "-h human friendly numbers, base 1024 (default)",
+ "-H human friendly numbers, base 1000",
+ "--iec use 1024 as a base (KiB, MiB, GiB, TiB)",
+ "--si use 1000 as a base (kB, MB, GB, TB)",
+ "-k|--kbytes show sizes in KiB, or kB with --si",
+ "-m|--mbytes show sizes in MiB, or MB with --si",
+ "-g|--gbytes show sizes in GiB, or GB with --si",
+ "-t|--tbytes show sizes in TiB, or TB with --si",
+ "-T show data in tabular format",
NULL
};
int cmd_filesystem_usage(int argc, char **argv)
{
- int mode = UNITS_HUMAN;
+ unsigned unit_mode = UNITS_DEFAULT;
int ret = 0;
int i, more_than_one = 0;
int tabular = 0;
optind = 1;
while (1) {
- int c = getopt(argc, argv, "bT");
+ int long_index;
+ static const struct option long_options[] = {
+ { "raw", no_argument, NULL, 'b'},
+ { "kbytes", no_argument, NULL, 'k'},
+ { "mbytes", no_argument, NULL, 'm'},
+ { "gbytes", no_argument, NULL, 'g'},
+ { "tbytes", no_argument, NULL, 't'},
+ { "si", no_argument, NULL, 256},
+ { "iec", no_argument, NULL, 257},
+ };
+ int c = getopt_long(argc, argv, "bhHkmgtT", long_options,
+ &long_index);
if (c < 0)
break;
-
switch (c) {
case 'b':
- mode = UNITS_RAW;
+ unit_mode = UNITS_RAW;
+ break;
+ case 'k':
+ units_set_base(&unit_mode, UNITS_KBYTES);
+ break;
+ case 'm':
+ units_set_base(&unit_mode, UNITS_MBYTES);
+ break;
+ case 'g':
+ units_set_base(&unit_mode, UNITS_GBYTES);
+ break;
+ case 't':
+ units_set_base(&unit_mode, UNITS_TBYTES);
+ break;
+ case 'h':
+ unit_mode = UNITS_HUMAN_BINARY;
+ break;
+ case 'H':
+ unit_mode = UNITS_HUMAN_DECIMAL;
+ break;
+ case 256:
+ units_set_mode(&unit_mode, UNITS_DECIMAL);
+ break;
+ case 257:
+ units_set_mode(&unit_mode, UNITS_BINARY);
break;
case 'T':
tabular = 1;
@@ -905,12 +947,12 @@ int cmd_filesystem_usage(int argc, char **argv)
goto cleanup;
ret = print_filesystem_usage_overall(fd, chunkinfo, chunkcount,
- devinfo, devcount, argv[i], mode);
+ devinfo, devcount, argv[i], unit_mode);
if (ret)
goto cleanup;
printf("\n");
ret = print_filesystem_usage_by_chunk(fd, chunkinfo, chunkcount,
- devinfo, devcount, argv[i], mode, tabular);
+ devinfo, devcount, argv[i], unit_mode, tabular);
cleanup:
close_file_or_dir(fd, dirstream);
free(chunkinfo);
--
2.1.3
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 4/6] btrfs-progs: dev usage, add switches to set output units
2014-12-18 14:27 [PATCH 0/6] Btrfs-progs, add units to 'usage' subcommands David Sterba
` (2 preceding siblings ...)
2014-12-18 14:27 ` [PATCH 3/6] btrfs-progs: fi usage, update manpage David Sterba
@ 2014-12-18 14:27 ` David Sterba
2014-12-18 14:27 ` [PATCH 5/6] btrfs-progs: dev usage, update manpage David Sterba
2014-12-18 14:28 ` [PATCH 6/6] btrfs-progs: unify unit mode parameters and variables David Sterba
5 siblings, 0 replies; 11+ messages in thread
From: David Sterba @ 2014-12-18 14:27 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
Same set of options as 'fi df': binary and decimal bases, human readable
options etc.
Signed-off-by: David Sterba <dsterba@suse.cz>
---
cmds-device.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++----------
1 file changed, 50 insertions(+), 10 deletions(-)
diff --git a/cmds-device.c b/cmds-device.c
index 33f1311a546c..13458d850c26 100644
--- a/cmds-device.c
+++ b/cmds-device.c
@@ -451,10 +451,17 @@ out:
}
const char * const cmd_device_usage_usage[] = {
- "btrfs device usage [-b] <path> [<path>..]",
- "Show which chunks are in a device.",
- "",
- "-b\tSet byte as unit",
+ "btrfs device usage [options] <path> [<path>..]",
+ "Show detailed information about internal allocations in devices.",
+ "-b|--raw raw numbers in bytes",
+ "-h human friendly numbers, base 1024 (default)",
+ "-H human friendly numbers, base 1000",
+ "--iec use 1024 as a base (KiB, MiB, GiB, TiB)",
+ "--si use 1000 as a base (kB, MB, GB, TB)",
+ "-k|--kbytes show sizes in KiB, or kB with --si",
+ "-m|--mbytes show sizes in MiB, or MB with --si",
+ "-g|--gbytes show sizes in GiB, or GB with --si",
+ "-t|--tbytes show sizes in TiB, or TB with --si",
NULL
};
@@ -489,21 +496,54 @@ out:
int cmd_device_usage(int argc, char **argv)
{
-
- int mode = UNITS_HUMAN;
+ unsigned unit_mode = UNITS_DEFAULT;
int ret = 0;
int i, more_than_one = 0;
optind = 1;
while (1) {
- int c = getopt(argc, argv, "b");
+ int long_index;
+ static const struct option long_options[] = {
+ { "raw", no_argument, NULL, 'b'},
+ { "kbytes", no_argument, NULL, 'k'},
+ { "mbytes", no_argument, NULL, 'm'},
+ { "gbytes", no_argument, NULL, 'g'},
+ { "tbytes", no_argument, NULL, 't'},
+ { "si", no_argument, NULL, 256},
+ { "iec", no_argument, NULL, 257},
+ };
+ int c = getopt_long(argc, argv, "bhHkmgt", long_options,
+ &long_index);
if (c < 0)
break;
-
switch (c) {
case 'b':
- mode = UNITS_RAW;
+ unit_mode = UNITS_RAW;
+ break;
+ case 'k':
+ units_set_base(&unit_mode, UNITS_KBYTES);
+ break;
+ case 'm':
+ units_set_base(&unit_mode, UNITS_MBYTES);
+ break;
+ case 'g':
+ units_set_base(&unit_mode, UNITS_GBYTES);
+ break;
+ case 't':
+ units_set_base(&unit_mode, UNITS_TBYTES);
+ break;
+ case 'h':
+ unit_mode = UNITS_HUMAN_BINARY;
+ break;
+ case 'H':
+ unit_mode = UNITS_HUMAN_DECIMAL;
+ break;
+ case 256:
+ units_set_mode(&unit_mode, UNITS_DECIMAL);
+ break;
+ case 257:
+ units_set_mode(&unit_mode, UNITS_BINARY);
break;
default:
usage(cmd_device_usage_usage);
@@ -527,7 +567,7 @@ int cmd_device_usage(int argc, char **argv)
goto out;
}
- ret = _cmd_device_usage(fd, argv[i], mode);
+ ret = _cmd_device_usage(fd, argv[i], unit_mode);
close_file_or_dir(fd, dirstream);
if (ret)
--
2.1.3
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 6/6] btrfs-progs: unify unit mode parameters and variables
2014-12-18 14:27 [PATCH 0/6] Btrfs-progs, add units to 'usage' subcommands David Sterba
` (4 preceding siblings ...)
2014-12-18 14:27 ` [PATCH 5/6] btrfs-progs: dev usage, update manpage David Sterba
@ 2014-12-18 14:28 ` David Sterba
5 siblings, 0 replies; 11+ messages in thread
From: David Sterba @ 2014-12-18 14:28 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
Use unsigned type and a common name everywhere.
Signed-off-by: David Sterba <dsterba@suse.cz>
---
cmds-device.c | 6 ++---
cmds-fi-disk_usage.c | 69 ++++++++++++++++++++++++++--------------------------
cmds-fi-disk_usage.h | 4 +--
3 files changed, 40 insertions(+), 39 deletions(-)
diff --git a/cmds-device.c b/cmds-device.c
index 13458d850c26..9dd52a4b9fac 100644
--- a/cmds-device.c
+++ b/cmds-device.c
@@ -465,7 +465,7 @@ const char * const cmd_device_usage_usage[] = {
NULL
};
-static int _cmd_device_usage(int fd, char *path, int mode)
+static int _cmd_device_usage(int fd, char *path, unsigned unit_mode)
{
int i;
int ret = 0;
@@ -481,9 +481,9 @@ static int _cmd_device_usage(int fd, char *path, int mode)
for (i = 0; i < devcount; i++) {
printf("%s, ID: %llu\n", devinfo[i].path, devinfo[i].devid);
- print_device_sizes(fd, &devinfo[i], mode);
+ print_device_sizes(fd, &devinfo[i], unit_mode);
print_device_chunks(fd, &devinfo[i], chunkinfo, chunkcount,
- mode);
+ unit_mode);
printf("\n");
}
diff --git a/cmds-fi-disk_usage.c b/cmds-fi-disk_usage.c
index b3b70cc23fd1..d81f01155e6c 100644
--- a/cmds-fi-disk_usage.c
+++ b/cmds-fi-disk_usage.c
@@ -310,7 +310,7 @@ static void get_raid56_used(int fd, struct chunk_info *chunks, int chunkcount,
#define MIN_UNALOCATED_THRESH (16 * 1024 * 1024)
static int print_filesystem_usage_overall(int fd, struct chunk_info *chunkinfo,
int chunkcount, struct device_info *devinfo, int devcount,
- char *path, int mode)
+ char *path, unsigned unit_mode)
{
struct btrfs_ioctl_space_args *sargs = 0;
int i;
@@ -450,30 +450,30 @@ static int print_filesystem_usage_overall(int fd, struct chunk_info *chunkinfo,
free_min += r_total_unused / max_data_ratio;
}
- if (mode != UNITS_HUMAN)
+ if (unit_mode != UNITS_HUMAN)
width = 18;
printf("Overall:\n");
printf(" Device size:\t\t%*s\n", width,
- pretty_size_mode(r_total_size, mode));
+ pretty_size_mode(r_total_size, unit_mode));
printf(" Device allocated:\t\t%*s\n", width,
- pretty_size_mode(r_total_chunks, mode));
+ pretty_size_mode(r_total_chunks, unit_mode));
printf(" Device unallocated:\t\t%*s\n", width,
- pretty_size_mode(r_total_unused, mode));
+ pretty_size_mode(r_total_unused, unit_mode));
printf(" Used:\t\t\t%*s\n", width,
- pretty_size_mode(r_total_used, mode));
+ pretty_size_mode(r_total_used, unit_mode));
printf(" Free (estimated):\t\t%*s\t(",
width,
- pretty_size_mode(free_estimated, mode));
- printf("min: %s)\n", pretty_size_mode(free_min, mode));
+ pretty_size_mode(free_estimated, unit_mode));
+ printf("min: %s)\n", pretty_size_mode(free_min, unit_mode));
printf(" Data ratio:\t\t\t%*.2f\n",
width, data_ratio);
printf(" Metadata ratio:\t\t%*.2f\n",
width, metadata_ratio);
printf(" Global reserve:\t\t%*s\t(used: %s)\n", width,
- pretty_size_mode(l_global_reserve, mode),
- pretty_size_mode(l_global_reserve_used, mode));
+ pretty_size_mode(l_global_reserve, unit_mode),
+ pretty_size_mode(l_global_reserve_used, unit_mode));
exit:
@@ -601,7 +601,7 @@ static u64 calc_chunk_size(struct chunk_info *ci)
* This function print the results of the command "btrfs fi usage"
* in tabular format
*/
-static void _cmd_filesystem_usage_tabular(int mode,
+static void _cmd_filesystem_usage_tabular(unsigned unit_mode,
struct btrfs_ioctl_space_args *sargs,
struct chunk_info *chunks_info_ptr,
int chunks_info_count,
@@ -678,7 +678,7 @@ static void _cmd_filesystem_usage_tabular(int mode,
if (size)
table_printf(matrix, col, i+3,
- ">%s", pretty_size_mode(size, mode));
+ ">%s", pretty_size_mode(size, unit_mode));
else
table_printf(matrix, col, i+3, ">-");
@@ -690,7 +690,7 @@ static void _cmd_filesystem_usage_tabular(int mode,
- total_allocated;
table_printf(matrix, sargs->total_spaces + 1, i + 3,
- ">%s", pretty_size_mode(unused, mode));
+ ">%s", pretty_size_mode(unused, unit_mode));
total_unused += unused;
}
@@ -702,15 +702,15 @@ static void _cmd_filesystem_usage_tabular(int mode,
table_printf(matrix, 0, device_info_count + 4, "<Total");
for (i = 0; i < sargs->total_spaces; i++)
table_printf(matrix, 1 + i, device_info_count + 4, ">%s",
- pretty_size_mode(sargs->spaces[i].total_bytes, mode));
+ pretty_size_mode(sargs->spaces[i].total_bytes, unit_mode));
table_printf(matrix, sargs->total_spaces + 1, device_info_count + 4,
- ">%s", pretty_size_mode(total_unused, mode));
+ ">%s", pretty_size_mode(total_unused, unit_mode));
table_printf(matrix, 0, device_info_count + 5, "<Used");
for (i = 0; i < sargs->total_spaces; i++)
table_printf(matrix, 1 + i, device_info_count+5, ">%s",
- pretty_size_mode(sargs->spaces[i].used_bytes, mode));
+ pretty_size_mode(sargs->spaces[i].used_bytes, unit_mode));
table_dump(matrix);
table_free(matrix);
@@ -723,7 +723,7 @@ static void print_unused(struct chunk_info *info_ptr,
int info_count,
struct device_info *device_info_ptr,
int device_info_count,
- int mode)
+ unsigned unit_mode)
{
int i;
for (i = 0; i < device_info_count; i++) {
@@ -736,7 +736,8 @@ static void print_unused(struct chunk_info *info_ptr,
printf(" %s\t%10s\n",
device_info_ptr[i].path,
- pretty_size_mode(device_info_ptr[i].size - total, mode));
+ pretty_size_mode(device_info_ptr[i].size - total,
+ unit_mode));
}
}
@@ -748,7 +749,7 @@ static void print_chunk_device(u64 chunk_type,
int chunks_info_count,
struct device_info *device_info_ptr,
int device_info_count,
- int mode)
+ unsigned unit_mode)
{
int i;
@@ -770,7 +771,7 @@ static void print_chunk_device(u64 chunk_type,
if (total > 0)
printf(" %s\t%10s\n",
device_info_ptr[i].path,
- pretty_size_mode(total, mode));
+ pretty_size_mode(total, unit_mode));
}
}
@@ -778,7 +779,7 @@ static void print_chunk_device(u64 chunk_type,
* This function print the results of the command "btrfs fi usage"
* in linear format
*/
-static void _cmd_filesystem_usage_linear(int mode,
+static void _cmd_filesystem_usage_linear(unsigned unit_mode,
struct btrfs_ioctl_space_args *sargs,
struct chunk_info *info_ptr,
int info_count,
@@ -802,23 +803,23 @@ static void _cmd_filesystem_usage_linear(int mode,
description,
r_mode,
pretty_size_mode(sargs->spaces[i].total_bytes,
- mode));
+ unit_mode));
printf("Used:%s\n",
- pretty_size_mode(sargs->spaces[i].used_bytes, mode));
+ pretty_size_mode(sargs->spaces[i].used_bytes, unit_mode));
print_chunk_device(flags, info_ptr, info_count,
- device_info_ptr, device_info_count, mode);
+ device_info_ptr, device_info_count, unit_mode);
printf("\n");
}
printf("Unallocated:\n");
print_unused(info_ptr, info_count, device_info_ptr, device_info_count,
- mode);
+ unit_mode);
}
static int print_filesystem_usage_by_chunk(int fd,
struct chunk_info *chunkinfo, int chunkcount,
struct device_info *devinfo, int devcount,
- char *path, int mode, int tabular)
+ char *path, unsigned unit_mode, int tabular)
{
struct btrfs_ioctl_space_args *sargs;
int ret = 0;
@@ -833,10 +834,10 @@ static int print_filesystem_usage_by_chunk(int fd,
}
if (tabular)
- _cmd_filesystem_usage_tabular(mode, sargs, chunkinfo,
+ _cmd_filesystem_usage_tabular(unit_mode, sargs, chunkinfo,
chunkcount, devinfo, devcount);
else
- _cmd_filesystem_usage_linear(mode, sargs, chunkinfo,
+ _cmd_filesystem_usage_linear(unit_mode, sargs, chunkinfo,
chunkcount, devinfo, devcount);
free(sargs);
@@ -969,7 +970,7 @@ out:
void print_device_chunks(int fd, struct device_info *devinfo,
struct chunk_info *chunks_info_ptr,
- int chunks_info_count, int mode)
+ int chunks_info_count, unsigned unit_mode)
{
int i;
u64 allocated = 0;
@@ -992,21 +993,21 @@ void print_device_chunks(int fd, struct device_info *devinfo,
description,
r_mode,
(int)(20 - strlen(description) - strlen(r_mode)), "",
- pretty_size_mode(size, mode));
+ pretty_size_mode(size, unit_mode));
allocated += size;
}
printf(" Unallocated: %*s%10s\n",
(int)(20 - strlen("Unallocated")), "",
- pretty_size_mode(devinfo->size - allocated, mode));
+ pretty_size_mode(devinfo->size - allocated, unit_mode));
}
-void print_device_sizes(int fd, struct device_info *devinfo, int mode)
+void print_device_sizes(int fd, struct device_info *devinfo, unsigned unit_mode)
{
printf(" Device size: %*s%10s\n",
(int)(20 - strlen("Device size")), "",
- pretty_size_mode(devinfo->device_size, mode));
+ pretty_size_mode(devinfo->device_size, unit_mode));
#if 0
/*
* The term has not seen an agreement and we don't want to change it
@@ -1014,6 +1015,6 @@ void print_device_sizes(int fd, struct device_info *devinfo, int mode)
*/
printf(" FS occupied: %*s%10s\n",
(int)(20 - strlen("FS occupied")), "",
- pretty_size_mode(devinfo->size, mode));
+ pretty_size_mode(devinfo->size, unit_mode));
#endif
}
diff --git a/cmds-fi-disk_usage.h b/cmds-fi-disk_usage.h
index 8a0c60f011e4..a76e77bf8c31 100644
--- a/cmds-fi-disk_usage.h
+++ b/cmds-fi-disk_usage.h
@@ -48,7 +48,7 @@ int load_chunk_and_device_info(int fd, struct chunk_info **chunkinfo,
int *chunkcount, struct device_info **devinfo, int *devcount);
void print_device_chunks(int fd, struct device_info *devinfo,
struct chunk_info *chunks_info_ptr,
- int chunks_info_count, int mode);
-void print_device_sizes(int fd, struct device_info *devinfo, int mode);
+ int chunks_info_count, unsigned unit_mode);
+void print_device_sizes(int fd, struct device_info *devinfo, unsigned unit_mode);
#endif
--
2.1.3
^ permalink raw reply related [flat|nested] 11+ messages in thread