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 <behlendorf1@llnl.gov> Signed-off-by: Teodor Spæren <teodor@sparen.no> Closes #10666 Closes #12610
This commit is contained in:
parent
afbc617921
commit
01b572bc62
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user