aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeodor Spæren <[email protected]>2021-10-16 00:55:34 +0200
committerGitHub <[email protected]>2021-10-15 15:55:34 -0700
commit01b572bc623cec3f7ff4f6ffb2dbf47d28ee7559 (patch)
tree34fabe35fa8e17e9ebe7b0d87ea7defd0f76fa8e
parentafbc61792116c9599afcccfd61204f968401d06e (diff)
zdb: fix overflow of time estimation
The calculation of estimated time remaining in zdb -cc could overflow, as reported in #10666. This patch fixes this, by using uint64_t instead of ints in the calculations. Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Teodor Spæren <[email protected]> Closes #10666 Closes #12610
-rw-r--r--cmd/zdb/zdb.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/cmd/zdb/zdb.c b/cmd/zdb/zdb.c
index 797cac087..81b9604f3 100644
--- a/cmd/zdb/zdb.c
+++ b/cmd/zdb/zdb.c
@@ -5469,9 +5469,9 @@ zdb_blkptr_cb(spa_t *spa, zilog_t *zilog, const blkptr_t *bp,
uint64_t now = gethrtime();
char buf[10];
uint64_t bytes = zcb->zcb_type[ZB_TOTAL][ZDB_OT_TOTAL].zb_asize;
- int kb_per_sec =
+ uint64_t kb_per_sec =
1 + bytes / (1 + ((now - zcb->zcb_start) / 1000 / 1000));
- int sec_remaining =
+ uint64_t sec_remaining =
(zcb->zcb_totalasize - bytes) / 1024 / kb_per_sec;
/* make sure nicenum has enough space */
@@ -5479,8 +5479,9 @@ zdb_blkptr_cb(spa_t *spa, zilog_t *zilog, const blkptr_t *bp,
zfs_nicebytes(bytes, buf, sizeof (buf));
(void) fprintf(stderr,
- "\r%5s completed (%4dMB/s) "
- "estimated time remaining: %uhr %02umin %02usec ",
+ "\r%5s completed (%4"PRIu64"MB/s) "
+ "estimated time remaining: "
+ "%"PRIu64"hr %02"PRIu64"min %02"PRIu64"sec ",
buf, kb_per_sec / 1024,
sec_remaining / 60 / 60,
sec_remaining / 60 % 60,