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:
parent
d9e9198485
commit
d60d48fce5
|
@ -101,6 +101,22 @@ for that filesystem or device.
|
|||
+
|
||||
-d::::
|
||||
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
|
||||
-----------
|
||||
|
|
30
cmds/scrub.c
30
cmds/scrub.c
|
@ -46,6 +46,8 @@
|
|||
#include "cmds/commands.h"
|
||||
#include "common/help.h"
|
||||
|
||||
static unsigned unit_mode = UNITS_DEFAULT;
|
||||
|
||||
static const char * const scrub_cmd_group_usage[] = {
|
||||
"btrfs scrub <command> [options] <path>|<device>",
|
||||
NULL
|
||||
|
@ -134,7 +136,8 @@ static void print_scrub_full(struct btrfs_scrub_progress *sp)
|
|||
printf(" %s=%llu", desc, test); \
|
||||
} 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_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",
|
||||
sec_left / 3600, (sec_left / 60) % 60, sec_left % 60);
|
||||
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",
|
||||
pretty_size(bytes_scrubbed),
|
||||
pretty_size_mode(bytes_scrubbed, unit_mode),
|
||||
100.0 * bytes_scrubbed / bytes_total);
|
||||
printf("Rate: %s/s\n", pretty_size(bytes_per_sec));
|
||||
} else {
|
||||
printf("Total to scrub: %s\n", pretty_size(bytes_total));
|
||||
printf("Rate: %s/s\n", pretty_size(bytes_per_sec));
|
||||
printf("Total to scrub: %s\n",
|
||||
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: ");
|
||||
|
@ -1703,6 +1717,7 @@ static const char * const cmd_scrub_status_usage[] = {
|
|||
"",
|
||||
"-d stats per device",
|
||||
"-R print raw stats",
|
||||
HELPINFO_UNITS_LONG,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
@ -1730,6 +1745,9 @@ static int cmd_scrub_status(const struct cmd_struct *cmd, int argc, char **argv)
|
|||
int err = 0;
|
||||
DIR *dirstream = NULL;
|
||||
|
||||
unit_mode = get_unit_mode_from_arg(&argc, argv, 1);
|
||||
|
||||
optind = 0;
|
||||
while ((c = getopt(argc, argv, "dR")) != -1) {
|
||||
switch (c) {
|
||||
case 'd':
|
||||
|
|
Loading…
Reference in New Issue