Skip to content

Commit

Permalink
Avoid divide by zero when there is no block device to migrate
Browse files Browse the repository at this point in the history
When block migration is requested and no read-write block device is
present, a divide by zero exception is triggered because
total_sector_sum equals zero.

Signed-off-by: Pierre Riteau <Pierre.Riteau@irisa.fr>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
  • Loading branch information
priteau authored and kevmw committed Jan 24, 2011
1 parent 70b4f4b commit 8b6b2af
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion block-migration.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,12 @@ static int blk_mig_save_bulked_block(Monitor *mon, QEMUFile *f)
}
}

progress = completed_sector_sum * 100 / block_mig_state.total_sector_sum;
if (block_mig_state.total_sector_sum != 0) {
progress = completed_sector_sum * 100 /
block_mig_state.total_sector_sum;
} else {
progress = 100;
}
if (progress != block_mig_state.prev_progress) {
block_mig_state.prev_progress = progress;
qemu_put_be64(f, (progress << BDRV_SECTOR_BITS)
Expand Down

0 comments on commit 8b6b2af

Please sign in to comment.