btrfs-progs: scrub status: add unit mode options

Add long options for size units, affecting total and currently scrubbed
bytes. The rate depends on the device speed and could be
disproportionate to the size so it is not affected, except the --raw
option that is in bytes without unit suffix.

Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2020-11-04 22:25:15 +01:00
parent d9e9198485
commit d60d48fce5
2 changed files with 43 additions and 9 deletions

View File

@ -101,6 +101,22 @@ for that filesystem or device.
+ +
-d:::: -d::::
print separate statistics for each device of the filesystem print separate statistics for each device of the filesystem
--raw::::
print all numbers raw values in bytes without the 'B' suffix
--human-readable::::
print human friendly numbers, base 1024, this is the default
--iec::::
select the 1024 base for the following options, according to the IEC standard
--si::::
select the 1000 base for the following options, according to the SI standard
-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
EXIT STATUS EXIT STATUS
----------- -----------

View File

@ -46,6 +46,8 @@
#include "cmds/commands.h" #include "cmds/commands.h"
#include "common/help.h" #include "common/help.h"
static unsigned unit_mode = UNITS_DEFAULT;
static const char * const scrub_cmd_group_usage[] = { static const char * const scrub_cmd_group_usage[] = {
"btrfs scrub <command> [options] <path>|<device>", "btrfs scrub <command> [options] <path>|<device>",
NULL NULL
@ -134,7 +136,8 @@ static void print_scrub_full(struct btrfs_scrub_progress *sp)
printf(" %s=%llu", desc, test); \ printf(" %s=%llu", desc, test); \
} while (0) } while (0)
static void print_scrub_summary(struct btrfs_scrub_progress *p, struct scrub_stats *s, u64 bytes_total) static void print_scrub_summary(struct btrfs_scrub_progress *p, struct scrub_stats *s,
u64 bytes_total)
{ {
u64 err_cnt; u64 err_cnt;
u64 err_cnt2; u64 err_cnt2;
@ -173,14 +176,25 @@ static void print_scrub_summary(struct btrfs_scrub_progress *p, struct scrub_sta
printf("Time left: %llu:%02llu:%02llu\n", printf("Time left: %llu:%02llu:%02llu\n",
sec_left / 3600, (sec_left / 60) % 60, sec_left % 60); sec_left / 3600, (sec_left / 60) % 60, sec_left % 60);
printf("ETA: %s\n", t); printf("ETA: %s\n", t);
printf("Total to scrub: %s\n", pretty_size(bytes_total)); printf("Total to scrub: %s\n",
pretty_size_mode(bytes_total, unit_mode));
printf("Bytes scrubbed: %s (%.2f%%)\n", printf("Bytes scrubbed: %s (%.2f%%)\n",
pretty_size(bytes_scrubbed), pretty_size_mode(bytes_scrubbed, unit_mode),
100.0 * bytes_scrubbed / bytes_total); 100.0 * bytes_scrubbed / bytes_total);
printf("Rate: %s/s\n", pretty_size(bytes_per_sec));
} else { } else {
printf("Total to scrub: %s\n", pretty_size(bytes_total)); printf("Total to scrub: %s\n",
printf("Rate: %s/s\n", pretty_size(bytes_per_sec)); pretty_size_mode(bytes_total, unit_mode));
}
/*
* Rate and size units are disproportionate so they are affected only
* by --raw, otherwise it's human readable
*/
if (unit_mode == UNITS_RAW) {
printf("Rate: %s/s\n",
pretty_size_mode(bytes_per_sec, UNITS_RAW));
} else {
printf("Rate: %s/s\n",
pretty_size(bytes_per_sec));
} }
printf("Error summary: "); printf("Error summary: ");
@ -1701,8 +1715,9 @@ static const char * const cmd_scrub_status_usage[] = {
"btrfs scrub status [-dR] <path>|<device>", "btrfs scrub status [-dR] <path>|<device>",
"Show status of running or finished scrub", "Show status of running or finished scrub",
"", "",
"-d stats per device", "-d stats per device",
"-R print raw stats", "-R print raw stats",
HELPINFO_UNITS_LONG,
NULL NULL
}; };
@ -1730,6 +1745,9 @@ static int cmd_scrub_status(const struct cmd_struct *cmd, int argc, char **argv)
int err = 0; int err = 0;
DIR *dirstream = NULL; DIR *dirstream = NULL;
unit_mode = get_unit_mode_from_arg(&argc, argv, 1);
optind = 0;
while ((c = getopt(argc, argv, "dR")) != -1) { while ((c = getopt(argc, argv, "dR")) != -1) {
switch (c) { switch (c) {
case 'd': case 'd':